9
9
"""
10
10
11
11
import django_dynamic_fixture as fixture
12
- import pytest
13
- from django .http import Http404
14
12
from django .test .utils import override_settings
15
13
16
14
from readthedocs .builds .constants import EXTERNAL
@@ -196,8 +194,8 @@ def test_disabled_redirect(self):
196
194
redirect .enabled = False
197
195
redirect .save ()
198
196
199
- with self .assertRaises ( Http404 ):
200
- self .client . get ( url , headers = { "host" : "project.dev.readthedocs.io" } )
197
+ r = self .client . get ( url , headers = { "host" : "project.dev.readthedocs.io" })
198
+ self .assertEqual ( r . status_code , 404 )
201
199
202
200
def test_redirect_order (self ):
203
201
redirect_a = fixture .get (
@@ -267,8 +265,8 @@ def test_redirect_ignored_on_external_domain(self):
267
265
slug = "22" ,
268
266
type = EXTERNAL ,
269
267
)
270
- with self .assertRaises ( Http404 ):
271
- self .client . get ( url , headers = { "host" : "project--22.readthedocs.build" } )
268
+ r = self .client . get ( url , headers = { "host" : "project--22.readthedocs.build" })
269
+ self .assertEqual ( r . status_code , 404 )
272
270
273
271
def test_infinite_redirect (self ):
274
272
host = "project.dev.readthedocs.io"
@@ -279,11 +277,11 @@ def test_infinite_redirect(self):
279
277
from_url = "/en/latest/install.html" ,
280
278
to_url = "/en/latest/install.html" ,
281
279
)
282
- with pytest . raises ( Http404 ):
283
- self .client . get ( "/en/latest/install.html" , headers = { "host" : host } )
280
+ r = self . client . get ( "/en/latest/install.html" , headers = { "host" : host })
281
+ self .assertEqual ( r . status_code , 404 )
284
282
285
- with pytest . raises ( Http404 ):
286
- self .client . get ( "/en/latest/install.html?foo=bar" , headers = { "host" : host } )
283
+ r = self . client . get ( "/en/latest/install.html?foo=bar" , headers = { "host" : host })
284
+ self .assertEqual ( r . status_code , 404 )
287
285
288
286
def test_infinite_redirect_changing_protocol (self ):
289
287
host = "project.dev.readthedocs.io"
@@ -294,11 +292,12 @@ def test_infinite_redirect_changing_protocol(self):
294
292
from_url = "/en/latest/install.html" ,
295
293
to_url = f"https://{ host } /en/latest/install.html" ,
296
294
)
297
- with pytest .raises (Http404 ):
298
- self .client .get ("/en/latest/install.html" , headers = {"host" : host })
299
295
300
- with pytest .raises (Http404 ):
301
- self .client .get ("/en/latest/install.html?foo=bar" , headers = {"host" : host })
296
+ r = self .client .get ("/en/latest/install.html" , headers = {"host" : host })
297
+ self .assertEqual (r .status_code , 404 )
298
+
299
+ r = self .client .get ("/en/latest/install.html?foo=bar" , headers = {"host" : host })
300
+ self .assertEqual (r .status_code , 404 )
302
301
303
302
def test_exact_redirect_avoid_infinite_redirect (self ):
304
303
"""
@@ -335,10 +334,10 @@ def test_exact_redirect_avoid_infinite_redirect(self):
335
334
"http://project.dev.readthedocs.io/en/latest/redirect/" ,
336
335
)
337
336
338
- with self .assertRaises ( Http404 ):
339
- self . client . get (
340
- "/en/latest/redirect/" , headers = { "host" : "project.dev.readthedocs.io" }
341
- )
337
+ r = self .client . get (
338
+ "/en/latest/redirect/" , headers = { "host" : "project.dev.readthedocs.io" }
339
+ )
340
+ self . assertEqual ( r . status_code , 404 )
342
341
343
342
fixture .get (
344
343
Redirect ,
@@ -356,11 +355,11 @@ def test_exact_redirect_avoid_infinite_redirect(self):
356
355
"http://project.dev.readthedocs.io/en/latest/subdir/redirect.html" ,
357
356
)
358
357
359
- with self .assertRaises ( Http404 ):
360
- self . client . get (
361
- "/en/latest/subdir/redirect.html" ,
362
- headers = { "host" : "project.dev.readthedocs.io" },
363
- )
358
+ r = self .client . get (
359
+ "/en/latest/subdir/redirect.html" ,
360
+ headers = { "host" : "project.dev.readthedocs.io" } ,
361
+ )
362
+ self . assertEqual ( r . status_code , 404 )
364
363
365
364
def test_page_redirect_avoid_infinite_redirect (self ):
366
365
fixture .get (
@@ -379,11 +378,11 @@ def test_page_redirect_avoid_infinite_redirect(self):
379
378
"http://project.dev.readthedocs.io/en/latest/subdir/redirect.html" ,
380
379
)
381
380
382
- with self .assertRaises ( Http404 ):
383
- self . client . get (
384
- "/en/latest/subdir/redirect.html" ,
385
- headers = { "host" : "project.dev.readthedocs.io" },
386
- )
381
+ r = self .client . get (
382
+ "/en/latest/subdir/redirect.html" ,
383
+ headers = { "host" : "project.dev.readthedocs.io" } ,
384
+ )
385
+ self . assertEqual ( r . status_code , 404 )
387
386
388
387
fixture .get (
389
388
Redirect ,
@@ -402,11 +401,11 @@ def test_page_redirect_avoid_infinite_redirect(self):
402
401
"http://project.dev.readthedocs.io/en/latest/dir/subdir/redirect.html" ,
403
402
)
404
403
405
- with self .assertRaises ( Http404 ):
406
- self . client . get (
407
- "/en/latest/dir/subdir/redirect.html" ,
408
- headers = { "host" : "project.dev.readthedocs.io" },
409
- )
404
+ r = self .client . get (
405
+ "/en/latest/dir/subdir/redirect.html" ,
406
+ headers = { "host" : "project.dev.readthedocs.io" } ,
407
+ )
408
+ self . assertEqual ( r . status_code , 404 )
410
409
411
410
def test_exact_redirect_to_parent_path (self ):
412
411
self .project .versioning_scheme = SINGLE_VERSION_WITHOUT_TRANSLATIONS
@@ -497,11 +496,11 @@ def test_redirect_root(self):
497
496
)
498
497
499
498
# Prefix redirects should match the whole path.
500
- with self .assertRaises ( Http404 ):
501
- self . client . get (
502
- "/en/latest/woot/faq.html" ,
503
- headers = { "host" : "project.dev.readthedocs.io" },
504
- )
499
+ r = self .client . get (
500
+ "/en/latest/woot/faq.html" ,
501
+ headers = { "host" : "project.dev.readthedocs.io" } ,
502
+ )
503
+ self . assertEqual ( r . status_code , 404 )
505
504
506
505
def test_redirect_page (self ):
507
506
Redirect .objects .create (
@@ -860,11 +859,11 @@ def test_redirect_html_root_index(self):
860
859
)
861
860
862
861
with override_settings (PYTHON_MEDIA = True ):
863
- with self . assertRaises ( Http404 ):
864
- # File does not exist in storage media
865
- r = self . client . get (
866
- "/en/latest/" , headers = { "host" : "project.dev.readthedocs.io" }
867
- )
862
+ # File does not exist in storage media
863
+ r = self . client . get (
864
+ "/en/latest/" , headers = { "host" : "project.dev.readthedocs.io" }
865
+ )
866
+ self . assertEqual ( r . status_code , 404 )
868
867
869
868
def test_redirect_html_index (self ):
870
869
fixture .get (
@@ -924,12 +923,12 @@ def test_not_found_page_without_trailing_slash(self):
924
923
to_url = "/en/latest/:splat" ,
925
924
)
926
925
927
- with self . assertRaises ( Http404 ):
928
- # Avoid infinite redirect
929
- r = self . client . get (
930
- "/en/latest/section/file-not-found" ,
931
- headers = { "host" : "project.dev.readthedocs.io" },
932
- )
926
+ # Avoid infinite redirect
927
+ r = self . client . get (
928
+ "/en/latest/section/file-not-found" ,
929
+ headers = { "host" : "project.dev.readthedocs.io" } ,
930
+ )
931
+ self . assertEqual ( r . status_code , 404 )
933
932
934
933
def test_page_redirect_with_and_without_trailing_slash (self ):
935
934
fixture .get (
0 commit comments