diff --git a/tests/__init__.py b/tests/__init__.py index de8b0e7..e051c66 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -62,6 +62,28 @@ PRODID:-//hacksw/handcal//NONSGML v1.0//EN ''' + BARE_EVENT_TEMPLATE + u''' END:VCALENDAR''' +EVENT_WITH_TIMEZONE_TEMPLATE = '''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 +''' + BARE_EVENT_TEMPLATE + ''' +END:VCALENDAR''' + SIMPLE_TEMPLATE = u'''BEGIN:FOO UID:{uid} diff --git a/tests/unit/test_exceptions.py b/tests/unit/test_exceptions.py new file mode 100644 index 0000000..436f034 --- /dev/null +++ b/tests/unit/test_exceptions.py @@ -0,0 +1,14 @@ +from vdirsyncer import exceptions + + +def test_user_error_problems(): + e = exceptions.UserError('A few problems occured', problems=[ + 'Problem one', + 'Problem two', + 'Problem three' + ]) + + assert 'one' in str(e) + assert 'two' in str(e) + assert 'three' in str(e) + assert 'problems occured' in str(e) diff --git a/tests/unit/utils/test_vobject.py b/tests/unit/utils/test_vobject.py index 5d27b63..93c56b4 100644 --- a/tests/unit/utils/test_vobject.py +++ b/tests/unit/utils/test_vobject.py @@ -2,8 +2,14 @@ from textwrap import dedent -from tests import BARE_EVENT_TEMPLATE, EVENT_TEMPLATE, VCARD_TEMPLATE, \ - normalize_item +import hypothesis.strategies as st +from hypothesis import given + +import pytest + +from tests import BARE_EVENT_TEMPLATE, EVENT_TEMPLATE, \ + EVENT_WITH_TIMEZONE_TEMPLATE, VCARD_TEMPLATE, normalize_item, \ + uid_strategy import vdirsyncer.utils.vobject as vobject @@ -195,3 +201,16 @@ def test_multiline_uid_complex(): assert vobject.Item(a).uid == (u'040000008200E00074C5B7101A82E008000000005' u'0AAABEEF50DCF001000000062548482FA830A46B9' u'EA62114AC9F0EF') + + +@pytest.mark.parametrize('template', [EVENT_TEMPLATE, + EVENT_WITH_TIMEZONE_TEMPLATE, + VCARD_TEMPLATE]) +@given(uid=st.one_of(st.none(), uid_strategy)) +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('\nUID:{}'.format(uid)) == 1 + else: + assert '\nUID:' not in item.raw