Debian Codegraph @

recurring_ical_events/test/test_duration.py

raw symbols SCIP
1 """
2 Test the DURATION property.
3
4 Not all events have an end.
5 Some events define no explicit end and some a DURATION.
6 RFC: https://www.kanzaki.com/docs/ical/duration.html
7
8 """
9
10 import pytest
11
12
13 @pytest.mark.parametrize(
14 ("date", "count"),
15 [
16 # event 3 days
17 ("20180110", 1),
18 ("20180111", 1),
19 ("20180112", 1),
20 ("20180109", 0),
21 ("20180114", 0),
22 # event 3 hours
23 ((2018, 1, 15, 10), 1),
24 ((2018, 1, 15, 11), 1),
25 ((2018, 1, 15, 12), 1),
26 ((2018, 1, 15, 9), 0),
27 ((2018, 1, 15, 14), 0),
28 # event with no duration nor end
29 ((2018, 1, 20), 1),
30 ((2018, 1, 19), 0),
31 ((2018, 1, 21), 0),
32 ],
33 )
34 def test_events_expected(date, count, calendars):
35 events = calendars.duration.at(date)
36 assert len(events) == count
37
38
39 @pytest.mark.parametrize(
40 ("date", "summary", "expected_hours"),
41 [
42 ("20190318", "original event", 1),
43 ("20190319", "edited duration", 3),
44 ("20190320", "original event", 1),
45 ],
46 )
47 def test_duration_is_edited(calendars, date, summary, expected_hours):
48 """Test that the duration of an event can be edited."""
49 events = calendars.duration_edited.at(date)
50 assert len(events) == 1
51 event = events[0]
52 event_hours = (event["DTEND"].dt - event["DTSTART"].dt).total_seconds() / 3600
53 assert summary == event["SUMMARY"], "we should have the correct event"
54 assert event_hours == expected_hours, (
55 "the duration is only edited in the edited event"
56 )