Beispiel #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(vobject.Item(item).hash
                for item in vobject.split_collection(full))
    expected = set(
        vobject.Item(u'\r\n'.join((
            u'BEGIN:VCALENDAR', item, timezone, u'END:VCALENDAR'
        ))).hash
        for item in items
    )

    assert given == expected
Beispiel #2
0
def test_split_collection_simple(benchmark):
    given = benchmark(lambda: list(vobject.split_collection(_simple_joined)))

    assert [vobject.Item(item).hash for item in given] == \
        [vobject.Item(item).hash for item in _simple_split]

    assert [x.splitlines() for x in given] == \
        [x.splitlines() for x in _simple_split]
Beispiel #3
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 [vobject.Item(item).hash for item in given] == \
        [vobject.Item(item).hash for item in _simple_split]

    assert [x.splitlines() for x in given] == \
        [x.splitlines() for x in _simple_split]
Beispiel #4
0
def test_hash_item_timezones():
    item1 = vobject.Item('BEGIN:VCALENDAR\r\n'
                         'HELLO:HAHA\r\n'
                         'BEGIN:VTIMEZONE\r\n'
                         'PROP:YES\r\n'
                         'END:VTIMEZONE\r\n'
                         'END:VCALENDAR\r\n')

    item2 = vobject.Item('BEGIN:VCALENDAR\r\n'
                         'HELLO:HAHA\r\n'
                         'END:VCALENDAR\r\n')

    assert item1.hash == item2.hash
Beispiel #5
0
def test_hash_item_line_wrapping():
    item1 = vobject.Item(
        'BEGIN:VCALENDAR\r\n'
        'PROP:a\r\n'
        ' b\r\n'
        ' c\r\n'
        'END:VCALENDAR\r\n'
    )

    item2 = vobject.Item(
        'BEGIN:VCALENDAR\r\n'
        'PROP:abc\r\n'
        'END:VCALENDAR\r\n'
    )

    assert item1.hash == item2.hash
Beispiel #6
0
def test_replace_uid(template, uid):
    item = vobject.Item(template.format(r=123, uid=123)).with_uid(uid)
    assert item.uid == uid
    if uid:
        assert item.raw.count(f"\nUID:{uid}") == 1
    else:
        assert "\nUID:" not in item.raw
Beispiel #7
0
def test_hash_item():
    item1 = vobject.Item('BEGIN:FOO\r\n'
                         'X-RADICALE-NAME:YES\r\n'
                         'END:FOO\r\n')

    item2 = vobject.Item('BEGIN:FOO\r\n'
                         'X-RADICALE-NAME:NO\r\n'
                         'END:FOO\r\n')

    assert item1.hash == item2.hash

    item2 = vobject.Item('BEGIN:FOO\r\n'
                         'X-RADICALE-NAME:NO\r\n'
                         'OTHER-PROP:YAY\r\n'
                         'END:FOO\r\n')

    assert item1.hash != item2.hash
Beispiel #8
0
def test_broken_item():
    with pytest.raises(ValueError) as excinfo:
        vobject._Component.parse('END:FOO')

    assert 'Parsing error at line 1' in str(excinfo.value)

    item = vobject.Item('END:FOO')
    assert not item.is_parseable
Beispiel #9
0
def test_broken_item():
    with pytest.raises(ValueError) as excinfo:
        vobject._Component.parse("END:FOO")

    assert "Parsing error at line 1" in str(excinfo.value)

    item = vobject.Item("END:FOO")
    assert item.parsed is None
Beispiel #10
0
def test_multiline_uid_complex():
    a = dedent(u'''
        BEGIN:VCALENDAR
        BEGIN:VTIMEZONE
        TZID:Europe/Rome
        X-LIC-LOCATION:Europe/Rome
        BEGIN:DAYLIGHT
        TZOFFSETFROM:+0100
        TZOFFSETTO:+0200
        TZNAME:CEST
        DTSTART:19700329T020000
        RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=3
        END:DAYLIGHT
        BEGIN:STANDARD
        TZOFFSETFROM:+0200
        TZOFFSETTO:+0100
        TZNAME:CET
        DTSTART:19701025T030000
        RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10
        END:STANDARD
        END:VTIMEZONE
        BEGIN:VEVENT
        DTSTART:20140124T133000Z
        DTEND:20140124T143000Z
        DTSTAMP:20140612T090652Z
        UID:040000008200E00074C5B7101A82E0080000000050AAABEEF50DCF
         001000000062548482FA830A46B9EA62114AC9F0EF
        CREATED:20140110T102231Z
        DESCRIPTION:Test.
        LAST-MODIFIED:20140123T095221Z
        LOCATION:25.12.01.51
        SEQUENCE:0
        STATUS:CONFIRMED
        SUMMARY:Präsentation
        TRANSP:OPAQUE
        END:VEVENT
        END:VCALENDAR
        ''').strip()
    assert vobject.Item(a).uid == (u'040000008200E00074C5B7101A82E008000000005'
                                   u'0AAABEEF50DCF001000000062548482FA830A46B9'
                                   u'EA62114AC9F0EF')
Beispiel #11
0
 def inner():
     return vobject.Item(complex_uid_item).with_uid("a").uid
Beispiel #12
0
def test_hash_item2():
    a = EVENT_TEMPLATE.format(r=1, uid=1)
    b = u'\n'.join(line for line in a.splitlines()
                   if u'PRODID' not in line)
    assert vobject.Item(a).hash == vobject.Item(b).hash
Beispiel #13
0
def test_multiline_uid_complex(benchmark):
    assert benchmark(lambda: vobject.Item(complex_uid_item).uid) == (
        "040000008200E00074C5B7101A82E008000000005"
        "0AAABEEF50DCF001000000062548482FA830A46B9"
        "EA62114AC9F0EF")
Beispiel #14
0
def test_multiline_uid(benchmark):
    a = "BEGIN:FOO\r\n" "UID:123456789abcd\r\n" " efgh\r\n" "END:FOO\r\n"
    assert benchmark(lambda: vobject.Item(a).uid) == "123456789abcdefgh"
Beispiel #15
0
def test_multiline_uid(benchmark):
    a = ('BEGIN:FOO\r\n' 'UID:123456789abcd\r\n' ' efgh\r\n' 'END:FOO\r\n')
    assert benchmark(lambda: vobject.Item(a).uid) == '123456789abcdefgh'
Beispiel #16
0
def test_join_collection_simple(benchmark):
    given = benchmark(lambda: vobject.join_collection(_simple_split))
    assert vobject.Item(given).hash == vobject.Item(_simple_joined).hash
    assert given.splitlines() == _simple_joined.splitlines()
Beispiel #17
0
    def inner(split):
        joined = benchmark(lambda: vobject.join_collection(split))
        split2 = benchmark(lambda: list(vobject.split_collection(joined)))

        assert [vobject.Item(item).hash for item in split] == \
            [vobject.Item(item).hash for item in split2]