2525
2626@pytest .mark .django_db
2727def test_list_animes (anonymous_user , anime ):
28- response = anonymous_user .get ("/api/v1/animes/" )
28+ endpoint = "/api/v1/animes/"
29+ response = anonymous_user .get (endpoint )
2930 assert response .status_code == status .HTTP_200_OK
3031 assert response .reason_phrase == "OK"
3132 assert len (response .data ) > 0
3233
3334
3435@pytest .mark .django_db
3536def test_list_animes_errors (anonymous_user ):
36- response = anonymous_user .get ("/api/v1/animes/" )
37+ endpoint = "/api/v1/animes/"
38+ response = anonymous_user .get (endpoint )
3739 assert response .status_code == status .HTTP_200_OK
3840 assert response .reason_phrase == "OK"
3941 # TODO: Update status code to 404
4042
4143
4244@pytest .mark .django_db
4345def test_retrieve_anime (anonymous_user , anime ):
44- response = anonymous_user .get (f"/api/v1/animes/{ anime .id } /" )
46+ endpoint = f"/api/v1/animes/{ anime .id } /"
47+ response = anonymous_user .get (endpoint )
4548 assert response .status_code == status .HTTP_200_OK
4649 assert response .reason_phrase == "OK"
4750 assert str (response .data ["id" ]) == str (anime .id )
@@ -51,7 +54,8 @@ def test_retrieve_anime(anonymous_user, anime):
5154@pytest .mark .django_db
5255def test_retrieve_anime_errors (anonymous_user ):
5356 anime_id = "989423d1-d6c0-431a-8f62-d805b8a5f321"
54- response = anonymous_user .get (f"/api/v1/animes/{ anime_id } /" )
57+ endpoint = f"/api/v1/animes/{ anime_id } /"
58+ response = anonymous_user .get (endpoint )
5559 assert response .status_code == status .HTTP_404_NOT_FOUND
5660 assert response .reason_phrase == "Not Found"
5761
@@ -60,6 +64,7 @@ def test_retrieve_anime_errors(anonymous_user):
6064def test_create_anime (contributor_user , genre , theme ):
6165 producer = ProducerFactory (type = TypeChoices .STUDIO )
6266 image = generate_test_image (size = (600 , 600 ))
67+ endpoint = "/api/v1/animes/"
6368 data = {
6469 "name" : "New Anime" ,
6570 "name_jpn" : "New Anime" ,
@@ -72,7 +77,7 @@ def test_create_anime(contributor_user, genre, theme):
7277 "themes" : [str (theme .id )],
7378 "duration" : timedelta (hours = 1 , minutes = 45 , seconds = 30 ),
7479 }
75- response = contributor_user .post ("/api/v1/animes/" , data , format = "multipart" )
80+ response = contributor_user .post (endpoint , data , format = "multipart" )
7681 assert response .status_code == status .HTTP_201_CREATED
7782 assert response .reason_phrase == "Created"
7883 assert Anime .objects .filter (name = "New Anime" ).exists ()
@@ -81,12 +86,13 @@ def test_create_anime(contributor_user, genre, theme):
8186
8287@pytest .mark .django_db
8388def test_create_anime_errors (member_user ):
89+ endpoint = "/api/v1/animes/"
8490 data = {}
85- member_response = member_user .post ("/api/v1/animes/" , data , format = "json" )
91+ member_response = member_user .post (endpoint , data , format = "json" )
8692 assert member_response .status_code == status .HTTP_403_FORBIDDEN
8793 assert member_response .reason_phrase == "Forbidden"
8894 member_user .logout ()
89- anonymus_response = member_user .post ("/api/v1/animes/" , data , format = "json" )
95+ anonymus_response = member_user .post (endpoint , data , format = "json" )
9096 assert anonymus_response .status_code == status .HTTP_401_UNAUTHORIZED
9197 assert anonymus_response .reason_phrase == "Unauthorized"
9298
@@ -95,6 +101,7 @@ def test_create_anime_errors(member_user):
95101def test_update_anime (contributor_user , anime , genre , theme ):
96102 producer = ProducerFactory (type = TypeChoices .STUDIO )
97103 image = generate_test_image (size = (600 , 600 ))
104+ endpoint = f"/api/v1/animes/{ anime .id } /"
98105 data = {
99106 "name" : "Updated Anime" ,
100107 "name_jpn" : "Updated Anime" ,
@@ -107,9 +114,7 @@ def test_update_anime(contributor_user, anime, genre, theme):
107114 "themes" : [str (theme .id )],
108115 "duration" : timedelta (hours = 1 , minutes = 45 , seconds = 30 ),
109116 }
110- response = contributor_user .put (
111- f"/api/v1/animes/{ anime .id } /" , data , format = "multipart"
112- )
117+ response = contributor_user .put (endpoint , data , format = "multipart" )
113118 assert response .status_code == status .HTTP_200_OK
114119 assert response .reason_phrase == "OK"
115120 anime .refresh_from_db ()
@@ -118,12 +123,9 @@ def test_update_anime(contributor_user, anime, genre, theme):
118123
119124@pytest .mark .django_db
120125def test_partial_update_anime (contributor_user , anime ):
126+ endpoint = f"/api/v1/animes/{ anime .id } /"
121127 data = {"name" : "Partially Updated Anime" }
122- response = contributor_user .patch (
123- f"/api/v1/animes/{ anime .id } /" ,
124- data ,
125- format = "json" ,
126- )
128+ response = contributor_user .patch (endpoint , data , format = "json" )
127129 assert response .status_code == status .HTTP_200_OK
128130 assert response .reason_phrase == "OK"
129131 anime .refresh_from_db ()
@@ -133,7 +135,8 @@ def test_partial_update_anime(contributor_user, anime):
133135@pytest .mark .django_db
134136def test_delete_anime (contributor_user , anime ):
135137 assert anime .is_available
136- response = contributor_user .delete (f"/api/v1/animes/{ anime .id } /" )
138+ endpoint = f"/api/v1/animes/{ anime .id } /"
139+ response = contributor_user .delete (endpoint )
137140 anime .refresh_from_db ()
138141 assert response .status_code == status .HTTP_204_NO_CONTENT
139142 assert response .reason_phrase == "No Content"
@@ -144,15 +147,17 @@ def test_delete_anime(contributor_user, anime):
144147@pytest .mark .django_db
145148def test_list_characters_by_anime (anonymous_user , anime , character ):
146149 CharacterAnimeFactory (character_id = character , anime_id = anime )
147- response = anonymous_user .get (f"/api/v1/animes/{ anime .id } /characters/" )
150+ endpoint = f"/api/v1/animes/{ anime .id } /characters/"
151+ response = anonymous_user .get (endpoint )
148152 assert response .status_code == status .HTTP_200_OK
149153 assert response .reason_phrase == "OK"
150154 assert len (response .data ) == 1
151155
152156
153157@pytest .mark .django_db
154158def test_list_characters_by_anime_errors (anonymous_user , anime ):
155- response = anonymous_user .get (f"/api/v1/animes/{ anime .id } /characters/" )
159+ endpoint = f"/api/v1/animes/{ anime .id } /characters/"
160+ response = anonymous_user .get (endpoint )
156161 assert response .status_code == status .HTTP_404_NOT_FOUND
157162 assert response .reason_phrase == "Not Found"
158163 assert response .data ["detail" ] == "No characters found for this anime."
@@ -164,7 +169,8 @@ def test_list_staff_by_anime(anonymous_user, anime):
164169 staff_two = PersonFactory ()
165170 StaffAnimeFactory (person_id = staff_one , anime_id = anime )
166171 StaffAnimeFactory (person_id = staff_two , anime_id = anime )
167- response = anonymous_user .get (f"/api/v1/animes/{ anime .id } /staff/" )
172+ endpoint = f"/api/v1/animes/{ anime .id } /staff/"
173+ response = anonymous_user .get (endpoint )
168174 assert response .status_code == status .HTTP_200_OK
169175 assert response .reason_phrase == "OK"
170176 staff_ids = StaffAnime .objects .filter (anime_id = anime .id ).values_list (
@@ -177,15 +183,17 @@ def test_list_staff_by_anime(anonymous_user, anime):
177183
178184@pytest .mark .django_db
179185def test_list_staff_by_anime_errors (anonymous_user , anime ):
180- response = anonymous_user .get (f"/api/v1/animes/{ anime .id } /staff/" )
186+ endpoint = f"/api/v1/animes/{ anime .id } /staff/"
187+ response = anonymous_user .get (endpoint )
181188 assert response .status_code == status .HTTP_404_NOT_FOUND
182189 assert response .reason_phrase == "Not Found"
183190 assert response .data ["detail" ] == "No staff found for this anime."
184191
185192
186193@pytest .mark .django_db
187194def test_retrieve_stats_by_anime (anonymous_user , anime ):
188- response = anonymous_user .get (f"/api/v1/animes/{ anime .id } /stats/" )
195+ endpoint = f"/api/v1/animes/{ anime .id } /stats/"
196+ response = anonymous_user .get (endpoint )
189197 assert response .status_code == status .HTTP_200_OK
190198 assert response .reason_phrase == "OK"
191199 assert "id" in response .data
@@ -200,7 +208,8 @@ def test_retrieve_stats_by_anime(anonymous_user, anime):
200208@pytest .mark .django_db
201209def test_retrieve_stats_by_anime_errors (anonymous_user ):
202210 anime_id = "88bf5d4f-115b-4dea-a7c5-4fc45b794c9a"
203- response = anonymous_user .get (f"/api/v1/animes/{ anime_id } /stats/" )
211+ endpoint = f"/api/v1/animes/{ anime_id } /stats/"
212+ response = anonymous_user .get (endpoint )
204213 assert response .status_code == status .HTTP_404_NOT_FOUND
205214 assert response .reason_phrase == "Not Found"
206215 assert response .data ["detail" ] == "Not found."
@@ -212,7 +221,8 @@ def test_list_reviews_by_anime(anonymous_user, anime):
212221 content_type = ContentType .objects .get_for_model (Anime ),
213222 object_id = anime .id ,
214223 )
215- response = anonymous_user .get (f"/api/v1/animes/{ anime .id } /reviews/" )
224+ endpoint = f"/api/v1/animes/{ anime .id } /reviews/"
225+ response = anonymous_user .get (endpoint )
216226 assert response .status_code == status .HTTP_200_OK
217227 assert response .reason_phrase == "OK"
218228 assert len (response .data ) > 0
@@ -221,14 +231,13 @@ def test_list_reviews_by_anime(anonymous_user, anime):
221231
222232@pytest .mark .django_db
223233def test_create_review_by_anime (member_user , anime , review ):
234+ endpoint = f"/api/v1/animes/{ anime .id } /reviews/create/"
224235 data = {
225236 "comment" : "Review created" ,
226237 "is_spoiler" : review .is_spoiler ,
227238 "rating" : review .rating ,
228239 }
229- response = member_user .post (
230- f"/api/v1/animes/{ anime .id } /reviews/create/" , data , format = "json"
231- )
240+ response = member_user .post (endpoint , data , format = "json" )
232241 assert response .status_code == status .HTTP_201_CREATED
233242 assert response .reason_phrase == "Created"
234243 assert Review .objects .filter (comment = "Review created" ).exists ()
@@ -245,14 +254,13 @@ def test_update_review_by_anime(anime):
245254 content_type = ContentType .objects .get_for_model (Anime ),
246255 object_id = anime .id ,
247256 )
257+ endpoint = f"/api/v1/animes/{ anime .id } /reviews/{ review .id } /"
248258 data = {
249259 "comment" : "Review updated" ,
250260 "is_spoiler" : review .is_spoiler ,
251261 "rating" : review .rating ,
252262 }
253- response = api_client .patch (
254- f"/api/v1/animes/{ anime .id } /reviews/{ review .id } /" , data , format = "json"
255- )
263+ response = api_client .patch (endpoint , data , format = "json" )
256264 assert response .status_code == status .HTTP_200_OK
257265 assert response .reason_phrase == "OK"
258266 anime .refresh_from_db ()
@@ -263,15 +271,17 @@ def test_update_review_by_anime(anime):
263271def test_list_recommendations_by_anime (anonymous_user , theme , genre ):
264272 anime = AnimeFactory (genres = [genre ], themes = [theme ])
265273 AnimeFactory .create_batch (3 , genres = [genre ], themes = [theme ])
266- response = anonymous_user .get (f"/api/v1/animes/{ anime .id } /recommendations/" )
274+ endpoint = f"/api/v1/animes/{ anime .id } /recommendations/"
275+ response = anonymous_user .get (endpoint )
267276 assert response .status_code == status .HTTP_200_OK
268277 assert response .reason_phrase == "OK"
269278 assert len (response .data ) == 3
270279
271280
272281@pytest .mark .django_db
273282def test_list_recommendations_by_anime_errors (anonymous_user , anime ):
274- response = anonymous_user .get (f"/api/v1/animes/{ anime .id } /recommendations/" )
283+ endpoint = f"/api/v1/animes/{ anime .id } /recommendations/"
284+ response = anonymous_user .get (endpoint )
275285 assert response .status_code == status .HTTP_404_NOT_FOUND
276286 assert response .reason_phrase == "Not Found"
277287 assert response .data ["detail" ] == "No recommendations found for this anime."
@@ -280,15 +290,17 @@ def test_list_recommendations_by_anime_errors(anonymous_user, anime):
280290@pytest .mark .django_db
281291def test_list_news_by_anime (anonymous_user , anime ):
282292 NewsFactory .create_batch (3 , anime_relations = [anime ])
283- response = anonymous_user .get (f"/api/v1/animes/{ anime .id } /news/" )
293+ endpoint = f"/api/v1/animes/{ anime .id } /news/"
294+ response = anonymous_user .get (endpoint )
284295 assert response .status_code == status .HTTP_200_OK
285296 assert response .reason_phrase == "OK"
286297 assert len (response .data ) == 3
287298
288299
289300@pytest .mark .django_db
290301def test_list_news_by_anime_errors (anonymous_user , anime ):
291- response = anonymous_user .get (f"/api/v1/animes/{ anime .id } /news/" )
302+ endpoint = f"/api/v1/animes/{ anime .id } /news/"
303+ response = anonymous_user .get (endpoint )
292304 assert response .status_code == status .HTTP_404_NOT_FOUND
293305 assert response .reason_phrase == "Not Found"
294306 assert response .data ["detail" ] == "No news found for this anime."
@@ -301,15 +313,17 @@ def test_list_videos_by_anime(anonymous_user, anime):
301313 content_type = ContentType .objects .get_for_model (Anime ),
302314 object_id = anime .id ,
303315 )
304- response = anonymous_user .get (f"/api/v1/animes/{ anime .id } /videos/" )
316+ endpoint = f"/api/v1/animes/{ anime .id } /videos/"
317+ response = anonymous_user .get (endpoint )
305318 assert response .status_code == status .HTTP_200_OK
306319 assert response .reason_phrase == "OK"
307320 assert len (response .data ) == 3
308321
309322
310323@pytest .mark .django_db
311324def test_list_videos_by_anime_errors (anonymous_user , anime ):
312- response = anonymous_user .get (f"/api/v1/animes/{ anime .id } /videos/" )
325+ endpoint = f"/api/v1/animes/{ anime .id } /videos/"
326+ response = anonymous_user .get (endpoint )
313327 assert response .status_code == status .HTTP_404_NOT_FOUND
314328 assert response .reason_phrase == "Not Found"
315329 assert response .data ["detail" ] == "No videos found for this anime."
@@ -322,15 +336,17 @@ def test_list_pictures_by_anime(anonymous_user, anime):
322336 content_type = ContentType .objects .get_for_model (Anime ),
323337 object_id = anime .id ,
324338 )
325- response = anonymous_user .get (f"/api/v1/animes/{ anime .id } /pictures/" )
339+ endpoint = f"/api/v1/animes/{ anime .id } /pictures/"
340+ response = anonymous_user .get (endpoint )
326341 assert response .status_code == status .HTTP_200_OK
327342 assert response .reason_phrase == "OK"
328343 assert len (response .data ) == 3
329344
330345
331346@pytest .mark .django_db
332347def test_list_pictures_by_anime_errors (anonymous_user , anime ):
333- response = anonymous_user .get (f"/api/v1/animes/{ anime .id } /pictures/" )
348+ endpoint = f"/api/v1/animes/{ anime .id } /pictures/"
349+ response = anonymous_user .get (endpoint )
334350 assert response .status_code == status .HTTP_404_NOT_FOUND
335351 assert response .reason_phrase == "Not Found"
336352 assert response .data ["detail" ] == "No pictures found for this anime."
0 commit comments