@@ -14,7 +14,6 @@ def test_get_outputs() -> None:
14
14
15
15
# Test case: None input
16
16
assert get_outputs (None ) is None
17
-
18
17
# Test case: Empty list
19
18
assert get_outputs ([]) is None
20
19
@@ -34,6 +33,7 @@ def test_get_outputs() -> None:
34
33
},
35
34
]
36
35
result = get_outputs (valid_input )
36
+
37
37
assert result is not None
38
38
assert len (result ) == 2
39
39
assert result [0 ].req_id == "test1"
@@ -54,6 +54,7 @@ def test_get_outputs() -> None:
54
54
"finished_at" : timestamp ,
55
55
}
56
56
]
57
+
57
58
assert get_outputs (invalid_missing_field ) is None
58
59
59
60
# Test case: Wrong type for success field
@@ -65,6 +66,7 @@ def test_get_outputs() -> None:
65
66
"finished_at" : timestamp ,
66
67
}
67
68
]
69
+
68
70
assert get_outputs (invalid_wrong_type ) is None
69
71
70
72
# Test case: Invalid timestamp
@@ -76,11 +78,15 @@ def test_get_outputs() -> None:
76
78
"finished_at" : timestamp ,
77
79
}
78
80
]
81
+
79
82
assert get_outputs (invalid_timestamp ) is None
80
83
81
84
82
85
def test_process () -> None :
83
- timestamp = datetime .datetime .now (datetime .timezone .utc )
86
+ timestamp = datetime .datetime .now (datetime .timezone .utc ) - datetime .timedelta (
87
+ seconds = 1
88
+ )
89
+ timestamp_e = datetime .datetime .now (datetime .timezone .utc )
84
90
85
91
# Test case: None or empty list
86
92
assert process (None ) == SanityCheckResult (
@@ -92,24 +98,34 @@ def test_process() -> None:
92
98
timestamp = None ,
93
99
)
94
100
95
- # Test case: More than 3 tests
96
- four_tests = [
101
+ # Test case: more than 3 tests
102
+ many_tests = [
97
103
SanityCheckOutput (
98
- req_id = "test1" , success = True , started_at = timestamp , finished_at = timestamp
104
+ req_id = "test1" , success = False , started_at = timestamp , finished_at = timestamp_e
99
105
),
100
106
SanityCheckOutput (
101
- req_id = "test2" , success = False , started_at = timestamp , finished_at = timestamp
107
+ req_id = "test2" , success = True , started_at = timestamp , finished_at = timestamp
102
108
),
103
109
SanityCheckOutput (
104
110
req_id = "test3" , success = False , started_at = timestamp , finished_at = timestamp
105
111
),
106
112
SanityCheckOutput (
107
113
req_id = "test4" , success = False , started_at = timestamp , finished_at = timestamp
108
114
),
115
+ SanityCheckOutput (
116
+ req_id = "test5" , success = False , started_at = timestamp , finished_at = timestamp
117
+ ),
118
+ SanityCheckOutput (
119
+ req_id = "test6" , success = False , started_at = timestamp , finished_at = timestamp
120
+ ),
121
+ SanityCheckOutput (
122
+ req_id = "test7" , success = False , started_at = timestamp , finished_at = timestamp
123
+ ),
109
124
]
110
- assert process (four_tests ) == SanityCheckResult (
111
- status = SanityCheckStatus .available ,
112
- timestamp = timestamp ,
125
+
126
+ assert process (many_tests ) == SanityCheckResult (
127
+ status = SanityCheckStatus .warning ,
128
+ timestamp = timestamp_e ,
113
129
)
114
130
115
131
# Test case: 1 test, successful
@@ -118,6 +134,7 @@ def test_process() -> None:
118
134
req_id = "test1" , success = True , started_at = timestamp , finished_at = timestamp
119
135
)
120
136
]
137
+
121
138
assert process (one_test_success ) == SanityCheckResult (
122
139
status = SanityCheckStatus .available ,
123
140
timestamp = timestamp ,
@@ -129,6 +146,7 @@ def test_process() -> None:
129
146
req_id = "test1" , success = False , started_at = timestamp , finished_at = timestamp
130
147
)
131
148
]
149
+
132
150
assert process (one_test_failed ) == SanityCheckResult (
133
151
status = SanityCheckStatus .down ,
134
152
timestamp = timestamp ,
@@ -143,6 +161,7 @@ def test_process() -> None:
143
161
req_id = "test2" , success = True , started_at = timestamp , finished_at = timestamp
144
162
),
145
163
]
164
+
146
165
assert process (two_tests_all_success ) == SanityCheckResult (
147
166
status = SanityCheckStatus .available ,
148
167
timestamp = timestamp ,
@@ -157,6 +176,7 @@ def test_process() -> None:
157
176
req_id = "test2" , success = False , started_at = timestamp , finished_at = timestamp
158
177
),
159
178
]
179
+
160
180
assert process (two_tests_one_success ) == SanityCheckResult (
161
181
status = SanityCheckStatus .warning ,
162
182
timestamp = timestamp ,
@@ -171,6 +191,7 @@ def test_process() -> None:
171
191
req_id = "test2" , success = False , started_at = timestamp , finished_at = timestamp
172
192
),
173
193
]
194
+
174
195
assert process (two_tests_none_success ) == SanityCheckResult (
175
196
status = SanityCheckStatus .down ,
176
197
timestamp = timestamp ,
@@ -188,6 +209,7 @@ def test_process() -> None:
188
209
req_id = "test3" , success = True , started_at = timestamp , finished_at = timestamp
189
210
),
190
211
]
212
+
191
213
assert process (three_tests_all_success ) == SanityCheckResult (
192
214
status = SanityCheckStatus .available ,
193
215
timestamp = timestamp ,
@@ -205,6 +227,7 @@ def test_process() -> None:
205
227
req_id = "test3" , success = False , started_at = timestamp , finished_at = timestamp
206
228
),
207
229
]
230
+
208
231
assert process (three_tests_two_success ) == SanityCheckResult (
209
232
status = SanityCheckStatus .available ,
210
233
timestamp = timestamp ,
@@ -222,6 +245,7 @@ def test_process() -> None:
222
245
req_id = "test3" , success = False , started_at = timestamp , finished_at = timestamp
223
246
),
224
247
]
248
+
225
249
assert process (three_tests_one_success ) == SanityCheckResult (
226
250
status = SanityCheckStatus .warning ,
227
251
timestamp = timestamp ,
@@ -239,6 +263,7 @@ def test_process() -> None:
239
263
req_id = "test3" , success = False , started_at = timestamp , finished_at = timestamp
240
264
),
241
265
]
266
+
242
267
assert process (three_tests_none_success ) == SanityCheckResult (
243
268
status = SanityCheckStatus .down ,
244
269
timestamp = timestamp ,
0 commit comments