Skip to content

Commit acdab9b

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 acdab9b

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

tcms/telemetry/api.py

+32
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,38 @@ 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] = {"positive": positive, "negative": negative, "all": all_count}
253+
positive, negative, all_count = 0, 0, 0
254+
255+
# append the last result
256+
res[plan_id] = {"positive": positive, "negative": negative, "all": all_count}
257+
258+
return res
259+
260+
229261
def _remove_all_excellent_executions(data):
230262
for key in dict.fromkeys(data):
231263
if data[key]["count"]["fail"] == 0:

0 commit comments

Comments
 (0)