diff --git a/tests/storage/test_http.py b/tests/storage/test_http.py index c65315a..85c5f4d 100644 --- a/tests/storage/test_http.py +++ b/tests/storage/test_http.py @@ -7,11 +7,61 @@ :license: MIT, see LICENSE for more details. ''' -from vdirsyncer.storage.http import HttpStorage +from vdirsyncer.storage.http import HttpStorage, split_collection from requests import Response -def test_list(self, monkeypatch): +def test_split_collection_timezones(): + items = [ + ( + u'BEGIN:VEVENT', + u'SUMMARY:Eine Kurzinfo', + u'DESCRIPTION:Beschreibung des Termines', + u'END:VEVENT' + ), + ( + u'BEGIN:VEVENT', + u'SUMMARY:Eine zweite Kurzinfo', + u'DESCRIPTION:Beschreibung des anderen Termines', + u' With an extra line for description', + u'BEGIN:VALARM', + u'ACTION:AUDIO', + u'TRIGGER:19980403T120000', + u'ATTACH;FMTTYPE=audio/basic:http://host.com/pub/ssbanner.aud', + u'REPEAT:4', + u'DURATION:PT1H', + u'END:VALARM', + u'END:VEVENT' + ) + ] + + timezone = ( + u'BEGIN:VTIMEZONE', + u'TZID:/mozilla.org/20070129_1/Asia/Tokyo', + u'X-LIC-LOCATION:Asia/Tokyo', + u'BEGIN:STANDARD', + u'TZOFFSETFROM:+0900', + u'TZOFFSETTO:+0900', + u'TZNAME:JST', + u'DTSTART:19700101T000000', + u'END:STANDARD', + u'END:VTIMEZONE' + ) + + full = u'\n'.join( + (u'BEGIN:VCALENDAR',) + + timezone + tuple(line for item in items for line in item) + + (u'END:VCALENDAR',) + ) + + given = [tuple(x.raw.splitlines()) for x in split_collection(full)] + expected = [item[:-1] + timezone + (item[-1],) for item in items] + print(given) + print(expected) + assert given == expected + + +def test_list(monkeypatch): collection_url = 'http://127.0.0.1/calendar/collection.ics' items = [ diff --git a/vdirsyncer/storage/http.py b/vdirsyncer/storage/http.py index e76b104..65818ff 100644 --- a/vdirsyncer/storage/http.py +++ b/vdirsyncer/storage/http.py @@ -16,9 +16,17 @@ USERAGENT = 'vdirsyncer' def split_collection(text): + ''' + This is a horrible "parser", but Python tooling isn't much better. The only + library which supports both calendars and addressbooks (VObject) is Python + 2 only and doesn't seem maintained anymore, the other one (icalendar) only + handles calendars... which wouldn't eliminate this function anyway. Let's + just hope this handles all cases. + ''' item = [] collection_type = None item_type = None + timezone = None for line in text.splitlines(): if u':' not in line: item.append(line) @@ -30,15 +38,21 @@ def split_collection(text): elif item_type is None: item_type = value item.append(line) + if item_type == u'VTIMEZONE': + timezone = item else: item.append(line) elif key == u'END': if value == collection_type: break elif value == item_type: + if timezone is not None and item_type != u'VTIMEZONE': + item.extend(timezone) item.append(line) - yield Item(u'\n'.join(item)) + if item_type != u'VTIMEZONE': + yield Item(u'\n'.join(item)) item = [] + item_type = None else: item.append(line) else: