diff --git a/tcms/telemetry/api.py b/tcms/telemetry/api.py index 6b42a06b06..6b9d997f73 100644 --- a/tcms/telemetry/api.py +++ b/tcms/telemetry/api.py @@ -226,6 +226,42 @@ def test_case_health(query=None): return data +@http_basic_auth_login_required +@rpc_method(name="Testing.individual_test_case_health") +def individual_test_case_health(query=None): + + if query is None: + query = {} + + res = {} + plan_id = 0 + positive, negative, all_count = 0, 0, 0 + for test_execution in TestExecution.objects.filter(**query).order_by( + "run__plan_id" + ): + status = test_execution.status + + if status.weight > 0: + positive += 1 + elif status.weight < 0: + negative += 1 + all_count += 1 + + if test_execution.run.plan_id != plan_id: + plan_id = test_execution.run_id + res[plan_id] = { + "positive": positive, + "negative": negative, + "all": all_count, + } + positive, negative, all_count = 0, 0, 0 + + # append the last result + res[plan_id] = {"positive": positive, "negative": negative, "all": all_count} + + return res + + def _remove_all_excellent_executions(data): for key in dict.fromkeys(data): if data[key]["count"]["fail"] == 0: