Skip to content

Commit

Permalink
test(profiles, randoms, recommendations, reviews): create new folder …
Browse files Browse the repository at this point in the history
…structure and update integration tests
  • Loading branch information
tyronejosee committed Dec 5, 2024
1 parent 390e8a6 commit 629383b
Show file tree
Hide file tree
Showing 14 changed files with 129 additions and 91 deletions.
Empty file.
28 changes: 28 additions & 0 deletions apps/profiles/tests/integration/test_endpoints.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""Endpoints Tests for Profiles App."""

import pytest
from rest_framework import status


@pytest.mark.django_db
def test_list_profiles(administrator_user, profile):
endpoint = "/api/v1/profiles/"
response = administrator_user.get(endpoint)
assert response.status_code == status.HTTP_200_OK
assert response.reason_phrase == "OK"
assert len(response.data["results"]) == 1


@pytest.mark.django_db
def test_list_profiles_errors(member_user, profile):
endpoint = "/api/v1/profiles/"
member_response = member_user.get(endpoint)
assert member_response.status_code == status.HTTP_403_FORBIDDEN
assert member_response.reason_phrase == "Forbidden"
member_user.logout()
anonymus_response = member_user.get(endpoint)
assert anonymus_response.status_code == status.HTTP_401_UNAUTHORIZED
assert anonymus_response.reason_phrase == "Unauthorized"


# TODO: Add action tests
31 changes: 0 additions & 31 deletions apps/profiles/tests/test_viewsets.py

This file was deleted.

Empty file.
1 change: 1 addition & 0 deletions apps/profiles/tests/unit/test_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Model Tests for Profiles App."""
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pytest

from ..serializers import (
from ...serializers import (
ProfileReadSerializer,
ProfileWriteSerializer,
ProfileMinimalSerializer,
Expand Down Expand Up @@ -31,7 +31,6 @@ def test_profile_read_serializer(self, profile):
"image": profile.image.url,
"cover": serializer.data["cover"], # TODO: Fix
}

assert serializer.data == expected_data

def test_profile_write_serializer_valid_data(self, profile):
Expand All @@ -44,15 +43,13 @@ def test_profile_write_serializer_valid_data(self, profile):
"cover": profile.cover,
}
serializer = ProfileWriteSerializer(data=data)

assert serializer.is_valid(), serializer.errors
assert serializer.validated_data["first_name"] == "First Name"
assert serializer.validated_data["last_name"] == "Last Name"

def test_profile_write_serializer_invalid_data(self):
data = {}
serializer = ProfileWriteSerializer(data=data)

assert not serializer.is_valid()
assert "image" in serializer.errors

Expand All @@ -70,13 +67,11 @@ def test_profile_minimal_serializer(self, profile):
"last_name": profile.last_name,
"image": profile.image.url,
}

assert serializer.data == expected_data

def test_profile_about_serializer(self, profile):
serializer = ProfileAboutSerializer(profile)
expected_data = {
"bio": profile.bio,
}

assert serializer.data == expected_data
Empty file.
80 changes: 80 additions & 0 deletions apps/randoms/tests/integration/test_endpoints.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
"""Endpoint Tests for Randoms App."""

import pytest
from rest_framework import status


@pytest.mark.django_db
def test_retrive_random_anime(anonymous_user, anime):
endpoint = "/api/v1/random/anime/"
response = anonymous_user.get(endpoint)
assert response.status_code == status.HTTP_200_OK
assert response.reason_phrase == "OK"
assert len(response.data) > 0
assert response.data["name"] == anime.name


@pytest.mark.django_db
def test_retrive_random_anime_errors(anonymous_user):
endpoint = "/api/v1/random/anime/"
response = anonymous_user.get(endpoint)
assert response.status_code == status.HTTP_404_NOT_FOUND
assert response.reason_phrase == "Not Found"
assert response.data["detail"] == "No available content found."


@pytest.mark.django_db
def test_retrieve_random_manga(anonymous_user, manga):
endpoint = "/api/v1/random/manga/"
response = anonymous_user.get(endpoint)
assert response.status_code == status.HTTP_200_OK
assert response.reason_phrase == "OK"
assert len(response.data) > 0
assert response.data["name"] == manga.name


