Skip to content

Commit 629383b

Browse files
committed
test(profiles, randoms, recommendations, reviews): create new folder structure and update integration tests
1 parent 390e8a6 commit 629383b

File tree

14 files changed

+129
-91
lines changed

14 files changed

+129
-91
lines changed

apps/profiles/tests/integration/__init__.py

Whitespace-only changes.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"""Endpoints Tests for Profiles App."""
2+
3+
import pytest
4+
from rest_framework import status
5+
6+
7+
@pytest.mark.django_db
8+
def test_list_profiles(administrator_user, profile):
9+
endpoint = "/api/v1/profiles/"
10+
response = administrator_user.get(endpoint)
11+
assert response.status_code == status.HTTP_200_OK
12+
assert response.reason_phrase == "OK"
13+
assert len(response.data["results"]) == 1
14+
15+
16+
@pytest.mark.django_db
17+
def test_list_profiles_errors(member_user, profile):
18+
endpoint = "/api/v1/profiles/"
19+
member_response = member_user.get(endpoint)
20+
assert member_response.status_code == status.HTTP_403_FORBIDDEN
21+
assert member_response.reason_phrase == "Forbidden"
22+
member_user.logout()
23+
anonymus_response = member_user.get(endpoint)
24+
assert anonymus_response.status_code == status.HTTP_401_UNAUTHORIZED
25+
assert anonymus_response.reason_phrase == "Unauthorized"
26+
27+
28+
# TODO: Add action tests

apps/profiles/tests/test_viewsets.py

Lines changed: 0 additions & 31 deletions
This file was deleted.

apps/profiles/tests/unit/__init__.py

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Model Tests for Profiles App."""

apps/profiles/tests/test_serializers.py renamed to apps/profiles/tests/unit/test_serializers.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import pytest
44

5-
from ..serializers import (
5+
from ...serializers import (
66
ProfileReadSerializer,
77
ProfileWriteSerializer,
88
ProfileMinimalSerializer,
@@ -31,7 +31,6 @@ def test_profile_read_serializer(self, profile):
3131
"image": profile.image.url,
3232
"cover": serializer.data["cover"], # TODO: Fix
3333
}
34-
3534
assert serializer.data == expected_data
3635

3736
def test_profile_write_serializer_valid_data(self, profile):
@@ -44,15 +43,13 @@ def test_profile_write_serializer_valid_data(self, profile):
4443
"cover": profile.cover,
4544
}
4645
serializer = ProfileWriteSerializer(data=data)
47-
4846
assert serializer.is_valid(), serializer.errors
4947
assert serializer.validated_data["first_name"] == "First Name"
5048
assert serializer.validated_data["last_name"] == "Last Name"
5149

5250
def test_profile_write_serializer_invalid_data(self):
5351
data = {}
5452
serializer = ProfileWriteSerializer(data=data)
55-
5653
assert not serializer.is_valid()
5754
assert "image" in serializer.errors
5855

@@ -70,13 +67,11 @@ def test_profile_minimal_serializer(self, profile):
7067
"last_name": profile.last_name,
7168
"image": profile.image.url,
7269
}
73-
7470
assert serializer.data == expected_data
7571

7672
def test_profile_about_serializer(self, profile):
7773
serializer = ProfileAboutSerializer(profile)
7874
expected_data = {
7975
"bio": profile.bio,
8076
}
81-
8277
assert serializer.data == expected_data

apps/randoms/tests/integration/__init__.py

Whitespace-only changes.
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
"""Endpoint Tests for Randoms App."""
2+
3+
import pytest
4+
from rest_framework import status
5+
6+
7+
@pytest.mark.django_db
8+
def test_retrive_random_anime(anonymous_user, anime):
9+
endpoint = "/api/v1/random/anime/"
10+
response = anonymous_user.get(endpoint)
11+
assert response.status_code == status.HTTP_200_OK
12+
assert response.reason_phrase == "OK"
13+
assert len(response.data) > 0
14+
assert response.data["name"] == anime.name
15+
16+
17+
@pytest.mark.django_db
18+
def test_retrive_random_anime_errors(anonymous_user):
19+
endpoint = "/api/v1/random/anime/"
20+
response = anonymous_user.get(endpoint)
21+
assert response.status_code == status.HTTP_404_NOT_FOUND
22+
assert response.reason_phrase == "Not Found"
23+
assert response.data["detail"] == "No available content found."
24+
25+
26+
@pytest.mark.django_db
27+
def test_retrieve_random_manga(anonymous_user, manga):
28+
endpoint = "/api/v1/random/manga/"
29+
response = anonymous_user.get(endpoint)
30+
assert response.status_code == status.HTTP_200_OK
31+
assert response.reason_phrase == "OK"
32+
assert len(response.data) > 0
33+
assert response.data["name"] == manga.name
34+
35+
36+
@pytest.mark.django_db
37+
def test_retrieve_random_manga_errors(anonymous_user):
38+
endpoint = "/api/v1/random/manga/"
39+
response = anonymous_user.get(endpoint)
40+
assert response.status_code == status.HTTP_404_NOT_FOUND
41+
assert response.reason_phrase == "Not Found"
42+
assert response.data["detail"] == "No available content found."
43+
44+
45+
@pytest.mark.django_db
46+
def test_retrieve_random_character(anonymous_user, character):
47+
endpoint = "/api/v1/random/character/"
48+
response = anonymous_user.get(endpoint)
49+
assert response.status_code == status.HTTP_200_OK
50+
assert response.reason_phrase == "OK"
51+
assert len(response.data) > 0
52+
assert response.data["name"] == character.name
53+
54+
55+
@pytest.mark.django_db
56+
def test_retrieve_random_character_errors(anonymous_user):
57+
endpoint = "/api/v1/random/character/"
58+
response = anonymous_user.get(endpoint)
59+
assert response.status_code == status.HTTP_404_NOT_FOUND
60+
assert response.reason_phrase == "Not Found"
61+
assert response.data["detail"] == "No available content found."
62+
63+
64+
@pytest.mark.django_db
65+
def test_retrieve_random_person(anonymous_user, person):
66+
endpoint = "/api/v1/random/person/"
67+
response = anonymous_user.get(endpoint)
68+
assert response.status_code == status.HTTP_200_OK
69+
assert response.reason_phrase == "OK"
70+
assert len(response.data) > 0
71+
assert response.data["name"] == person.name
72+
73+
74+
@pytest.mark.django_db
75+
def test_retrieve_random_person_errors(anonymous_user):
76+
endpoint = "/api/v1/random/person/"
77+
response = anonymous_user.get(endpoint)
78+
assert response.status_code == status.HTTP_404_NOT_FOUND
79+
assert response.reason_phrase == "Not Found"
80+
assert response.data["detail"] == "No available content found."

apps/randoms/tests/test_views.py

Lines changed: 0 additions & 40 deletions
This file was deleted.

apps/recommendations/tests/integration/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)