diff --git a/tcms/static/js/testrun_actions.js b/tcms/static/js/testrun_actions.js index c5c116021e..027786fb8e 100644 --- a/tcms/static/js/testrun_actions.js +++ b/tcms/static/js/testrun_actions.js @@ -237,12 +237,6 @@ Nitrate.TestRuns.Details.on_load = function() { jQ('#btn_delete').bind('click', function() { window.location.href = jQ(this).data('param'); }); - jQ('#btn_export_csv').bind('click', function() { - window.location.href = jQ(this).data('param') + '?format=csv&' + jQ('#id_form_case_runs').serialize(); - }); - jQ('#btn_export_xml').bind('click', function() { - window.location.href = jQ(this).data('param') + '?format=xml&' + jQ('#id_form_case_runs').serialize(); - }); jQ('.js-remove-tag').bind('click', function() { var params = jQ(this).data('params'); removeRuntag(jQ('.js-tag-ul')[0], params[0], params[1]); diff --git a/tcms/templates/run/get.html b/tcms/templates/run/get.html index 76ace0c853..250afcb718 100644 --- a/tcms/templates/run/get.html +++ b/tcms/templates/run/get.html @@ -66,8 +66,6 @@ {% endifequal %} {% endifequal %} - - {% endif %}

{{ test_run.summary }}

diff --git a/tcms/testruns/helpers/serializer.py b/tcms/testruns/helpers/serializer.py index 61a1b73157..285e9cc266 100644 --- a/tcms/testruns/helpers/serializer.py +++ b/tcms/testruns/helpers/serializer.py @@ -1,10 +1,4 @@ # -*- coding: utf-8 -*- -''' -A serializer to import/export between model objects and file formats. -''' - -import csv - from xml.sax.saxutils import escape @@ -17,108 +11,3 @@ def escape_entities(text): @rtype: str ''' return escape(text, {'"': '"'}) if text else text - - -# TODO: rewrite export module to export TestCaseRuns, TestPlans and other -# Nitrate objects. - - -class TCR2File(object): - ''' - Write TestCaseRun queryset into CSV or XML. - ''' - ROOT = 'testcaseruns' - HEADERS = ("Case Run ID", "Case ID", - "Category", "Status", "Summary", - "script", "Automated", "Log Link", - "Bug IDs") - - def __init__(self, tcrs): - self.root = self.ROOT - self.headers = self.HEADERS - - qs = tcrs.select_related('case', - 'case_run_status') - self.tcrs = qs.only('case__summary', - 'case__script', - 'case__is_automated', - 'case__category__name', - 'case_run_status__name') - self.rows = [] - - def tcr_attrs_in_a_list(self, tcr): - if tcr.case.script is None: - case_script = '' - else: - case_script = tcr.case.script.encode('utf-8') - - line = (tcr.pk, tcr.case.pk, - tcr.case.category.name.encode('utf-8'), - tcr.case_run_status.name.encode('utf-8'), - tcr.case.summary.encode('utf-8'), - case_script, - tcr.case.is_automated, - self.log_links(tcr), - self.bug_ids(tcr)) - return line - - def log_links(self, tcr): - ''' - Wrap log links into a single cell by - joining log links. - ''' - return '\n'.join( - (url.encode('utf-8') - for url in tcr.links.values_list('url', flat=True)) - ) - - def bug_ids(self, tcr): - ''' - Wrap bugs into a single cell by - joining bug IDs. - ''' - bug_ids = tcr.case_run_bug.values_list('bug_id', flat=True) - return ' '.join((str(pk) for pk in bug_ids.iterator())) - - def tcrs_in_rows(self): - tcr_attrs_in_a_list = self.tcr_attrs_in_a_list - for tcr in self.tcrs.iterator(): - row = tcr_attrs_in_a_list(tcr) - yield row - - def write_to_csv(self, fileobj): - writer = csv.writer(fileobj) - writer.writerow(self.headers) - writer.writerows(self.tcrs_in_rows()) - - def write_to_xml(self, output): - write_to_output = output.write - tcr_start_elem = u'' - - def write_loglink(link): - return write_to_output( - u'' % (link.name, link.url)) - - def write_bug(bug): - return write_to_output(u'' % bug.bug_id) - - write_to_output(u'<%s>' % self.root) - for tcr in self.tcrs.iterator(): - summary = escape_entities(tcr.case.summary) - script = escape_entities(tcr.case.script) - write_to_output(tcr_start_elem % (tcr.pk, tcr.case.pk, - tcr.case.category.name or u'', - tcr.case_run_status.name, - summary or u'', - script or u'', - str(tcr.case.is_automated))) - write_to_output(u'') - map(write_loglink, tcr.links.iterator()) - write_to_output(u'') - write_to_output(u'') - map(write_bug, tcr.case_run_bug.iterator()) - write_to_output(u'') - write_to_output(u'') - write_to_output(u'' % self.root) diff --git a/tcms/testruns/tests/test_views.py b/tcms/testruns/tests/test_views.py index 2c2b34cd56..d837b6f62b 100644 --- a/tcms/testruns/tests/test_views.py +++ b/tcms/testruns/tests/test_views.py @@ -1,11 +1,8 @@ # -*- coding: utf-8 -*- -import os import json import http.client from datetime import timedelta -from mock import patch -from xml.etree import ElementTree from django.utils import formats from django.urls import reverse @@ -1023,43 +1020,6 @@ def test_delete_env_value_from_runs(self): self.assertFalse(rel.exists()) -class TestExportTestRunCases(BaseCaseRun): - """Test export view method to export test case runs""" - - @classmethod - def setUpTestData(cls): - super(TestExportTestRunCases, cls).setUpTestData() - - cls.export_url = reverse('testruns-export', - args=[cls.test_run.pk]) - - @patch('tcms.testruns.views.time.strftime', return_value='2017-06-17') - def test_export_to_xml_file(self, strftime): - response = self.client.get(self.export_url, {'format': 'xml'}) - self.assertEqual( - 'attachment; filename=tcms-testcase-runs-2017-06-17.xml', - response['Content-Disposition']) - - @patch('tcms.testruns.views.time.strftime', return_value='2017-06-17') - def test_export_to_csv_file(self, strftime): - response = self.client.get(self.export_url, {'format': 'csv'}) - self.assertEqual( - 'attachment; filename=tcms-testcase-runs-2017-06-17.csv', - response['Content-Disposition']) - - def test_export_all_case_runs_to_csv_by_default(self): - response = self.client.get(self.export_url, {'format': 'csv'}) - self.assertEqual(self.test_run.case_run.count(), - # Do not count header line - len(str(response.content, encoding=settings.DEFAULT_CHARSET).strip().split(os.linesep)) - 1) - - def test_export_all_case_runs_to_xml_by_default(self): - response = self.client.get(self.export_url, {'format': 'xml'}) - xmldoc = ElementTree.fromstring(response.content) - case_run_nodes = xmldoc.findall('testcaserun') - self.assertEqual(self.test_run.case_run.count(), len(case_run_nodes)) - - class TestBugActions(BaseCaseRun): """Test bug view method""" diff --git a/tcms/testruns/urls/run_urls.py b/tcms/testruns/urls/run_urls.py index c499758ea2..023935e1ce 100644 --- a/tcms/testruns/urls/run_urls.py +++ b/tcms/testruns/urls/run_urls.py @@ -26,5 +26,4 @@ url(r'^(?P\d+)/cc/$', views.cc, name='testruns-cc'), url(r'^(?P\d+)/update/$', views.update_case_run_text, name='testruns-update_case_run_text'), - url(r'^(?P\d+)/export/$', views.export, name='testruns-export'), ] diff --git a/tcms/testruns/views.py b/tcms/testruns/views.py index 9d7c1b698d..58d6d960cb 100755 --- a/tcms/testruns/views.py +++ b/tcms/testruns/views.py @@ -3,7 +3,6 @@ import datetime import itertools import json -import time from urllib.parse import urlencode from functools import reduce @@ -47,7 +46,6 @@ from tcms.testruns.data import TestCaseRunDataMixin from tcms.testruns.forms import MulitpleRunsCloneForm, PlanFilterRunForm from tcms.testruns.forms import NewRunForm, SearchRunForm, EditRunForm, RunCloneForm -from tcms.testruns.helpers.serializer import TCR2File from tcms.testruns.models import TestRun, TestCaseRun, TestCaseRunStatus, TCMSEnvRunValueMap from tcms.issuetracker.types import IssueTrackerType @@ -1386,31 +1384,6 @@ def update_case_run_text(request, run_id): ) -@require_GET -def export(request, run_id): - timestamp_str = time.strftime('%Y-%m-%d') - case_runs = request.GET.getlist('case_run') - format = request.GET.get('format', 'csv') - # Export selected case runs - if case_runs: - tcrs = TestCaseRun.objects.filter(case_run_id__in=case_runs) - # Export all case runs - else: - tcrs = TestCaseRun.objects.filter(run=run_id) - response = HttpResponse() - writer = TCR2File(tcrs) - if format == 'csv': - writer.write_to_csv(response) - response['Content-Disposition'] = \ - 'attachment; filename=tcms-testcase-runs-%s.csv' % timestamp_str - else: - writer.write_to_xml(response) - response['Content-Disposition'] = \ - 'attachment; filename=tcms-testcase-runs-%s.xml' % timestamp_str - - return response - - @require_GET def env_value(request): """Run environment property edit function"""