Skip to content

Commit

Permalink
Add test_template_args
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewbaldwin44 committed Jan 18, 2024
1 parent ac3e744 commit 8c409c5
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions locust/test/test_web.py
Original file line number Diff line number Diff line change
Expand Up @@ -1065,6 +1065,32 @@ def test_logs(self):

self.assertIn(log_line, response.json().get("logs"))

def test_template_args(self):
class MyUser(User):
@task
def do_something(self):
self.client.get("/")

host = "http://example.com"

class MyUser2(User):
host = "http://example.com"

self.environment.user_classes = [MyUser, MyUser2]
self.environment.available_user_classes = {"User1": MyUser, "User2": MyUser2}
self.environment.available_user_tasks = {"User1": MyUser.tasks, "User2": MyUser2.tasks}

users = {"User1": MyUser.json(), "User2": MyUser2.json()}
available_user_tasks = {"User1": ["do_something"], "User2": []}

self.web_ui.update_template_args()

self.assertEqual(self.web_ui.template_args.get("users"), users)
self.assertEqual(
self.web_ui.template_args.get("available_user_classes"), sorted(self.environment.available_user_classes)
)
self.assertEqual(self.web_ui.template_args.get("available_user_tasks"), available_user_tasks)


class TestWebUIAuth(LocustTestCase):
def setUp(self):
Expand Down

0 comments on commit 8c409c5

Please sign in to comment.