mirror of
https://github.com/samsonjs/vdirsyncer.git
synced 2026-04-27 14:57:41 +00:00
Small refactor
This commit is contained in:
parent
5b4ca2975a
commit
4cfca383d9
2 changed files with 29 additions and 18 deletions
|
|
@ -19,6 +19,14 @@ def format_item(item_template, uid=None):
|
||||||
|
|
||||||
|
|
||||||
class StorageTests(object):
|
class StorageTests(object):
|
||||||
|
storage_class = None
|
||||||
|
supports_collections = True
|
||||||
|
|
||||||
|
@pytest.fixture(params=['VEVENT', 'VTODO', 'VCARD'])
|
||||||
|
def item_type(self, request):
|
||||||
|
'''Parametrize with all supported item types.'''
|
||||||
|
return request.param
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def get_storage_args(self):
|
def get_storage_args(self):
|
||||||
'''
|
'''
|
||||||
|
|
@ -32,17 +40,19 @@ class StorageTests(object):
|
||||||
def s(self, get_storage_args):
|
def s(self, get_storage_args):
|
||||||
return self.storage_class(**get_storage_args())
|
return self.storage_class(**get_storage_args())
|
||||||
|
|
||||||
@pytest.fixture(params=[EVENT_TEMPLATE, TASK_TEMPLATE, VCARD_TEMPLATE])
|
|
||||||
def item_template(self, request):
|
|
||||||
return request.param
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def get_item(self, item_template):
|
def get_item(self, item_type):
|
||||||
return lambda **kw: format_item(item_template, **kw)
|
template = {
|
||||||
|
'VEVENT': EVENT_TEMPLATE,
|
||||||
|
'VTODO': TASK_TEMPLATE,
|
||||||
|
'VCARD': VCARD_TEMPLATE,
|
||||||
|
}[item_type]
|
||||||
|
|
||||||
|
return lambda **kw: format_item(template, **kw)
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def requires_collections(self):
|
def requires_collections(self):
|
||||||
if not getattr(self, 'supports_collections', True):
|
if not self.supports_collections:
|
||||||
pytest.skip('This storage does not support collections.')
|
pytest.skip('This storage does not support collections.')
|
||||||
|
|
||||||
def test_generic(self, s, get_item):
|
def test_generic(self, s, get_item):
|
||||||
|
|
|
||||||
|
|
@ -52,11 +52,10 @@ class DavStorageTests(ServerMixin, StorageTests):
|
||||||
class TestCaldavStorage(DavStorageTests):
|
class TestCaldavStorage(DavStorageTests):
|
||||||
storage_class = CaldavStorage
|
storage_class = CaldavStorage
|
||||||
|
|
||||||
@pytest.fixture(params=[EVENT_TEMPLATE, TASK_TEMPLATE])
|
@pytest.fixture(params=['VTODO', 'VEVENT'])
|
||||||
def item_template(self, request):
|
def item_type(self, request):
|
||||||
return request.param
|
return request.param
|
||||||
|
|
||||||
@pytest.mark.parametrize('item_type', ['VTODO', 'VEVENT'])
|
|
||||||
def test_doesnt_accept_vcard(self, item_type, get_storage_args):
|
def test_doesnt_accept_vcard(self, item_type, get_storage_args):
|
||||||
s = self.storage_class(item_types=(item_type,), **get_storage_args())
|
s = self.storage_class(item_types=(item_type,), **get_storage_args())
|
||||||
|
|
||||||
|
|
@ -66,16 +65,18 @@ class TestCaldavStorage(DavStorageTests):
|
||||||
pass
|
pass
|
||||||
assert not list(s.list())
|
assert not list(s.list())
|
||||||
|
|
||||||
@pytest.mark.parametrize('item_types,calls_num', [
|
# The `arg` param is not named `item_types` because that would hit
|
||||||
|
# https://bitbucket.org/pytest-dev/pytest/issue/745/
|
||||||
|
@pytest.mark.parametrize('arg,calls_num', [
|
||||||
(('VTODO',), 1),
|
(('VTODO',), 1),
|
||||||
(('VEVENT',), 1),
|
(('VEVENT',), 1),
|
||||||
(('VTODO', 'VEVENT'), 2),
|
(('VTODO', 'VEVENT'), 2),
|
||||||
(('VTODO', 'VEVENT', 'VJOURNAL'), 3),
|
(('VTODO', 'VEVENT', 'VJOURNAL'), 3),
|
||||||
((), 1)
|
((), 1)
|
||||||
])
|
])
|
||||||
def test_item_types_performance(self, get_storage_args, item_types,
|
def test_item_types_performance(self, get_storage_args, arg, calls_num,
|
||||||
calls_num, monkeypatch, get_item):
|
monkeypatch):
|
||||||
s = self.storage_class(item_types=item_types, **get_storage_args())
|
s = self.storage_class(item_types=arg, **get_storage_args())
|
||||||
old_parse = s._parse_prop_responses
|
old_parse = s._parse_prop_responses
|
||||||
calls = []
|
calls = []
|
||||||
|
|
||||||
|
|
@ -163,7 +164,7 @@ class TestCaldavStorage(DavStorageTests):
|
||||||
list(s.list())
|
list(s.list())
|
||||||
assert len(calls) == 1
|
assert len(calls) == 1
|
||||||
|
|
||||||
def test_item_types(self, s):
|
def test_item_types_general(self, s):
|
||||||
event = s.upload(format_item(EVENT_TEMPLATE))
|
event = s.upload(format_item(EVENT_TEMPLATE))
|
||||||
task = s.upload(format_item(TASK_TEMPLATE))
|
task = s.upload(format_item(TASK_TEMPLATE))
|
||||||
s.item_types = ('VTODO', 'VEVENT')
|
s.item_types = ('VTODO', 'VEVENT')
|
||||||
|
|
@ -179,6 +180,6 @@ class TestCaldavStorage(DavStorageTests):
|
||||||
class TestCarddavStorage(DavStorageTests):
|
class TestCarddavStorage(DavStorageTests):
|
||||||
storage_class = CarddavStorage
|
storage_class = CarddavStorage
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture(params=['VCARD'])
|
||||||
def item_template(self):
|
def item_type(self, request):
|
||||||
return VCARD_TEMPLATE
|
return request.param
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue