Skip to content

Commit

Permalink
TestCase page - display bug URLs using LinkReference
Browse files Browse the repository at this point in the history
- in later commits superseded by using TestExecution.get_links()
- also update how we query bugs in TC details template. Only for
  visual clues on the page showing TC details inside TestPlan
  • Loading branch information
atodorov committed Aug 27, 2019
1 parent c750b0b commit 6c381c7
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 37 deletions.
8 changes: 3 additions & 5 deletions tcms/templates/case/get_details.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,11 @@ <h4><span class="title strong">{% trans "Tag" %}:</span></h4>
</ul>
<h4><span class="title strong">{% trans "bug" %}:</span></h4>
<ul class="ul-no-format">
{% for bug in test_case.get_bugs %}
{% for bug in bugs %}
<li>
<a href="{{ bug.get_full_url }}">{{ bug }}</a>
{% if bug.case_run_id %}
<a href="{{ bug.url }}">{{ bug.url }}</a>
<span class="grey"> - {% trans "From Run" %}</span>
<a href="{% url "testruns-get" bug.case_run.run_id %}">{{ bug.case_run.run_id }}</a>
{% endif %}
<a href="{% url "testruns-get" bug.execution.run_id %}">{{ bug.execution.run_id }}</a>
</li>
{% empty %}
<li class="grey">{% trans "No bug found" %}</li>
Expand Down
5 changes: 0 additions & 5 deletions tcms/testcases/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,6 @@ def add_component(self, component):
def add_tag(self, tag):
return TestCaseTag.objects.get_or_create(case=self, tag=tag)

def get_bugs(self):
return Bug.objects.select_related(
'case_run', 'bug_system'
).filter(case__case_id=self.case_id)

def get_previous_and_next(self, pk_list):
current_idx = pk_list.index(self.pk)
prev = TestCase.objects.get(pk=pk_list[current_idx - 1])
Expand Down
13 changes: 2 additions & 11 deletions tcms/testcases/static/testcases/js/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,6 @@ function addComponent(object_id, _input, to_table) {


$(document).ready(function() {
var bug_systems_cache = {}
jsonRPC('BugSystem.filter', {}, function(data) {
data.forEach(function(element) {
bug_systems_cache[element.id] = element
});
});

var case_id = $('#test_case_pk').data('pk');
var product_id = $('#product_pk').data('pk');
var perm_remove_tag = $('#test_case_pk').data('perm-remove-tag') === 'True';
Expand Down Expand Up @@ -224,15 +217,13 @@ $(document).ready(function() {
// bugs table
var bugs_table = $('#bugs').DataTable({
ajax: function(data, callback, settings) {
dataTableJsonRPC('Bug.filter', {case: case_id}, callback);
dataTableJsonRPC('Bug.filter', {execution__case: case_id}, callback);
},
columns: [
{
data: null,
render: function (data, type, full, meta) {
var url = bug_systems_cache[data.bug_system_id].url_reg_exp.replace('%s', data.bug_id).replace('%d', data.bug_id);
var name = bug_systems_cache[data.bug_system_id].name + ' #' + data.bug_id;
return '<a href="' + url + '">' + name + '</a>';
return '<a href="' + data.url + '">' + data.url + '</a>';
}
},
],
Expand Down
9 changes: 3 additions & 6 deletions tcms/testcases/templates/testcases/get.html
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,8 @@ <h2 class="card-pf-title">
</div>
<div class="list-view-pf-body">
<div class="list-view-pf-description">
<div class="list-group-item-heading">
<a href="{{ bug.get_full_url }}">{{ bug.bug_id }}</a>
</div>
<div class="list-group-item-text">
<a href="{{ bug.get_full_url }}">{{ bug.get_full_url }}</a>
<a href="{{ bug.url }}">{{ bug.url }}</a>
</div>
</div>
<div class="list-view-pf-additional-info">
Expand Down Expand Up @@ -277,7 +274,7 @@ <h2 class="card-pf-title">
</div>

<div class="row row-cards-pf">
<div class="col-xs-12 col-sm-6 col-md-3">
<div class="col-xs-12 col-sm-6 col-md-4">
<div class="card-pf card-pf-accented">
<h2 class="card-pf-title">
<span class="fa fa-bug"></span>
Expand All @@ -296,7 +293,7 @@ <h2 class="card-pf-title">
</div>
</div>

<div class="col-xs-12 col-sm-6 col-md-9">
<div class="col-xs-12 col-sm-6 col-md-8">
<div class="card-pf card-pf-accented">
<h2 class="card-pf-title">
<span class="fa pficon-topology"></span>
Expand Down
3 changes: 3 additions & 0 deletions tcms/testcases/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from tcms.testcases.forms import NewCaseForm, \
SearchCaseForm, CaseNotifyForm, CloneCaseForm
from tcms.testcases.fields import MultipleEmailField
from tcms.core.contrib.linkreference.models import LinkReference


TESTCASE_OPERATION_ACTIONS = (
Expand Down Expand Up @@ -482,6 +483,8 @@ def get_context_data(self, **kwargs):
'components': case.component.only('name'),
'tags': case.tag.only('name'),
'case_comments': get_comments(case),
'bugs': LinkReference.objects.filter(is_defect=True,
execution__case=case)
})

return data
Expand Down
14 changes: 8 additions & 6 deletions tcms/xmlrpc/api/bug.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

from django.utils.translation import ugettext_lazy as _

from tcms.testcases.models import Bug
from tcms.testcases.models import BugSystem
from tcms.testruns.models import TestExecution
from tcms.issuetracker.types import IssueTrackerType
from tcms.xmlrpc.decorators import permissions_required
from tcms.core.contrib.linkreference.models import LinkReference


__all__ = (
Expand All @@ -26,19 +26,21 @@ def filter(query): # pylint: disable=redefined-builtin
Get list of bugs that are associated with TestCase or
a TestExecution.
:param query: Field lookups for :class:`tcms.testcases.models.Bug`
:param query: Field lookups for :class:`tcms.core.contrib.linkreference.LinkReference`
:type query: dict
:return: List of serialized :class:`tcms.testcases.models.Bug` objects.
:return: List of serialized :class:`tcms.core.contrib.linkreference.LinkReference`
objects.
Get all bugs for particular TestCase::
>>> Bug.filter({'case': 123}) or Bug.filter({'case_id': 123})
>>> Bug.filter({'execution__case': 123})
Get all bugs for a particular TestExecution::
>>> Bug.filter({'case_run': 1234}) or Bug.filter({'case_run_id': 1234})
>>> Bug.filter({'execution': 1234})
"""
return Bug.to_xmlrpc(query)
query['is_defect'] = True
return list(LinkReference.objects.filter(**query).values())


@permissions_required('testcases.add_bug')
Expand Down
8 changes: 4 additions & 4 deletions tcms/xmlrpc/tests/test_testcasebug.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,25 @@ class BugFilter(XmlrpcAPIBaseTest):
def _fixture_setup(self):
super(BugFilter, self)._fixture_setup()

self.case_run = TestExecutionFactory()
self.execution = TestExecutionFactory()
self.bug_system_bz = BugSystem.objects.get(name='Bugzilla')

self.rpc_client.exec.Bug.create({
'case_id': self.case_run.case.pk,
'case_run_id': self.case_run.pk,
'case_run_id': self.execution.pk,
'bug_id': '67890',
'bug_system_id': self.bug_system_bz.pk,
'summary': 'Testing TCMS',
'description': 'Just foo and bar',
})

def test_get_bugs_with_non_existing_caserun(self):
bugs = self.rpc_client.exec.Bug.filter({'case_run': -1})
bugs = self.rpc_client.exec.Bug.filter({'execution': -1})
self.assertEqual(len(bugs), 0)
self.assertIsInstance(bugs, list)

def test_get_bugs_for_caserun(self):
bugs = self.rpc_client.exec.Bug.filter({'case_run': self.case_run.pk})
bugs = self.rpc_client.exec.Bug.filter({'execution': self.execution.pk})
self.assertIsNotNone(bugs)
self.assertEqual(1, len(bugs))
self.assertEqual(bugs[0]['summary'], 'Testing TCMS')
Expand Down

0 comments on commit 6c381c7

Please sign in to comment.