Skip to content

Commit

Permalink
Combine ModernUi tests into single test
Browse files Browse the repository at this point in the history
Andrew Baldwin committed Oct 10, 2023
1 parent 573f363 commit 804a19a
Showing 1 changed file with 17 additions and 22 deletions.
39 changes: 17 additions & 22 deletions locust/test/test_web.py
Original file line number Diff line number Diff line change
@@ -1103,36 +1103,20 @@ def tearDown(self):
self.web_ui.stop()
self.runner.quit()

def test_web_ui_reference_on_environment(self):
def test_index_with_modern_ui(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)
html_to_option = {
"num_users": ["-u", "100"],
"spawn_rate": ["-r", "10.0"],
}

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.assertEqual(200, response.status_code)
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])
@@ -1143,3 +1127,14 @@ def test_index_with_spawn_options(self):
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")))

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()

0 comments on commit 804a19a

Please sign in to comment.