diff --git a/tests/test_sync.py b/tests/test_sync.py index a2b7644..ac368a9 100644 --- a/tests/test_sync.py +++ b/tests/test_sync.py @@ -2,6 +2,8 @@ import pytest +from copy import deepcopy + import vdirsyncer.exceptions as exceptions from vdirsyncer.storage.base import Item from vdirsyncer.storage.memory import MemoryStorage @@ -336,12 +338,19 @@ def test_moved_href(): sync(a, b, status) b.items['lol'] = b.items.pop('haha') - a.delete = a.update = a.upload = blow_up + a.delete = a.update = a.upload = b.delete = b.update = b.upload = blow_up sync(a, b, status) assert len(status) == 1 assert len(list(a.list())) == len(list(b.list())) == 1 - assert status['haha'][1]['href'] == 'haha' + assert status['haha'][1]['href'] == 'lol' + old_status = deepcopy(status) + + # Further sync should be a noop + b.get_multi = blow_up + sync(a, b, status) + assert old_status == status + assert len(list(a.list())) == len(list(b.list())) == 1 def test_bogus_etag_change(): diff --git a/vdirsyncer/sync.py b/vdirsyncer/sync.py index c15cb81..80b787b 100644 --- a/vdirsyncer/sync.py +++ b/vdirsyncer/sync.py @@ -81,7 +81,7 @@ class StorageSyncer(object): things.''' def __init__(self, storage, status): ''' - :param status: {ident: (href, etag)} + :param status: {ident: {'href': href, 'etag': etag}} ''' self.storage = storage self.status = status @@ -101,6 +101,11 @@ class StorageSyncer(object): hrefs=[self.idents[ident]['href'], href]) + if ident in self.status: + # Necessary if item's href changes. + # Otherwise it's a no-op, like `a = a`. + self.status[ident]['href'] = props['href'] + for href, etag in self.storage.list(): props = {'href': href, 'etag': etag} ident, old_meta = href_to_status.get(href, (None, None))