vdirsyncer/tests/storage/test_http.py
2014-04-04 13:20:18 +02:00

63 lines
1.8 KiB
Python

# -*- coding: utf-8 -*-
'''
tests.storage.test_http
~~~~~~~~~~~~~~~~~~~~~~~
:copyright: (c) 2014 Markus Unterwaditzer
:license: MIT, see LICENSE for more details.
'''
from .. import assert_item_equals
from textwrap import dedent
from vdirsyncer.storage.http import HttpStorage, Item
from requests import Response
class TestHttpStorage(object):
def test_list(self, monkeypatch):
collection_url = 'http://127.0.0.1/calendar/collection/'
items = [
dedent(b'''
BEGIN:VEVENT
SUMMARY:Eine Kurzinfo
DESCRIPTION:Beschreibung des Termines
END:VEVENT
''').strip(),
dedent(b'''
BEGIN:VEVENT
SUMMARY:Eine zweite Kurzinfo
DESCRIPTION:Beschreibung des anderen Termines
BEGIN:VALARM
ACTION:AUDIO
TRIGGER:19980403T120000
ATTACH;FMTTYPE=audio/basic:http://host.com/pub/ssbanner.aud
REPEAT:4
DURATION:PT1H
END:VALARM
END:VEVENT
''').strip()
]
responses = [
'\n'.join([b'BEGIN:VCALENDAR'] + items + [b'END:VCALENDAR'])
]
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)
for href, etag in s.list():
item, etag2 = s.get(href)
assert etag2 == etag
items.remove(item.raw.strip())
assert not items