Skip to content

Commit

Permalink
Add auth tests
Browse files Browse the repository at this point in the history
  • Loading branch information
brylie committed Jan 5, 2024
1 parent 37c0872 commit 0e75760
Showing 1 changed file with 38 additions and 3 deletions.
41 changes: 38 additions & 3 deletions metrics/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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."""
Expand All @@ -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,
)

Expand Down Expand Up @@ -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,
)

Expand Down

0 comments on commit 0e75760

Please sign in to comment.