gridfs: add pymongo to test-requirements and update tests
pymongo is an optional requirement for glance_store if you're not using the gridfs backend, but for tests we should have it in test-requirements.txt with other optional backend dependencies like boto for s3 and oslo.vmware for the vmware backend. This adds pymongo to test-requirements.txt and removes the conditional imports and skips in the gridfs tests. Change-Id: I9332fc5b27e35ed6194eedf5ccd1586c3ba9096e
This commit is contained in:
parent
84562f3578
commit
dc378a77ab
@ -31,3 +31,6 @@ oslo.vmware>=0.4 # Apache-2.0
|
||||
# Swift Backend
|
||||
httplib2>=0.7.5
|
||||
python-swiftclient>=2.0.2
|
||||
|
||||
# GridFS backend
|
||||
pymongo>=2.6.3
|
||||
|
@ -15,18 +15,14 @@
|
||||
|
||||
import StringIO
|
||||
|
||||
import gridfs
|
||||
import mock
|
||||
import pymongo
|
||||
|
||||
from glance_store._drivers import gridfs as gfs
|
||||
from glance_store.tests import base
|
||||
from tests.unit import test_store_capabilities
|
||||
|
||||
try:
|
||||
import gridfs
|
||||
import pymongo
|
||||
except ImportError:
|
||||
pymongo = None
|
||||
|
||||
|
||||
GRIDFS_CONF = {'mongodb_store_uri': 'mongodb://fake_store_uri',
|
||||
'mongodb_store_db': 'fake_store_db'}
|
||||
@ -83,24 +79,19 @@ class TestStore(base.StoreBaseTest,
|
||||
"""Establish a clean test environment."""
|
||||
super(TestStore, self).setUp()
|
||||
|
||||
if pymongo is not None:
|
||||
conn = mock.patch.object(pymongo, 'MongoClient').start()
|
||||
conn.side_effect = FakeMongoClient
|
||||
self.addCleanup(conn.stop)
|
||||
conn = mock.patch.object(pymongo, 'MongoClient').start()
|
||||
conn.side_effect = FakeMongoClient
|
||||
self.addCleanup(conn.stop)
|
||||
|
||||
pgfs = mock.patch.object(gridfs, 'GridFS').start()
|
||||
pgfs.side_effect = FakeGridFS
|
||||
self.addCleanup(pgfs.stop)
|
||||
pgfs = mock.patch.object(gridfs, 'GridFS').start()
|
||||
pgfs.side_effect = FakeGridFS
|
||||
self.addCleanup(pgfs.stop)
|
||||
|
||||
self.store = gfs.Store(self.conf)
|
||||
self.config(group='glance_store', **GRIDFS_CONF)
|
||||
self.store.configure()
|
||||
|
||||
def test_cleanup_when_add_image_exception(self):
|
||||
if pymongo is None:
|
||||
msg = 'GridFS store can not add images, skip test.'
|
||||
self.skipTest(msg)
|
||||
|
||||
self.store.add('fake_image_id', StringIO.StringIO('xx'), 2)
|
||||
self.assertEqual(self.store.fs.called_commands,
|
||||
['exists', 'put', 'get'])
|
||||
|
Loading…
Reference in New Issue
Block a user