Skip to content

Commit 6d2a296

Browse files
committed
Add Testing.individual_test_case_health API
This will be used to render individual test case health widget Add UI
1 parent 4245b6b commit 6d2a296

File tree

3 files changed

+73
-4
lines changed

3 files changed

+73
-4
lines changed

tcms/telemetry/api.py

+16
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,22 @@ 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_simple(query=None):
232+
233+
if query is None:
234+
query = {}
235+
236+
res = (
237+
TestExecution.objects.filter(**query)
238+
.values("run__plan", "case_id", "status__name", "status__weight")
239+
.order_by("case", "run__plan", "status__weight")
240+
)
241+
242+
return list(res)
243+
244+
229245
def _remove_all_excellent_executions(data):
230246
for key in dict.fromkeys(data):
231247
if data[key]["count"]["fail"] == 0:

tcms/templates/include/tc_executions.html

+15-1
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,24 @@ <h2 class="card-pf-title">
2323
</div>
2424

2525
<div class="list-view-pf-body">
26-
<div class="list-view-pf-description">
26+
<div class="list-view-pf-description" style="display: flex; justify-content: space-between;">
2727
<div class="list-group-item-text">
2828
<a href="{% url 'test_plan_url_short' execution.run.plan.pk %}">TP-{{ execution.run.plan.pk }}: {{ execution.run.plan.name }}</a>
2929
</div>
30+
<div class="list-group-item-text">
31+
<div class="completion-rate-container">{% trans 'Completion rate' %}: <span class="completion-rate"></span>
32+
<div class="progress">
33+
<div class="progress-bar progress-bar-danger" role="progressbar"></div>
34+
<div class="progress-bar progress-bar-success" role="progressbar"></div>
35+
</div>
36+
</div>
37+
<div class="failure-rate-container">{% trans 'Failure rate' %}:<span class="failure-rate"></span>
38+
<div class="progress">
39+
<div class="progress-bar progress-bar-danger" role="progressbar"></div>
40+
<div class="progress-bar progress-bar-success" role="progressbar"></div>
41+
</div>
42+
</div>
43+
</div>
3044
</div>
3145
</div>
3246
</div> <!-- /main info -->

tcms/testcases/static/testcases/js/get.js

+42-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const plan_cache = {}
22

3-
function addComponent (object_id, _input, to_table) {
3+
function addComponent(object_id, _input, to_table) {
44
const _name = _input.value
55

66
if (_name.length > 0) {
@@ -15,7 +15,7 @@ function addComponent (object_id, _input, to_table) {
1515
}
1616
}
1717

18-
function addTestPlanToTestCase (case_id, plans_table) {
18+
function addTestPlanToTestCase(case_id, plans_table) {
1919
const plan_name = $('#input-add-plan')[0].value
2020
const plan = plan_cache[plan_name]
2121

@@ -31,7 +31,7 @@ function addTestPlanToTestCase (case_id, plans_table) {
3131
})
3232
}
3333

34-
function initAddPlan (case_id, plans_table) {
34+
function initAddPlan(case_id, plans_table) {
3535
// + button
3636
$('#btn-add-plan').click(function () {
3737
addTestPlanToTestCase(case_id, plans_table)
@@ -210,6 +210,45 @@ $(document).ready(function () {
210210
})
211211
})
212212

213+
jsonRPC('Testing.individual_test_case_health', { case_id: case_id }, ress => {
214+
215+
let res = {};
216+
let planId = 0;
217+
ress.forEach(r => {
218+
let positive = 0;
219+
let negative = 0;
220+
let allCount = 0;
221+
if (r.status__weight > 0) {
222+
positive++
223+
} else if (r.status__weight < 0) {
224+
negative++
225+
}
226+
allCount++
227+
228+
if (r.run__plan !== planId) {
229+
planId = r.run__plan;
230+
res[planId] = {
231+
"completion_rate": allCount > 0 ? ((positive + negative) / allCount) : 0,
232+
"failure_rate": allCount > 0 ? (negative / allCount) : 0,
233+
}
234+
positive = 0;
235+
negative = 0;
236+
allCount = 0;
237+
}
238+
})
239+
240+
Object.entries(res).forEach(([runId, data]) => {
241+
const executionRow = $(`#execution-for-plan-${runId}`)
242+
executionRow.find('.completion-rate').html(data.completion_rate)
243+
executionRow.find('.completion-rate-container .progress-bar-danger').css('width', `${(1 - data.completion_rate) * 100}%`)
244+
executionRow.find('.completion-rate-container .progress-bar-success').css('width', `${(data.completion_rate) * 100}%`)
245+
246+
executionRow.find('.failure-rate').html(data.failure_rate)
247+
executionRow.find('.failure-rate-container .progress-bar-danger').css('width', `${(data.failure_rate) * 100}%`)
248+
executionRow.find('.failure-rate-container .progress-bar-success').css('width', `${(1 - data.failure_rate) * 100}%`)
249+
})
250+
})
251+
213252
// bind add TP to TC widget
214253
initAddPlan(case_id, plans_table)
215254

0 commit comments

Comments
 (0)