mirror of
https://github.com/samsonjs/vdirsyncer.git
synced 2026-04-16 12:35:53 +00:00
New testcases for vobject joining
This commit is contained in:
parent
6bd5bf7422
commit
4857292b5c
2 changed files with 46 additions and 11 deletions
|
|
@ -6,7 +6,7 @@
|
|||
:copyright: (c) 2014 Markus Unterwaditzer & contributors
|
||||
:license: MIT, see LICENSE for more details.
|
||||
'''
|
||||
import textwrap
|
||||
from textwrap import dedent
|
||||
|
||||
import icalendar
|
||||
|
||||
|
|
@ -80,6 +80,39 @@ def test_join_collection_simple():
|
|||
assert given.splitlines() == _simple_joined.splitlines()
|
||||
|
||||
|
||||
def test_join_collection_vevents():
|
||||
actual = vobject.join_collection([
|
||||
dedent("""
|
||||
BEGIN:VCALENDAR
|
||||
BEGIN:VTIMEZONE
|
||||
VALUE:The Timezone
|
||||
END:VTIMEZONE
|
||||
BEGIN:VEVENT
|
||||
VALUE:Event {}
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
""").format(i) for i in range(3)
|
||||
])
|
||||
expected = dedent("""
|
||||
BEGIN:VCALENDAR
|
||||
BEGIN:VTIMEZONE
|
||||
VALUE:The Timezone
|
||||
END:VTIMEZONE
|
||||
BEGIN:VEVENT
|
||||
VALUE:Event 0
|
||||
END:VEVENT
|
||||
BEGIN:VEVENT
|
||||
VALUE:Event 1
|
||||
END:VEVENT
|
||||
BEGIN:VEVENT
|
||||
VALUE:Event 2
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
""").lstrip()
|
||||
|
||||
assert actual.splitlines() == expected.splitlines()
|
||||
|
||||
|
||||
def test_split_collection_timezones():
|
||||
items = [
|
||||
BARE_EVENT_TEMPLATE.format(r=123),
|
||||
|
|
@ -133,7 +166,7 @@ def test_multiline_uid():
|
|||
|
||||
|
||||
def test_multiline_uid_complex():
|
||||
a = textwrap.dedent(u'''
|
||||
a = dedent(u'''
|
||||
BEGIN:VCALENDAR
|
||||
BEGIN:VTIMEZONE
|
||||
TZID:Europe/Rome
|
||||
|
|
@ -179,7 +212,7 @@ def test_multiline_uid_complex():
|
|||
reason=('version of icalendar doesn\'t support dots in '
|
||||
'property names'))
|
||||
def test_vcard_property_groups():
|
||||
vcard = textwrap.dedent(u'''
|
||||
vcard = dedent(u'''
|
||||
BEGIN:VCARD
|
||||
VERSION:3.0
|
||||
MYLABEL123.ADR:;;This is the Address 08; Some City;;12345;Germany
|
||||
|
|
@ -202,7 +235,7 @@ def test_vcard_semicolons_in_values():
|
|||
# If this test fails because proper vCard support was added to icalendar,
|
||||
# we can remove some ugly postprocessing code in to_unicode_lines.
|
||||
|
||||
vcard = textwrap.dedent(u'''
|
||||
vcard = dedent(u'''
|
||||
BEGIN:VCARD
|
||||
VERSION:3.0
|
||||
ADR:;;Address 08;City;;12345;Germany
|
||||
|
|
|
|||
|
|
@ -183,19 +183,21 @@ def to_unicode_lines(item):
|
|||
|
||||
_default_join_wrappers = {
|
||||
u'VCALENDAR': (u'VCALENDAR', (u'VTIMEZONE',)),
|
||||
u'VEVENT': (u'VCALENDAR', (u'VTIMEZONE',)),
|
||||
u'VTODO': (u'VCALENDAR', (u'VTIMEZONE',)),
|
||||
u'VCARD': (u'VADDRESSBOOK', ())
|
||||
}
|
||||
|
||||
|
||||
def join_collection(items, wrappers=None):
|
||||
def join_collection(items, wrappers=_default_join_wrappers):
|
||||
'''
|
||||
:param wrappers: {
|
||||
item_type: wrapper_type, items_to_inline
|
||||
item_type: wrapper_type, common_components
|
||||
}
|
||||
'''
|
||||
if wrappers is None:
|
||||
wrappers = _default_join_wrappers
|
||||
|
||||
Common components are those who can be moved from the item into the
|
||||
wrapper, with duplicates removed.
|
||||
'''
|
||||
inline = {}
|
||||
components = []
|
||||
wrapper_type = None
|
||||
|
|
@ -204,7 +206,7 @@ def join_collection(items, wrappers=None):
|
|||
|
||||
def handle_item(item):
|
||||
if item.name in inline_types:
|
||||
inline[item.name] = item
|
||||
inline[tuple(to_unicode_lines(item))] = item
|
||||
else:
|
||||
components.append(item)
|
||||
|
||||
|
|
@ -234,4 +236,4 @@ def join_collection(items, wrappers=None):
|
|||
lines.extend(to_unicode_lines(component))
|
||||
lines.append(end)
|
||||
|
||||
return u''.join(line + u'\r\n' for line in lines if line)
|
||||
return u''.join(line + u'\r\n' for line in lines)
|
||||
|
|
|
|||
Loading…
Reference in a new issue