11from util import parse_yaml
22
3- from yaml2ics import event_ics_from_yaml
3+ from yaml2ics import event_from_yaml
44
55
66def test_basic_structure ():
7- event = event_ics_from_yaml (
7+ event = event_from_yaml (
88 parse_yaml (
99 '''
10- name : Earth Day
10+ summary : Earth Day
1111 begin: 2021-04-22
1212 url: https://earthday.org
13+ location: Earth
1314 '''
1415 )
1516 )
1617
1718 # All lines must be separated by CRLF
18- lines = event .split ('\n ' )
19+ event_str = event .serialize ()
20+ lines = event_str .split ('\n ' )
1921 for line in lines [:- 1 ]:
2022 assert line .endswith ('\r ' )
21-
23+ assert 'SUMMARY:Earth Day' in event_str
24+ assert 'URL:https://earthday.org' in event_str
25+ assert 'LOCATION:Earth' in event_str
2226 # All events must have a DTSTAMP
23- assert 'DTSTAMP' in event
27+ assert 'DTSTAMP' in event_str
2428
2529
2630def test_all_day_event ():
27- event = event_ics_from_yaml (
31+ event = event_from_yaml (
2832 parse_yaml (
2933 '''
30- name : Earth Day
34+ summary : Earth Day
3135 begin: 2021-04-22
3236 url: https://earthday.org
3337 '''
3438 )
3539 )
36- assert event .startswith ('BEGIN:VEVENT' )
37- assert event .endswith ('END:VEVENT' )
38- assert 'DTSTART;VALUE=DATE:20210422' in event
39- assert 'DTEND' not in event
40+ event_str = event .serialize ()
41+ assert event_str .startswith ('BEGIN:VEVENT' )
42+ assert event_str .endswith ('END:VEVENT' )
43+ assert 'DTSTART;VALUE=DATE:20210422' in event_str
44+ # ics 0.8.0 does have DTEND that is the next day.
45+ #assert 'DTEND' not in event_str
4046
4147
4248def test_rrule ():
43- event = event_ics_from_yaml (
49+ event = event_from_yaml (
4450 parse_yaml (
4551 '''
46- name : Earth Day
52+ summary : Earth Day
4753 begin: 2021-04-22
4854 url: https://earthday.org
4955 repeat:
@@ -53,40 +59,43 @@ def test_rrule():
5359 '''
5460 )
5561 )
56- assert 'DTEND' not in event
57- assert 'RRULE:FREQ=YEARLY;UNTIL=20300422T000000Z' in event
62+ event_str = event .serialize ()
63+ assert 'DTEND' not in event_str
64+ assert 'RRULE:FREQ=YEARLY;UNTIL=20300422T000000' in event_str
5865
5966
6067def test_event_with_time_range ():
61- event = event_ics_from_yaml (
68+ event = event_from_yaml (
6269 parse_yaml (
6370 '''
64- name : Event of the Century
65- begin: 2021-09-21 15:00-07:00
66- end: 2021-09-21 15:30:00-07:00
71+ summary : Event of the Century
72+ begin: 2021-09-21 15:00:00 -07:00
73+ end: 2021-09-21 15:30:00 -07:00
6774 description: |
6875 Meet the team on the northern side of the field.
6976 '''
7077 )
7178 )
72- assert 'DTSTART' in event
73- assert 'DTEND' in event
79+ event_str = event .serialize ()
80+ assert 'DTSTART' in event_str
81+ assert 'DTEND' in event_str
7482
7583
7684def test_event_with_duration ():
77- event = event_ics_from_yaml (
85+ event = event_from_yaml (
7886 parse_yaml (
7987 '''
80- name : Event of the Century
81- begin: 2021-09-21 15:00-07:00
88+ summary : Event of the Century
89+ begin: 2021-09-21 15:00:00 -07:00
8290 duration:
8391 minutes: 30
8492 description: |
8593 Meet the team on the northern side of the field.
8694 '''
8795 )
8896 )
97+ event_str = event .serialize ()
98+ assert 'DURATION:PT30M' in event_str
99+ assert 'DTEND' not in event_str
100+ assert 'DTSTART' in event_str
89101
90- assert 'DURATION:PT30M' in event
91- assert 'DTEND' not in event
92- assert 'DTSTART' in event
0 commit comments