Skip to content

Commit

Permalink
add TS test for disabled hg push
Browse files Browse the repository at this point in the history
  • Loading branch information
martenson committed Mar 30, 2016
1 parent d1f438f commit 20aa85b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
9 changes: 7 additions & 2 deletions test/tool_shed/base/twilltestcase.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,12 +261,17 @@ def commit_and_push( self, repository, hgrepo, options, username, password ):
commands.commit( ui.ui(), hgrepo, **options )
try:
commands.push( ui.ui(), hgrepo, dest=url )
except Abort, e:
message = e
except Abort as a:
message = a
if 'authorization failed' in message:
return False
else:
raise
except Exception as e:
if str(e).find('Pushing to Tool Shed is disabled') != -1:
return False
else:
raise
return True

def create_category( self, **kwd ):
Expand Down
22 changes: 22 additions & 0 deletions test/tool_shed/functional/test_0310_hg_clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
'''
1. Create a repository.
2. Clone the repository to a local path.
3. Check Mercurial push is disabled.
'''


Expand Down Expand Up @@ -92,3 +93,24 @@ def test_0010_clone( self ):
self.clone_repository( repository, clone_path )
files_in_repository = os.listdir( clone_path )
assert 'filtering.py' in files_in_repository, 'File not found in repository: filtering.py'

def test_0015_commit_and_push( self ):
'''
Edit a file and attempt a push as a user that does have write access.
We expect this to fail as pushing is disabled by default via disable_push config option.
We are at step 3 - Check Mercurial push is disabled.
'''
repository = self.test_db_util.get_repository_by_name_and_owner( repository_name, common.test_user_1_name )
clone_path = self.generate_temp_path( 'test_0310', additional_paths=[ 'filtering_0310', 'user1' ] )
self.clone_repository( repository, clone_path )
hgrepo = self.get_hg_repo( clone_path )
files_in_repository = os.listdir( clone_path )
assert 'filtering.py' in files_in_repository, 'File not found in repository: filtering.py'
filepath = os.path.join( clone_path, 'filtering.py' )
file_contents = [ '# This is another dummy comment to generate a new changeset.' ]
file_contents.extend( file( filepath, 'r' ).readlines() )
file( filepath, 'w' ).write( '\n'.join( file_contents ) )
commit_options = dict( user=common.test_user_1_name, message='Added another line to filtering.py.' )
success = self.commit_and_push( repository, hgrepo, commit_options, username=common.test_user_1_name, password='testuser' )
assert success is False, 'Test user 1 (repo owner) was able to commit and push to the remote repository.'

0 comments on commit 20aa85b

Please sign in to comment.