mirror of
https://github.com/samsonjs/vdirsyncer.git
synced 2026-04-27 14:57:41 +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.
|
:license: MIT, see LICENSE for more details.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
import mock
|
||||||
|
import requests
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
|
from . import StorageTests
|
||||||
from .. import assert_item_equals
|
from .. import assert_item_equals
|
||||||
from textwrap import dedent
|
from textwrap import dedent
|
||||||
from vdirsyncer.storage.http import HttpStorage, Item, split_collection
|
from vdirsyncer.storage.http import HttpStorage, Item, split_collection
|
||||||
|
|
@ -15,12 +18,13 @@ from vdirsyncer.storage.http import HttpStorage, Item, split_collection
|
||||||
|
|
||||||
class HttpStorageTests(TestCase):
|
class HttpStorageTests(TestCase):
|
||||||
|
|
||||||
def _get_storage(self, **kwargs):
|
def test_list(self):
|
||||||
return HttpStorage(**kwargs)
|
collection_url = 'http://127.0.0.1/calendar/collection/'
|
||||||
|
|
||||||
def test_split_collection(self):
|
with mock.patch('requests.get') as p:
|
||||||
(item,) = list(split_collection(
|
p.return_value = r = mock.Mock()
|
||||||
dedent(u'''
|
r.status_code = 200
|
||||||
|
r.text = dedent(u'''
|
||||||
BEGIN:VCALENDAR
|
BEGIN:VCALENDAR
|
||||||
VERSION:2.0
|
VERSION:2.0
|
||||||
PRODID:http://www.example.com/calendarapplication/
|
PRODID:http://www.example.com/calendarapplication/
|
||||||
|
|
@ -36,9 +40,31 @@ class HttpStorageTests(TestCase):
|
||||||
DTEND:20060919T215900Z
|
DTEND:20060919T215900Z
|
||||||
DTSTAMP:20060812T125900Z
|
DTSTAMP:20060812T125900Z
|
||||||
END:VEVENT
|
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
|
END:VCALENDAR
|
||||||
''')
|
''')
|
||||||
))
|
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'''
|
assert_item_equals(item, Item(dedent(u'''
|
||||||
BEGIN:VEVENT
|
BEGIN:VEVENT
|
||||||
UID:461092315540@example.com
|
UID:461092315540@example.com
|
||||||
|
|
@ -52,3 +78,20 @@ class HttpStorageTests(TestCase):
|
||||||
DTSTAMP:20060812T125900Z
|
DTSTAMP:20060812T125900Z
|
||||||
END:VEVENT
|
END:VEVENT
|
||||||
''').strip()))
|
''').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:
|
elif item_type is None:
|
||||||
item_type = value
|
item_type = value
|
||||||
item.append(line)
|
item.append(line)
|
||||||
|
else:
|
||||||
|
item.append(line)
|
||||||
elif key == u'END':
|
elif key == u'END':
|
||||||
if value == collection_type:
|
if value == collection_type:
|
||||||
break
|
break
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue