Skip to content

Commit 99335ab

Browse files
committed
Add Testing.individual_test_case_health API
This will be used to render individual test case health widget
1 parent 062849b commit 99335ab

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

tcms/telemetry/api.py

+38
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,44 @@ def test_case_health(query=None):
226226
return data
227227

228228

229+
@http_basic_auth_login_required
230+
@rpc_method(name="Testing.individual_test_case_health")
231+
def individual_test_case_health(query=None):
232+
233+
if query is None:
234+
query = {}
235+
236+
res = {}
237+
plan_id = 0
238+
positive, negative, all_count = 0, 0, 0
239+
for test_execution in (
240+
TestExecution.objects.filter(**query)
241+
.values("run__plan", "case_id", "status__name", "status__weight")
242+
.order_by("case", "run__plan", "status__weight")
243+
):
244+
if test_execution["status__weight"] > 0:
245+
positive += 1
246+
elif test_execution["status__weight"] < 0:
247+
negative += 1
248+
all_count += 1
249+
250+
if test_execution["run__plan"] != plan_id:
251+
plan_id = test_execution["run__plan"]
252+
res[plan_id] = {
253+
"completion_rate": (positive + negative) / all_count,
254+
"failure_rate": negative / all_count,
255+
}
256+
positive, negative, all_count = 0, 0, 0
257+
258+
# append the last result
259+
res[plan_id] = {
260+
"completion_rate": (positive + negative) / all_count,
261+
"failure_rate": negative / all_count,
262+
}
263+
264+
return res
265+
266+
229267
def _remove_all_excellent_executions(data):
230268
for key in dict.fromkeys(data):
231269
if data[key]["count"]["fail"] == 0:

0 commit comments

Comments
 (0)