def get(self, request, **kwargs): solution = self.get_object(**kwargs) if solution.status() == 'pending': messages.info( request, 'This solution is still being checked. Please try again later.' ) return redirect('solutions:list', slug=solution.task.slug) if solution.status() in ['lost', 'error']: messages.warning( request, 'Sorry, but the server had trouble checking this solution. Please try ' 'to upload it again or contact the administrator if the problem persists.' ) return redirect('solutions:list', slug=solution.task.slug) result = solution.testresult_set.last() xml_reports_junit = checkeroutput_filter(result.testoutput_set) testsuites = [xml_to_dict(xml) for xml in xml_reports_junit] context = { 'solution': solution, 'result': result, 'testsuites': testsuites, 'files': solution.solutionfile_set.all(), 'requested_archive': kwargs.get('requested_archive') } context.update(self.get_context_data()) return TemplateResponse(request, 'solutions/solution_detail.html', context)
def test_missing_systemerr_or_systemout(self): documents = [ "<testsuite><system-err /></testsuite>", "<testsuite><system-out /></testsuite>", "<testsuite></testsuite>", ] for document in documents: ts = junit.xml_to_dict(document) self.assertEqual(len(ts["testcases"]), 0)
def test_missing_systemerr_or_systemout(self): documents = [ "<testsuite><system-err /></testsuite>", "<testsuite><system-out /></testsuite>", "<testsuite></testsuite>", ] for document in documents: ts = junit.xml_to_dict(document) self.assertEqual(len(ts["testcases"]), 0)
def get(self, request, **kwargs): solution = self.get_object(**kwargs) if solution.status() == "pending": messages.info( request, "This solution is still being checked. Please try again later." ) return redirect("solutions:list", slug=solution.task.slug) if solution.status() in ["lost", "error"]: messages.warning( request, "Sorry, but the server had trouble checking this solution. Please try " "to upload it again or contact the administrator if the problem persists." ) return redirect("solutions:list", slug=solution.task.slug) result = solution.testresult_set.last() xml_reports_junit = checkeroutput_filter(result.testoutput_set) testsuites = [xml_to_dict(xml) for xml in xml_reports_junit] xml_strings_checkstyle = xml_strings_from_testoutput( testoutput_set=result.testoutput_set, startswith="checkstyle_errors", endswith=".xml") if xml_strings_checkstyle: checkstyle_context = context_from_xml_strings( xml_strings=xml_strings_checkstyle, filter_keys=[]) checkstyle_data = CheckstyleData(checkstyle_context, solution.solutionfile_set.all()) else: checkstyle_data = None context = { "solution": solution, "result": result, "testsuites": testsuites, "checkstyle_data": checkstyle_data, "files": solution.solutionfile_set.all(), "requested_archive": kwargs.get("requested_archive") } context.update(self.get_context_data()) return TemplateResponse(request, "solutions/solution_detail.html", context)
def get(self, request, **kwargs): solution = self.get_object(**kwargs) if solution.status() == "pending": messages.info(request, "This solution is still being checked. Please try again later.") return redirect("solutions:list", slug=solution.task.slug) if solution.status() in ["lost", "error"]: messages.warning( request, "Sorry, but the server had trouble checking this solution. Please try " "to upload it again or contact the administrator if the problem persists." ) return redirect("solutions:list", slug=solution.task.slug) result = solution.testresult_set.last() xml_reports_junit = checkeroutput_filter(result.testoutput_set) testsuites = [xml_to_dict(xml) for xml in xml_reports_junit] xml_strings_checkstyle = xml_strings_from_testoutput( testoutput_set=result.testoutput_set, startswith="checkstyle_errors", endswith=".xml" ) if xml_strings_checkstyle: checkstyle_context = context_from_xml_strings( xml_strings=xml_strings_checkstyle, filter_keys=[]) checkstyle_data = CheckstyleData(checkstyle_context, solution.solutionfile_set.all()) else: checkstyle_data = None context = { 'solution': solution, 'result': result, 'testsuites': testsuites, 'checkstyle_data': checkstyle_data, 'files': solution.solutionfile_set.all(), } context.update(self.get_context_data()) return TemplateResponse(request, "solutions/solution_detail.html", context)
def test_malicious_xmlfile(self): with self.assertRaises(ValueError): junit.xml_to_dict(MALICIOUS_XML)
def test_no_testcases(self): ts = junit.xml_to_dict( "<testsuite><system-out /><system-err /></testsuite>") self.assertEqual(len(ts["testcases"]), 0)
def test_invalid_input(self): with self.assertRaises(ValueError): junit.xml_to_dict("<invalid-root />")
def setUp(self): self.ts = junit.xml_to_dict(JUNIT_SAMPLE_XML)
def test_malicious_xmlfile(self): with self.assertRaises(ValueError): junit.xml_to_dict(MALICIOUS_XML)
def test_no_testcases(self): ts = junit.xml_to_dict("<testsuite><system-out /><system-err /></testsuite>") self.assertEqual(len(ts["testcases"]), 0)
def test_invalid_input(self): with self.assertRaises(ValueError): junit.xml_to_dict("<invalid-root />")
def setUp(self): self.ts = junit.xml_to_dict(JUNIT_SAMPLE_XML)