Skip to content

Commit

Permalink
fix linting
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathias-a committed Oct 10, 2023
1 parent 27a038f commit df209b6
Showing 1 changed file with 50 additions and 48 deletions.
98 changes: 50 additions & 48 deletions backend/samfundet/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -217,14 +216,16 @@ def test_put_informationpage(


class TestBlogPostView:

def test_get_blogpost(
self,
fixture_rest_client: APIClient,
fixture_user: User,
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)
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -414,6 +426,7 @@ def test_crud_not_possible(


class TestAssignGroupView:

def test_assign_group(
self,
fixture_rest_client: APIClient,
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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)

0 comments on commit df209b6

Please sign in to comment.