From 0e7576079e88dc1a56449fc3ee4c200d8a7b73f7 Mon Sep 17 00:00:00 2001 From: Brylie Christopher Oxley Date: Fri, 5 Jan 2024 22:27:36 +0200 Subject: [PATCH] Add auth tests --- metrics/tests.py | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/metrics/tests.py b/metrics/tests.py index 22c0f9a..16ffbb7 100644 --- a/metrics/tests.py +++ b/metrics/tests.py @@ -12,7 +12,7 @@ class ResidentActivityFormViewTestCase(TestCase): - def setUp(self): + def setUp(self) -> None: # Create a user self.general_user = user_model.objects.create_user( username="gerneraluser", @@ -52,6 +52,41 @@ def setUp(self): move_out=None, ) + self.url = reverse("resident-activity-form-view") + + def test_general_user_gets_403(self): + """Test that a general user gets a 403 response.""" + # log in general user + self.client.force_login(self.general_user) + + # Make GET request + response = self.client.get(self.url) + + # The response should indicate a failure to process the form + self.assertEqual(response.status_code, HTTPStatus.FORBIDDEN) + + def test_home_user_gets_200(self): + """Test that a home user gets a 200 response.""" + # log in home user + self.client.force_login(self.home_user) + + # Make GET request + response = self.client.get(self.url) + + # The response should indicate a successful form submission + self.assertEqual(response.status_code, HTTPStatus.OK) + + def test_superuser_gets_200(self): + """Test that a superuser gets a 200 response.""" + # log in superuser + self.client.force_login(self.superuser) + + # Make GET request + response = self.client.get(self.url) + + # The response should indicate a successful form submission + self.assertEqual(response.status_code, HTTPStatus.OK) + def test_resident_activity_form_view_create_multiple_resident_activity(self): """Test that multiple resident activities can be created with one POST request.""" @@ -73,7 +108,7 @@ def test_resident_activity_form_view_create_multiple_resident_activity(self): # Make POST request response = self.client.post( - reverse("resident-activity-form-view"), + self.url, self.data, ) @@ -126,7 +161,7 @@ def test_activity_rollback_on_residency_exception(self): # Make POST request response = self.client.post( - reverse("resident-activity-form-view"), + self.url, self.data, )