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
200
201
202
203
204
205
206
207
208
209
210
211
212
|
import datetime
import pytest
from django.db import IntegrityError
from ctrack.register.models import (
EventType,
SingleDateTimeEvent,
CAFSingleDateEvent,
CAFTwinDateEvent,
)
pytestmark = pytest.mark.django_db
@pytest.mark.parametrize(
"allowed_type",
[
"CAF_INITIAL_CAF_RECEIVED",
"CAF_FEEDBACK_EMAILED_OES",
"CAF_RECEIVED",
"CAF_EMAILED_ROSA",
"CAF_VALIDATION_SIGN_OFF",
"CAF_VALIDATION_RECORD_EMAILED_TO_OES",
],
)
def test_caf_single_date_events(allowed_type, user, caf):
now = datetime.datetime.now()
e = CAFSingleDateEvent.objects.create(
type_descriptor=allowed_type,
related_caf=caf,
short_description="CAF received for X Company",
date="2020-10-10",
comments="Nice comments for this event",
user=user,
)
assert e.created_date.day == now.day
assert e.type_descriptor == allowed_type
@pytest.mark.parametrize(
"allowed_type", ["CAF_PEER_REVIEW_PERIOD", "CAF_VALIDATION_PERIOD"]
)
def test_caf_twin_date_events(allowed_type, user, caf):
now = datetime.datetime.now()
e = CAFTwinDateEvent.objects.create(
type_descriptor=allowed_type,
related_caf=caf,
short_description="CAF received for X Company",
start_date="2020-10-10",
end_date="2020-10-25",
comments="Nice comments for this event",
user=user,
)
assert e.created_date.day == now.day
assert e.type_descriptor == allowed_type
@pytest.mark.parametrize(
"allowed_type", ["CAF_PEER_REVIEW_PERIOD", "CAF_VALIDATION_PERIOD"]
)
def test_caf_twin_date_event_no_end_date(allowed_type, user, caf):
e = CAFTwinDateEvent.objects.create(
type_descriptor=allowed_type,
related_caf=caf,
short_description="CAF received for X Company",
start_date="2020-10-10",
comments="Nice comments for this event",
user=user,
)
assert e.end_date is None
@pytest.mark.parametrize(
"allowed_type", ["CAF_PEER_REVIEW_PERIOD", "CAF_VALIDATION_PERIOD"]
)
def test_caf_twin_date_event_no_start_date_not_allowed(allowed_type, user, caf):
with pytest.raises(IntegrityError):
CAFTwinDateEvent.objects.create(
type_descriptor=allowed_type,
related_caf=caf,
short_description="CAF received for X Company",
end_date="2020-10-10",
comments="Nice comments for this event",
user=user,
)
def test_cannot_add_two_caf_initial_caf_received_events_on_same_date(user, caf):
CAFSingleDateEvent.objects.create(
type_descriptor="CAF_INITIAL_CAF_RECEIVED",
related_caf=caf,
short_description="CAF received for X Company",
date="2020-10-10",
comments="Nice comments for this event",
user=user,
)
with pytest.raises(IntegrityError):
CAFSingleDateEvent.objects.create(
type_descriptor="CAF_INITIAL_CAF_RECEIVED",
related_caf=caf,
short_description="CAF received for X Company",
date="2020-10-10",
comments="Nice comments for this event",
user=user,
)
def test_can_email_two_caf_on_same_date(user, caf):
CAFSingleDateEvent.objects.create(
type_descriptor="CAF_EMAILED_ROSA",
related_caf=caf,
short_description="CAF sent to Rosa for X Company",
date="2020-10-10",
comments="Nice comments for this event",
user=user,
)
CAFSingleDateEvent.objects.create(
type_descriptor="CAF_EMAILED_ROSA",
related_caf=caf,
short_description="CAF sent to Rosa for X Company",
date="2020-10-10",
comments="Nice comments for this event",
user=user,
)
def test_cannot_receive_the_same_caf_on_the_same_day(user, caf):
CAFSingleDateEvent.objects.create(
type_descriptor="CAF_RECEIVED",
related_caf=caf,
short_description="CAF received to Rosa for X Company",
date="2020-10-10",
comments="Nice comments for this event",
user=user,
)
with pytest.raises(IntegrityError):
CAFSingleDateEvent.objects.create(
type_descriptor="CAF_RECEIVED",
related_caf=caf,
short_description="CAF received to Rosa for X Company",
date="2020-10-10",
comments="Nice comments for this event",
user=user,
)
def test_event_type_enum():
assert EventType.MEETING.name == "MEETING"
assert EventType.PHONE_CALL.name == "PHONE_CALL"
assert EventType.VIDEO_CALL.name == "VIDEO_CALL"
assert EventType.CAF_INITIAL_CAF_RECEIVED.name == "CAF_INITIAL_CAF_RECEIVED"
assert EventType.CAF_FEEDBACK_EMAILED_OES.name == "CAF_FEEDBACK_EMAILED_OES"
assert EventType.CAF_RECEIVED.name == "CAF_RECEIVED"
assert EventType.CAF_EMAILED_ROSA.name == "CAF_EMAILED_ROSA"
assert EventType.CAF_PEER_REVIEW_PERIOD.name == "CAF_PEER_REVIEW_PERIOD"
assert EventType.CAF_VALIDATION_PERIOD.name == "CAF_VALIDATION_PERIOD"
assert EventType.CAF_VALIDATION_SIGN_OFF.name == "CAF_VALIDATION_SIGN_OFF"
assert (
EventType.CAF_VALIDATION_RECORD_EMAILED_TO_OES.name
== "CAF_VALIDATION_RECORD_EMAILED_TO_OES"
)
@pytest.mark.parametrize("allowed_type", [("PHONE_CALL"), ("MEETING"), ("VIDEO_CALL")])
def test_single_datetime_event(person, user, allowed_type):
"""This tests for phone call, video call and email events"""
now = datetime.datetime.now()
event = SingleDateTimeEvent.objects.create(
type_descriptor=allowed_type,
short_description="Important event",
datetime="2020-10-10T15:00",
comments="Comments on important event",
# location is optional
user=user,
)
event.participants.add(person)
assert event.type_descriptor == allowed_type
assert person in event.participants.all()
assert event.created_date.day == now.day
def test_cannot_create_twin_date_event_model_end_date_precedes_start(user, caf):
with pytest.raises(IntegrityError):
CAFTwinDateEvent.objects.create(
type_descriptor="CAF_PEER_REVIEW_PERIOD",
related_caf=caf,
start_date="2010-10-10",
end_date="2010-01-01",
short_description="Bobbins",
user=user
)
def test_meeting_event(user, person):
uname = user.name
now = datetime.datetime.now()
e = SingleDateTimeEvent.objects.create(
type_descriptor="Meeting",
short_description="Big Important Meeting",
datetime="2020-10-10T15:00",
comments="Nice comments",
location="Harvey's House",
user=user,
)
e.participants.add(person)
assert len(e.participants.all()) == 1
assert e.type_descriptor == "Meeting"
assert person in e.participants.all()
assert e.user.name == uname
assert e.created_date.day == now.day
assert e.modified_date.day == now.day
|