@@ -134,77 +134,14 @@ def test_views_disabled_for_auth_exclusive_host(
134134 assert response .status_code == 302
135135
136136
137- @pytest .mark .django_db
138- def test_thumbnail_redirect_success (dummy_cover_image , client , community_site ):
139- community = community_site .community
140- community .cover_image = dummy_cover_image
141- community .save ()
142-
143- url = reverse ("cdn_thumb_redirect" , kwargs = {"path" : community .cover_image .name })
144- params = {"width" : 100 , "height" : 100 }
145-
146- response = client .get (url , params , HTTP_HOST = community_site .site .domain )
147-
148- assert response .status_code == 302
149- assert response ["Location" ].endswith (".jpg" )
150- assert "Cache-Control" in response
151- assert "max-age=86400" in response ["Cache-Control" ]
152-
153-
154- @pytest .mark .django_db
155- def test_thumbnail_redirect_exception (dummy_cover_image , community_site , client ):
156- community = community_site .community
157- community .cover_image = dummy_cover_image
158- community .save ()
159-
160- url = reverse ("cdn_thumb_redirect" , kwargs = {"path" : community .cover_image .name })
161- params = {"width" : 100 , "height" : 100 }
162-
163- path = "thunderstore.frontend.views.get_or_create_thumbnail"
164- with patch (path ) as mock_get_thumbnail :
165- mock_get_thumbnail .return_value = None
166- response = client .get (url , params , HTTP_HOST = community_site .site .domain )
167-
168- assert response .status_code == 404
169- assert "Cache-Control" in response
170- assert "max-age=300" in response ["Cache-Control" ]
171-
172-
173- @pytest .mark .django_db
174- @pytest .mark .parametrize (
175- "params" ,
176- [
177- {"width" : "abc" , "height" : "100" },
178- {"width" : "100" , "height" : "abc" },
179- {"width" : "0" , "height" : "100" },
180- {"width" : "100" , "height" : "0" },
181- {"width" : "-1" , "height" : "100" },
182- {},
183- ],
184- )
185- def test_thumbnail_redirect_invalid_params_returns_fallback (
186- params , dummy_cover_image , client , community_site
187- ):
188- community = community_site .community
189- community .cover_image = dummy_cover_image
190- community .save ()
191-
192- url = reverse ("cdn_thumb_redirect" , kwargs = {"path" : community .cover_image .name })
193- response = client .get (url , params , HTTP_HOST = community_site .site .domain )
194-
195- assert response .status_code == 404
196- assert "Cache-Control" in response
197- assert "max-age=300" in response ["Cache-Control" ]
198-
199-
200137@pytest .mark .django_db
201138def test_thumbnail_serve_success (dummy_cover_image , client , community_site ):
202139 community = community_site .community
203140 community .cover_image = dummy_cover_image
204141 community .save ()
205142
206143 url = reverse ("cdn_thumb_serve" , kwargs = {"path" : community .cover_image .name })
207- params = {"width" : 100 , "height" : 100 }
144+ params = {"width" : 64 , "height" : 64 }
208145
209146 response = client .get (url , params , HTTP_HOST = community_site .site .domain )
210147 assert response .status_code == 200
@@ -235,7 +172,7 @@ def test_thumbnail_serve_exception(params, dummy_cover_image, client, community_
235172 url = reverse ("cdn_thumb_serve" , kwargs = {"path" : community .cover_image .name })
236173
237174 response = client .get (url , params , HTTP_HOST = community_site .site .domain )
238- assert response .status_code == 404
175+ assert response .status_code == 403
239176 assert response .get ("Cache-Control" ) == "max-age=300, public"
240177
241178
@@ -246,7 +183,7 @@ def test_thumbnail_serve_invalid(client, community_site):
246183 community .save ()
247184
248185 url = reverse ("cdn_thumb_serve" , kwargs = {"path" : community .cover_image .name })
249- params = {"width" : 100 , "height" : 100 }
186+ params = {"width" : 64 , "height" : 64 }
250187
251188 response = client .get (url , params , HTTP_HOST = community_site .site .domain )
252189 assert response .status_code == 404
0 commit comments