From 600cc64e46ee549fa957778bbd93a5d31fef38a2 Mon Sep 17 00:00:00 2001 From: Markus Unterwaditzer Date: Sun, 9 Mar 2014 02:02:22 +0100 Subject: [PATCH] Add more tests for HttpStorage --- tests/storage/test_http.py | 111 +++++++++++++++++++++++++------------ vdirsyncer/storage/http.py | 2 + 2 files changed, 79 insertions(+), 34 deletions(-) diff --git a/tests/storage/test_http.py b/tests/storage/test_http.py index aa6e60f..f3d0821 100644 --- a/tests/storage/test_http.py +++ b/tests/storage/test_http.py @@ -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())) diff --git a/vdirsyncer/storage/http.py b/vdirsyncer/storage/http.py index 1d7105c..874fd69 100644 --- a/vdirsyncer/storage/http.py +++ b/vdirsyncer/storage/http.py @@ -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