@@ -37,33 +37,59 @@ class DeleteRepoTest(rdiffweb.test.WebCase):
3737
3838 login = True
3939
40- def _delete (self , user , repo , confirm , redirect = None ):
40+ def _delete (self , user , repo , confirm ):
4141 body = {}
4242 if confirm is not None :
4343 body .update ({'confirm' : confirm })
44- if redirect is not None :
45- body ['redirect' ] = redirect
4644 self .getPage ("/delete/" + user + "/" + repo + "/" , method = "POST" , body = body )
4745
4846 @skipIf (RDIFF_BACKUP_VERSION < (2 , 0 , 1 ), "rdiff-backup-delete is available since 2.0.1" )
4947 @parameterized .expand (
5048 [
51- ("with_dir" , 'admin' , '/testcases/Revisions' , 'Revisions' , 303 , 404 ),
49+ ("with_dir" , 'admin' , '/testcases/Revisions' , 'Revisions' , 303 , 404 , '/browse/admin/testcases' ),
5250 ("with_dir_wrong_confirmation" , 'admin' , '/testcases/Revisions' , 'invalid' , 400 , 200 ),
53- ("with_file" , 'admin' , '/testcases/Revisions/Data' , 'Data' , 303 , 404 ),
51+ ("with_file" , 'admin' , '/testcases/Revisions/Data' , 'Data' , 303 , 404 , '/browse/admin/testcases/Revisions' ),
5452 ("with_file_wrong_confirmation" , 'admin' , '/testcases/Revisions/Data' , 'invalid' , 400 , 200 ),
5553 ("with_invalid" , 'admin' , '/testcases/invalid' , 'invalid' , 404 , 404 ),
56- ("with_broken_symlink" , 'admin' , '/testcases/BrokenSymlink' , 'BrokenSymlink' , 303 , 404 ),
57- ("with_utf8" , 'admin' , '/testcases/R%C3%A9pertoire%20Existant' , 'Répertoire Existant' , 303 , 404 ),
54+ (
55+ "with_broken_symlink" ,
56+ 'admin' ,
57+ '/testcases/BrokenSymlink' ,
58+ 'BrokenSymlink' ,
59+ 303 ,
60+ 404 ,
61+ '/browse/admin/testcases' ,
62+ ),
63+ (
64+ "with_utf8" ,
65+ 'admin' ,
66+ '/testcases/R%C3%A9pertoire%20Existant' ,
67+ 'Répertoire Existant' ,
68+ 303 ,
69+ 404 ,
70+ '/browse/admin/testcases' ,
71+ ),
5872 ("with_rdiff_backup_data" , 'admin' , '/testcases/rdiff-backup-data' , 'rdiff-backup-data' , 404 , 404 ),
59- ("with_quoted_path" , 'admin' , '/testcases/Char%20%3B090%20to%20quote' , 'Char Z to quote' , 303 , 404 ),
73+ (
74+ "with_quoted_path" ,
75+ 'admin' ,
76+ '/testcases/Char%20%3B090%20to%20quote' ,
77+ 'Char Z to quote' ,
78+ 303 ,
79+ 404 ,
80+ '/browse/admin/testcases' ,
81+ ),
6082 ]
6183 )
62- def test_delete_path (self , unused , username , path , confirmation , expected_status , expected_history_status ):
84+ def test_delete_path (
85+ self , unused , username , path , confirmation , expected_status , expected_history_status , expected_redirect = None
86+ ):
6387 # When trying to delete a file or a folder with a confirmation
6488 self ._delete (username , path , confirmation )
6589 # Then a status is returned
6690 self .assertStatus (expected_status )
91+ if expected_redirect :
92+ self .assertHeaderItemValue ('Location' , self .baseurl + expected_redirect )
6793 # Check filesystem
6894 sleep (1 )
6995 self .getPage ("/history/" + username + "/" + path )
@@ -78,6 +104,7 @@ def test_delete_repo(self):
78104 # Delete repo
79105 self ._delete (self .USERNAME , self .REPO , 'testcases' )
80106 self .assertStatus (303 )
107+ self .assertHeaderItemValue ('Location' , self .baseurl + '/' )
81108 # Check filesystem
82109 sleep (1 )
83110 self .assertEqual (['broker-repo' ], [r .name for r in self .app .store .get_user ('admin' ).repo_objs ])
@@ -89,6 +116,7 @@ def test_delete_repo_with_slash(self):
89116 # Then delete it.
90117 self ._delete (self .USERNAME , self .REPO , 'testcases' )
91118 self .assertStatus (303 )
119+ self .assertHeaderItemValue ('Location' , self .baseurl + '/' )
92120 # Check filesystem
93121 sleep (1 )
94122 self .assertEqual (['broker-repo' ], [r .name for r in self .app .store .get_user ('admin' ).repo_objs ])
@@ -125,10 +153,9 @@ def test_delete_repo_as_admin(self):
125153 user_obj .user_root = self .testcases
126154 self .assertEqual (['broker-repo' , 'testcases' ], [r .name for r in user_obj .repo_objs ])
127155
128- self ._delete ('anotheruser' , 'testcases' , 'testcases' , redirect = '/admin/repos/' )
156+ self ._delete ('anotheruser' , 'testcases' , 'testcases' )
129157 self .assertStatus (303 )
130- location = self .assertHeader ('Location' )
131- self .assertTrue (location .endswith ('/admin/repos/' ))
158+ self .assertHeaderItemValue ('Location' , self .baseurl + '/' )
132159
133160 # Check filesystem
134161 sleep (1 )
@@ -147,11 +174,10 @@ def test_delete_repo_as_maintainer(self):
147174 # Login as maintainer
148175 self ._login ('maintainer' , 'password' )
149176
150- # Try to delete own own repo
151- self ._delete ('maintainer' , 'testcases' , 'testcases' , redirect = '/admin/repos/' )
177+ # Try to delete your own repo
178+ self ._delete ('maintainer' , 'testcases' , 'testcases' )
152179 self .assertStatus (303 )
153- location = self .assertHeader ('Location' )
154- self .assertTrue (location .endswith ('/admin/repos/' ))
180+ self .assertHeaderItemValue ('Location' , self .baseurl + '/' )
155181
156182 # Check filesystem
157183 sleep (1 )
@@ -169,7 +195,7 @@ def test_delete_repo_as_user(self):
169195 self ._login ('user' , 'password' )
170196
171197 # Try to delete own own repo
172- self ._delete ('user' , 'testcases' , 'testcases' , redirect = '/admin/repos/' )
198+ self ._delete ('user' , 'testcases' , 'testcases' )
173199 self .assertStatus (403 )
174200
175201 # Check database don't change
@@ -183,3 +209,13 @@ def test_delete_repo_does_not_exists(self):
183209 self ._delete (self .USERNAME , repo , repo )
184210 # Then a 404 is return to the user
185211 self .assertStatus (404 )
212+
213+ def test_delete_method_get (self ):
214+ # Given a user with repo
215+ self .assertEqual (['broker-repo' , 'testcases' ], [r .name for r in self .app .store .get_user ('admin' ).repo_objs ])
216+ # When trying to deleted repo with GET method
217+ self .getPage ("/delete/" + self .USERNAME + "/" + self .REPO + "/?confirm=" + self .REPO , method = "GET" )
218+ # Then An error is returned
219+ self .assertStatus (405 )
220+ # Then repo still exists
221+ self .assertEqual (['broker-repo' , 'testcases' ], [r .name for r in self .app .store .get_user ('admin' ).repo_objs ])
0 commit comments