Skip to content

Commit cec22e0

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 ed6604a commit cec22e0

File tree

3 files changed

+69
-1
lines changed

3 files changed

+69
-1
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

+38
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,44 @@ $(document).ready(function () {
210210
})
211211
})
212212

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

0 commit comments

Comments
 (0)