示例#1
0
def test_split_collection_timezones():
    items = [
        BARE_EVENT_TEMPLATE.format(r=123, uid=123),
        BARE_EVENT_TEMPLATE.format(r=345, uid=345)
    ]

    timezone = (
        u'BEGIN:VTIMEZONE\r\n'
        u'TZID:/mozilla.org/20070129_1/Asia/Tokyo\r\n'
        u'X-LIC-LOCATION:Asia/Tokyo\r\n'
        u'BEGIN:STANDARD\r\n'
        u'TZOFFSETFROM:+0900\r\n'
        u'TZOFFSETTO:+0900\r\n'
        u'TZNAME:JST\r\n'
        u'DTSTART:19700101T000000\r\n'
        u'END:STANDARD\r\n'
        u'END:VTIMEZONE'
    )

    full = u'\r\n'.join(
        [u'BEGIN:VCALENDAR'] +
        items +
        [timezone, u'END:VCALENDAR']
    )

    given = set(normalize_item(item)
                for item in vobject.split_collection(full))
    expected = set(
        normalize_item(u'\r\n'.join((
            u'BEGIN:VCALENDAR', item, timezone, u'END:VCALENDAR'
        )))
        for item in items
    )

    assert given == expected
示例#2
0
def test_split_collection_timezones():
    items = [
        BARE_EVENT_TEMPLATE.format(r=123, uid=123),
        BARE_EVENT_TEMPLATE.format(r=345, uid=345),
    ]

    timezone = ("BEGIN:VTIMEZONE\r\n"
                "TZID:/mozilla.org/20070129_1/Asia/Tokyo\r\n"
                "X-LIC-LOCATION:Asia/Tokyo\r\n"
                "BEGIN:STANDARD\r\n"
                "TZOFFSETFROM:+0900\r\n"
                "TZOFFSETTO:+0900\r\n"
                "TZNAME:JST\r\n"
                "DTSTART:19700101T000000\r\n"
                "END:STANDARD\r\n"
                "END:VTIMEZONE")

    full = "\r\n".join(["BEGIN:VCALENDAR"] + items +
                       [timezone, "END:VCALENDAR"])

    given = {normalize_item(item) for item in vobject.split_collection(full)}
    expected = {
        normalize_item("\r\n".join(
            ("BEGIN:VCALENDAR", item, timezone, "END:VCALENDAR")))
        for item in items
    }

    assert given == expected
示例#3
0
def test_split_collection_timezones():
    items = [
        BARE_EVENT_TEMPLATE.format(r=123, uid=123),
        BARE_EVENT_TEMPLATE.format(r=345, uid=345)
    ]

    timezone = (u'BEGIN:VTIMEZONE\r\n'
                u'TZID:/mozilla.org/20070129_1/Asia/Tokyo\r\n'
                u'X-LIC-LOCATION:Asia/Tokyo\r\n'
                u'BEGIN:STANDARD\r\n'
                u'TZOFFSETFROM:+0900\r\n'
                u'TZOFFSETTO:+0900\r\n'
                u'TZNAME:JST\r\n'
                u'DTSTART:19700101T000000\r\n'
                u'END:STANDARD\r\n'
                u'END:VTIMEZONE')

    full = u'\r\n'.join([u'BEGIN:VCALENDAR'] + items +
                        [timezone, u'END:VCALENDAR'])

    given = set(
        normalize_item(item) for item in vobject.split_collection(full))
    expected = set(
        normalize_item(u'\r\n'.join((u'BEGIN:VCALENDAR', item, timezone,
                                     u'END:VCALENDAR'))) for item in items)

    assert given == expected
示例#4
0
def test_split_collection_multiple_wrappers(benchmark):
    joined = u"\r\n".join(u"BEGIN:VADDRESSBOOK\r\n" + x + u"\r\nEND:VADDRESSBOOK\r\n" for x in _simple_split)
    given = benchmark(lambda: list(vobject.split_collection(joined)))

    assert [normalize_item(item) for item in given] == [normalize_item(item) for item in _simple_split]

    assert [x.splitlines() for x in given] == [x.splitlines() for x in _simple_split]
