def testjob_csv(request, job): job = get_object_or_404(TestJob, pk=job) check_request_auth(request, job) def testjob_stream(suites, pseudo_buffer): fieldnames = testcase_export_fields() writer = csv.DictWriter(pseudo_buffer, fieldnames=fieldnames) # writer.writeheader does not return the string while writer.writerow # does. Copy writeheader code from csv.py and yield the value. yield writer.writerow(dict(zip(fieldnames, fieldnames))) for test_suite in suites: for test_case in test_suite.testcase_set.all(): yield writer.writerow(export_testcase(test_case)) suites = job.testsuite_set.all().prefetch_related( "test_sets__test_cases__actionlevels" ) pseudo_buffer = StreamEcho() response = StreamingHttpResponse( testjob_stream(suites, pseudo_buffer), content_type="text/csv" ) filename = "lava_%s.csv" % job.id response["Content-Disposition"] = 'attachment; filename="%s"' % filename return response
def suite_csv_stream(request, job, pk): """ Django is designed for short-lived requests. Streaming responses will tie a worker process for the entire duration of the response. This may result in poor performance. Generally speaking, you should perform expensive tasks outside of the request-response cycle, rather than resorting to a streamed response. https://docs.djangoproject.com/en/1.8/ref/request-response/#django.http.StreamingHttpResponse https://docs.djangoproject.com/en/1.8/howto/outputting-csv/ """ job = get_object_or_404(TestJob, pk=job) test_suite = get_object_or_404(TestSuite, name=pk, job=job) check_request_auth(request, job) querydict = request.GET offset = int(querydict.get("offset", default=0)) limit = int(querydict.get("limit", default=0)) pseudo_buffer = StreamEcho() writer = csv.writer(pseudo_buffer) testcases = get_testcases_with_limit(test_suite, limit, offset) response = StreamingHttpResponse( (writer.writerow(export_testcase(row)) for row in testcases), content_type="text/csv", ) filename = "lava_stream_%s.csv" % test_suite.name response["Content-Disposition"] = 'attachment; filename="%s"' % filename return response
def suite(request, job, pk): job = get_object_or_404(TestJob, pk=job) check_request_auth(request, job) test_suite = get_object_or_404(TestSuite, name=pk, job=job) data = SuiteView(request, model=TestCase, table_class=SuiteTable) suite_table = SuiteTable(data.get_table_data().filter(suite=test_suite)) RequestConfig(request, paginate={ "per_page": suite_table.length }).configure(suite_table) template = loader.get_template("lava_results_app/suite.html") return HttpResponse( template.render( { 'bread_crumb_trail': BreadCrumbTrail.leading_to(suite, pk=pk, job=job.id), 'job': job, 'job_link': pklink(job), 'content_type_id': ContentType.objects.get_for_model(TestCase).id, 'suite_name': pk, 'suite_table': suite_table, 'bug_links': BugLink.objects.filter( object_id=test_suite.id, content_type_id=ContentType.objects.get_for_model( TestSuite).id, ) }, request=request))
def suite_csv_stream(request, job, pk): """ Django is designed for short-lived requests. Streaming responses will tie a worker process for the entire duration of the response. This may result in poor performance. Generally speaking, you should perform expensive tasks outside of the request-response cycle, rather than resorting to a streamed response. https://docs.djangoproject.com/en/1.8/ref/request-response/#django.http.StreamingHttpResponse https://docs.djangoproject.com/en/1.8/howto/outputting-csv/ """ job = get_object_or_404(TestJob, pk=job) test_suite = get_object_or_404(TestSuite, name=pk, job=job) check_request_auth(request, job) querydict = request.GET offset = querydict.get('offset', default=None) limit = querydict.get('limit', default=None) pseudo_buffer = StreamEcho() writer = csv.writer(pseudo_buffer) testcases = get_testcases_with_limit(test_suite, limit, offset) response = StreamingHttpResponse( (writer.writerow(export_testcase(row)) for row in testcases), content_type="text/csv") filename = "lava_stream_%s.csv" % test_suite.name response['Content-Disposition'] = 'attachment; filename="%s"' % filename return response
def testcase_yaml(request, pk): testcase = get_object_or_404(TestCase, pk=pk) check_request_auth(request, testcase.suite.job) response = HttpResponse(content_type="text/yaml") filename = "lava_%s.yaml" % testcase.name response["Content-Disposition"] = 'attachment; filename="%s"' % filename yaml_dump(export_testcase(testcase, with_buglinks=True), response) return response
def testcase_yaml(request, pk): testcase = get_object_or_404(TestCase, pk=pk) check_request_auth(request, testcase.suite.job) response = HttpResponse(content_type='text/yaml') filename = "lava_%s.yaml" % testcase.name response['Content-Disposition'] = 'attachment; filename="%s"' % filename yaml.dump(export_testcase(testcase, with_buglinks=True), response, Dumper=yaml.CDumper) return response
def suite_yaml(request, job, pk): job = get_object_or_404(TestJob, pk=job) check_request_auth(request, job) test_suite = get_object_or_404(TestSuite, name=pk, job=job) response = HttpResponse(content_type='text/yaml') filename = "lava_%s.yaml" % test_suite.name response['Content-Disposition'] = 'attachment; filename="%s"' % filename yaml_list = [] for test_case in test_suite.testcase_set.all(): yaml_list.append(export_testcase(test_case)) yaml.dump(yaml_list, response) return response
def testjob_yaml_summary(request, job): job = get_object_or_404(TestJob, pk=job) check_request_auth(request, job) suites = job.testsuite_set.all() response = HttpResponse(content_type="text/yaml") filename = "lava_%s_summary.yaml" % job.id response["Content-Disposition"] = 'attachment; filename="%s"' % filename yaml_list = [] for test_suite in suites: yaml_list.append(export_testsuite(test_suite)) yaml.dump(yaml_list, response, Dumper=yaml.CDumper) return response
def testjob_yaml_summary(request, job): job = get_object_or_404(TestJob, pk=job) check_request_auth(request, job) suites = job.testsuite_set.all() response = HttpResponse(content_type='text/yaml') filename = "lava_%s_summary.yaml" % job.id response['Content-Disposition'] = 'attachment; filename="%s"' % filename yaml_list = [] for test_suite in suites: yaml_list.append(export_testsuite(test_suite)) yaml.dump(yaml_list, response, Dumper=yaml.CDumper) return response
def testjob_yaml(request, job): job = get_object_or_404(TestJob, pk=job) check_request_auth(request, job) response = HttpResponse(content_type='text/yaml') filename = "lava_%s.yaml" % job.id response['Content-Disposition'] = 'attachment; filename="%s"' % filename yaml_list = [] suites = job.testsuite_set.all().prefetch_related( 'test_sets__test_cases__actionlevels') for test_suite in suites: for test_case in test_suite.testcase_set.all(): yaml_list.append(export_testcase(test_case)) yaml.dump(yaml_list, response, Dumper=yaml.CDumper) return response
def suite_csv(request, job, pk): job = get_object_or_404(TestJob, pk=job) check_request_auth(request, job) test_suite = get_object_or_404(TestSuite, name=pk, job=job) response = HttpResponse(content_type='text/csv') filename = "lava_%s.csv" % test_suite.name response['Content-Disposition'] = 'attachment; filename="%s"' % filename writer = csv.DictWriter(response, quoting=csv.QUOTE_ALL, extrasaction='ignore', fieldnames=testcase_export_fields()) writer.writeheader() for row in test_suite.testcase_set.all(): writer.writerow(export_testcase(row)) return response
def testjob_yaml(request, job): job = get_object_or_404(TestJob, pk=job) check_request_auth(request, job) suites = job.testsuite_set.all().prefetch_related( "test_sets__test_cases__actionlevels" ) def test_case_stream(): for test_suite in suites: for test_case in test_suite.testcase_set.all(): yield yaml.dump([export_testcase(test_case)], Dumper=yaml.CDumper) response = StreamingHttpResponse(test_case_stream(), content_type="text/yaml") filename = "lava_%s.yaml" % job.id response["Content-Disposition"] = 'attachment; filename="%s"' % filename return response
def suite_yaml(request, job, pk): job = get_object_or_404(TestJob, pk=job) check_request_auth(request, job) test_suite = get_object_or_404(TestSuite, name=pk, job=job) querydict = request.GET offset = querydict.get('offset', default=None) limit = querydict.get('limit', default=None) response = HttpResponse(content_type='text/yaml') filename = "lava_%s.yaml" % test_suite.name response['Content-Disposition'] = 'attachment; filename="%s"' % filename yaml_list = [] testcases = get_testcases_with_limit(test_suite, limit, offset) for test_case in testcases: yaml_list.append(export_testcase(test_case)) yaml.dump(yaml_list, response, Dumper=yaml.CDumper) return response
def suite_csv(request, job, pk): job = get_object_or_404(TestJob, pk=job) check_request_auth(request, job) test_suite = get_object_or_404(TestSuite, name=pk, job=job) response = HttpResponse(content_type='text/csv') filename = "lava_%s.csv" % test_suite.name response['Content-Disposition'] = 'attachment; filename="%s"' % filename writer = csv.DictWriter( response, quoting=csv.QUOTE_ALL, extrasaction='ignore', fieldnames=testcase_export_fields()) writer.writeheader() for row in test_suite.testcase_set.all(): writer.writerow(export_testcase(row)) return response
def suite_yaml(request, job, pk): job = get_object_or_404(TestJob, pk=job) check_request_auth(request, job) test_suite = get_object_or_404(TestSuite, name=pk, job=job) querydict = request.GET offset = int(querydict.get("offset", default=0)) limit = int(querydict.get("limit", default=0)) response = HttpResponse(content_type="text/yaml") filename = "lava_%s.yaml" % test_suite.name response["Content-Disposition"] = 'attachment; filename="%s"' % filename yaml_list = [] testcases = get_testcases_with_limit(test_suite, limit, offset) for test_case in testcases: yaml_list.append(export_testcase(test_case)) yaml.dump(yaml_list, response, Dumper=yaml.CDumper) return response
def testjob_yaml(request, job): job = get_object_or_404(TestJob, pk=job) check_request_auth(request, job) suites = job.testsuite_set.all().prefetch_related( 'test_sets__test_cases__actionlevels') def test_case_stream(): for test_suite in suites: for test_case in test_suite.testcase_set.all(): yield yaml.dump([export_testcase(test_case)], Dumper=yaml.CDumper) response = StreamingHttpResponse(test_case_stream(), content_type="text/yaml") filename = "lava_%s.yaml" % job.id response['Content-Disposition'] = 'attachment; filename="%s"' % filename return response
def testjob_csv(request, job): job = get_object_or_404(TestJob, pk=job) check_request_auth(request, job) response = HttpResponse(content_type='text/csv') filename = "lava_%s.csv" % job.id response['Content-Disposition'] = 'attachment; filename="%s"' % filename writer = csv.DictWriter(response, quoting=csv.QUOTE_ALL, extrasaction='ignore', fieldnames=testcase_export_fields()) writer.writeheader() suites = job.testsuite_set.all().prefetch_related( 'test_sets__test_cases__actionlevels') for test_suite in suites: for test_case in test_suite.testcase_set.all(): writer.writerow(export_testcase(test_case)) return response
def suite(request, job, pk): job = get_object_or_404(TestJob, pk=job) check_request_auth(request, job) test_suite = get_object_or_404(TestSuite, name=pk, job=job) data = SuiteView(request, model=TestCase, table_class=SuiteTable) suite_table = SuiteTable( data.get_table_data().filter(suite=test_suite) ) RequestConfig(request, paginate={"per_page": suite_table.length}).configure(suite_table) template = loader.get_template("lava_results_app/suite.html") return HttpResponse(template.render( { 'bread_crumb_trail': BreadCrumbTrail.leading_to(suite, pk=pk, job=job.id), 'job': job, 'job_link': pklink(job), 'suite_name': pk, 'suite_table': suite_table, }, request=request))
def suite_csv(request, job, pk): job = get_object_or_404(TestJob, pk=job) check_request_auth(request, job) test_suite = get_object_or_404(TestSuite, name=pk, job=job) querydict = request.GET offset = querydict.get('offset', default=None) limit = querydict.get('limit', default=None) response = HttpResponse(content_type='text/csv') filename = "lava_%s.csv" % test_suite.name response['Content-Disposition'] = 'attachment; filename="%s"' % filename writer = csv.DictWriter(response, quoting=csv.QUOTE_ALL, extrasaction='ignore', fieldnames=testcase_export_fields()) writer.writeheader() testcases = get_testcases_with_limit(test_suite, limit, offset) for row in testcases: writer.writerow(export_testcase(row)) return response
def metadata_export(request, job): """ Dispatcher adds some metadata, Job submitter can add more. CSV is not supported as the user-supplied metadata can include nested dicts or lists. """ job = get_object_or_404(TestJob, pk=job) check_request_auth(request, job) # testdata from job & export testdata = get_object_or_404(TestData, testjob=job) response = HttpResponse(content_type='text/yaml') filename = "lava_metadata_%s.yaml" % job.id response['Content-Disposition'] = 'attachment; filename="%s"' % filename yaml_dict = {} # hide internal python objects for data in testdata.attributes.all(): yaml_dict[str(data.name)] = str(data.value) yaml.dump(yaml_dict, response) return response
def suite_csv(request, job, pk): job = get_object_or_404(TestJob, pk=job) check_request_auth(request, job) test_suite = get_object_or_404(TestSuite, name=pk, job=job) querydict = request.GET offset = querydict.get('offset', default=None) limit = querydict.get('limit', default=None) response = HttpResponse(content_type='text/csv') filename = "lava_%s.csv" % test_suite.name response['Content-Disposition'] = 'attachment; filename="%s"' % filename writer = csv.DictWriter( response, quoting=csv.QUOTE_ALL, extrasaction='ignore', fieldnames=testcase_export_fields()) writer.writeheader() testcases = get_testcases_with_limit(test_suite, limit, offset) for row in testcases: writer.writerow(export_testcase(row)) return response
def testjob_csv(request, job): job = get_object_or_404(TestJob, pk=job) check_request_auth(request, job) def testjob_stream(suites, pseudo_buffer): fieldnames = testcase_export_fields() writer = csv.DictWriter(pseudo_buffer, fieldnames=fieldnames) # writer.writeheader does not return the string while writer.writerow # does. Copy writeheader code from csv.py and yield the value. yield writer.writerow(dict(zip(fieldnames, fieldnames))) for test_suite in suites: for test_case in test_suite.testcase_set.all(): yield writer.writerow(export_testcase(test_case)) suites = job.testsuite_set.all().prefetch_related('test_sets__test_cases__actionlevels') pseudo_buffer = StreamEcho() response = StreamingHttpResponse(testjob_stream(suites, pseudo_buffer), content_type="text/csv") filename = "lava_%s.csv" % job.id response['Content-Disposition'] = 'attachment; filename="%s"' % filename return response
def check_user_auth(user, job, request=None): if request: check_request_auth(request, job) return True return job.can_view(user)
def suite_testcase_count(request, job, pk): job = get_object_or_404(TestJob, pk=job) check_request_auth(request, job) test_suite = get_object_or_404(TestSuite, name=pk, job=job) test_case_count = test_suite.testcase_set.all().count() return HttpResponse(test_case_count, content_type="text/plain")
def suite_testcase_count(request, job, pk): job = get_object_or_404(TestJob, pk=job) check_request_auth(request, job) test_suite = get_object_or_404(TestSuite, name=pk, job=job) test_case_count = test_suite.testcase_set.all().count() return HttpResponse(test_case_count, content_type='text/plain')