mirror of
https://github.com/samsonjs/vdirsyncer.git
synced 2026-04-27 14:57:41 +00:00
Remove indirection for get_storage_args fixture
This commit is contained in:
parent
c234bce656
commit
566a988f32
7 changed files with 62 additions and 51 deletions
|
|
@ -26,23 +26,17 @@ def format_item(item_template):
|
||||||
|
|
||||||
class BaseStorageTests(object):
|
class BaseStorageTests(object):
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def storage_args(self):
|
def get_storage_args(self):
|
||||||
return self.get_storage_args
|
'''
|
||||||
|
Return a function with the following properties:
|
||||||
|
|
||||||
def get_storage_args(self, collection=None):
|
:param collection: The collection name to use.
|
||||||
|
'''
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def get_storage(self, storage_args):
|
def s(self, get_storage_args):
|
||||||
def inner(collection=None, **kw):
|
return self.storage_class(**get_storage_args())
|
||||||
kw.update(storage_args(collection=collection))
|
|
||||||
return self.storage_class(**kw)
|
|
||||||
|
|
||||||
return inner
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def s(self, get_storage):
|
|
||||||
return get_storage()
|
|
||||||
|
|
||||||
@pytest.fixture(params=[EVENT_TEMPLATE, TASK_TEMPLATE, VCARD_TEMPLATE])
|
@pytest.fixture(params=[EVENT_TEMPLATE, TASK_TEMPLATE, VCARD_TEMPLATE])
|
||||||
def item_template(self, request):
|
def item_template(self, request):
|
||||||
|
|
@ -137,14 +131,14 @@ class BaseStorageTests(object):
|
||||||
in s.get_multi(href for href, etag in iteritems(info))
|
in s.get_multi(href for href, etag in iteritems(info))
|
||||||
) == info
|
) == info
|
||||||
|
|
||||||
def test_repr(self, s, get_storage):
|
def test_repr(self, s, get_storage_args):
|
||||||
assert self.storage_class.__name__ in repr(s)
|
assert self.storage_class.__name__ in repr(s)
|
||||||
assert s.instance_name is None
|
assert s.instance_name is None
|
||||||
|
|
||||||
|
|
||||||
class SupportsCollections(object):
|
class SupportsCollections(object):
|
||||||
|
|
||||||
def test_discover(self, storage_args, get_item):
|
def test_discover(self, get_storage_args, get_item):
|
||||||
collections = set()
|
collections = set()
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
@ -153,7 +147,8 @@ class SupportsCollections(object):
|
||||||
# Create collections on-the-fly for most storages
|
# Create collections on-the-fly for most storages
|
||||||
# Except ownCloud, which already has all of them, and more
|
# Except ownCloud, which already has all of them, and more
|
||||||
i += 1
|
i += 1
|
||||||
s = self.storage_class(**storage_args(collection=collection))
|
s = self.storage_class(
|
||||||
|
**get_storage_args(collection=collection))
|
||||||
|
|
||||||
# radicale ignores empty collections during discovery
|
# radicale ignores empty collections during discovery
|
||||||
item = get_item()
|
item = get_item()
|
||||||
|
|
@ -163,7 +158,7 @@ class SupportsCollections(object):
|
||||||
main() # remove leftover variables from loop for safety
|
main() # remove leftover variables from loop for safety
|
||||||
|
|
||||||
d = self.storage_class.discover(
|
d = self.storage_class.discover(
|
||||||
**storage_args(collection=None))
|
**get_storage_args(collection=None))
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
for s in d:
|
for s in d:
|
||||||
|
|
@ -178,15 +173,15 @@ class SupportsCollections(object):
|
||||||
|
|
||||||
assert not collections
|
assert not collections
|
||||||
|
|
||||||
def test_discover_collection_arg(self, storage_args):
|
def test_discover_collection_arg(self, get_storage_args):
|
||||||
args = storage_args(collection='test2')
|
args = get_storage_args(collection='test2')
|
||||||
with pytest.raises(TypeError) as excinfo:
|
with pytest.raises(TypeError) as excinfo:
|
||||||
list(self.storage_class.discover(**args))
|
list(self.storage_class.discover(**args))
|
||||||
|
|
||||||
assert 'collection argument must not be given' in str(excinfo.value)
|
assert 'collection argument must not be given' in str(excinfo.value)
|
||||||
|
|
||||||
def test_collection_arg(self, get_storage):
|
def test_collection_arg(self, get_storage_args):
|
||||||
s = get_storage(collection='test2')
|
s = self.storage_class(**get_storage_args(collection='test2'))
|
||||||
# Can't do stronger assertion because of radicale, which needs a
|
# Can't do stronger assertion because of radicale, which needs a
|
||||||
# fileextension to guess the collection type.
|
# fileextension to guess the collection type.
|
||||||
assert 'test2' in s.collection
|
assert 'test2' in s.collection
|
||||||
|
|
|
||||||
|
|
@ -104,10 +104,13 @@ class ServerMixin(object):
|
||||||
wsgi_intercept.requests_intercept.uninstall()
|
wsgi_intercept.requests_intercept.uninstall()
|
||||||
request.addfinalizer(teardown)
|
request.addfinalizer(teardown)
|
||||||
|
|
||||||
def get_storage_args(self, collection='test'):
|
@pytest.fixture
|
||||||
url = 'http://127.0.0.1/bob/'
|
def get_storage_args(self):
|
||||||
if collection is not None:
|
def inner(collection='test'):
|
||||||
collection += self.storage_class.fileext
|
url = 'http://127.0.0.1/bob/'
|
||||||
|
if collection is not None:
|
||||||
|
collection += self.storage_class.fileext
|
||||||
|
|
||||||
return {'url': url, 'username': 'bob', 'password': 'bob',
|
return {'url': url, 'username': 'bob', 'password': 'bob',
|
||||||
'collection': collection, 'unsafe_href_chars': ''}
|
'collection': collection, 'unsafe_href_chars': ''}
|
||||||
|
return inner
|
||||||
|
|
|
||||||
|
|
@ -63,8 +63,8 @@ class TestCaldavStorage(DavStorageTests):
|
||||||
return request.param
|
return request.param
|
||||||
|
|
||||||
@pytest.mark.parametrize('item_type', ['VTODO', 'VEVENT'])
|
@pytest.mark.parametrize('item_type', ['VTODO', 'VEVENT'])
|
||||||
def test_doesnt_accept_vcard(self, item_type, storage_args):
|
def test_doesnt_accept_vcard(self, item_type, get_storage_args):
|
||||||
s = self.storage_class(item_types=(item_type,), **storage_args())
|
s = self.storage_class(item_types=(item_type,), **get_storage_args())
|
||||||
|
|
||||||
try:
|
try:
|
||||||
s.upload(format_item(VCARD_TEMPLATE))
|
s.upload(format_item(VCARD_TEMPLATE))
|
||||||
|
|
@ -79,9 +79,9 @@ class TestCaldavStorage(DavStorageTests):
|
||||||
(('VTODO', 'VEVENT', 'VJOURNAL'), 3),
|
(('VTODO', 'VEVENT', 'VJOURNAL'), 3),
|
||||||
((), 1)
|
((), 1)
|
||||||
])
|
])
|
||||||
def test_item_types_performance(self, storage_args, item_types, calls_num,
|
def test_item_types_performance(self, get_storage_args, item_types,
|
||||||
monkeypatch, get_item):
|
calls_num, monkeypatch, get_item):
|
||||||
s = self.storage_class(item_types=item_types, **storage_args())
|
s = self.storage_class(item_types=item_types, **get_storage_args())
|
||||||
old_dav_query = s._dav_query
|
old_dav_query = s._dav_query
|
||||||
calls = []
|
calls = []
|
||||||
|
|
||||||
|
|
@ -95,11 +95,11 @@ class TestCaldavStorage(DavStorageTests):
|
||||||
|
|
||||||
@pytest.mark.xfail(dav_server == 'radicale',
|
@pytest.mark.xfail(dav_server == 'radicale',
|
||||||
reason='Radicale doesn\'t support timeranges.')
|
reason='Radicale doesn\'t support timeranges.')
|
||||||
def test_timerange_correctness(self, storage_args):
|
def test_timerange_correctness(self, get_storage_args):
|
||||||
start_date = datetime.datetime(2013, 9, 10)
|
start_date = datetime.datetime(2013, 9, 10)
|
||||||
end_date = datetime.datetime(2013, 9, 13)
|
end_date = datetime.datetime(2013, 9, 13)
|
||||||
s = self.storage_class(start_date=start_date, end_date=end_date,
|
s = self.storage_class(start_date=start_date, end_date=end_date,
|
||||||
**storage_args())
|
**get_storage_args())
|
||||||
|
|
||||||
too_old_item = format_item(dedent(u'''
|
too_old_item = format_item(dedent(u'''
|
||||||
BEGIN:VCALENDAR
|
BEGIN:VCALENDAR
|
||||||
|
|
@ -149,15 +149,15 @@ class TestCaldavStorage(DavStorageTests):
|
||||||
|
|
||||||
assert list(s.list()) == [(href, etag)]
|
assert list(s.list()) == [(href, etag)]
|
||||||
|
|
||||||
def test_item_types_passed_as_string(self, storage_args):
|
def test_item_types_passed_as_string(self, get_storage_args):
|
||||||
kw = storage_args()
|
kw = get_storage_args()
|
||||||
a = self.storage_class(item_types='VTODO,VEVENT', **kw)
|
a = self.storage_class(item_types='VTODO,VEVENT', **kw)
|
||||||
b = self.storage_class(item_types=('VTODO', 'VEVENT'), **kw)
|
b = self.storage_class(item_types=('VTODO', 'VEVENT'), **kw)
|
||||||
assert a.item_types == b.item_types == ('VTODO', 'VEVENT')
|
assert a.item_types == b.item_types == ('VTODO', 'VEVENT')
|
||||||
|
|
||||||
def test_invalid_resource(self, monkeypatch, storage_args):
|
def test_invalid_resource(self, monkeypatch, get_storage_args):
|
||||||
calls = []
|
calls = []
|
||||||
args = storage_args(collection=None)
|
args = get_storage_args(collection=None)
|
||||||
|
|
||||||
def request(session, method, url, data=None, headers=None, auth=None,
|
def request(session, method, url, data=None, headers=None, auth=None,
|
||||||
verify=None):
|
verify=None):
|
||||||
|
|
|
||||||
|
|
@ -25,11 +25,14 @@ class TestFilesystemStorage(StorageTests):
|
||||||
def setup(self, tmpdir):
|
def setup(self, tmpdir):
|
||||||
self.tmpdir = str(tmpdir)
|
self.tmpdir = str(tmpdir)
|
||||||
|
|
||||||
def get_storage_args(self, collection=None):
|
@pytest.fixture
|
||||||
path = self.tmpdir
|
def get_storage_args(self):
|
||||||
if collection is not None:
|
def inner(collection=None):
|
||||||
os.makedirs(os.path.join(path, collection))
|
path = self.tmpdir
|
||||||
return {'path': path, 'fileext': '.txt', 'collection': collection}
|
if collection is not None:
|
||||||
|
os.makedirs(os.path.join(path, collection))
|
||||||
|
return {'path': path, 'fileext': '.txt', 'collection': collection}
|
||||||
|
return inner
|
||||||
|
|
||||||
def test_create_is_false(self, tmpdir):
|
def test_create_is_false(self, tmpdir):
|
||||||
with pytest.raises(IOError):
|
with pytest.raises(IOError):
|
||||||
|
|
|
||||||
|
|
@ -73,10 +73,13 @@ class TestHttpStorage(BaseStorageTests):
|
||||||
|
|
||||||
monkeypatch.setattr(vdirsyncer.storage.http, 'request', _request)
|
monkeypatch.setattr(vdirsyncer.storage.http, 'request', _request)
|
||||||
|
|
||||||
def get_storage_args(self, collection=None):
|
@pytest.fixture
|
||||||
assert collection is None
|
def get_storage_args(self):
|
||||||
return {'url': 'http://localhost:123/collection.txt',
|
def inner(collection=None):
|
||||||
'path': self.tmpfile}
|
assert collection is None
|
||||||
|
return {'url': 'http://localhost:123/collection.txt',
|
||||||
|
'path': self.tmpfile}
|
||||||
|
return inner
|
||||||
|
|
||||||
def test_update(self, s, get_item):
|
def test_update(self, s, get_item):
|
||||||
'''The original testcase tries to fetch with the old href. But this
|
'''The original testcase tries to fetch with the old href. But this
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,8 @@
|
||||||
:license: MIT, see LICENSE for more details.
|
:license: MIT, see LICENSE for more details.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
from vdirsyncer.storage.memory import MemoryStorage
|
from vdirsyncer.storage.memory import MemoryStorage
|
||||||
|
|
||||||
from . import BaseStorageTests
|
from . import BaseStorageTests
|
||||||
|
|
@ -17,5 +19,6 @@ class TestMemoryStorage(BaseStorageTests):
|
||||||
|
|
||||||
storage_class = MemoryStorage
|
storage_class = MemoryStorage
|
||||||
|
|
||||||
def get_storage_args(self, **kwargs):
|
@pytest.fixture
|
||||||
return kwargs
|
def get_storage_args(self):
|
||||||
|
return lambda **kw: kw
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,12 @@ class TestSingleFileStorage(BaseStorageTests):
|
||||||
def setup(self, tmpdir):
|
def setup(self, tmpdir):
|
||||||
self._path = str(tmpdir.join('test.txt'))
|
self._path = str(tmpdir.join('test.txt'))
|
||||||
|
|
||||||
def get_storage_args(self, **kwargs):
|
@pytest.fixture
|
||||||
return dict(path=self._path)
|
def get_storage_args(self):
|
||||||
|
def inner(**kwargs):
|
||||||
|
kwargs.update(path=self._path)
|
||||||
|
return kwargs
|
||||||
|
return inner
|
||||||
|
|
||||||
def test_collection_arg(self, tmpdir):
|
def test_collection_arg(self, tmpdir):
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue