Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor test_create_to_ical from test_encoding to test_examples.py #439

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Plönë.org//NONSGML plone.app.event//EN
X-WR-CALDESC:test non ascii: äöü ÄÖÜ €
X-WR-CALNAME:äöü ÄÖÜ €
X-WR-RELCALID:12345
BEGIN:VEVENT
SUMMARY:Non-ASCII Test: ÄÖÜ äöü €
DTSTART;VALUE=DATE-TIME:20101010T100000Z
DTEND;VALUE=DATE-TIME:20101010T120000Z
UID:123456
CREATED;VALUE=DATE-TIME:20101010T000000Z
DESCRIPTION:icalendar should be able to de/serialize non-ascii.
LOCATION:Tribstrül
END:VEVENT
BEGIN:VEVENT
SUMMARY:åäö
DTSTART;VALUE=DATE-TIME:20101010T000000Z
END:VEVENT
BEGIN:VEVENT
DESCRIPTION:äöüßÄÖÜ
END:VEVENT
END:VCALENDAR
60 changes: 0 additions & 60 deletions src/icalendar/tests/test_encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,66 +31,6 @@ def test_create_from_ical(self):
self.assertEqual(event['LOCATION'].to_ical().decode('utf-8'),
'Tribstrül')

def test_create_to_ical(self):
cal = icalendar.Calendar()

cal.add('prodid', "-//Plönë.org//NONSGML plone.app.event//EN")
cal.add('version', "2.0")
cal.add('x-wr-calname', "äöü ÄÖÜ €")
cal.add('x-wr-caldesc', "test non ascii: äöü ÄÖÜ €")
cal.add('x-wr-relcalid', "12345")

event = icalendar.Event()
event.add(
'dtstart',
pytz.utc.localize(datetime.datetime(2010, 10, 10, 10, 0, 0))
)
event.add(
'dtend',
pytz.utc.localize(datetime.datetime(2010, 10, 10, 12, 0, 0))
)
event.add(
'created',
pytz.utc.localize(datetime.datetime(2010, 10, 10, 0, 0, 0))
)
event.add('uid', '123456')
event.add('summary', 'Non-ASCII Test: ÄÖÜ äöü €')
event.add(
'description',
'icalendar should be able to de/serialize non-ascii.'
)
event.add('location', 'Tribstrül')
cal.add_component(event)

ical_lines = cal.to_ical().splitlines()
cmp = b'PRODID:-//Pl\xc3\xb6n\xc3\xab.org//NONSGML plone.app.event//EN'
self.assertTrue(cmp in ical_lines)

def test_create_event_simple(self):
event = icalendar.Event()
event.add(
"dtstart",
pytz.utc.localize(datetime.datetime(2010, 10, 10, 0, 0, 0))
)
event.add("summary", "åäö")
out = event.to_ical()
summary = b'SUMMARY:\xc3\xa5\xc3\xa4\xc3\xb6'
self.assertTrue(summary in out.splitlines())

def test_unicode_parameter_name(self):
# Test for issue #80
cal = icalendar.Calendar()
event = icalendar.Event()
event.add('DESCRIPTION', 'äöüßÄÖÜ')
cal.add_component(event)
c = cal.to_ical()
self.assertEqual(
c,
b'BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nDESCRIPTION:'
+ b'\xc3\xa4\xc3\xb6\xc3\xbc\xc3\x9f\xc3\x84\xc3\x96\xc3\x9c\r\n'
+ b'END:VEVENT\r\nEND:VCALENDAR\r\n'
)

@pytest.mark.parametrize('event_name', [
# Non-unicode characters in summary
'issue_64_event_with_non_unicode_summary',
Expand Down
41 changes: 41 additions & 0 deletions src/icalendar/tests/test_examples.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
'''tests ensuring that *the* way of doing things works'''
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docstring does not explain anything.


import datetime

from icalendar import Calendar, Event

import pytest

def test_creating_calendar_with_unicode_fields(calendars, utc):
''' create a calendar with events that contain unicode characters in their fields '''
cal = Calendar()
cal.add('PRODID', '-//Plönë.org//NONSGML plone.app.event//EN')
cal.add('VERSION', '2.0')
cal.add('X-WR-CALNAME', 'äöü ÄÖÜ €')
cal.add('X-WR-CALDESC', 'test non ascii: äöü ÄÖÜ €')
cal.add('X-WR-RELCALID', '12345')

event = Event()
event.add('DTSTART', datetime.datetime(2010, 10, 10, 10, 0, 0, tzinfo=utc))
event.add('DTEND', datetime.datetime(2010, 10, 10, 12, 0, 0, tzinfo=utc))
event.add('CREATED', datetime.datetime(2010, 10, 10, 0, 0, 0, tzinfo=utc))
event.add('UID', '123456')
event.add('SUMMARY', 'Non-ASCII Test: ÄÖÜ äöü €')
event.add('DESCRIPTION', 'icalendar should be able to de/serialize non-ascii.')
event.add('LOCATION', 'Tribstrül')
cal.add_component(event)

# test_create_event_simple
event1 = Event()
event1.add('DTSTART', datetime.datetime(2010, 10, 10, 0, 0, 0, tzinfo=utc))
event1.add('SUMMARY', 'åäö')
cal.add_component(event1)

# test_unicode_parameter_name
# test for issue #80 https://github.com/collective/icalendar/issues/80
event2 = Event()
event2.add('DESCRIPTION', 'äöüßÄÖÜ')
cal.add_component(event2)

assert cal.to_ical() == calendars.created_calendar_with_unicode_fields.raw_ics