diff --git a/backend/samfundet/tests/test_views.py b/backend/samfundet/tests/test_views.py index a034411fd..ef5e63588 100644 --- a/backend/samfundet/tests/test_views.py +++ b/backend/samfundet/tests/test_views.py @@ -4,7 +4,6 @@ from django.contrib.auth.models import Permission, Group from django.urls import reverse -from django.utils import timezone from rest_framework import status from guardian.shortcuts import assign_perm @@ -111,6 +110,7 @@ def test_get_groups(fixture_rest_client: APIClient, fixture_user: User): class TestInformationPagesView: + def test_get_informationpage( self, fixture_rest_client: APIClient, @@ -148,9 +148,8 @@ def test_get_informationpages( assert status.is_success(code=response.status_code) assert data[0]["slug_field"] == fixture_informationpage.slug_field - def test_create_informationpage( - self, fixture_rest_client: APIClient, fixture_user: User - ): + def test_create_informationpage(self, fixture_rest_client: APIClient, + fixture_user: User): ### Arrange ### fixture_rest_client.force_authenticate(user=fixture_user) url = reverse(routes.samfundet__information_list) @@ -217,6 +216,7 @@ def test_put_informationpage( class TestBlogPostView: + def test_get_blogpost( self, fixture_rest_client: APIClient, @@ -224,7 +224,8 @@ def test_get_blogpost( fixture_blogpost: BlogPost, ): ### Arrange ### - url = reverse(routes.samfundet__blog_detail, kwargs={"pk": fixture_blogpost.id}) + url = reverse(routes.samfundet__blog_detail, + kwargs={"pk": fixture_blogpost.id}) ### Act ### response: Response = fixture_rest_client.get(path=url) @@ -251,14 +252,17 @@ def test_get_blogposts( assert status.is_success(code=response.status_code) assert data[0]["id"] == fixture_blogpost.id - def test_create_blogpost( - self, fixture_rest_client: APIClient, fixture_user: User, fixture_image: Image - ): + def test_create_blogpost(self, fixture_rest_client: APIClient, + fixture_user: User, fixture_image: Image): ### Arrange ### fixture_rest_client.force_authenticate(user=fixture_user) url = reverse(routes.samfundet__blog_list) - post_data = {"title_nb": "lol", "title_en": "lol", "image": fixture_image.id} + post_data = { + "title_nb": "lol", + "title_en": "lol", + "image": fixture_image.id + } response: Response = fixture_rest_client.post(path=url, data=post_data) assert response.status_code == status.HTTP_403_FORBIDDEN @@ -279,7 +283,8 @@ def test_delete_blogpost( fixture_blogpost: BlogPost, ): fixture_rest_client.force_authenticate(user=fixture_user) - url = reverse(routes.samfundet__blog_detail, kwargs={"pk": fixture_blogpost.id}) + url = reverse(routes.samfundet__blog_detail, + kwargs={"pk": fixture_blogpost.id}) response: Response = fixture_rest_client.delete(path=url) assert response.status_code == status.HTTP_403_FORBIDDEN @@ -297,7 +302,8 @@ def test_put_blogpost( fixture_blogpost: BlogPost, ): fixture_rest_client.force_authenticate(user=fixture_user) - url = reverse(routes.samfundet__blog_detail, kwargs={"pk": fixture_blogpost.id}) + url = reverse(routes.samfundet__blog_detail, + kwargs={"pk": fixture_blogpost.id}) put_data = {"title_nb": "Samfundet blir gult!"} response: Response = fixture_rest_client.put(path=url, data=put_data) assert response.status_code == status.HTTP_403_FORBIDDEN @@ -314,10 +320,13 @@ def test_put_blogpost( class TestKeyValueView: - def test_anyone_can_retrieve_keyvalues(self, fixture_rest_client: APIClient): + + def test_anyone_can_retrieve_keyvalues(self, + fixture_rest_client: APIClient): ### Arrange ### keyvalue = KeyValue.objects.create(key="FOO", value="bar") - url = reverse(routes.samfundet__key_value_detail, kwargs={"key": keyvalue.key}) + url = reverse(routes.samfundet__key_value_detail, + kwargs={"key": keyvalue.key}) ### Act ### response: Response = fixture_rest_client.get(path=url) @@ -342,14 +351,14 @@ def test_anyone_can_list_keyvalues(self, fixture_rest_client: APIClient): assert status.is_success(code=response.status_code) assert any([kv["id"] == keyvalue.id for kv in data]) - def test_crud_not_possible( - self, fixture_rest_client: APIClient, fixture_superuser: User - ): + def test_crud_not_possible(self, fixture_rest_client: APIClient, + fixture_superuser: User): """Not even superuser can do anything.""" ### Arrange ### fixture_rest_client.force_authenticate(user=fixture_superuser) create_url = reverse(routes.samfundet__key_value_list) - detail_url = reverse(routes.samfundet__key_value_detail, kwargs={"key": "FOO"}) + detail_url = reverse(routes.samfundet__key_value_detail, + kwargs={"key": "FOO"}) ### Act ### create_response: Response = fixture_rest_client.post(path=create_url) @@ -365,10 +374,13 @@ def test_crud_not_possible( class TestTextItemView: - def test_anyone_can_retrieve_textitems(self, fixture_rest_client: APIClient): + + def test_anyone_can_retrieve_textitems(self, + fixture_rest_client: APIClient): ### Arrange ### textitem = TextItem.objects.create(key="FOO") - url = reverse(routes.samfundet__text_item_detail, kwargs={"pk": textitem.key}) + url = reverse(routes.samfundet__text_item_detail, + kwargs={"pk": textitem.key}) ### Act ### response: Response = fixture_rest_client.get(path=url) @@ -391,14 +403,14 @@ def test_anyone_can_list_textitems(self, fixture_rest_client: APIClient): assert status.is_success(code=response.status_code) assert any([kv["key"] == textitem.key for kv in data]) - def test_crud_not_possible( - self, fixture_rest_client: APIClient, fixture_superuser: User - ): + def test_crud_not_possible(self, fixture_rest_client: APIClient, + fixture_superuser: User): """Not even superuser can do anything.""" ### Arrange ### fixture_rest_client.force_authenticate(user=fixture_superuser) create_url = reverse(routes.samfundet__text_item_list) - detail_url = reverse(routes.samfundet__text_item_detail, kwargs={"pk": "FOO"}) + detail_url = reverse(routes.samfundet__text_item_detail, + kwargs={"pk": "FOO"}) ### Act ### create_response: Response = fixture_rest_client.post(path=create_url) @@ -414,6 +426,7 @@ def test_crud_not_possible( class TestAssignGroupView: + def test_assign_group( self, fixture_rest_client: APIClient, @@ -453,9 +466,8 @@ def test_remove_group( assert status.is_success(code=response.status_code) assert group not in fixture_user.groups.all() - def test_assign_group_not_possible( - self, fixture_rest_client: APIClient, fixture_user: User - ): + def test_assign_group_not_possible(self, fixture_rest_client: APIClient, + fixture_user: User): ### Arrange ### fixture_rest_client.force_authenticate(user=fixture_user) url = reverse(routes.samfundet__assign_group) @@ -468,9 +480,8 @@ def test_assign_group_not_possible( ### Assert ### assert response.status_code == status.HTTP_403_FORBIDDEN - def test_remove_group_not_possible( - self, fixture_rest_client: APIClient, fixture_user: User - ): + def test_remove_group_not_possible(self, fixture_rest_client: APIClient, + fixture_user: User): ### Arrange ### fixture_rest_client.force_authenticate(user=fixture_user) url = reverse(routes.samfundet__assign_group) @@ -484,9 +495,8 @@ def test_remove_group_not_possible( ### Assert ### assert response.status_code == status.HTTP_403_FORBIDDEN - def test_assign_group_not_found( - self, fixture_rest_client: APIClient, fixture_superuser: User - ): + def test_assign_group_not_found(self, fixture_rest_client: APIClient, + fixture_superuser: User): ### Arrange ### fixture_rest_client.force_authenticate(user=fixture_superuser) url = reverse(routes.samfundet__assign_group) @@ -552,8 +562,7 @@ def test_recruitment_positions_per_recruitment( ### Act ### response: Response = fixture_rest_client.get( - path=url, data={"recruitment": fixture_recruitment.id} - ) + path=url, data={"recruitment": fixture_recruitment.id}) ### Assert ### assert response.status_code == status.HTTP_200_OK @@ -574,8 +583,7 @@ def test_get_applicants_without_interviews( ### Act ### response: Response = fixture_rest_client.get( - path=url, data={"recruitment": fixture_recruitment.id} - ) + path=url, data={"recruitment": fixture_recruitment.id}) ### Assert ### assert response.status_code == status.HTTP_200_OK @@ -602,8 +610,7 @@ def test_get_applicants_without_interviews_when_interview_is_set( ### Act ### response: Response = fixture_rest_client.get( - path=url, data={"recruitment": fixture_recruitment.id} - ) + path=url, data={"recruitment": fixture_recruitment.id}) ### Assert ### assert response.status_code == status.HTTP_200_OK @@ -622,18 +629,13 @@ def test_recruitment_admission_for_applicant( ### Act ### response: Response = fixture_rest_client.get( - path=url, data={"recruitment": fixture_recruitment.id} - ) + path=url, data={"recruitment": fixture_recruitment.id}) ### Assert ### assert response.status_code == status.HTTP_200_OK # Assert the returned data based on the logic in the view assert len(response.data) == 1 - assert ( - response.data[0]["admission_text"] - == fixture_recruitment_admission.admission_text - ) - assert ( - response.data[0]["recruitment_position"] - == fixture_recruitment_admission.recruitment_position.id - ) + assert (response.data[0]["admission_text"] == + fixture_recruitment_admission.admission_text) + assert (response.data[0]["recruitment_position"] == + fixture_recruitment_admission.recruitment_position.id)