From 8c120d84efa961286cebc1375d80b376b2808521 Mon Sep 17 00:00:00 2001 From: Markus Unterwaditzer Date: Sun, 9 Mar 2014 20:13:51 +0100 Subject: [PATCH] More tests --- tests/storage/__init__.py | 4 ++++ tests/storage/dav/__init__.py | 4 +--- tests/storage/test_filesystem.py | 5 ++--- tests/storage/test_memory.py | 7 +++++-- vdirsyncer/storage/filesystem.py | 3 +++ 5 files changed, 15 insertions(+), 8 deletions(-) diff --git a/tests/storage/__init__.py b/tests/storage/__init__.py index 4e68b25..fc570bc 100644 --- a/tests/storage/__init__.py +++ b/tests/storage/__init__.py @@ -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' diff --git a/tests/storage/dav/__init__.py b/tests/storage/dav/__init__.py index 9bedcff..3f6e8a8 100644 --- a/tests/storage/dav/__init__.py +++ b/tests/storage/dav/__init__.py @@ -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 diff --git a/tests/storage/test_filesystem.py b/tests/storage/test_filesystem.py index 503f4c3..5d93e62 100644 --- a/tests/storage/test_filesystem.py +++ b/tests/storage/test_filesystem.py @@ -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} diff --git a/tests/storage/test_memory.py b/tests/storage/test_memory.py index 29e6972..eca9184 100644 --- a/tests/storage/test_memory.py +++ b/tests/storage/test_memory.py @@ -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.''' diff --git a/vdirsyncer/storage/filesystem.py b/vdirsyncer/storage/filesystem.py index eeedad3..212ce00 100644 --- a/vdirsyncer/storage/filesystem.py +++ b/vdirsyncer/storage/filesystem.py @@ -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: