Skip to content

Commit

Permalink
Add TestModernWebUi
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Baldwin committed Sep 25, 2023
1 parent c90f116 commit 2956155
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions locust/test/test_web.py
Original file line number Diff line number Diff line change
Expand Up @@ -1083,3 +1083,63 @@ def test_request_stats_full_history_csv(self):
self.assertEqual("/test2", rows[2][3])
self.assertEqual("", rows[3][2])
self.assertEqual("Aggregated", rows[3][3])


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

parser = get_parser(default_config_files=[])
self.environment.parsed_options = parser.parse_args(["--modern-ui"])
self.stats = self.environment.stats

self.web_ui = self.environment.create_web_ui("127.0.0.1", 0, modern_ui=True)
self.web_ui.app.view_functions["request_stats"].clear_cache()
gevent.sleep(0.01)
self.web_port = self.web_ui.server.server_port

def tearDown(self):
super().tearDown()
self.web_ui.stop()
self.runner.quit()

def test_web_ui_reference_on_environment(self):
self.assertEqual(self.web_ui, self.environment.web_ui)

def test_web_ui_no_runner(self):
env = Environment()
web_ui = WebUI(env, "127.0.0.1", 0)
gevent.sleep(0.01)
try:
response = requests.get("http://127.0.0.1:%i/" % web_ui.server.server_port)
self.assertEqual(500, response.status_code)
self.assertEqual("Error: Locust Environment does not have any runner", response.text)
finally:
web_ui.stop()

def test_index_with_modern_ui(self):
self.assertEqual(200, requests.get("http://127.0.0.1:%i/" % self.web_port).status_code)

def test_index_uses_correct_template(self):
response = requests.get("http://127.0.0.1:%i/" % self.web_port)

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

self.assertTrue(d("#root"))

def test_index_with_spawn_options(self):
html_to_option = {
"num_users": ["-u", "100"],
"spawn_rate": ["-r", "10.0"],
}

for html_name_to_test in html_to_option.keys():
# Test that setting each spawn option individually populates the corresponding field in the html, and none of the others
self.environment.parsed_options = parse_options(html_to_option[html_name_to_test])

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

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

self.assertIn(f"\"{html_name_to_test}\": {html_to_option[html_name_to_test][1]}",str(d("script")))

0 comments on commit 2956155

Please sign in to comment.