mirror of
https://github.com/samsonjs/vdirsyncer.git
synced 2026-04-27 14:57:41 +00:00
Fix tests
This commit is contained in:
parent
3af84ccf90
commit
2d30d1b7f2
2 changed files with 33 additions and 17 deletions
|
|
@ -20,7 +20,7 @@ class StorageTests(object):
|
||||||
def _get_storage(self, **kwargs):
|
def _get_storage(self, **kwargs):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
def test_generic_upload(self):
|
def test_generic(self):
|
||||||
items = [
|
items = [
|
||||||
'UID:1',
|
'UID:1',
|
||||||
'UID:2',
|
'UID:2',
|
||||||
|
|
@ -36,9 +36,14 @@ class StorageTests(object):
|
||||||
s = self._get_storage(fileext=fileext)
|
s = self._get_storage(fileext=fileext)
|
||||||
for item in items:
|
for item in items:
|
||||||
s.upload(Item(item))
|
s.upload(Item(item))
|
||||||
a = set(uid for uid, etag in s.list_items())
|
a = set(uid for uid, etag in s.list())
|
||||||
b = set(str(y) for y in range(1, 10))
|
b = set(str(y) for y in range(1, 10))
|
||||||
assert a == b
|
assert a == b
|
||||||
|
for i in b:
|
||||||
|
assert s.has(i)
|
||||||
|
item, uid, etag = s.get(i)
|
||||||
|
assert uid == i
|
||||||
|
assert item.raw == 'UID:{}'.format(i)
|
||||||
|
|
||||||
|
|
||||||
class FilesystemStorageTests(TestCase, StorageTests):
|
class FilesystemStorageTests(TestCase, StorageTests):
|
||||||
|
|
|
||||||
|
|
@ -13,40 +13,51 @@ from vdirsyncer.storage.memory import MemoryStorage
|
||||||
from vdirsyncer.sync import sync
|
from vdirsyncer.sync import sync
|
||||||
import vdirsyncer.exceptions as exceptions
|
import vdirsyncer.exceptions as exceptions
|
||||||
|
|
||||||
|
def only(x):
|
||||||
|
x = list(x)
|
||||||
|
assert len(x) == 1, x
|
||||||
|
return x[0]
|
||||||
|
|
||||||
|
def empty_storage(x):
|
||||||
|
return list(x.list()) == []
|
||||||
|
|
||||||
class SyncTests(TestCase):
|
class SyncTests(TestCase):
|
||||||
def test_basic(self):
|
def test_basic(self):
|
||||||
a = MemoryStorage()
|
a = MemoryStorage()
|
||||||
b = MemoryStorage()
|
b = MemoryStorage()
|
||||||
status = {}
|
status = {}
|
||||||
sync(a, b, status)
|
sync(a, b, status)
|
||||||
assert len(status) == 0
|
assert not status
|
||||||
assert list(a.list_items()) == []
|
assert empty_storage(a)
|
||||||
assert list(b.list_items()) == []
|
assert empty_storage(b)
|
||||||
|
|
||||||
|
# creation
|
||||||
item = Item('UID:1')
|
item = Item('UID:1')
|
||||||
a.upload(item)
|
a.upload(item)
|
||||||
sync(a, b, status)
|
sync(a, b, status)
|
||||||
assert list(status) == ['1']
|
obj_a, uid_a, etag_a = a.get('1')
|
||||||
obj, uid, etag = next(b.get_items(['1']))
|
obj_b, uid_b, etag_b = b.get('1')
|
||||||
assert obj.raw == item.raw
|
assert obj_a.raw == obj_b.raw == item.raw
|
||||||
|
assert uid_a == uid_b == only(status) == '1'
|
||||||
|
|
||||||
|
# creation and deletion
|
||||||
item2 = Item('UID:2')
|
item2 = Item('UID:2')
|
||||||
b.upload(item2)
|
b.upload(item2)
|
||||||
b.delete('1')
|
b.delete('1', etag_b)
|
||||||
sync(a, b, status)
|
sync(a, b, status)
|
||||||
assert list(status) == ['2']
|
assert list(status) == ['2']
|
||||||
assert next(a.list_items())[0] == '2'
|
assert next(a.list())[0] == '2'
|
||||||
assert next(b.list_items())[0] == '2'
|
assert next(b.list())[0] == '2'
|
||||||
obj, uid, etag = next(a.get_items(['2']))
|
obj2_a, uid2_a, etag2_a = a.get('2')
|
||||||
assert obj.raw == item2.raw
|
assert obj2_a.raw == item2.raw
|
||||||
|
|
||||||
new_item2 = Item('UID:2\nHUEHUEHUE:PRECISELY')
|
new_item2 = Item('UID:2\nHUEHUEHUE:PRECISELY')
|
||||||
old_status = status.copy()
|
old_status = status.copy()
|
||||||
a.update(new_item2, next(a.list_items())[1])
|
a.update(new_item2, next(a.list())[1])
|
||||||
sync(a, b, status)
|
sync(a, b, status)
|
||||||
assert status != old_status
|
assert status != old_status
|
||||||
assert list(status) == list(old_status)
|
assert list(status) == list(old_status)
|
||||||
assert next(a.list_items())[0] == '2'
|
assert next(a.list())[0] == '2'
|
||||||
assert next(b.list_items())[0] == '2'
|
assert next(b.list())[0] == '2'
|
||||||
obj, uid, etag = next(b.get_items(['2']))
|
obj, uid, etag = b.get('2')
|
||||||
assert obj.raw == new_item2.raw
|
assert obj.raw == new_item2.raw
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue