Switch sync tests to function-based

This commit is contained in:
Markus Unterwaditzer 2014-03-16 10:47:28 +01:00
parent 27888317d1
commit b3a720be75

View file

@ -8,6 +8,7 @@
'''
from unittest import TestCase
import pytest
from vdirsyncer.storage.base import Item
from vdirsyncer.storage.memory import MemoryStorage
from vdirsyncer.sync import sync
@ -19,9 +20,7 @@ def empty_storage(x):
return list(x.list()) == []
class SyncTests(TestCase):
def test_irrelevant_status(self):
def test_irrelevant_status():
a = MemoryStorage()
b = MemoryStorage()
status = {'1': ('1.txt', 1234, '1.ics', 2345)}
@ -30,7 +29,7 @@ class SyncTests(TestCase):
assert empty_storage(a)
assert empty_storage(b)
def test_missing_status(self):
def test_missing_status():
a = MemoryStorage()
b = MemoryStorage()
status = {}
@ -42,7 +41,7 @@ class SyncTests(TestCase):
assert a.has('1.txt')
assert b.has('1.txt')
def test_missing_status_and_different_items(self):
def test_missing_status_and_different_items():
return # TODO
a = MemoryStorage()
b = MemoryStorage()
@ -55,7 +54,7 @@ class SyncTests(TestCase):
assert status
assert_item_equals(a.get('1.txt')[0], b.get('1.txt')[0])
def test_upload_and_update(self):
def test_upload_and_update():
a = MemoryStorage()
b = MemoryStorage()
status = {}
@ -80,7 +79,7 @@ class SyncTests(TestCase):
sync(a, b, status)
assert_item_equals(b.get('2.txt')[0], item2)
def test_deletion(self):
def test_deletion():
a = MemoryStorage()
b = MemoryStorage()
status = {}
@ -99,7 +98,7 @@ class SyncTests(TestCase):
sync(a, b, status)
assert not a.has('1.txt') and not b.has('1.txt')
def test_already_synced(self):
def test_already_synced():
a = MemoryStorage()
b = MemoryStorage()
item = Item(u'UID:1')
@ -110,12 +109,12 @@ class SyncTests(TestCase):
}
old_status = dict(status)
a.update = b.update = a.upload = b.upload = \
lambda *a, **kw: self.fail('Method shouldn\'t have been called.')
lambda *a, **kw: pytest.fail('Method shouldn\'t have been called.')
sync(a, b, status)
assert status == old_status
assert a.has('1.txt') and b.has('1.txt')
def test_conflict_resolution_both_etags_new(self):
def test_conflict_resolution_both_etags_new():
a = MemoryStorage()
b = MemoryStorage()
item = Item(u'UID:1')
@ -126,7 +125,8 @@ class SyncTests(TestCase):
assert status
a.update(href_a, Item(u'UID:1\nASDASD'), etag_a)
b.update(href_b, Item(u'UID:1\nHUEHUE'), etag_b)
self.assertRaises(exceptions.SyncConflict, sync, a, b, status)
with pytest.raises(exceptions.SyncConflict):
sync(a, b, status)
sync(a, b, status, conflict_resolution='a wins')
obj_a, _ = a.get(href_a)
obj_b, _ = b.get(href_b)
@ -135,7 +135,7 @@ class SyncTests(TestCase):
assert u'UID:1' in n
assert u'ASDASD' in n
def tset_conflict_resolution_new_etags_without_changes(self):
def test_conflict_resolution_new_etags_without_changes():
a = MemoryStorage()
b = MemoryStorage()
item = Item(u'UID:1')