示例#5
0
def test_list(monkeypatch):
    collection_url = "http://127.0.0.1/calendar/collection.ics"

    items = [
        ("BEGIN:VEVENT\n"
         "SUMMARY:Eine Kurzinfo\n"
         "DESCRIPTION:Beschreibung des Termines\n"
         "END:VEVENT"),
        ("BEGIN:VEVENT\n"
         "SUMMARY:Eine zweite Küèrzinfo\n"
         "DESCRIPTION:Beschreibung des anderen Termines\n"
         "BEGIN:VALARM\n"
         "ACTION:AUDIO\n"
         "TRIGGER:19980403T120000\n"
         "ATTACH;FMTTYPE=audio/basic:http://host.com/pub/ssbanner.aud\n"
         "REPEAT:4\n"
         "DURATION:PT1H\n"
         "END:VALARM\n"
         "END:VEVENT"),
    ]

    responses = ["\n".join(["BEGIN:VCALENDAR"] + items + ["END:VCALENDAR"])
                 ] * 2

    def get(self, method, url, *a, **kw):
        assert method == "GET"
        assert url == collection_url
        r = Response()
        r.status_code = 200
        assert responses
        r._content = responses.pop().encode("utf-8")
        r.headers["Content-Type"] = "text/calendar"
        r.encoding = "ISO-8859-1"
        return r

    monkeypatch.setattr("requests.sessions.Session.request", get)

    s = HttpStorage(url=collection_url)

    found_items = {}

    for href, etag in s.list():
        item, etag2 = s.get(href)
        assert item.uid is not None
        assert etag2 == etag
        found_items[normalize_item(item)] = href

    expected = {
        normalize_item("BEGIN:VCALENDAR\n" + x + "\nEND:VCALENDAR")
        for x in items
    }

    assert set(found_items) == expected

    for href, etag in s.list():
        item, etag2 = s.get(href)
        assert item.uid is not None
        assert etag2 == etag
        assert found_items[normalize_item(item)] == href
示例#6
0
def test_split_collection_simple(benchmark):
    given = benchmark(lambda: list(vobject.split_collection(_simple_joined)))

    assert [normalize_item(item) for item in given
            ] == [normalize_item(item) for item in _simple_split]

    assert [x.splitlines()
            for x in given] == [x.splitlines() for x in _simple_split]
示例#7
0
def test_split_collection_simple(benchmark):
    given = benchmark(lambda: list(vobject.split_collection(_simple_joined)))

    assert [normalize_item(item) for item in given] == \
        [normalize_item(item) for item in _simple_split]

    assert [x.splitlines() for x in given] == \
        [x.splitlines() for x in _simple_split]
示例#8
0
def test_list(monkeypatch):
    collection_url = 'http://127.0.0.1/calendar/collection.ics'

    items = [
        (u'BEGIN:VEVENT\n'
         u'SUMMARY:Eine Kurzinfo\n'
         u'DESCRIPTION:Beschreibung des Termines\n'
         u'END:VEVENT'),
        (u'BEGIN:VEVENT\n'
         u'SUMMARY:Eine zweite Küèrzinfo\n'
         u'DESCRIPTION:Beschreibung des anderen Termines\n'
         u'BEGIN:VALARM\n'
         u'ACTION:AUDIO\n'
         u'TRIGGER:19980403T120000\n'
         u'ATTACH;FMTTYPE=audio/basic:http://host.com/pub/ssbanner.aud\n'
         u'REPEAT:4\n'
         u'DURATION:PT1H\n'
         u'END:VALARM\n'
         u'END:VEVENT')
    ]

    responses = [
        u'\n'.join([u'BEGIN:VCALENDAR'] + items + [u'END:VCALENDAR'])
    ] * 2

    def get(self, method, url, *a, **kw):
        assert method == 'GET'
        assert url == collection_url
        r = Response()
        r.status_code = 200
        assert responses
        r._content = responses.pop().encode('utf-8')
        r.headers['Content-Type'] = 'text/icalendar'
        r.encoding = 'ISO-8859-1'
        return r

    monkeypatch.setattr('requests.sessions.Session.request', get)

    s = HttpStorage(url=collection_url)

    found_items = {}

    for href, etag in s.list():
        item, etag2 = s.get(href)
        assert item.uid is None
        assert etag2 == etag
        found_items[normalize_item(item)] = href

    expected = set(normalize_item(u'BEGIN:VCALENDAR\n' + x + '\nEND:VCALENDAR')
                   for x in items)

    assert set(found_items) == expected

    for href, etag in s.list():
        item, etag2 = s.get(href)
        assert item.uid is None
        assert etag2 == etag
        assert found_items[normalize_item(item)] == href
