Fix http storage tests

This commit is contained in:
Markus Unterwaditzer 2014-03-28 20:45:02 +01:00
parent 8b7b55cdc2
commit 8f1531a4b2
2 changed files with 79 additions and 71 deletions

View file

@ -7,21 +7,19 @@
:license: MIT, see LICENSE for more details. :license: MIT, see LICENSE for more details.
''' '''
import mock
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 from vdirsyncer.storage.http import HttpStorage, Item
from requests import Response
class TestHttpStorage(object): class TestHttpStorage(object):
def test_list(self): def test_list(self, monkeypatch):
collection_url = 'http://127.0.0.1/calendar/collection/' collection_url = 'http://127.0.0.1/calendar/collection/'
with mock.patch('requests.get') as p: responses = [
p.return_value = r = mock.Mock() dedent(b'''
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/
@ -51,10 +49,20 @@ class TestHttpStorage(object):
END:VEVENT END:VEVENT
END:VCALENDAR END:VCALENDAR
''') ''')
s = HttpStorage(url=collection_url) ]
def get(*a, **kw):
r = Response()
r.status_code = 200
assert responses
r._content = responses.pop()
return r
monkeypatch.setattr('requests.get', get)
s = HttpStorage(url=collection_url)
l = list(s.list()) l = list(s.list())
r.side_effect = IOError('Nope.')
hrefs = set(href for href, etag in l) hrefs = set(href for href, etag in l)
href1 = u'461092315540@example.com' href1 = u'461092315540@example.com'
href2 = u'461092315asdasd540@example.com' href2 = u'461092315asdasd540@example.com'

View file

@ -109,7 +109,7 @@ class HttpStorage(HttpStorageBase):
def list(self): def list(self):
if self._items is None: if self._items is None:
r = requests.get(self.url, **self._settings) r = requests.get(self.url, **self._settings)
r.raise_on_status() r.raise_for_status()
self._items = {} self._items = {}
for item in split_collection(r.text): for item in split_collection(r.text):
self._items[item.uid] = item self._items[item.uid] = item