Skip to content

Commit

Permalink
Add Testing.individual_test_case_health API
Browse files Browse the repository at this point in the history
This will be used to render individual test case health widget
  • Loading branch information
asankov committed Mar 3, 2021
1 parent 062849b commit 948046c
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions tcms/telemetry/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 948046c

Please sign in to comment.