Skip to content

Commit 948046c

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 948046c

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

tcms/telemetry/api.py

+36
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,42 @@ 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 TestExecution.objects.filter(**query).order_by(
240+
"run__plan_id"
241+
):
242+
status = test_execution.status
243+
244+
if status.weight > 0:
245+
positive += 1
246+
elif status.weight < 0:
247+
negative += 1
248+
all_count += 1
249+
250+
if test_execution.run.plan_id != plan_id:
251+
plan_id = test_execution.run_id
252+
res[plan_id] = {
253+
"positive": positive,
254+
"negative": negative,
255+
"all": all_count,
256+
}
257+
positive, negative, all_count = 0, 0, 0
258+
259+
# append the last result
260+
res[plan_id] = {"positive": positive, "negative": negative, "all": all_count}
261+
262+
return res
263+
264+
229265
def _remove_all_excellent_executions(data):
230266
for key in dict.fromkeys(data):
231267
if data[key]["count"]["fail"] == 0:

0 commit comments

Comments
 (0)