Add testcase for #70

This commit is contained in:
Markus Unterwaditzer 2014-05-30 16:53:22 +02:00
parent c54836b1cf
commit f59c8d1fdf
3 changed files with 13 additions and 14 deletions

View file

@ -18,7 +18,8 @@ vdirsyncer.log.set_level(vdirsyncer.log.logging.DEBUG)
def normalize_item(item):
if not isinstance(item, text_type):
item = item.raw
return tuple(sorted(_normalize_item(item).splitlines()))
return tuple(sorted(_normalize_item(
item, use_icalendar=False).splitlines()))
def assert_item_equals(a, b):

View file

@ -10,22 +10,21 @@
from vdirsyncer.utils.vobject import split_collection, join_collection, \
hash_item
from .. import normalize_item, SIMPLE_TEMPLATE, BARE_EVENT_TEMPLATE, \
from .. import normalize_item, VCARD_TEMPLATE, BARE_EVENT_TEMPLATE, \
EVENT_TEMPLATE
_simple_joined = u'\r\n'.join((
u'BEGIN:VADDRESSBOOK',
SIMPLE_TEMPLATE.format(r=123),
SIMPLE_TEMPLATE.format(r=345),
SIMPLE_TEMPLATE.format(r=678),
VCARD_TEMPLATE.format(r=123),
VCARD_TEMPLATE.format(r=345),
VCARD_TEMPLATE.format(r=678),
u'END:VADDRESSBOOK'
))
_simple_split = [
SIMPLE_TEMPLATE.format(r=123),
SIMPLE_TEMPLATE.format(r=345),
SIMPLE_TEMPLATE.format(r=678)
VCARD_TEMPLATE.format(r=123),
VCARD_TEMPLATE.format(r=345),
VCARD_TEMPLATE.format(r=678)
]
@ -36,10 +35,7 @@ def test_split_collection_simple():
def test_join_collection_simple():
item_type = _simple_split[0].splitlines()[0][len(u'BEGIN:'):]
given = join_collection(_simple_split, wrappers={
item_type: (u'VADDRESSBOOK', ())
})
given = join_collection(_simple_split)
print(given)
print(_simple_joined)
assert normalize_item(given) == normalize_item(_simple_joined)

View file

@ -27,8 +27,10 @@ IGNORE_PROPS = frozenset((
))
def normalize_item(text, ignore_props=IGNORE_PROPS):
def normalize_item(text, ignore_props=IGNORE_PROPS, use_icalendar=True):
try:
if not use_icalendar:
raise Exception()
lines = to_unicode_lines(icalendar.cal.Component.from_ical(text))
except Exception:
lines = sorted(text.splitlines())