Skip to content

Commit

Permalink
Fix GridFS tests not running
Browse files Browse the repository at this point in the history
  • Loading branch information
amol- committed May 31, 2023
1 parent f5097c1 commit 0abc88d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion depot/io/gridfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def replace(self, file_or_id, content, filename=None, content_type=None):
elif not self.exists(fileid):
# Check file existed and we are not using replace
# as a way to force a specific file id on creation.
raise IOError('File %s not existing' % file_id)
raise IOError('File %s not existing' % fileid)

content, filename, content_type = self.fileinfo(content, filename, content_type,
lambda: self.get(fileid))
Expand Down
14 changes: 7 additions & 7 deletions tests/test_storage_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def test_exists(self):
def test_list(self):
file_ids = list()
for i in range(3):
file_ids.append(self.fs.create(FILE_CONTENT, 'file{0}.txt'.format(i)))
file_ids.append(self.fs.create(FILE_CONTENT, 'file_for_listing-{0}.txt'.format(i)))

existing_files = self.fs.list()
for _id in file_ids:
Expand Down Expand Up @@ -310,15 +310,16 @@ def get_storage(cls, collection_name):
from depot.io.gridfs import GridFSStorage
import pymongo.errors
try:
cls.fs = GridFSStorage('mongodb://localhost/gridfs_example?serverSelectionTimeoutMS=1', collection_name)
cls.fs._gridfs.exists("") # Any operation to test that mongodb is up.
fs = GridFSStorage('mongodb://localhost/gridfs_example?serverSelectionTimeoutMS=100', collection_name)
fs._gridfs.exists("") # Any operation to test that mongodb is up.
return fs
except pymongo.errors.ConnectionFailure:
return None

@classmethod
def delete_storage(cls, storage):
storage._db.drop_collection('%s.files' % storage._collection_name)
storage._db.drop_collection('%s.chunks' % storage._collection_name)
storage._db.drop_collection('%s.files' % storage._collection)
storage._db.drop_collection('%s.chunks' % storage._collection)

@classmethod
def setUpClass(cls):
Expand All @@ -333,7 +334,7 @@ def setUp(self):
if self.fs is None:
self.skipTest('MongoDB not running')

def teardown(self):
def tearDown(self):
self.delete_storage(self.fs)


Expand Down Expand Up @@ -375,7 +376,6 @@ def setUpClass(cls):
if cls.fs is None:
raise unittest.SkipTest('Amazon S3 credentials not available')


def tearDown(self):
keys = [key.name for key in self.fs._bucket_driver.bucket]
if keys:
Expand Down

0 comments on commit 0abc88d

Please sign in to comment.