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

Add UI
  • Loading branch information
asankov committed Aug 3, 2021
1 parent 4245b6b commit 4d60aca
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 1 deletion.
16 changes: 16 additions & 0 deletions tcms/telemetry/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,22 @@ 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_simple(query=None):

if query is None:
query = {}

res = (
TestExecution.objects.filter(**query)
.values("run__plan", "case_id", "status__name", "status__weight")
.order_by("case", "run__plan", "status__weight")
)

return list(res)


def _remove_all_excellent_executions(data):
for key in dict.fromkeys(data):
if data[key]["count"]["fail"] == 0:
Expand Down
16 changes: 15 additions & 1 deletion tcms/templates/include/tc_executions.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,24 @@ <h2 class="card-pf-title">
</div>

<div class="list-view-pf-body">
<div class="list-view-pf-description">
<div class="list-view-pf-description" style="display: flex; justify-content: space-between;">
<div class="list-group-item-text">
<a href="{% url 'test_plan_url_short' execution.run.plan.pk %}">TP-{{ execution.run.plan.pk }}: {{ execution.run.plan.name }}</a>
</div>
<div class="list-group-item-text">
<div class="completion-rate-container">{% trans 'Completion rate' %}: <span class="completion-rate"></span>
<div class="progress">
<div class="progress-bar progress-bar-danger" role="progressbar"></div>
<div class="progress-bar progress-bar-success" role="progressbar"></div>
</div>
</div>
<div class="failure-rate-container">{% trans 'Failure rate' %}:<span class="failure-rate"></span>
<div class="progress">
<div class="progress-bar progress-bar-danger" role="progressbar"></div>
<div class="progress-bar progress-bar-success" role="progressbar"></div>
</div>
</div>
</div>
</div>
</div>
</div> <!-- /main info -->
Expand Down
38 changes: 38 additions & 0 deletions tcms/testcases/static/testcases/js/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,44 @@ $(document).ready(function () {
})
})

jsonRPC('Testing.individual_test_case_health', { case_id: case_id }, ress => {
const res = {}
let planId = 0
ress.forEach(r => {
let positive = 0
let negative = 0
let allCount = 0
if (r.status__weight > 0) {
positive++
} else if (r.status__weight < 0) {
negative++
}
allCount++

if (r.run__plan !== planId) {
planId = r.run__plan
res[planId] = {
completion_rate: allCount > 0 ? ((positive + negative) / allCount) : 0,
failure_rate: allCount > 0 ? (negative / allCount) : 0
}
positive = 0
negative = 0
allCount = 0
}
})

Object.entries(res).forEach(([runId, data]) => {
const executionRow = $(`#execution-for-plan-${runId}`)
executionRow.find('.completion-rate').html(data.completion_rate)
executionRow.find('.completion-rate-container .progress-bar-danger').css('width', `${(1 - data.completion_rate) * 100}%`)
executionRow.find('.completion-rate-container .progress-bar-success').css('width', `${(data.completion_rate) * 100}%`)

executionRow.find('.failure-rate').html(data.failure_rate)
executionRow.find('.failure-rate-container .progress-bar-danger').css('width', `${(data.failure_rate) * 100}%`)
executionRow.find('.failure-rate-container .progress-bar-success').css('width', `${(1 - data.failure_rate) * 100}%`)
})
})

// bind add TP to TC widget
initAddPlan(case_id, plans_table)

Expand Down

0 comments on commit 4d60aca

Please sign in to comment.