mirror of
https://github.com/samsonjs/vdirsyncer.git
synced 2026-04-03 10:25:51 +00:00
Deduplication
This commit is contained in:
parent
bef7b3e25a
commit
03b6d11ac8
6 changed files with 45 additions and 36 deletions
|
|
@ -21,9 +21,12 @@ class StorageTests(object):
|
|||
item_template = item_template or self.item_template
|
||||
return Item(item_template.format(uid=uid, r=r))
|
||||
|
||||
def _get_storage(self, **kwargs):
|
||||
def get_storage_args(self, collection=None):
|
||||
raise NotImplementedError()
|
||||
|
||||
def _get_storage(self):
|
||||
return self.storage_class(**self.get_storage_args())
|
||||
|
||||
def test_generic(self):
|
||||
items = map(self._create_bogus_item, range(1, 10))
|
||||
for i, item in enumerate(items):
|
||||
|
|
@ -90,5 +93,15 @@ class StorageTests(object):
|
|||
assert list(s.list())
|
||||
|
||||
def test_discover(self):
|
||||
# Too storage specific to implement in an abstract way
|
||||
raise NotImplementedError()
|
||||
items = []
|
||||
for i in range(4):
|
||||
s = self.storage_class(**self.get_storage_args(collection=str(i)))
|
||||
items.append(self._create_bogus_item(str(i)))
|
||||
s.upload(items[-1])
|
||||
|
||||
d = self.storage_class.discover(
|
||||
**self.get_storage_args(collection=None))
|
||||
for s in d:
|
||||
((href, etag),) = s.list()
|
||||
item, etag = s.get(href)
|
||||
assert item.raw in set(x.raw for x in items)
|
||||
|
|
|
|||
|
|
@ -1,9 +1,6 @@
|
|||
import pytest
|
||||
import tempfile
|
||||
import shutil
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def class_tmpdir(request):
|
||||
request.cls.tmpdir = x = tempfile.mkdtemp()
|
||||
request.addfinalizer(lambda: shutil.rmtree(x))
|
||||
def class_tmpdir(request, tmpdir):
|
||||
request.instance.tmpdir = str(tmpdir)
|
||||
|
|
|
|||
|
|
@ -16,7 +16,8 @@
|
|||
import sys
|
||||
import os
|
||||
import urlparse
|
||||
import pytest
|
||||
import tempfile
|
||||
import shutil
|
||||
import mock
|
||||
|
||||
from werkzeug.test import Client
|
||||
|
|
@ -70,24 +71,22 @@ class Response(object):
|
|||
raise HTTPError(str(self.status_code))
|
||||
|
||||
|
||||
@pytest.mark.usefixtures('class_tmpdir')
|
||||
class DavStorageTests(StorageTests):
|
||||
'''hrefs are paths without scheme or netloc'''
|
||||
storage_class = None
|
||||
patcher = None
|
||||
tmpdir = None
|
||||
|
||||
def _get_storage(self, **kwargs):
|
||||
def setup_method(self, method):
|
||||
self.tmpdir = tempfile.mkdtemp()
|
||||
do_the_radicale_dance(self.tmpdir)
|
||||
from radicale import Application
|
||||
app = Application()
|
||||
|
||||
c = Client(app, WerkzeugResponse)
|
||||
server = 'http://127.0.0.1'
|
||||
fileext = self.storage_class.fileext
|
||||
full_url = server + '/bob/test{}/'.format(fileext)
|
||||
|
||||
def x(session, method, url, data=None, headers=None, **kw):
|
||||
path = urlparse.urlparse(url).path or self.radicale_path
|
||||
path = urlparse.urlparse(url).path
|
||||
assert isinstance(data, bytes) or data is None
|
||||
r = c.open(path=path, method=method, data=data, headers=headers)
|
||||
r = Response(r)
|
||||
|
|
@ -96,10 +95,17 @@ class DavStorageTests(StorageTests):
|
|||
self.patcher = p = mock.patch('requests.Session.request', new=x)
|
||||
p.start()
|
||||
|
||||
return self.storage_class(url=full_url, **kwargs)
|
||||
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}
|
||||
|
||||
def teardown_method(self, method):
|
||||
self.app = None
|
||||
if self.tmpdir is not None:
|
||||
shutil.rmtree(self.tmpdir)
|
||||
self.tmpdir = None
|
||||
if self.patcher is not None:
|
||||
self.patcher.stop()
|
||||
self.patcher = None
|
||||
|
|
|
|||
|
|
@ -17,22 +17,11 @@ from . import StorageTests
|
|||
|
||||
@pytest.mark.usefixtures('class_tmpdir')
|
||||
class FilesystemStorageTests(TestCase, StorageTests):
|
||||
storage_class = FilesystemStorage
|
||||
|
||||
def _get_storage(self, **kwargs):
|
||||
return FilesystemStorage(path=self.tmpdir, fileext='.txt', **kwargs)
|
||||
|
||||
def test_discover(self):
|
||||
paths = set()
|
||||
for i, collection in enumerate('abcd'):
|
||||
p = os.path.join(self.tmpdir, collection)
|
||||
os.makedirs(os.path.join(self.tmpdir, collection))
|
||||
fname = os.path.join(p, 'asdf.txt')
|
||||
with open(fname, 'w+') as f:
|
||||
f.write(self._create_bogus_item(i).raw)
|
||||
paths.add(p)
|
||||
|
||||
storages = list(FilesystemStorage.discover(path=self.tmpdir,
|
||||
fileext='.txt'))
|
||||
assert len(storages) == 4
|
||||
for s in storages:
|
||||
assert s.path in paths
|
||||
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'}
|
||||
|
|
|
|||
|
|
@ -15,8 +15,10 @@ from . import StorageTests
|
|||
|
||||
class MemoryStorageTests(TestCase, StorageTests):
|
||||
|
||||
def _get_storage(self, **kwargs):
|
||||
return MemoryStorage(**kwargs)
|
||||
storage_class = MemoryStorage
|
||||
|
||||
def get_storage_args(collection=None):
|
||||
return {}
|
||||
|
||||
def test_discover(self):
|
||||
'''This test doesn't make any sense here.'''
|
||||
|
|
|
|||
|
|
@ -177,6 +177,8 @@ class DavStorage(Storage):
|
|||
|
||||
def update(self, href, obj, etag):
|
||||
href = self._normalize_href(href)
|
||||
if etag is None:
|
||||
raise ValueError('etag must be given and must not be None.')
|
||||
return self._put(href, obj, etag)
|
||||
|
||||
def upload(self, obj):
|
||||
|
|
|
|||
Loading…
Reference in a new issue