@pytest.mark.django_db
def test_retrieve_random_manga_errors(anonymous_user):
endpoint = "/api/v1/random/manga/"
response = anonymous_user.get(endpoint)
assert response.status_code == status.HTTP_404_NOT_FOUND
assert response.reason_phrase == "Not Found"
assert response.data["detail"] == "No available content found."


@pytest.mark.django_db
def test_retrieve_random_character(anonymous_user, character):
endpoint = "/api/v1/random/character/"
response = anonymous_user.get(endpoint)
assert response.status_code == status.HTTP_200_OK
assert response.reason_phrase == "OK"
assert len(response.data) > 0
assert response.data["name"] == character.name


@pytest.mark.django_db
def test_retrieve_random_character_errors(anonymous_user):
endpoint = "/api/v1/random/character/"
response = anonymous_user.get(endpoint)
assert response.status_code == status.HTTP_404_NOT_FOUND
assert response.reason_phrase == "Not Found"
assert response.data["detail"] == "No available content found."


@pytest.mark.django_db
def test_retrieve_random_person(anonymous_user, person):
endpoint = "/api/v1/random/person/"
response = anonymous_user.get(endpoint)
assert response.status_code == status.HTTP_200_OK
assert response.reason_phrase == "OK"
assert len(response.data) > 0
assert response.data["name"] == person.name


@pytest.mark.django_db
def test_retrieve_random_person_errors(anonymous_user):
endpoint = "/api/v1/random/person/"
response = anonymous_user.get(endpoint)
assert response.status_code == status.HTTP_404_NOT_FOUND
assert response.reason_phrase == "Not Found"
assert response.data["detail"] == "No available content found."
40 changes: 0 additions & 40 deletions apps/randoms/tests/test_views.py

This file was deleted.

Empty file.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""View Tests for Recommendations App."""
"""Endpoint Tests for Recommendations App."""

import pytest
from rest_framework import status
Expand All @@ -8,38 +8,42 @@


@pytest.mark.django_db
def test_anime_recommendation_view_success(anonymous_user):
def test_list_anime_recommendation(anonymous_user):
AnimeFactory.create_batch(3, is_recommended=True)
response = anonymous_user.get("/api/v1/recommendations/anime/")

endpoint = "/api/v1/recommendations/anime/"
response = anonymous_user.get(endpoint)
assert response.status_code == status.HTTP_200_OK
assert response.reason_phrase == "OK"
assert response.data["count"] == 3
assert len(response.data["results"]) == 3


@pytest.mark.django_db
def test_anime_recommendation_view_not_found(anonymous_user):
response = anonymous_user.get("/api/v1/recommendations/anime/")

def test_list_anime_recommendation_errors(anonymous_user):
endpoint = "/api/v1/recommendations/anime/"
response = anonymous_user.get(endpoint)
assert response.status_code == status.HTTP_200_OK
assert response.reason_phrase == "OK"
assert response.data["count"] == 0
assert len(response.data["results"]) == 0


@pytest.mark.django_db
def test_manga_recommendation_view_success(anonymous_user):
def test_list_manga_recommendation(anonymous_user):
MangaFactory.create_batch(3, is_recommended=True)
response = anonymous_user.get("/api/v1/recommendations/manga/")

endpoint = "/api/v1/recommendations/manga/"
response = anonymous_user.get(endpoint)
assert response.status_code == status.HTTP_200_OK
assert response.reason_phrase == "OK"
assert response.data["count"] == 3
assert len(response.data["results"]) == 3


@pytest.mark.django_db
def test_manga_recommendation_view_not_found(anonymous_user):
response = anonymous_user.get("/api/v1/recommendations/manga/")

def test_list_manga_recommendation_errors(anonymous_user):
endpoint = "/api/v1/recommendations/manga/"
response = anonymous_user.get(endpoint)
assert response.status_code == status.HTTP_200_OK
assert response.reason_phrase == "OK"
assert response.data["count"] == 0
assert len(response.data["results"]) == 0
Empty file.
1 change: 1 addition & 0 deletions apps/reviews/tests/unit/test_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Model Test for Reviews App."""
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pytest

from ..serializers import ReviewReadSerializer, ReviewWriteSerializer
from ...serializers import ReviewReadSerializer, ReviewWriteSerializer


@pytest.mark.django_db
Expand Down

0 comments on commit 629383b

Please sign in to comment.