Skip to content

Commit 390e8a6

Browse files
committed
test(tops, users, utils): create new folder structure and update integration tests
1 parent 79fb650 commit 390e8a6

File tree

12 files changed

+2628
-114
lines changed

12 files changed

+2628
-114
lines changed

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@ db.sqlite3
44
.env.prod
55
desktop.ini
66
static/import_export/
7-
logs/
8-
logs/general.log
97
static/
10-
logs/
118

129
# Byte-compiled / optimized / DLL files
1310
__pycache__/

apps/tops/tests/integration/__init__.py

Whitespace-only changes.
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
"""Endpoint Tests for Tops App."""
2+
3+
import pytest
4+
from rest_framework import status
5+
6+
from apps.persons.choices import CategoryChoices
7+
from apps.persons.tests.factories import PersonFactory
8+
from apps.animes.tests.factories import AnimeFactory
9+
from apps.mangas.tests.factories import MangaFactory
10+
from apps.characters.tests.factories import CharacterFactory
11+
from apps.reviews.tests.factories import ReviewFactory
12+
13+
14+
@pytest.mark.django_db
15+
def test_list_top_anime(anonymous_user):
16+
AnimeFactory.create_batch(3, favorites=10)
17+
endpoint = "/api/v1/top/animes/"
18+
response = anonymous_user.get(endpoint)
19+
assert response.status_code == status.HTTP_200_OK
20+
assert response.reason_phrase == "OK"
21+
assert len(response.data["results"]) == 3
22+
assert all(anime["favorites"] == 10 for anime in response.data["results"])
23+
24+
25+
@pytest.mark.django_db
26+
def test_list_top_anime_errors(anonymous_user):
27+
endpoint = "/api/v1/top/animes/"
28+
response = anonymous_user.get(endpoint)
29+
assert response.status_code == status.HTTP_404_NOT_FOUND
30+
assert response.reason_phrase == "Not Found"
31+
assert response.data["detail"] == "No anime found."
32+
33+
34+
@pytest.mark.django_db
35+
def test_list_top_manga(anonymous_user):
36+
MangaFactory.create_batch(3, favorites=10)
37+
endpoint = "/api/v1/top/mangas/"
38+
response = anonymous_user.get(endpoint)
39+
assert response.status_code == status.HTTP_200_OK
40+
assert response.reason_phrase == "OK"
41+
assert len(response.data["results"]) == 3
42+
assert all(manga["favorites"] == 10 for manga in response.data["results"])
43+
44+
45+
@pytest.mark.django_db
46+
def test_list_top_manga_errors(anonymous_user):
47+
endpoint = "/api/v1/top/mangas/"
48+
response = anonymous_user.get(endpoint)
49+
assert response.status_code == status.HTTP_404_NOT_FOUND
50+
assert response.reason_phrase == "Not Found"
51+
assert response.data["detail"] == "No manga found."
52+
53+
54+
@pytest.mark.django_db
55+
def test_list_top_character(anonymous_user):
56+
CharacterFactory.create_batch(3, favorites=10)
57+
endpoint = "/api/v1/top/characters/"
58+
response = anonymous_user.get(endpoint)
59+
assert response.status_code == status.HTTP_200_OK
60+
assert response.reason_phrase == "OK"
61+
assert len(response.data["results"]) == 3
62+
assert all(character["favorites"] == 10 for character in response.data["results"])
63+
64+
65+
@pytest.mark.django_db
66+
def test_list_top_character_errors(anonymous_user):
67+
endpoint = "/api/v1/top/characters/"
68+
response = anonymous_user.get(endpoint)
69+
assert response.status_code == status.HTTP_404_NOT_FOUND
70+
assert response.reason_phrase == "Not Found"
71+
assert response.data["detail"] == "No character found."
72+
73+
74+
@pytest.mark.django_db
75+
def test_list_top_artist(anonymous_user):
76+
PersonFactory.create_batch(
77+
3,
78+
category=CategoryChoices.ARTIST,
79+
favorites=10,
80+
)
81+
endpoint = "/api/v1/top/artists/"
82+
response = anonymous_user.get(endpoint)
83+
assert response.status_code == status.HTTP_200_OK
84+
assert response.reason_phrase == "OK"
85+
assert len(response.data["results"]) == 3
86+
assert all(artist["favorites"] == 10 for artist in response.data["results"])
87+
88+
89+
@pytest.mark.django_db
90+
def test_list_top_artist_errors(anonymous_user):
91+
endpoint = "/api/v1/top/artists/"
92+
response = anonymous_user.get(endpoint)
93+
assert response.status_code == status.HTTP_404_NOT_FOUND
94+
assert response.reason_phrase == "Not Found"
95+
assert response.data["detail"] == "No artists found."
96+
97+
98+
@pytest.mark.django_db
99+
def test_list_top_review(anonymous_user):
100+
ReviewFactory.create_batch(3, helpful_count=10)
101+
endpoint = "/api/v1/top/reviews/"
102+
response = anonymous_user.get(endpoint)
103+
assert response.status_code == status.HTTP_200_OK
104+
assert response.reason_phrase == "OK"
105+
assert len(response.data["results"]) == 3
106+
assert all(review["helpful_count"] == 10 for review in response.data["results"])
107+
108+
109+
@pytest.mark.django_db
110+
def test_list_top_review_errors(anonymous_user):
111+
endpoint = "/api/v1/top/reviews/"
112+
response = anonymous_user.get(endpoint)
113+
assert response.status_code == status.HTTP_404_NOT_FOUND
114+
assert response.reason_phrase == "Not Found"
115+
assert response.data["detail"] == "No reviews found."

apps/tops/tests/test_views.py

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

apps/users/tests/integration/__init__.py

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

apps/users/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 Users App."""
Lines changed: 1 addition & 3 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
UserReadSerializer,
77
UserWriteSerializer,
88
UserMinimalSerializer,
@@ -40,14 +40,12 @@ def test_user_read_serializer(self, user):
4040
# "is_staff": user.is_staff,
4141
# }
4242
# serializer = UserWriteSerializer(data=data)
43-
4443
# assert serializer.is_valid(), serializer.errors
4544
# assert serializer.validated_data["email"] == "[email protected]"
4645

4746
def test_user_write_serializer_invalid_data(self):
4847
data = {}
4948
serializer = UserWriteSerializer(data=data)
50-
5149
assert not serializer.is_valid()
5250
assert "email" in serializer.errors
5351
assert "username" in serializer.errors

apps/utils/tests/unit/test_models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# """Model tests for Utils App."""
1+
"""Model tests for Utils App."""
22

33
import pytest
44
from django.core.exceptions import ValidationError

0 commit comments

Comments
 (0)