mirror of
https://github.com/samsonjs/vdirsyncer.git
synced 2026-04-27 14:57:41 +00:00
Fix http storage tests
This commit is contained in:
parent
8b7b55cdc2
commit
8f1531a4b2
2 changed files with 79 additions and 71 deletions
|
|
@ -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'
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue