@@ -796,10 +796,42 @@ def test_404_storage_serves_custom_404_sphinx(self, storage_exists, storage_open
796
796
self .assertEqual (response .status_code , 404 )
797
797
798
798
@mock .patch .object (BuildMediaFileSystemStorageTest , 'exists' )
799
- def test_redirects_to_correct_index (self , storage_exists ):
800
- """This case is when the project uses a README.html as index."""
799
+ def test_redirects_to_correct_index_ending_with_slash (self , storage_exists ):
800
+ """When the path ends with a slash, we try README.html as index."""
801
801
self .project .versions .update (active = True , built = True )
802
- fancy_version = fixture .get (
802
+ fixture .get (
803
+ Version ,
804
+ slug = "fancy-version" ,
805
+ privacy_level = constants .PUBLIC ,
806
+ active = True ,
807
+ built = True ,
808
+ project = self .project ,
809
+ documentation_type = SPHINX ,
810
+ )
811
+
812
+ storage_exists .side_effect = [True ]
813
+ response = self .client .get (
814
+ reverse (
815
+ "proxito_404_handler" ,
816
+ kwargs = {"proxito_path" : "/en/fancy-version/not-found/" },
817
+ ),
818
+ HTTP_HOST = "project.readthedocs.io" ,
819
+ )
820
+ storage_exists .assert_has_calls (
821
+ [
822
+ mock .call ("html/project/fancy-version/not-found/README.html" ),
823
+ ]
824
+ )
825
+ self .assertEqual (response .status_code , 302 )
826
+ self .assertEqual (
827
+ response ["location" ], "/en/fancy-version/not-found/README.html"
828
+ )
829
+
830
+ @mock .patch .object (BuildMediaFileSystemStorageTest , "exists" )
831
+ def test_redirects_to_correct_index_ending_without_slash (self , storage_exists ):
832
+ """When the path doesn't end with a slash, we try both, index.html and README.html."""
833
+ self .project .versions .update (active = True , built = True )
834
+ fixture .get (
803
835
Version ,
804
836
slug = 'fancy-version' ,
805
837
privacy_level = constants .PUBLIC ,
@@ -811,8 +843,11 @@ def test_redirects_to_correct_index(self, storage_exists):
811
843
812
844
storage_exists .side_effect = [False , True ]
813
845
response = self .client .get (
814
- reverse ('proxito_404_handler' , kwargs = {'proxito_path' : '/en/fancy-version/not-found/' }),
815
- HTTP_HOST = 'project.readthedocs.io' ,
846
+ reverse (
847
+ "proxito_404_handler" ,
848
+ kwargs = {"proxito_path" : "/en/fancy-version/not-found" },
849
+ ),
850
+ HTTP_HOST = "project.readthedocs.io" ,
816
851
)
817
852
storage_exists .assert_has_calls (
818
853
[
@@ -1143,7 +1178,7 @@ def test_track_broken_link_custom_404(self, storage_exists, storage_open):
1143
1178
HTTP_HOST = "project.readthedocs.io" ,
1144
1179
)
1145
1180
self .assertEqual (resp .status_code , 404 )
1146
- storage_open .assert_called_once_with ( "html/project/latest/404.html" )
1181
+ storage_open .assert_called_once ( )
1147
1182
1148
1183
self .assertEqual (PageView .objects .all ().count (), 2 )
1149
1184
version = self .project .versions .get (slug = "latest" )
0 commit comments