-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathtest_events.py
More file actions
187 lines (166 loc) · 5.21 KB
/
test_events.py
File metadata and controls
187 lines (166 loc) · 5.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
import io
from yaml2ics import event_from_yaml, files_to_events
from .util import parse_yaml
def test_basic_structure():
event = event_from_yaml(
parse_yaml(
"""
summary: Earth Day
begin: 2021-04-22
location: https://earthday.org
"""
)
)
# All lines must be separated by CRLF
event_str = event.serialize()
lines = event_str.split("\n")
for line in lines[:-1]:
assert line.endswith("\r")
assert "SUMMARY:Earth Day" in event_str
assert "LOCATION:https://earthday.org" in event_str
# All events must have a DTSTAMP
assert "DTSTAMP" in event_str
def test_all_day_event():
event = event_from_yaml(
parse_yaml(
"""
summary: Earth Day
begin: 2021-04-22
location: https://earthday.org
"""
)
)
event_str = event.serialize()
assert event_str.startswith("BEGIN:VEVENT")
assert event_str.endswith("END:VEVENT")
assert "DTSTART;VALUE=DATE:20210422" in event_str
# ics 0.8.0 does have DTEND that is the next day.
# assert 'DTEND' not in event_str
def test_rrule():
event = event_from_yaml(
parse_yaml(
"""
summary: Earth Day
begin: 2021-04-22
repeat:
interval:
years: 1
until: 2030-04-22
"""
)
)
event_str = event.serialize()
# DTEND exists and is the next day, calendar tools import this
# correctly as being a one-day event
assert "RRULE:FREQ=YEARLY;UNTIL=20300422T000000" in event_str
def test_exception():
event = event_from_yaml(
parse_yaml(
"""
summary: Recurring event with exception and additional date
timezone: America/Los_Angeles
begin: 2022-07-01 10:00:00
duration: {minutes: 60}
repeat:
interval:
hours: 4
until: 2022-07-31
except_on:
- 2022-07-13
- 2022-07-14 06:00:00
also_on:
- 2022-12-24 06:00:00
"""
)
)
event_str = event.serialize()
# DTEND exists and is the next day, calendar tools import this
# correctly as being a one-day event
assert (
"EXDATE;TZID=/ics.py/2020.1/America/Los_Angeles:20220713,20220714T060000"
in event_str
)
assert "RDATE;TZID=/ics.py/2020.1/America/Los_Angeles:20221224T060000" in event_str
def test_event_with_time_range():
event = event_from_yaml(
parse_yaml(
"""
summary: Event of the Century
begin: 2021-09-21 15:00:00 -07:00
end: 2021-09-21 15:30:00 -07:00
description: |
Meet the team on the northern side of the field.
"""
)
)
event_str = event.serialize()
assert "DTSTART" in event_str
assert "DTEND" in event_str
def test_event_with_duration():
event = event_from_yaml(
parse_yaml(
"""
summary: Event of the Century
begin: 2021-09-21 15:00:00 -07:00
duration:
minutes: 30
description: |
Meet the team on the northern side of the field.
"""
)
)
event_str = event.serialize()
assert "DURATION:PT30M" in event_str
assert "DTEND" not in event_str
assert "DTSTART" in event_str
def test_event_with_custom_ics():
event = event_from_yaml(
parse_yaml(
"""
summary: Earth Day
begin: 2021-04-22
ics: |
RRULE:FREQ=YEARLY;UNTIL=20280422T000000
"""
)
)
event_str = event.serialize()
assert "RRULE:FREQ=YEARLY;UNTIL=20280422T000000" in event_str
def test_events_with_multiple_timezones():
f = io.BytesIO(b"""
name: Multiple Timezone Cal
timezone: America/Los_Angeles
events:
- summary: Meeting A
begin: 2025-07-15 17:00:00 +00:00
duration: { minutes: 60 }
- summary: Meeting B
timezone: UTC
begin: 2025-12-01 09:00:00
duration: { minutes: 60 }
- summary: Meeting C
begin: 2025-09-02 17:00:00
duration: { minutes: 60 }
- summary: Meeting D
begin: 2025-12-01 09:00:00
duration: { minutes: 60 }
""")
events, _ = files_to_events([f])
assert events[0].begin.tzname() in ("UTC", "Coordinated Universal Time")
assert events[1].begin.tzname() in ("UTC", "Coordinated Universal Time")
assert events[2].begin.tzname() == "PDT"
assert events[3].begin.tzname() == "PST"
def test_events_without_timezone():
f = io.BytesIO(b"""
name: Default Timezone
events:
- summary: Meeting A
begin: 2025-09-02 17:00:00
duration: { minutes: 60 }
- summary: Meeting B
begin: 2025-12-01 09:00:00
end: 2025-12-01 10:00:00
""")
events, _ = files_to_events([f])
assert events[0].begin.tzname() in ("UTC", "Coordinated Universal Time")
assert events[1].begin.tzname() in ("UTC", "Coordinated Universal Time")