fix: unittests for html report
This commit is contained in:
parent
42bd882c99
commit
d15d811b6f
|
@ -3,7 +3,7 @@ import re
|
|||
import shutil
|
||||
import time
|
||||
|
||||
from httprunner import exceptions, loader, parser
|
||||
from httprunner import exceptions, loader, parser, report
|
||||
from httprunner.api import HttpRunner
|
||||
from tests.api_server import HTTPBIN_SERVER
|
||||
from tests.base import ApiServerUnittest
|
||||
|
@ -34,7 +34,8 @@ class TestHttpRunner(ApiServerUnittest):
|
|||
'request': {
|
||||
'url': 'http://127.0.0.1:5000/api/get-token',
|
||||
'method': 'POST',
|
||||
'headers': {'Content-Type': 'application/json', 'app_version': '2.8.6', 'device_sn': 'FwgRiO7CNA50DSU', 'os_platform': 'ios', 'user_agent': 'iOS/10.3'},
|
||||
'headers': {'Content-Type': 'application/json', 'app_version': '2.8.6',
|
||||
'device_sn': 'FwgRiO7CNA50DSU', 'os_platform': 'ios', 'user_agent': 'iOS/10.3'},
|
||||
'json': {'sign': '9c0c7e51c91ae963c833a4ccbab8d683c4a90c98'}
|
||||
},
|
||||
'extract': [
|
||||
|
@ -51,7 +52,8 @@ class TestHttpRunner(ApiServerUnittest):
|
|||
'request': {
|
||||
'url': 'http://127.0.0.1:5000/api/users/1000',
|
||||
'method': 'POST',
|
||||
'headers': {'Content-Type': 'application/json', 'device_sn': 'FwgRiO7CNA50DSU','token': '$token'},
|
||||
'headers': {'Content-Type': 'application/json',
|
||||
'device_sn': 'FwgRiO7CNA50DSU','token': '$token'},
|
||||
'json': {'name': 'user1', 'password': '123456'}
|
||||
},
|
||||
'validate': [
|
||||
|
@ -179,27 +181,30 @@ class TestHttpRunner(ApiServerUnittest):
|
|||
self.assertEqual(token1, token2)
|
||||
|
||||
def test_html_report(self):
|
||||
report_save_dir = os.path.join(os.getcwd(), 'reports', "demo")
|
||||
runner = HttpRunner(failfast=True, report_dir=report_save_dir)
|
||||
runner.run(self.testcase_cli_path)
|
||||
summary = runner.summary
|
||||
runner = HttpRunner(failfast=True)
|
||||
summary = runner.run(self.testcase_cli_path)
|
||||
self.assertEqual(summary["stat"]["testcases"]["total"], 1)
|
||||
self.assertEqual(summary["stat"]["teststeps"]["total"], 10)
|
||||
self.assertEqual(summary["stat"]["teststeps"]["skipped"], 4)
|
||||
|
||||
report_save_dir = os.path.join(os.getcwd(), 'reports', "demo")
|
||||
report.render_html_report(summary, report_dir=report_save_dir)
|
||||
self.assertGreater(len(os.listdir(report_save_dir)), 0)
|
||||
shutil.rmtree(report_save_dir)
|
||||
|
||||
def test_html_report_with_fixed_report_file(self):
|
||||
report_save_dir = os.path.join(os.getcwd(), 'reports', "demo")
|
||||
report_file = 'test.html'
|
||||
runner = HttpRunner(failfast=True, report_dir=report_save_dir, report_file=report_file)
|
||||
runner = HttpRunner(failfast=True)
|
||||
runner.run(self.testcase_cli_path)
|
||||
summary = runner.summary
|
||||
self.assertEqual(summary["stat"]["testcases"]["total"], 1)
|
||||
self.assertEqual(summary["stat"]["teststeps"]["total"], 10)
|
||||
self.assertEqual(summary["stat"]["teststeps"]["skipped"], 4)
|
||||
|
||||
report_file = os.path.join(os.getcwd(), 'reports', "demo", "test.html")
|
||||
report.render_html_report(summary, report_file=report_file)
|
||||
report_save_dir = os.path.dirname(report_file)
|
||||
self.assertEqual(len(os.listdir(report_save_dir)), 1)
|
||||
self.assertTrue(os.path.isfile(os.path.join(report_save_dir, report_file)))
|
||||
self.assertTrue(os.path.isfile(report_file))
|
||||
shutil.rmtree(report_save_dir)
|
||||
|
||||
def test_log_file(self):
|
||||
|
@ -267,10 +272,12 @@ class TestHttpRunner(ApiServerUnittest):
|
|||
)
|
||||
|
||||
def test_html_report_repsonse_image(self):
|
||||
runner = HttpRunner(failfast=True)
|
||||
summary = runner.run("tests/httpbin/load_image.yml")
|
||||
|
||||
report_save_dir = os.path.join(os.getcwd(), 'reports', "demo")
|
||||
runner = HttpRunner(failfast=True, report_dir=report_save_dir)
|
||||
report = runner.run("tests/httpbin/load_image.yml")
|
||||
self.assertTrue(os.path.isfile(report))
|
||||
report_path = report.render_html_report(summary, report_dir=report_save_dir)
|
||||
self.assertTrue(os.path.isfile(report_path))
|
||||
shutil.rmtree(report_save_dir)
|
||||
|
||||
def test_testcase_layer_with_api(self):
|
||||
|
@ -582,7 +589,8 @@ class TestHttpRunner(ApiServerUnittest):
|
|||
tests_mapping = {
|
||||
"testcases": testcases
|
||||
}
|
||||
report_path = self.runner.run(tests_mapping)
|
||||
summary = self.runner.run(tests_mapping)
|
||||
report_path = report.render_html_report(summary)
|
||||
with open(report_path) as f:
|
||||
content = f.read()
|
||||
m = re.findall(
|
||||
|
|
Loading…
Reference in New Issue