Rewrite collections test

This commit is contained in:
Markus Unterwaditzer 2014-12-30 13:23:45 +01:00
parent 40b64139fd
commit ce30ed7b8a
4 changed files with 20 additions and 16 deletions

View file

@ -6,6 +6,7 @@
:copyright: (c) 2014 Markus Unterwaditzer & contributors
:license: MIT, see LICENSE for more details.
'''
import functools
import random
import pytest
@ -24,7 +25,7 @@ def format_item(item_template):
return Item(item_template.format(r=r))
class BaseStorageTests(object):
class StorageTests(object):
@pytest.fixture
def get_storage_args(self):
'''
@ -46,6 +47,11 @@ class BaseStorageTests(object):
def get_item(self, item_template):
return lambda: format_item(item_template)
@pytest.fixture
def requires_collections(self):
if not getattr(self, 'supports_collections', True):
pytest.skip('This storage does not support collections.')
def test_generic(self, s, get_item):
items = [get_item() for i in range(1, 10)]
hrefs = []
@ -144,9 +150,7 @@ class BaseStorageTests(object):
assert s.instance_name is None
class SupportsCollections(object):
def test_discover(self, get_storage_args, get_item):
def test_discover(self, requires_collections, get_storage_args, get_item):
expected = set()
items = {}
@ -172,19 +176,16 @@ class SupportsCollections(object):
rv = list(s.list())
assert rv == items[collection]
def test_discover_collection_arg(self, get_storage_args):
def test_discover_collection_arg(self, requires_collections,
get_storage_args):
args = get_storage_args(collection='test2')
with pytest.raises(TypeError) as excinfo:
list(self.storage_class.discover(**args))
assert 'collection argument must not be given' in str(excinfo.value)
def test_collection_arg(self, get_storage_args):
def test_collection_arg(self, requires_collections, get_storage_args):
s = self.storage_class(**get_storage_args(collection='test2'))
# Can't do stronger assertion because of radicale, which needs a
# fileextension to guess the collection type.
assert 'test2' in s.collection
class StorageTests(BaseStorageTests, SupportsCollections):
pass

View file

@ -15,7 +15,7 @@ from vdirsyncer.storage.base import Storage
import vdirsyncer.storage.http
from vdirsyncer.storage.singlefile import SingleFileStorage
from . import BaseStorageTests
from . import StorageTests
from .. import assert_item_equals
@ -48,8 +48,9 @@ class CombinedStorage(Storage):
return self._writer.delete(*a, **kw)
class TestHttpStorage(BaseStorageTests):
class TestHttpStorage(StorageTests):
storage_class = CombinedStorage
supports_collections = False
@pytest.fixture(autouse=True)
def setup_tmpdir(self, tmpdir, monkeypatch):

View file

@ -12,12 +12,13 @@ import pytest
from vdirsyncer.storage.memory import MemoryStorage
from . import BaseStorageTests
from . import StorageTests
class TestMemoryStorage(BaseStorageTests):
class TestMemoryStorage(StorageTests):
storage_class = MemoryStorage
supports_collections = False
@pytest.fixture
def get_storage_args(self):

View file

@ -11,13 +11,14 @@ import pytest
from vdirsyncer.storage.singlefile import SingleFileStorage
from . import BaseStorageTests
from . import StorageTests
from .. import assert_item_equals
class TestSingleFileStorage(BaseStorageTests):
class TestSingleFileStorage(StorageTests):
storage_class = SingleFileStorage
supports_collections = False
@pytest.fixture(autouse=True)
def setup(self, tmpdir):