示例#9
0
def test_list(monkeypatch):
    collection_url = 'http://127.0.0.1/calendar/collection.ics'

    items = [
        (u'BEGIN:VEVENT\n'
         u'SUMMARY:Eine Kurzinfo\n'
         u'DESCRIPTION:Beschreibung des Termines\n'
         u'END:VEVENT'),
        (u'BEGIN:VEVENT\n'
         u'SUMMARY:Eine zweite Küèrzinfo\n'
         u'DESCRIPTION:Beschreibung des anderen Termines\n'
         u'BEGIN:VALARM\n'
         u'ACTION:AUDIO\n'
         u'TRIGGER:19980403T120000\n'
         u'ATTACH;FMTTYPE=audio/basic:http://host.com/pub/ssbanner.aud\n'
         u'REPEAT:4\n'
         u'DURATION:PT1H\n'
         u'END:VALARM\n'
         u'END:VEVENT')
    ]

    responses = [
        u'\n'.join([u'BEGIN:VCALENDAR'] + items + [u'END:VCALENDAR'])
    ] * 2

    def get(method, url, *a, **kw):
        assert method == 'GET'
        assert url == collection_url
        r = Response()
        r.status_code = 200
        assert responses
        r._content = responses.pop().encode('utf-8')
        r.headers['Content-Type'] = 'text/icalendar'
        r.encoding = 'ISO-8859-1'
        return r

    monkeypatch.setattr('requests.request', get)

    s = HttpStorage(url=collection_url)

    found_items = {}

    for href, etag in s.list():
        item, etag2 = s.get(href)
        assert item.uid is None
        assert etag2 == etag
        found_items[normalize_item(item)] = href

    expected = set(normalize_item(u'BEGIN:VCALENDAR\n' + x + '\nEND:VCALENDAR')
                   for x in items)

    assert set(found_items) == expected

    for href, etag in s.list():
        item, etag2 = s.get(href)
        assert item.uid is None
        assert etag2 == etag
        assert found_items[normalize_item(item)] == href
示例#10
0
def test_split_collection_multiple_wrappers(benchmark):
    joined = "\r\n".join("BEGIN:VADDRESSBOOK\r\n" + x +
                         "\r\nEND:VADDRESSBOOK\r\n" for x in _simple_split)
    given = benchmark(lambda: list(vobject.split_collection(joined)))

    assert [normalize_item(item) for item in given
            ] == [normalize_item(item) for item in _simple_split]

    assert [x.splitlines()
            for x in given] == [x.splitlines() for x in _simple_split]
示例#11
0
def test_join_collection_simple(benchmark):
    given = benchmark(lambda: vobject.join_collection(_simple_split))
    assert normalize_item(given) == normalize_item(_simple_joined)
    assert given.splitlines() == _simple_joined.splitlines()
示例#12
0
def test_join_collection_simple(benchmark):
    given = benchmark(lambda: vobject.join_collection(_simple_split))
    assert normalize_item(given) == normalize_item(_simple_joined)
    assert given.splitlines() == _simple_joined.splitlines()