|
| 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." |
0 commit comments