@@ -35,33 +35,59 @@ class DeleteRepoTest(rdiffweb.test.WebCase):
3535
3636 login = True
3737
38- def _delete (self , user , repo , confirm , redirect = None ):
38+ def _delete (self , user , repo , confirm ):
3939 body = {}
4040 if confirm is not None :
4141 body .update ({'confirm' : confirm })
42- if redirect is not None :
43- body ['redirect' ] = redirect
4442 self .getPage ("/delete/" + user + "/" + repo + "/" , method = "POST" , body = body )
4543
4644 @parameterized .expand (
4745 [
48- ("with_dir" , 'admin' , '/testcases/Revisions' , 'Revisions' , 303 , 404 ),
46+ ("with_dir" , 'admin' , '/testcases/Revisions' , 'Revisions' , 303 , 404 , '/browse/admin/testcases' ),
4947 ("with_dir_wrong_confirmation" , 'admin' , '/testcases/Revisions' , 'invalid' , 400 , 200 ),
50- ("with_file" , 'admin' , '/testcases/Revisions/Data' , 'Data' , 303 , 404 ),
48+ ("with_file" , 'admin' , '/testcases/Revisions/Data' , 'Data' , 303 , 404 , '/browse/admin/testcases/Revisions' ),
5149 ("with_file_wrong_confirmation" , 'admin' , '/testcases/Revisions/Data' , 'invalid' , 400 , 200 ),
5250 ("with_invalid" , 'admin' , '/testcases/invalid' , 'invalid' , 404 , 404 ),
53- ("with_broken_symlink" , 'admin' , '/testcases/BrokenSymlink' , 'BrokenSymlink' , 303 , 404 ),
54- ("with_utf8" , 'admin' , '/testcases/R%C3%A9pertoire%20Existant' , 'Répertoire Existant' , 303 , 404 ),
51+ (
52+ "with_broken_symlink" ,
53+ 'admin' ,
54+ '/testcases/BrokenSymlink' ,
55+ 'BrokenSymlink' ,
56+ 303 ,
57+ 404 ,
58+ '/browse/admin/testcases' ,
59+ ),
60+ (
61+ "with_utf8" ,
62+ 'admin' ,
63+ '/testcases/R%C3%A9pertoire%20Existant' ,
64+ 'Répertoire Existant' ,
65+ 303 ,
66+ 404 ,
67+ '/browse/admin/testcases' ,
68+ ),
5569 ("with_rdiff_backup_data" , 'admin' , '/testcases/rdiff-backup-data' , 'rdiff-backup-data' , 404 , 404 ),
56- ("with_quoted_path" , 'admin' , '/testcases/Char%20%3B090%20to%20quote' , 'Char Z to quote' , 303 , 404 ),
70+ (
71+ "with_quoted_path" ,
72+ 'admin' ,
73+ '/testcases/Char%20%3B090%20to%20quote' ,
74+ 'Char Z to quote' ,
75+ 303 ,
76+ 404 ,
77+ '/browse/admin/testcases' ,
78+ ),
5779 ]
5880 )
5981 @skipIf (rdiff_backup_version () < (2 , 0 , 1 ), "rdiff-backup-delete is available since 2.0.1" )
60- def test_delete_path (self , unused , username , path , confirmation , expected_status , expected_history_status ):
82+ def test_delete_path (
83+ self , unused , username , path , confirmation , expected_status , expected_history_status , expected_redirect = None
84+ ):
6185 # When trying to delete a file or a folder with a confirmation
6286 self ._delete (username , path , confirmation )
6387 # Then a status is returned
6488 self .assertStatus (expected_status )
89+ if expected_redirect :
90+ self .assertHeaderItemValue ('Location' , self .baseurl + expected_redirect )
6591 # Check filesystem
6692 sleep (1 )
6793 self .getPage ("/history/" + username + "/" + path )
@@ -77,6 +103,7 @@ def test_delete_repo(self):
77103 # Delete repo
78104 self ._delete (self .USERNAME , self .REPO , 'testcases' )
79105 self .assertStatus (303 )
106+ self .assertHeaderItemValue ('Location' , self .baseurl + '/' )
80107 # Check filesystem
81108 sleep (1 )
82109 userobj .expire ()
@@ -90,6 +117,7 @@ def test_delete_repo_with_slash(self):
90117 # Then delete it.
91118 self ._delete (self .USERNAME , self .REPO , 'testcases' )
92119 self .assertStatus (303 )
120+ self .assertHeaderItemValue ('Location' , self .baseurl + '/' )
93121 # Check filesystem
94122 sleep (1 )
95123 userobj .expire ()
@@ -132,10 +160,9 @@ def test_delete_repo_as_admin(self):
132160 user_obj .refresh_repos ()
133161 self .assertEqual (['broker-repo' , 'testcases' ], [r .name for r in user_obj .repo_objs ])
134162
135- self ._delete ('anotheruser' , 'testcases' , 'testcases' , redirect = '/admin/repos/' )
163+ self ._delete ('anotheruser' , 'testcases' , 'testcases' )
136164 self .assertStatus (303 )
137- location = self .assertHeader ('Location' )
138- self .assertTrue (location .endswith ('/admin/repos/' ))
165+ self .assertHeaderItemValue ('Location' , self .baseurl + '/' )
139166
140167 # Check filesystem
141168 sleep (1 )
@@ -156,11 +183,10 @@ def test_delete_repo_as_maintainer(self):
156183 # Login as maintainer
157184 self ._login ('maintainer' , 'password' )
158185
159- # Try to delete own own repo
160- self ._delete ('maintainer' , 'testcases' , 'testcases' , redirect = '/admin/repos/' )
186+ # Try to delete your own repo
187+ self ._delete ('maintainer' , 'testcases' , 'testcases' )
161188 self .assertStatus (303 )
162- location = self .assertHeader ('Location' )
163- self .assertTrue (location .endswith ('/admin/repos/' ))
189+ self .assertHeaderItemValue ('Location' , self .baseurl + '/' )
164190
165191 # Check filesystem
166192 sleep (1 )
@@ -179,8 +205,8 @@ def test_delete_repo_as_user(self):
179205 # Login as maintainer
180206 self ._login ('user' , 'password' )
181207
182- # Try to delete our own repo
183- self ._delete ('user' , 'testcases' , 'testcases' , redirect = '/admin/repos/' )
208+ # Try to delete own own repo
209+ self ._delete ('user' , 'testcases' , 'testcases' )
184210 self .assertStatus (403 )
185211
186212 # Check database don't change
@@ -194,3 +220,13 @@ def test_delete_repo_does_not_exists(self):
194220 self ._delete (self .USERNAME , repo , repo )
195221 # Then a 404 is return to the user
196222 self .assertStatus (404 )
223+
224+ def test_delete_method_get (self ):
225+ # Given a user with repo
226+ self .assertEqual (['broker-repo' , 'testcases' ], [r .name for r in UserObject .get_user ('admin' ).repo_objs ])
227+ # When trying to deleted repo with GET method
228+ self .getPage ("/delete/" + self .USERNAME + "/" + self .REPO + "/?confirm=" + self .REPO , method = "GET" )
229+ # Then An error is returned
230+ self .assertStatus (405 )
231+ # Then repo still exists
232+ self .assertEqual (['broker-repo' , 'testcases' ], [r .name for r in UserObject .get_user ('admin' ).repo_objs ])
0 commit comments