From 20aa85b168aa0987071c44b461bbafda22660364 Mon Sep 17 00:00:00 2001 From: Martin Cech Date: Wed, 30 Mar 2016 11:39:44 -0400 Subject: [PATCH] add TS test for disabled hg push --- test/tool_shed/base/twilltestcase.py | 9 ++++++-- .../functional/test_0310_hg_clone.py | 22 +++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/test/tool_shed/base/twilltestcase.py b/test/tool_shed/base/twilltestcase.py index e1ce9fbebe3d..4d05b5c02707 100644 --- a/test/tool_shed/base/twilltestcase.py +++ b/test/tool_shed/base/twilltestcase.py @@ -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 ): diff --git a/test/tool_shed/functional/test_0310_hg_clone.py b/test/tool_shed/functional/test_0310_hg_clone.py index 8ee78857df50..a10cede4ccf4 100644 --- a/test/tool_shed/functional/test_0310_hg_clone.py +++ b/test/tool_shed/functional/test_0310_hg_clone.py @@ -15,6 +15,7 @@ ''' 1. Create a repository. 2. Clone the repository to a local path. +3. Check Mercurial push is disabled. ''' @@ -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.'