mirror of
https://github.com/samsonjs/vdirsyncer.git
synced 2026-03-25 08:55:50 +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):
|
||||
@pytest.fixture
|
||||
def storage_args(self):
|
||||
return self.get_storage_args
|
||||
def get_storage_args(self):
|
||||
'''
|
||||
Return a function with the following properties:
|
||||
|
||||
def get_storage_args(self, collection=None):
|
||||
:param collection: The collection name to use.
|
||||
'''
|
||||
raise NotImplementedError()
|
||||
|
||||
@pytest.fixture
|
||||
def get_storage(self, storage_args):
|
||||
def inner(collection=None, **kw):
|
||||
kw.update(storage_args(collection=collection))
|
||||
return self.storage_class(**kw)
|
||||
|
||||
return inner
|
||||
|
||||
@pytest.fixture
|
||||
def s(self, get_storage):
|
||||
return get_storage()
|
||||
def s(self, get_storage_args):
|
||||
return self.storage_class(**get_storage_args())
|
||||
|
||||
@pytest.fixture(params=[EVENT_TEMPLATE, TASK_TEMPLATE, VCARD_TEMPLATE])
|
||||
def item_template(self, request):
|
||||
|
|
@ -137,14 +131,14 @@ class BaseStorageTests(object):
|
|||
in s.get_multi(href for href, etag in iteritems(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 s.instance_name is None
|
||||
|
||||
|
||||
class SupportsCollections(object):
|
||||
|
||||
def test_discover(self, storage_args, get_item):
|
||||
def test_discover(self, get_storage_args, get_item):
|
||||
collections = set()
|
||||
|
||||
def main():
|
||||
|
|
@ -153,7 +147,8 @@ class SupportsCollections(object):
|
|||
# Create collections on-the-fly for most storages
|
||||
# Except ownCloud, which already has all of them, and more
|
||||
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
|
||||
item = get_item()
|
||||
|
|
@ -163,7 +158,7 @@ class SupportsCollections(object):
|
|||
main() # remove leftover variables from loop for safety
|
||||
|
||||
d = self.storage_class.discover(
|
||||
**storage_args(collection=None))
|
||||
**get_storage_args(collection=None))
|
||||
|
||||
def main():
|
||||
for s in d:
|
||||
|
|
@ -178,15 +173,15 @@ class SupportsCollections(object):
|
|||
|
||||
assert not collections
|
||||
|
||||
def test_discover_collection_arg(self, storage_args):
|
||||
args = storage_args(collection='test2')
|
||||
def test_discover_collection_arg(self, 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):
|
||||
s = get_storage(collection='test2')
|
||||
def test_collection_arg(self, 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
|
||||
|
|
|
|||
|
|
@ -104,10 +104,13 @@ class ServerMixin(object):
|
|||
wsgi_intercept.requests_intercept.uninstall()
|
||||
request.addfinalizer(teardown)
|
||||
|
||||
def get_storage_args(self, collection='test'):
|
||||
url = 'http://127.0.0.1/bob/'
|
||||
if collection is not None:
|
||||
collection += self.storage_class.fileext
|
||||
@pytest.fixture
|
||||
def get_storage_args(self):
|
||||
def inner(collection='test'):
|
||||
url = 'http://127.0.0.1/bob/'
|
||||
if collection is not None:
|
||||
collection += self.storage_class.fileext
|
||||
|
||||
return {'url': url, 'username': 'bob', 'password': 'bob',
|
||||
'collection': collection, 'unsafe_href_chars': ''}
|
||||
return {'url': url, 'username': 'bob', 'password': 'bob',
|
||||
'collection': collection, 'unsafe_href_chars': ''}
|
||||
return inner
|
||||
|
|
|
|||
|
|
@ -63,8 +63,8 @@ class TestCaldavStorage(DavStorageTests):
|
|||
return request.param
|
||||
|
||||
@pytest.mark.parametrize('item_type', ['VTODO', 'VEVENT'])
|
||||
def test_doesnt_accept_vcard(self, item_type, storage_args):
|
||||
s = self.storage_class(item_types=(item_type,), **storage_args())
|
||||
def test_doesnt_accept_vcard(self, item_type, get_storage_args):
|
||||
s = self.storage_class(item_types=(item_type,), **get_storage_args())
|
||||
|
||||
try:
|
||||
s.upload(format_item(VCARD_TEMPLATE))
|
||||
|
|
@ -79,9 +79,9 @@ class TestCaldavStorage(DavStorageTests):
|
|||
(('VTODO', 'VEVENT', 'VJOURNAL'), 3),
|
||||
((), 1)
|
||||
])
|
||||
def test_item_types_performance(self, storage_args, item_types, calls_num,
|
||||
monkeypatch, get_item):
|
||||
s = self.storage_class(item_types=item_types, **storage_args())
|
||||
def test_item_types_performance(self, get_storage_args, item_types,
|
||||
calls_num, monkeypatch, get_item):
|
||||
s = self.storage_class(item_types=item_types, **get_storage_args())
|
||||
old_dav_query = s._dav_query
|
||||
calls = []
|
||||
|
||||
|
|
@ -95,11 +95,11 @@ class TestCaldavStorage(DavStorageTests):
|
|||
|
||||
@pytest.mark.xfail(dav_server == 'radicale',
|
||||
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)
|
||||
end_date = datetime.datetime(2013, 9, 13)
|
||||
s = self.storage_class(start_date=start_date, end_date=end_date,
|
||||
**storage_args())
|
||||
**get_storage_args())
|
||||
|
||||
too_old_item = format_item(dedent(u'''
|
||||
BEGIN:VCALENDAR
|
||||
|
|
@ -149,15 +149,15 @@ class TestCaldavStorage(DavStorageTests):
|
|||
|
||||
assert list(s.list()) == [(href, etag)]
|
||||
|
||||
def test_item_types_passed_as_string(self, storage_args):
|
||||
kw = storage_args()
|
||||
def test_item_types_passed_as_string(self, get_storage_args):
|
||||
kw = get_storage_args()
|
||||
a = 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')
|
||||
|
||||
def test_invalid_resource(self, monkeypatch, storage_args):
|
||||
def test_invalid_resource(self, monkeypatch, get_storage_args):
|
||||
calls = []
|
||||
args = storage_args(collection=None)
|
||||
args = get_storage_args(collection=None)
|
||||
|
||||
def request(session, method, url, data=None, headers=None, auth=None,
|
||||
verify=None):
|
||||
|
|
|
|||
|
|
@ -25,11 +25,14 @@ class TestFilesystemStorage(StorageTests):
|
|||
def setup(self, tmpdir):
|
||||
self.tmpdir = str(tmpdir)
|
||||
|
||||
def get_storage_args(self, collection=None):
|
||||
path = self.tmpdir
|
||||
if collection is not None:
|
||||
os.makedirs(os.path.join(path, collection))
|
||||
return {'path': path, 'fileext': '.txt', 'collection': collection}
|
||||
@pytest.fixture
|
||||
def get_storage_args(self):
|
||||
def inner(collection=None):
|
||||
path = self.tmpdir
|
||||
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):
|
||||
with pytest.raises(IOError):
|
||||
|
|
|
|||
|
|
@ -73,10 +73,13 @@ class TestHttpStorage(BaseStorageTests):
|
|||
|
||||
monkeypatch.setattr(vdirsyncer.storage.http, 'request', _request)
|
||||
|
||||
def get_storage_args(self, collection=None):
|
||||
assert collection is None
|
||||
return {'url': 'http://localhost:123/collection.txt',
|
||||
'path': self.tmpfile}
|
||||
@pytest.fixture
|
||||
def get_storage_args(self):
|
||||
def inner(collection=None):
|
||||
assert collection is None
|
||||
return {'url': 'http://localhost:123/collection.txt',
|
||||
'path': self.tmpfile}
|
||||
return inner
|
||||
|
||||
def test_update(self, s, get_item):
|
||||
'''The original testcase tries to fetch with the old href. But this
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@
|
|||
:license: MIT, see LICENSE for more details.
|
||||
'''
|
||||
|
||||
import pytest
|
||||
|
||||
from vdirsyncer.storage.memory import MemoryStorage
|
||||
|
||||
from . import BaseStorageTests
|
||||
|
|
@ -17,5 +19,6 @@ class TestMemoryStorage(BaseStorageTests):
|
|||
|
||||
storage_class = MemoryStorage
|
||||
|
||||
def get_storage_args(self, **kwargs):
|
||||
return kwargs
|
||||
@pytest.fixture
|
||||
def get_storage_args(self):
|
||||
return lambda **kw: kw
|
||||
|
|
|
|||
|
|
@ -23,8 +23,12 @@ class TestSingleFileStorage(BaseStorageTests):
|
|||
def setup(self, tmpdir):
|
||||
self._path = str(tmpdir.join('test.txt'))
|
||||
|
||||
def get_storage_args(self, **kwargs):
|
||||
return dict(path=self._path)
|
||||
@pytest.fixture
|
||||
def get_storage_args(self):
|
||||
def inner(**kwargs):
|
||||
kwargs.update(path=self._path)
|
||||
return kwargs
|
||||
return inner
|
||||
|
||||
def test_collection_arg(self, tmpdir):
|
||||
with pytest.raises(ValueError):
|
||||
|
|
|
|||
Loading…
Reference in a new issue