Skip to content

Commit

Permalink
Add test_html_stats_report
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Baldwin committed Oct 11, 2023
1 parent d59e20e commit 68203e2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion locust/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def get_html_report(
"response_time_statistics": [
{
"name": escape(stat.name),
"method": escape(stat.method),
"method": escape(stat.method or ""),
**{
str(percentile): stat.get_response_time_percentile(percentile)
for percentile in PERCENTILES_FOR_HTML_REPORT
Expand Down
2 changes: 1 addition & 1 deletion locust/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ def _cache_response_times(self, t: int) -> None:

def to_dict(self, escape_string_values=False):
return {
"method": escape(self.method) if escape_string_values else self.method,
"method": escape(self.method or "") if escape_string_values else self.method,
"name": escape(self.name) if escape_string_values else self.name,
"safe_name": escape(self.name, quote=False),
"num_requests": self.num_requests,
Expand Down
27 changes: 26 additions & 1 deletion locust/test/test_web.py
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,18 @@ def tick(self):
self.assertRegex(response.text, re_spawn_rate)
self.assertNotRegex(response.text, re_disabled_spawn_rate)

def test_html_stats_report(self):
self.environment.locustfile = "locust.py"
self.environment.host = "http://localhost"

response = requests.get("http://127.0.0.1:%i/stats/report" % self.web_port)
self.assertEqual(200, response.status_code)

d = pq(response.content.decode("utf-8"))

self.assertIn("Script: <span>locust.py</span>", str(d))
self.assertIn("Target Host: <span>http://localhost</span>", str(d))


class TestWebUIAuth(LocustTestCase):
def setUp(self):
Expand Down Expand Up @@ -1133,7 +1145,7 @@ def test_request_stats_full_history_csv(self):
self.assertEqual("Aggregated", rows[3][3])


class TestModernWebUi(LocustTestCase, _HeaderCheckMixin):
class TestModernWebUI(LocustTestCase, _HeaderCheckMixin):
def setUp(self):
super().setUp()

Expand Down Expand Up @@ -1186,3 +1198,16 @@ def test_web_ui_no_runner(self):
self.assertEqual("Error: Locust Environment does not have any runner", response.text)
finally:
web_ui.stop()

def test_html_stats_report(self):
self.environment.locustfile = "locust.py"
self.environment.host = "http://localhost"

response = requests.get("http://127.0.0.1:%i/stats/report" % self.web_port)
self.assertEqual(200, response.status_code)

d = pq(response.content.decode("utf-8"))

self.assertTrue(d("#root"))
self.assertIn('"locustfile": "locust.py"', str(d))
self.assertIn('"host": "http://localhost"', str(d))

0 comments on commit 68203e2

Please sign in to comment.