kopia lustrzana https://github.com/collective/icalendar
Merge branch 'master' into test_restructure_test_encoding_create_from_ical
commit
97c470d680
|
|
@ -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
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
BEGIN:VEVENT
|
||||
ATTACH;ENCODING=BASE64;FMTTYPE=text/plain;VALUE=BINARY:dGV4dA==
|
||||
END:VEVENT
|
||||
|
|
@ -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: äöü ÄÖÜ €'),
|
||||
|
|
@ -34,66 +27,3 @@ def test_events_parameter_unicoded(events):
|
|||
https://github.com/collective/icalendar/issues/101
|
||||
'''
|
||||
assert events.issue_101_icalendar_chokes_on_umlauts_in_organizer['ORGANIZER'].params['CN'] == 'acme, ädmin'
|
||||
|
||||
|
||||
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'
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
@ -13,24 +13,6 @@ except ModuleNotFoundError:
|
|||
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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
|
|||
Ładowanie…
Reference in New Issue