-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_generator.py
328 lines (255 loc) · 11.3 KB
/
test_generator.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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
import pytest
from kafka import generator as generator
import datetime
patient_payload_sample = {
"id" : 1,
"name": "test person",
"age":34,
"gender" : "Female",
"phone": "+353-88-3658730",
"address" : "87591 Angel Pines Suite 496,Dublin 3, Dublin, Republic of Ireland",
"condition": "hypertension",
"bmi": 26.43,
"status": "critical unhealthy",
"device_id": "SMARTWATCH3-372788e3655e4f73ad6427c517d97d8c"
}
sensor_payload_sample = {
"reading_id": "26d537f50a294c77af90b7cfb9d38e5f",
"heart_rate": 132,
"blood_pressure_top" : 167,
"blood_pressure_bottom": 111,
"body_temperature":37.15,
"blood_sugar_level" :119,
"timestamp" : "2021-08-04 22:11:00",
"longitude": -6.315947,
"latitude": 53.364602
}
def test_generate_seed():
"""
This test asserts that the generate_seed function output is less than/equal to 100.
"""
assert generator.generate_seed() <= 100
def test_unique_id():
"""
This test asserts that the create_unique_id function is an instance of the type string.
"""
assert isinstance(generator.create_unique_id(), str)
def test_create_device_id():
"""
This test asserts that the create_device_id function is an instance of the type string.
"""
assert isinstance(generator.create_device_id(), str)
def test_create_heart_rate():
""""
This test asserts that the create_heart_rate function output is greater
than/equal to 40 and less than/equal to 219 when the parameter/input
emergency is set to False.
"""
assert 40 <= generator.create_heart_rate(emergency=False) <= 219
def test_emergency_heart_rate():
"""
This test asserts that the create_heart_rate function output is greater
than/equal to 40 and less than/equal to 300 when the parameter/input
emergency is set to True.
"""
assert 40 <= generator.create_heart_rate(emergency=True) <= 300
def test_blood_pressure_top():
"""
This test asserts that the create_blood_pressure_top function output is greater than/equal to
100 and less than/equal to 179 when the parameter/input
emergency is set to True.
"""
assert 100 <= generator.create_blood_pressure_top(emergency=False) <= 179
def test_emergency_blood_pressure_top():
"""
This test asserts that the create_emergency_blood_pressure_top function output is greater than/equal
to 100 and less than/equal to 200 when the parameter/input
emergency is set to True.
"""
assert 100 <= generator.create_blood_pressure_top(emergency=True) <= 220
def test_blood_pressure_bottom():
"""
This test asserts that the create_blood_pressure_bottom function output is greater than/equal to 50 and less than/equal
to 119 when the parameter/input emergency is set to False.
"""
assert 50 <= generator.create_blood_pressure_bottom(emergency=False) <= 119
def test_emergency_blood_pressure_bottom():
"""
This test asserts that the create_emergency_blood_pressure_bottom function output
is greater than/equal to 50 and less than/equal to 140 when the parameter/input
emergency is set to True.
"""
assert 50 <= generator.create_blood_pressure_bottom(emergency=True) <= 140
def test_body_temperature():
"""
This test asserts that the create_body_temperature function output is greater than/equal to 35.0 and
less than/equal to 37.3 when the parameter/input emergency is set to False.
"""
assert 35.0 <= generator.create_body_temperature(emergency=False) <= 37.3
def test_emergency_body_temperature():
"""
This test asserts that the create_emergency_body_temperature function output is greater than/equal to 35.0
and less than/equal to 41.9 when the parameter/input emergency is set to True
"""
assert 35.0 <= generator.create_body_temperature(emergency=True) <= 41.9
def test_blood_sugar_level():
"""
This test asserts that the create_blood_sugar_level function output is greater
than/equal to 35 and less than/equal to 199 when the parameter/input emergency is set to False.
"""
assert 35 <= generator.create_blood_sugar_level(emergency=False) <= 199
def test_emergency_blood_sugar_level():
"""
This test asserts that the create_emergency_blood_sugar_level function output is greater than/equal to 35 and less than/equal
to 400 when the parameter/input emergency is set to True.
"""
assert 35 <= generator.create_blood_sugar_level(emergency=True) <= 400
def test_phone_number():
"""
This test asserts that the prefix +353 is a string of the function create_phone_number.
"""
assert '+353-' in str(generator.create_phone_number())
def test_geolocation_longitude():
"""
This test asserts that the create_geolocation_longitude function output is greater than/equal to -6.44 and less than/equal to -6.20
"""
assert -6.44 <= generator.create_geolocation('longitude') <= -6.20
def test_geolocation_latitude():
"""
This test asserts that the create_geolocation_latitude function output is greater than/equal to 53.20 and less than/equal to 53.40
"""
assert 53.20 <= generator.create_geolocation('latitude') <= 53.40
def test_dublin_address():
"""
This test asserts that the Dublin, Republic of Ireland is a string of the function create_dublin_address.
"""
assert ', Dublin, Republic of Ireland' in str(generator.create_dublin_address())
def test_health_status():
"""
This test asserts that the function create_health_status is present in the array conditions and status that were created.
It also checks if the bmi than/equal to 18.5 and less than/equal to 40.5
"""
conditions = ['diabetes', 'hypertension', 'heart disease', 'none']
statuses = ['critical unhealthy', 'stable unhealthy', 'stable healthy', 'emergency']
# Loop it time times so we pick random conditions, statues and BMI for the patient_health to check
for x in range(10):
patient_health = generator.create_health_status()
actual_condition = patient_health[0]
actual_bmi = patient_health[1]
actual_status = patient_health[2]
assert actual_condition in conditions
assert 18.5 <= actual_bmi <= 40.5
assert actual_status in statuses
def test_time_of_measurement():
actual_timestamps = generator.create_time_of_measurement()
#Test if the output is a list
assert isinstance(actual_timestamps, list)
#Test that an element in the list is datetime format
assert isinstance(actual_timestamps[0], datetime.date)
def test_patient_content():
"""
This test asserts if the column of the patient content are part of the function
create_patient_content.
"""
payload = generator.create_patient_content()
columns = ['id',
'name',
'age',
'gender',
'phone',
'address',
'condition',
'bmi',
'status',
'device_id']
for column in columns:
assert column in payload.keys()
def test_sensor_content():
"""
This test asserts if the column of the sensor content are part of the function
create_sensor_content.
"""
payload = generator.create_sensor_content(timestamp='2021-08-04 22:17:00')
columns = ['reading_id',
'heart_rate',
'blood_pressure_top',
'blood_pressure_bottom',
'body_temperature',
'blood_sugar_level',
'timestamp',
'longitude',
'latitude']
for column in columns:
assert column in payload.keys()
def test_emergency_alerts_payload():
"""
This test asserts if the column emergency are part of the function
create_emergency_alerts.
:return:
"""
patient_payload = generator.create_patient_content()
sensor_payload = generator.create_sensor_content(timestamp='2021-08-04 22:17:00')
payload = generator.create_emergency_alerts(patient_payload,sensor_payload)
column = 'alert'
assert column in payload.keys()
def test_emergency_condition_one():
"""
This function will test if condition one, 'EMERGENCY! HYPERTENSION DETECTED,
from create_emergency_alerts() is part the string alert payload.
"""
alert_payload = generator.create_emergency_alerts(patient_payload_sample,
sensor_payload_sample)
assert 'EMERGENCY! HYPERTENSION DETECTED' in str(alert_payload)
def test_emergency_condition_two():
"""
This function will test if condition two body temperature equals 34 and the message EMERGENCY! HYPOTHERMIA DETECTED
from create_emergency_alerts() is part the string alert payload.
"""
sensor_payload_sample["body_temperature"] = 34
alert_payload = generator.create_emergency_alerts(patient_payload_sample,
sensor_payload_sample)
assert 'EMERGENCY! HYPOTHERMIA DETECTED' in str(alert_payload)
def test_emergency_condition_three():
"""
This function will test if condition two body temperature equals 42 and the message EMERGENCY! HYPERTHERMIA DETECTED
from create_emergency_alerts() is part the string alert payload.
:return:
"""
sensor_payload_sample["body_temperature"] = 42
alert_payload = generator.create_emergency_alerts(patient_payload_sample,
sensor_payload_sample)
assert 'EMERGENCY! HYPERTHERMIA DETECTED' in str(alert_payload)
def test_emergency_condition_four():
"""
This function will test if condition four,body temperature equals 39 and the status is stable unhealthy , then
the message to be printed is WARNING! FEVER DETECTED from create_emergency_alerts()
is part the string alert payload.
"""
sensor_payload_sample["body_temperature"] = 39
patient_payload_sample["status"] = "stable unhealthy "
alert_payload = generator.create_emergency_alerts(patient_payload_sample,
sensor_payload_sample)
assert 'WARNING! FEVER DETECTED' in str(alert_payload)
def test_emergency_condition_five():
"""
This function will test if condition five,blood sugar level equals 350 and the condition is diabetes, then
the message to be printed is EMERGENCY! HYPERGLYCEMIA DETECTED from create_emergency_alerts()
is part the string alert payload.
"""
sensor_payload_sample["blood_sugar_level"] = 350
patient_payload_sample["condition"] = "diabetes"
alert_payload = generator.create_emergency_alerts(patient_payload_sample,
sensor_payload_sample)
assert 'EMERGENCY! HYPERGLYCEMIA DETECTED' in str(alert_payload)
def test_emergency_condition_six():
"""
This function will test if condition six,bheart_rate equals 290 and the condition is heart disease, then
the message to be printed is WARNING! TACHYCARDIA DETECTED from create_emergency_alerts()
is part the string alert payload.
:return:
"""
sensor_payload_sample["heart_rate"] = 290
patient_payload_sample["condition"] = "heart disease"
alert_payload = generator.create_emergency_alerts(patient_payload_sample,
sensor_payload_sample)
assert 'WARNING! TACHYCARDIA DETECTED' in str(alert_payload)