def test_providers(self): report = model.Report(results=[ model.SuiteResult(provider='aws'), model.SuiteResult(provider='gce'), model.SuiteResult(provider='azure'), ]) self.assertEqual(report.providers, ['aws', 'azure', 'gce'])
def test_remove_by_bundle_name_dry_run(self): report = model.Report(test_id='test', bundle=model.BundleInfo(name='foo'), date=datetime(2000, 1, 1), results=[ model.SuiteResult( provider='gce', test_outcome='PASS', ), ]) report_index = model.ReportIndex() report_index.upsert_report(report) report_2 = model.Report(test_id='test_2', bundle=model.BundleInfo(name='bar'), date=datetime(2000, 2, 2), results=[ model.SuiteResult( provider='aws', test_outcome='PASS', ), ]) report_index.upsert_report(report_2) removed_reports = report_index.remove_by_bundle_name('foo', dry_run=True) self.assertEqual(len(removed_reports), 1) self.assertEqual(removed_reports[0].bundle_name, 'foo') self.assertEqual(len(report_index.reports), 2) self.assertEqual(report_index.reports[0].bundle_name, 'bar') self.assertEqual(report_index.reports[1].bundle_name, 'foo')
def test_update_from_report(self): report = model.Report(test_id='test_id', bundle=model.BundleInfo(name='bundle'), date=datetime.now(), results=[ model.SuiteResult(provider='aws', test_outcome='PASS'), model.SuiteResult(provider='gce', test_outcome='FAIL'), ]) rii = model.ReportIndexItem( test_id='my-test', bundle_name='my-bundle', date=datetime(2000, 1, 1), ) self.assertEqual(rii.test_id, 'my-test') self.assertEqual(rii.bundle_name, 'my-bundle') self.assertEqual(rii.date, datetime(2000, 1, 1)) self.assertIsNone(rii.results) rii.update_from_report(report) self.assertEqual(rii.test_id, 'my-test') self.assertEqual(rii.bundle_name, 'my-bundle') self.assertEqual(rii.date, datetime(2000, 1, 1)) self.assertEqual(rii.results, {'aws': 'PASS', 'gce': 'FAIL'})
def test_upsert_result(self): result1 = model.SuiteResult( provider='aws', test_outcome='PASS', tests=[ model.TestResult( suite='bundle', name='charm proof', result='FAIL', duration=0.5, ), model.TestResult( suite='bundle', name='00-setup', result='FAIL', duration=0.5, ), ], ) result2 = model.SuiteResult( provider='aws', test_outcome='PASS', tests=[ model.TestResult( suite='bundle', name='charm proof', result='PASS', duration=0.5, ), ], ) result3 = model.SuiteResult( provider='gce', test_outcome='PASS', tests=[ model.TestResult( suite='bundle', name='charm proof', result='PASS', duration=0.5, ), ], ) report = model.Report( test_id='test2', bundle=model.BundleInfo(name='cs:my-bundle'), ) report.upsert_result(result1) self.assertEqual(report.results, [result1]) self.assertIsNot(report.results[0], result1) report.upsert_result(result2) self.assertEqual(report.results, [result2]) report.upsert_result(result3) self.assertEqual(report.results, [result2, result3])
def test_from_report(self): report = model.Report(test_id='test_id', bundle=model.BundleInfo(name='bundle'), date=datetime.now(), results=[ model.SuiteResult(provider='aws', test_outcome='PASS'), model.SuiteResult(provider='gce', test_outcome='FAIL'), ]) rii = model.ReportIndexItem.from_report(report) self.assertEqual(rii.test_id, 'test_id') self.assertEqual(rii.bundle_name, 'bundle') self.assertEqual(rii.date, report.date) self.assertEqual(rii.results, {'aws': 'PASS', 'gce': 'FAIL'})
def test_upsert_report(self): ri = model.ReportIndex() self.assertEqual(ri.providers, []) self.assertEqual(len(ri.reports), 0) report = model.Report(test_id='test', bundle=model.BundleInfo(name='bundle'), date=datetime(2000, 1, 1), results=[ model.SuiteResult( provider='gce', test_outcome='PASS', ), ]) ri.upsert_report(report) self.assertEqual(ri.providers, ['gce']) self.assertEqual(len(ri.reports), 1) report.results.append( model.SuiteResult( provider='aws', test_outcome='FAIL', )) # we're not just storing a copy of the Report instance self.assertEqual(ri.providers, ['gce']) self.assertEqual(len(ri.reports), 1) ri.upsert_report(report) self.assertEqual(ri.providers, ['aws', 'gce']) self.assertEqual(len(ri.reports), 1) ri.upsert_report( model.Report(test_id='test2', bundle=model.BundleInfo(name='bundle'), date=datetime(2000, 1, 2))) self.assertEqual(len(ri.reports), 2) self.assertEqual(ri.reports[0].test_id, 'test2')
def generate_test_result(provider, test_name, output, suite='Error', test_outcome=None, bundle_yaml=None): test_outcome = test_outcome or model.TEST_OUTCOMES.infra if test_outcome not in list(model.TEST_OUTCOMES): raise ValueError('Invalid test outcome value.') return model.SuiteResult(provider=provider, test_outcome=test_outcome, bundle_yaml=bundle_yaml, tests=[ model.TestResult(name=test_name, duration=0.0, output=output, result=test_outcome, suite=suite) ])
def test_as_html_xml(self): test_dir = os.path.dirname(__file__) with open(os.path.join(test_dir, 'data/hadoop-processing.svg')) as fp: svg_data = fp.read() report = model.Report( test_id='test2', bundle=model.BundleInfo(name='cs:my-bundle'), results=[ model.SuiteResult( provider='aws', test_outcome='PASS', tests=[ model.TestResult(suite='bundle', name='charm proof', result='PASS', duration=0.5, output="Some output"), model.TestResult(suite='bundle', name='00-setup', result='PASS', duration=0.5, output="Some other output"), model.TestResult(suite='mysql', name='00-setup', result='PASS', duration=1.5, output="Some more output"), ], ), model.SuiteResult( provider='gce', test_outcome='Some Failed', tests=[ model.TestResult( suite='bundle', name='charm proof', result='PASS', duration=0.5, ), model.TestResult( suite='bundle', name='00-setup', result='PASS', duration=0.5, ), model.TestResult( suite='mysql', name='00-setup', result='FAIL', duration=2.5, ), ], ), ], benchmarks=[ model.Benchmark(name='bench1', results=[ model.BenchmarkResult( test_id='test1', provider_results=[ model.BenchmarkProviderResult( provider='aws', value=1.1, ), model.BenchmarkProviderResult( provider='gce', value=0.5, ), ]), model.BenchmarkResult( test_id='test2', provider_results=[ model.BenchmarkProviderResult( provider='aws', value=1.2, ), ]), model.BenchmarkResult( test_id='test3', provider_results=[ model.BenchmarkProviderResult( provider='aws', value=1.2, ), model.BenchmarkProviderResult( provider='gce', value=0.9, ), ]), model.BenchmarkResult( test_id='test4', provider_results=[ model.BenchmarkProviderResult( provider='aws', value=1.0, ), model.BenchmarkProviderResult( provider='gce', value=1.2, ), ]), ]), model.Benchmark(name='bench2', results=[ model.BenchmarkResult( test_id='test1', provider_results=[ model.BenchmarkProviderResult( provider='aws', value=2.1, ), ]), model.BenchmarkResult( test_id='test2', provider_results=[ model.BenchmarkProviderResult( provider='aws', value=2.2, ), ]), ]), ]) html = report.as_html(None) soup = BeautifulSoup(html, 'html.parser') self.assertIn('Image not available', html) self.assertEqual(soup.title.text, 'cs:my-bundle') self.assertIn("display_chart(1, {", html) self.assertIn("display_chart(2, {", html) html = report.as_html(svg_data) self.assertNotIn('Image not available', html) self.assertIn('src="data:image/svg+xml;base64,', html) xml = report.as_xml() self.assertIn('Some other output', xml) self.assertIn('testsuite', xml)