Skip to content

Commit

Permalink
Merge branch 'master' into test_restructure_test_encoding_create_from…
Browse files Browse the repository at this point in the history
…_ical
  • Loading branch information
jacadzaca authored Oct 8, 2022
2 parents a9b666c + 70a5f20 commit 916464e
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 87 deletions.
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
3 changes: 3 additions & 0 deletions src/icalendar/tests/events/issue_82_expected_output.ics
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
BEGIN:VEVENT
ATTACH;ENCODING=BASE64;FMTTYPE=text/plain;VALUE=BINARY:dGV4dA==
END:VEVENT
69 changes: 0 additions & 69 deletions src/icalendar/tests/test_encoding.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import unittest

import pytest

import datetime
import icalendar
import os
import pytz

@pytest.mark.parametrize('field, expected_value', [
('PRODID', '-//Plönë.org//NONSGML plone.app.event//EN'),
('X-WR-CALDESC', 'test non ascii: äöü ÄÖÜ €'),
Expand All @@ -31,65 +24,3 @@ def test_calendar_from_ical_respects_unicode(field, expected_value, calendars):
def test_event_from_ical_respects_unicode(test_input, field, expected_value, events):
event = events[test_input]
event[field].to_ical().decode('utf-8') == expected_value

class TestEncoding(unittest.TestCase):
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'
)

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'''

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

18 changes: 0 additions & 18 deletions src/icalendar/tests/test_fixed_issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,6 @@
from backports import zoneinfo

class TestIssues(unittest.TestCase):

def test_issue_82(self):
"""Issue #82 - vBinary __repr__ called rather than to_ical from
container types
https://github.com/collective/icalendar/issues/82
"""

b = icalendar.vBinary('text')
b.params['FMTTYPE'] = 'text/plain'
self.assertEqual(b.to_ical(), b'dGV4dA==')
e = icalendar.Event()
e.add('ATTACH', b)
self.assertEqual(
e.to_ical(),
b"BEGIN:VEVENT\r\nATTACH;ENCODING=BASE64;FMTTYPE=text/plain;"
b"VALUE=BINARY:dGV4dA==\r\nEND:VEVENT\r\n"
)

def test_issue_116(self):
"""Issue #116/#117 - How to add 'X-APPLE-STRUCTURED-LOCATION'
https://github.com/collective/icalendar/issues/116
Expand Down
21 changes: 21 additions & 0 deletions src/icalendar/tests/test_parsing.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'''Tests checking that parsing works'''
import pytest
import base64
from icalendar import Calendar, vRecur, vBinary, Event
from datetime import datetime
from icalendar.parser import Contentline, Parameters
Expand Down Expand Up @@ -133,3 +134,23 @@ def test_no_tzid_when_utc(utc, date, expected_output):
event = Event()
event.add('dtstart', date)
assert expected_output in event.to_ical()

def test_vBinary_base64_encoded_issue_82():
'''Issue #82 - vBinary __repr__ called rather than to_ical from
container types
https://github.com/collective/icalendar/issues/82
'''
b = vBinary('text')
b.params['FMTTYPE'] = 'text/plain'
assert b.to_ical() == base64.b64encode(b'text')

def test_creates_event_with_base64_encoded_attachment_issue_82(events):
'''Issue #82 - vBinary __repr__ called rather than to_ical from
container types
https://github.com/collective/icalendar/issues/82
'''
b = vBinary('text')
b.params['FMTTYPE'] = 'text/plain'
event = Event()
event.add('ATTACH', b)
assert event.to_ical() == events.issue_82_expected_output.raw_ics

0 comments on commit 916464e

Please sign in to comment.