-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_event.py
199 lines (149 loc) · 4.96 KB
/
test_event.py
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
188
189
190
191
192
193
194
195
196
197
198
199
import pytest
import datetime
import math
from event import Event
from freezegun import freeze_time
from dateutil.tz import tzutc
from dateutil import parser
@pytest.fixture(params=[15, 25, 30, 55, 60])
def event(request):
"""
Returns a mock event starting at 2022-01-01T00:00:00Z with data pre-populated
Duration is determined by the param to allow for variable event durrations
"""
start = datetime.datetime(2022, 1, 1, 0, 0, tzinfo=tzutc())
end = start + datetime.timedelta(minutes=request.param)
data = {
'summary': 'Test',
'start': {'dateTime': str(start)},
'end': {'dateTime': str(end)},
'status': 'confirmed',
'attendees': [
{'self': True, 'responseStatus': 'accepted'},
],
'_duration': request.param
}
return Event(data)
@pytest.fixture
def declined_event(event):
attendees = [
{'self': True, 'responseStatus': 'needsAction'},
]
event.data["attendees"] = attendees
return event
@pytest.fixture(params=[30, 15, 10, 5, 4, 3, 2, 1, 0])
def minutes_to_display(request):
"""
Fixture to iterate through times intended to display
"""
return request.param
@pytest.fixture(params=[120, 90, 70, 65, 61, 60, 59, 55, 51, 50, 49, 45, 41,
40, 36, 35, 32, 27, 25, 22, 20, 11, 6])
def minutes_not_to_display(request):
"""
Fixture to iterate through times not intended to display
"""
return request.param
def test_stores_data(event):
"""
Test that the data is stored
"""
assert event.data["summary"] == "Test"
def test_title(event):
"""
Test the title is stored
"""
assert event.title() == "Test"
def test_start(event):
"""
Test that the start time is parsed and stored
"""
assert event.start() == datetime.datetime(2022, 1, 1, 0, 0, tzinfo=tzutc())
def test_end(event):
"""
Test that the end time is parsed and stored
"""
end = event.start() + datetime.timedelta(minutes=event.data["_duration"])
assert event.end() == end
@freeze_time("2022-01-01 00:30:00Z")
def test_time_remaining(event):
"""
Test that the time remaining is calculated correctly
"""
half = datetime.timedelta(minutes=event.data["_duration"] / 2)
with freeze_time(event.start() + half):
assert event.time_remaining() == half
def test_durration(event):
"""
Test that the durration is calculated correctly
"""
assert event.durration() == datetime.timedelta(
minutes=event.data["_duration"])
def test_perceived_durration(event):
"""
Test that the perceived_durration is calculated correctly
"""
if event.data["_duration"] in [25, 55]:
expected = event.data["_duration"] + 5
elif event.data["_duration"] == 50:
expected = event.data["_duration"] + 10
else:
expected = event.data["_duration"]
assert event.perceived_durration() == datetime.timedelta(minutes=expected)
@freeze_time("2022-01-01 00:15:00Z")
def test_in_progress(event):
"""
Test that the event determined to be in progress correctly
"""
assert event.in_progress()
def test_is_attending(event):
"""
Test that the authorized user is attending the event
"""
assert event.is_attending() is True
def test_is_not_attending(declined_event):
"""
Test that the authorized user is not attending the event
"""
assert declined_event.is_attending() is False
def test_percent_remaining(event):
"""
Test that the percent remaining is calculated correctly
"""
half = event.perceived_durration() / 2
with freeze_time(event.end() - half):
assert event.percent_remaining() == 0.5
@freeze_time("2021-01-01 01:00:00Z")
def test_not_in_progress(event):
"""
Test that the event determined to not be in progress correctly
"""
assert not event.in_progress()
@freeze_time("2022-01-01 00:30:00Z")
def test_minutes_remaining(event):
"""
Test that the minutes remaining is calculated correctly
"""
half = datetime.timedelta(minutes=event.data["_duration"] / 2)
with freeze_time(event.start() + half):
assert event.minutes_remaining() == round(half.total_seconds() / 60)
def test_should_display_time(event, minutes_to_display):
"""
Test times when the time should be displayed
"""
diff = datetime.timedelta(
minutes=event.data["_duration"]) - datetime.timedelta(minutes=minutes_to_display)
with freeze_time(event.start() + diff):
if not event.in_progress():
return
assert event.should_display_time() is True
def test_should_not_display_time(event, minutes_not_to_display):
"""
Test times when the time should not be displayed
"""
diff = datetime.timedelta(
minutes=event.data["_duration"]) - datetime.timedelta(minutes=minutes_not_to_display)
with freeze_time(event.start() + diff):
if not event.in_progress():
return
assert event.should_display_time() is False