mirror of
https://github.com/samsonjs/vdirsyncer.git
synced 2026-03-25 08:55:50 +00:00
Add more tests for HttpStorage
This commit is contained in:
parent
5e2c66ece1
commit
600cc64e46
2 changed files with 79 additions and 34 deletions
|
|
@ -7,7 +7,10 @@
|
|||
:license: MIT, see LICENSE for more details.
|
||||
'''
|
||||
|
||||
import mock
|
||||
import requests
|
||||
from unittest import TestCase
|
||||
from . import StorageTests
|
||||
from .. import assert_item_equals
|
||||
from textwrap import dedent
|
||||
from vdirsyncer.storage.http import HttpStorage, Item, split_collection
|
||||
|
|
@ -15,40 +18,80 @@ from vdirsyncer.storage.http import HttpStorage, Item, split_collection
|
|||
|
||||
class HttpStorageTests(TestCase):
|
||||
|
||||
def _get_storage(self, **kwargs):
|
||||
return HttpStorage(**kwargs)
|
||||
def test_list(self):
|
||||
collection_url = 'http://127.0.0.1/calendar/collection/'
|
||||
|
||||
def test_split_collection(self):
|
||||
(item,) = list(split_collection(
|
||||
dedent(u'''
|
||||
BEGIN:VCALENDAR
|
||||
VERSION:2.0
|
||||
PRODID:http://www.example.com/calendarapplication/
|
||||
METHOD:PUBLISH
|
||||
BEGIN:VEVENT
|
||||
UID:461092315540@example.com
|
||||
ORGANIZER;CN="Alice Balder, Example Inc.":MAILTO:alice@example.com
|
||||
LOCATION:Somewhere
|
||||
SUMMARY:Eine Kurzinfo
|
||||
DESCRIPTION:Beschreibung des Termines
|
||||
CLASS:PUBLIC
|
||||
DTSTART:20060910T220000Z
|
||||
DTEND:20060919T215900Z
|
||||
DTSTAMP:20060812T125900Z
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
with mock.patch('requests.get') as p:
|
||||
p.return_value = r = mock.Mock()
|
||||
r.status_code = 200
|
||||
r.text = dedent(u'''
|
||||
BEGIN:VCALENDAR
|
||||
VERSION:2.0
|
||||
PRODID:http://www.example.com/calendarapplication/
|
||||
METHOD:PUBLISH
|
||||
BEGIN:VEVENT
|
||||
UID:461092315540@example.com
|
||||
ORGANIZER;CN="Alice Balder, Example Inc.":MAILTO:alice@example.com
|
||||
LOCATION:Somewhere
|
||||
SUMMARY:Eine Kurzinfo
|
||||
DESCRIPTION:Beschreibung des Termines
|
||||
CLASS:PUBLIC
|
||||
DTSTART:20060910T220000Z
|
||||
DTEND:20060919T215900Z
|
||||
DTSTAMP:20060812T125900Z
|
||||
END:VEVENT
|
||||
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/audio-files/ssbanner.aud
|
||||
REPEAT:4
|
||||
DURATION:PT1H
|
||||
END:VALARM
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
''')
|
||||
))
|
||||
assert_item_equals(item, Item(dedent(u'''
|
||||
BEGIN:VEVENT
|
||||
UID:461092315540@example.com
|
||||
ORGANIZER;CN="Alice Balder, Example Inc.":MAILTO:alice@example.com
|
||||
LOCATION:Somewhere
|
||||
SUMMARY:Eine Kurzinfo
|
||||
DESCRIPTION:Beschreibung des Termines
|
||||
CLASS:PUBLIC
|
||||
DTSTART:20060910T220000Z
|
||||
DTEND:20060919T215900Z
|
||||
DTSTAMP:20060812T125900Z
|
||||
END:VEVENT
|
||||
s = HttpStorage(url=collection_url)
|
||||
|
||||
l = list(s.list())
|
||||
r.side_effect = IOError('Nope.')
|
||||
hrefs = set(href for href, etag in l)
|
||||
href1 = u'461092315540@example.com'
|
||||
href2 = u'461092315asdasd540@example.com'
|
||||
assert hrefs == set((href1, href2))
|
||||
|
||||
item, etag = s.get(href1)
|
||||
assert_item_equals(item, Item(dedent(u'''
|
||||
BEGIN:VEVENT
|
||||
UID:461092315540@example.com
|
||||
ORGANIZER;CN="Alice Balder, Example Inc.":MAILTO:alice@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/audio-files/ssbanner.aud
|
||||
REPEAT:4
|
||||
DURATION:PT1H
|
||||
END:VALARM
|
||||
END:VEVENT
|
||||
''').strip()))
|
||||
|
|
|
|||
|
|
@ -27,6 +27,8 @@ def split_collection(text):
|
|||
elif item_type is None:
|
||||
item_type = value
|
||||
item.append(line)
|
||||
else:
|
||||
item.append(line)
|
||||
elif key == u'END':
|
||||
if value == collection_type:
|
||||
break
|
||||
|
|
|
|||
Loading…
Reference in a new issue