22
33import pytest
44from rest_framework import status
5+ from rest_framework .test import APIClient
56
67from apps .animes .tests .factories import AnimeFactory
78from apps .animes .serializers import AnimeMinimalSerializer
2223
2324
2425@pytest .mark .django_db
25- def test_list_character (anonymous_user , character ) :
26- endpoint = "/api/v1/characters/"
26+ def test_list_character (anonymous_user : APIClient , character : Character ) -> None :
27+ endpoint : str = "/api/v1/characters/"
2728 response = anonymous_user .get (endpoint )
2829 assert response .status_code == status .HTTP_200_OK
2930 assert response .reason_phrase == "OK"
@@ -32,8 +33,8 @@ def test_list_character(anonymous_user, character):
3233
3334
3435@pytest .mark .django_db
35- def test_retrieve_character (anonymous_user , character ) :
36- endpoint = f"/api/v1/characters/{ character .id } /"
36+ def test_retrieve_character (anonymous_user : APIClient , character : Character ) -> None :
37+ endpoint : str = f"/api/v1/characters/{ character .id } /"
3738 response = anonymous_user .get (endpoint )
3839 assert response .status_code == status .HTTP_200_OK
3940 assert response .reason_phrase == "OK"
@@ -42,18 +43,18 @@ def test_retrieve_character(anonymous_user, character):
4243
4344
4445@pytest .mark .django_db
45- def test_retrieve_character_errors (anonymous_user ) :
46- endpoint = "/api/v1/characters/989423d1-d6c0-431a-8f62-d805b8a5f321/"
46+ def test_retrieve_character_errors (anonymous_user : APIClient ) -> None :
47+ endpoint : str = "/api/v1/characters/989423d1-d6c0-431a-8f62-d805b8a5f321/"
4748 response = anonymous_user .get (endpoint )
4849 assert response .status_code == status .HTTP_404_NOT_FOUND
4950 assert response .reason_phrase == "Not Found"
5051 assert response .data ["detail" ] == "Not found."
5152
5253
5354@pytest .mark .django_db
54- def test_create_character (contributor_user , character ) :
55- endpoint = "/api/v1/characters/"
56- data = {
55+ def test_create_character (contributor_user : APIClient , character : Character ) -> None :
56+ endpoint : str = "/api/v1/characters/"
57+ data : dict [ str , str ] = {
5758 "name" : "Makoto" ,
5859 "name_kanji" : character .name_kanji ,
5960 "about" : character .about ,
@@ -68,9 +69,9 @@ def test_create_character(contributor_user, character):
6869
6970
7071@pytest .mark .django_db
71- def test_create_character_unauthorized (member_user ) :
72- endpoint = "/api/v1/characters/"
73- data = {}
72+ def test_create_character_unauthorized (member_user : APIClient ) -> None :
73+ endpoint : str = "/api/v1/characters/"
74+ data : dict = {}
7475 member_response = member_user .post (endpoint , data , format = "json" )
7576 assert member_response .status_code == status .HTTP_403_FORBIDDEN
7677 assert member_response .reason_phrase == "Forbidden"
@@ -81,9 +82,9 @@ def test_create_character_unauthorized(member_user):
8182
8283
8384@pytest .mark .django_db
84- def test_update_character (contributor_user , character ) :
85- endpoint = f"/api/v1/characters/{ character .id } /"
86- data = {
85+ def test_update_character (contributor_user : APIClient , character : Character ) -> None :
86+ endpoint : str = f"/api/v1/characters/{ character .id } /"
87+ data : dict [ str , str ] = {
8788 "name" : "Updated Character" ,
8889 "name_kanji" : character .name_kanji ,
8990 "about" : character .about ,
@@ -98,9 +99,11 @@ def test_update_character(contributor_user, character):
9899
99100
100101@pytest .mark .django_db
101- def test_partial_update_character (contributor_user , character ):
102- endpoint = f"/api/v1/characters/{ character .id } /"
103- data = {"name" : "Partially Updated Character" }
102+ def test_partial_update_character (
103+ contributor_user : APIClient , character : Character
104+ ) -> None :
105+ endpoint : str = f"/api/v1/characters/{ character .id } /"
106+ data : dict [str , str ] = {"name" : "Partially Updated Character" }
104107 response = contributor_user .patch (endpoint , data , format = "json" )
105108 assert response .status_code == status .HTTP_200_OK
106109 assert response .reason_phrase == "OK"
@@ -109,9 +112,9 @@ def test_partial_update_character(contributor_user, character):
109112
110113
111114@pytest .mark .django_db
112- def test_delete_character (contributor_user , character ) :
115+ def test_delete_character (contributor_user : APIClient , character : Character ) -> None :
113116 assert character .is_available
114- endpoint = f"/api/v1/characters/{ character .id } /"
117+ endpoint : str = f"/api/v1/characters/{ character .id } /"
115118 response = contributor_user .delete (endpoint )
116119 character .refresh_from_db ()
117120 assert response .status_code == status .HTTP_204_NO_CONTENT
@@ -121,12 +124,14 @@ def test_delete_character(contributor_user, character):
121124
122125
123126@pytest .mark .django_db
124- def test_list_pictures_by_character (anonymous_user , character ):
127+ def test_list_pictures_by_character (
128+ anonymous_user : APIClient , character : Character
129+ ) -> None :
125130 picture = PictureFactory (
126131 content_object = character ,
127132 object_id = character .id ,
128133 )
129- endpoint = f"/api/v1/characters/{ character .id } /pictures/"
134+ endpoint : str = f"/api/v1/characters/{ character .id } /pictures/"
130135 response = anonymous_user .get (endpoint )
131136 expected_data = PictureReadSerializer ([picture ], many = True ).data
132137 assert response .status_code == status .HTTP_200_OK
@@ -135,8 +140,10 @@ def test_list_pictures_by_character(anonymous_user, character):
135140
136141
137142@pytest .mark .django_db
138- def test_list_pictures_by_character_errors (anonymous_user , character ):
139- endpoint = f"/api/v1/characters/{ character .id } /pictures/"
143+ def test_list_pictures_by_character_errors (
144+ anonymous_user : APIClient , character : Character
145+ ) -> None :
146+ endpoint : str = f"/api/v1/characters/{ character .id } /pictures/"
140147 response = anonymous_user .get (endpoint )
141148 assert response .status_code == status .HTTP_404_NOT_FOUND
142149 assert response .reason_phrase == "Not Found"
@@ -147,9 +154,11 @@ def test_list_pictures_by_character_errors(anonymous_user, character):
147154
148155
149156@pytest .mark .django_db
150- def test_create_picture_by_character (contributor_user , character ):
151- endpoint = f"/api/v1/characters/{ character .id } /pictures/create/"
152- data = {
157+ def test_create_picture_by_character (
158+ contributor_user : APIClient , character : Character
159+ ) -> None :
160+ endpoint : str = f"/api/v1/characters/{ character .id } /pictures/create/"
161+ data : dict [str , str ] = {
153162 "name" : "Momo Ayase" ,
154163 "image" : character .image ,
155164 }
@@ -161,12 +170,15 @@ def test_create_picture_by_character(contributor_user, character):
161170
162171
163172@pytest .mark .django_db
164- def test_list_voices_by_character (anonymous_user , character ):
173+ def test_list_voices_by_character (
174+ anonymous_user : APIClient ,
175+ character : Character ,
176+ ) -> None :
165177 staff_one = PersonFactory ()
166178 staff_two = PersonFactory ()
167179 CharacterVoiceFactory (voice_id = staff_one , character_id = character )
168180 CharacterVoiceFactory (voice_id = staff_two , character_id = character )
169- endpoint = f"/api/v1/characters/{ character .id } /voices/"
181+ endpoint : int = f"/api/v1/characters/{ character .id } /voices/"
170182 response = anonymous_user .get (endpoint )
171183 voices_ids = CharacterVoice .objects .filter (character_id = character .id ).values_list (
172184 "voice_id" , flat = True
@@ -179,7 +191,10 @@ def test_list_voices_by_character(anonymous_user, character):
179191
180192
181193@pytest .mark .django_db
182- def test_retrieve_anime_by_character (anonymous_user , character ):
194+ def test_retrieve_anime_by_character (
195+ anonymous_user : APIClient ,
196+ character : Character ,
197+ ) -> None :
183198 anime = AnimeFactory ()
184199 CharacterAnimeFactory (character_id = character , anime_id = anime )
185200 endpoint = f"/api/v1/characters/{ character .id } /anime/"
@@ -191,7 +206,9 @@ def test_retrieve_anime_by_character(anonymous_user, character):
191206
192207
193208@pytest .mark .django_db
194- def test_retrieve_anime_by_character_not_found (anonymous_user , character ):
209+ def test_retrieve_anime_by_character_not_found (
210+ anonymous_user : APIClient , character : Character
211+ ):
195212 endpoint = f"/api/v1/characters/{ character .id } /anime/"
196213 response = anonymous_user .get (endpoint )
197214 assert response .status_code == status .HTTP_404_NOT_FOUND
@@ -200,10 +217,13 @@ def test_retrieve_anime_by_character_not_found(anonymous_user, character):
200217
201218
202219@pytest .mark .django_db
203- def test_retrieve_manga_by_character (anonymous_user , character ):
220+ def test_retrieve_manga_by_character (
221+ anonymous_user : APIClient ,
222+ character : Character ,
223+ ) -> None :
204224 manga = MangaFactory ()
205225 CharacterMangaFactory (character_id = character , manga_id = manga )
206- endpoint = f"/api/v1/characters/{ character .id } /manga/"
226+ endpoint : str = f"/api/v1/characters/{ character .id } /manga/"
207227 response = anonymous_user .get (endpoint )
208228 expected_data = MangaMinimalSerializer (manga ).data
209229 assert response .status_code == status .HTTP_200_OK
@@ -212,8 +232,11 @@ def test_retrieve_manga_by_character(anonymous_user, character):
212232
213233
214234@pytest .mark .django_db
215- def test_retrieve_manga_by_character_not_found (anonymous_user , character ):
216- endpoint = f"/api/v1/characters/{ character .id } /manga/"
235+ def test_retrieve_manga_by_character_not_found (
236+ anonymous_user : APIClient ,
237+ character : Character ,
238+ ) -> None :
239+ endpoint : str = f"/api/v1/characters/{ character .id } /manga/"
217240 response = anonymous_user .get (endpoint )
218241 assert response .status_code == status .HTTP_404_NOT_FOUND
219242 assert response .reason_phrase == "Not Found"
0 commit comments