More tests

This commit is contained in:
Markus Unterwaditzer 2014-03-09 20:13:51 +01:00
parent cff730e02e
commit 8c120d84ef
5 changed files with 15 additions and 8 deletions

View file

@ -105,3 +105,7 @@ class StorageTests(object):
((href, etag),) = s.list()
item, etag = s.get(href)
assert item.raw in set(x.raw for x in items)
def test_collection_arg(self):
s = self.storage_class(**self.get_storage_args(collection='asd'))
assert s.collection == 'asd'

View file

@ -97,9 +97,7 @@ class DavStorageTests(StorageTests):
def get_storage_args(self, collection=None):
url = 'http://127.0.0.1/bob/'
if collection is not None:
url += '{}{}'.format(collection, self.storage_class.fileext)
return {'url': url}
return {'url': url, 'collection': collection}
def teardown_method(self, method):
self.app = None

View file

@ -22,6 +22,5 @@ class FilesystemStorageTests(TestCase, StorageTests):
def get_storage_args(self, collection=None):
path = self.tmpdir
if collection is not None:
path = os.path.join(path, collection)
os.makedirs(path)
return {'path': path, 'fileext': '.txt'}
os.makedirs(os.path.join(path, collection))
return {'path': path, 'fileext': '.txt', 'collection': collection}

View file

@ -17,8 +17,11 @@ class MemoryStorageTests(TestCase, StorageTests):
storage_class = MemoryStorage
def get_storage_args(collection=None):
return {}
def get_storage_args(self, **kwargs):
return kwargs
def test_discover(self):
'''This test doesn't make any sense here.'''
def test_collection_arg(self):
'''This test doesn't make any sense here.'''

View file

@ -36,12 +36,15 @@ class FilesystemStorage(Storage):
super(FilesystemStorage, self).__init__(**kwargs)
if collection is not None:
path = os.path.join(path, collection)
self.collection = collection
self.path = expand_path(path)
self.encoding = encoding
self.fileext = fileext
@classmethod
def discover(cls, path, **kwargs):
if kwargs.pop('collection', None) is not None:
raise TypeError('collection argument must not be given.')
for collection in os.listdir(path):
s = cls(path=path, collection=collection, **kwargs)
if next(s.list(), None) is not None: