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 10, 2021
1 parent 2d7275e commit f2bd8f3
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions tcms/telemetry/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,44 @@ 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)
.values("run__plan", "case_id", "status__name", "status__weight")
.order_by("case", "run__plan", "status__weight")
):
if test_execution["status__weight"] > 0:
positive += 1
elif test_execution["status__weight"] < 0:
negative += 1
all_count += 1

if test_execution["run__plan"] != plan_id:
plan_id = test_execution["run__plan"]
res[plan_id] = {
"completion_rate": (positive + negative) / all_count,
"failure_rate": negative / all_count,
}
positive, negative, all_count = 0, 0, 0

# append the last result
res[plan_id] = {
"completion_rate": (positive + negative) / all_count,
"failure_rate": negative / 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 f2bd8f3

Please sign in to comment.