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_encoding create_from_ical #438

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
7 changes: 7 additions & 0 deletions src/icalendar/tests/calendars/calendar_with_unicode.ics
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
BEGIN:VCALENDAR
PRODID:-//Plönë.org//NONSGML plone.app.event//EN
VERSION:2.0
X-WR-CALNAME:äöü ÄÖÜ €
X-WR-CALDESC:test non ascii: äöü ÄÖÜ €
X-WR-RELCALID:12345
END:VCALENDAR
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
BEGIN:VCALENDAR
PRODID:-//Plönë.org//NONSGML plone.app.event//EN
VERSION:2.0
X-WR-CALNAME:äöü ÄÖÜ €
X-WR-CALDESC:test non ascii: äöü ÄÖÜ €
X-WR-RELCALID:12345
BEGIN:VEVENT
DTSTART:20101010T100000Z
DTEND:20101010T120000Z
CREATED:20101010T100000Z
UID:123456
SUMMARY:Non-ASCII Test: ÄÖÜ äöü €
DESCRIPTION:icalendar should be able to handle non-ascii: €äüöÄÜÖ.
LOCATION:Tribstrül
END:VEVENT
END:VCALENDAR
BEGIN:VEVENT
DTSTART:20101010T100000Z
DTEND:20101010T120000Z
CREATED:20101010T100000Z
UID:123456
SUMMARY:Non-ASCII Test: ÄÖÜ äöü €
DESCRIPTION:icalendar should be able to handle non-ascii: €äüöÄÜÖ.
LOCATION:Tribstrül
END:VEVENT
64 changes: 21 additions & 43 deletions src/icalendar/tests/test_encoding.py
Original file line number Diff line number Diff line change
@@ -1,51 +1,29 @@
import unittest

import pytest

import datetime
import icalendar
import os
import pytz


class TestEncoding(unittest.TestCase):

def test_create_from_ical(self):
directory = os.path.dirname(__file__)
with open(os.path.join(directory, 'encoding.ics'), 'rb') as fp:
data = fp.read()
cal = icalendar.Calendar.from_ical(data)

self.assertEqual(cal['prodid'].to_ical().decode('utf-8'),
"-//Plönë.org//NONSGML plone.app.event//EN")
self.assertEqual(cal['X-WR-CALDESC'].to_ical().decode('utf-8'),
"test non ascii: äöü ÄÖÜ €")

event = cal.walk('VEVENT')[0]
self.assertEqual(event['SUMMARY'].to_ical().decode('utf-8'),
'Non-ASCII Test: ÄÖÜ äöü €')
self.assertEqual(
event['DESCRIPTION'].to_ical().decode('utf-8'),
'icalendar should be able to handle non-ascii: €äüöÄÜÖ.'
)
self.assertEqual(event['LOCATION'].to_ical().decode('utf-8'),
'Tribstrül')

@pytest.mark.parametrize('event_name', [
@pytest.mark.parametrize('field, expected_value', [
('PRODID', '-//Plönë.org//NONSGML plone.app.event//EN'),
('X-WR-CALDESC', 'test non ascii: äöü ÄÖÜ €'),
])
def test_calendar_from_ical_respects_unicode(field, expected_value, calendars):
cal = calendars.calendar_with_unicode
assert cal[field].to_ical().decode('utf-8') == expected_value

@pytest.mark.parametrize('test_input, field, expected_value', [
('event_with_unicode_fields', 'SUMMARY', 'Non-ASCII Test: ÄÖÜ äöü €'),
('event_with_unicode_fields', 'DESCRIPTION', 'icalendar should be able to handle non-ascii: €äüöÄÜÖ.'),
('event_with_unicode_fields', 'LOCATION', 'Tribstrül'),
# Non-unicode characters in summary
'issue_64_event_with_non_unicode_summary',
# https://github.com/collective/icalendar/issues/64
('issue_64_event_with_non_ascii_summary', 'SUMMARY', 'åäö'),
# Unicode characters in summary
'issue_64_event_with_unicode_summary',
# chokes on umlauts in ORGANIZER
'issue_101_icalendar_chokes_on_umlauts_in_organizer'
('issue_64_event_with_ascii_summary', 'SUMMARY', 'abcdef'),
])
def test_events_unicoded(events, event_name):
'''Issue #64 - Event.to_ical() fails for unicode strings
Issue #101 - icalendar is choking on umlauts in ORGANIZER
def test_event_from_ical_respects_unicode(test_input, field, expected_value, events):
event = events[test_input]
assert event[field].to_ical().decode('utf-8') == expected_value

https://github.com/collective/icalendar/issues/64
def test_events_parameter_unicoded(events):
'''chokes on umlauts in ORGANIZER
https://github.com/collective/icalendar/issues/101
'''
event = getattr(events, event_name)
assert event.to_ical() == event.raw_ics

assert events.issue_101_icalendar_chokes_on_umlauts_in_organizer['ORGANIZER'].params['CN'] == 'acme, ädmin'