mirror of
https://github.com/samsonjs/vdirsyncer.git
synced 2026-03-25 08:55:50 +00:00
Ability to handle missing UIDs.
This commit is contained in:
parent
50314418ec
commit
f4cdde9a52
2 changed files with 28 additions and 59 deletions
|
|
@ -18,25 +18,15 @@ class TestHttpStorage(object):
|
|||
def test_list(self, monkeypatch):
|
||||
collection_url = 'http://127.0.0.1/calendar/collection/'
|
||||
|
||||
responses = [
|
||||
items = [
|
||||
dedent(b'''
|
||||
BEGIN:VCALENDAR
|
||||
VERSION:2.0
|
||||
PRODID:http://www.example.com/calendarapplication/
|
||||
METHOD:PUBLISH
|
||||
BEGIN:VEVENT
|
||||
UID:461092315540@example.com
|
||||
LOCATION:Somewhere
|
||||
SUMMARY:Eine Kurzinfo
|
||||
DESCRIPTION:Beschreibung des Termines
|
||||
CLASS:PUBLIC
|
||||
DTSTART:20060910T220000Z
|
||||
DTEND:20060919T215900Z
|
||||
DTSTAMP:20060812T125900Z
|
||||
END:VEVENT
|
||||
''').strip(),
|
||||
dedent(b'''
|
||||
BEGIN:VEVENT
|
||||
UID:461092315asdasd540@example.com
|
||||
LOCATION:Somewhere else
|
||||
SUMMARY:Eine zweite Kurzinfo
|
||||
DESCRIPTION:Beschreibung des anderen Termines
|
||||
BEGIN:VALARM
|
||||
|
|
@ -47,8 +37,11 @@ class TestHttpStorage(object):
|
|||
DURATION:PT1H
|
||||
END:VALARM
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
''')
|
||||
''').strip()
|
||||
]
|
||||
|
||||
responses = [
|
||||
'\n'.join([b'BEGIN:VCALENDAR'] + items + [b'END:VCALENDAR'])
|
||||
]
|
||||
|
||||
def get(*a, **kw):
|
||||
|
|
@ -61,40 +54,10 @@ class TestHttpStorage(object):
|
|||
monkeypatch.setattr('requests.get', get)
|
||||
|
||||
s = HttpStorage(url=collection_url)
|
||||
l = list(s.list())
|
||||
|
||||
hrefs = set(href for href, etag in l)
|
||||
href1 = u'461092315540@example.com'
|
||||
href2 = u'461092315asdasd540@example.com'
|
||||
assert hrefs == set((href1, href2))
|
||||
for href, etag in s.list():
|
||||
item, etag2 = s.get(href)
|
||||
assert etag2 == etag
|
||||
items.remove(item.raw.strip())
|
||||
|
||||
item, etag = s.get(href1)
|
||||
assert_item_equals(item, Item(dedent(u'''
|
||||
BEGIN:VEVENT
|
||||
UID:461092315540@example.com
|
||||
LOCATION:Somewhere
|
||||
SUMMARY:Eine Kurzinfo
|
||||
DESCRIPTION:Beschreibung des Termines
|
||||
CLASS:PUBLIC
|
||||
DTSTART:20060910T220000Z
|
||||
DTEND:20060919T215900Z
|
||||
DTSTAMP:20060812T125900Z
|
||||
END:VEVENT
|
||||
''').strip()))
|
||||
|
||||
item, etag = s.get(href2)
|
||||
assert_item_equals(item, Item(dedent(u'''
|
||||
BEGIN:VEVENT
|
||||
UID:461092315asdasd540@example.com
|
||||
LOCATION:Somewhere else
|
||||
SUMMARY:Eine zweite Kurzinfo
|
||||
DESCRIPTION:Beschreibung des anderen Termines
|
||||
BEGIN:VALARM
|
||||
ACTION:AUDIO
|
||||
TRIGGER:19980403T120000
|
||||
ATTACH;FMTTYPE=audio/basic:http://host.com/pub/ssbanner.aud
|
||||
REPEAT:4
|
||||
DURATION:PT1H
|
||||
END:VALARM
|
||||
END:VEVENT
|
||||
''').strip()))
|
||||
assert not items
|
||||
|
|
|
|||
|
|
@ -65,7 +65,6 @@ def prepare_verify(verify):
|
|||
|
||||
class HttpStorageBase(Storage):
|
||||
_repr_attributes = ('username', 'url')
|
||||
_items = None
|
||||
|
||||
def __init__(self, url, username='', password='', collection=None,
|
||||
verify=True, auth=None, useragent='vdirsyncer', **kwargs):
|
||||
|
|
@ -106,20 +105,27 @@ class HttpStorageBase(Storage):
|
|||
|
||||
|
||||
class HttpStorage(HttpStorageBase):
|
||||
|
||||
_items = None
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super(HttpStorage, self).__init__(**kwargs)
|
||||
self._items = {}
|
||||
|
||||
def list(self):
|
||||
if self._items is None:
|
||||
r = requests.get(self.url, **self._settings)
|
||||
r.raise_for_status()
|
||||
self._items = {}
|
||||
for item in split_collection(r.text):
|
||||
self._items[item.uid] = item
|
||||
r = requests.get(self.url, **self._settings)
|
||||
r.raise_for_status()
|
||||
self._items.clear()
|
||||
for i, item in enumerate(split_collection(r.text)):
|
||||
uid = item.uid if item.uid is not None else i
|
||||
self._items[uid] = item
|
||||
|
||||
for uid, item in self._items.items():
|
||||
yield uid, hashlib.sha256(item.raw)
|
||||
yield uid, hashlib.sha256(item.raw).hexdigest()
|
||||
|
||||
def get(self, href):
|
||||
x = self._items[href]
|
||||
return x, hashlib.sha256(x.raw)
|
||||
return x, hashlib.sha256(x.raw).hexdigest()
|
||||
|
||||
def has(self, href):
|
||||
return href in self._items
|
||||
|
|
|
|||
Loading…
Reference in a new issue