def test_exception_is_raised_if_travis_is_failing(self): def mock_input(): return 'n' input_swap = self.swap(python_utils, 'INPUT', mock_input) args_swap = self.swap( sys, 'argv', ['cut_release_or_hotfix_branch.py', '--release_version=1.2.3']) with self.verify_local_repo_swap, self.verify_branch_name_swap: with self.verify_target_branch_swap: with self.verify_target_version_swap, self.open_tab_swap: with self.get_remote_alias_swap, self.check_call_swap: with input_swap, args_swap, self.assertRaises( SystemExit): cut_release_or_hotfix_branch.execute_branch_cut() self.expected_check_function_calls[ 'verify_hotfix_number_is_one_ahead_of_previous_' 'hotfix_number_is_called'] = False self.expected_check_function_calls[ 'verify_target_version_compatible_with_' 'latest_released_version_is_called'] = False self.expected_check_function_calls[ 'ask_user_to_confirm_is_called'] = False self.assertEqual(self.check_function_calls, self.expected_check_function_calls)
def test_exception_is_raised_if_actions_ci_is_failing(self): def mock_input(): return 'n' input_swap = self.swap(python_utils, 'INPUT', mock_input) with self.verify_local_repo_swap, self.verify_branch_name_swap: with self.verify_target_branch_swap: with self.verify_target_version_swap, self.open_tab_swap: with self.get_remote_alias_swap, self.check_call_swap: with input_swap, self.assertRaisesRegexp( Exception, 'Tests should pass on develop before this ' 'script is run.'): cut_release_or_hotfix_branch.execute_branch_cut( '1.2.3', 0) self.expected_check_function_calls[ 'verify_hotfix_number_is_one_ahead_of_previous_' 'hotfix_number_is_called'] = False self.expected_check_function_calls[ 'verify_target_version_compatible_with_' 'latest_released_version_is_called'] = False self.expected_check_function_calls[ 'ask_user_to_confirm_is_called'] = False self.assertEqual(self.check_function_calls, self.expected_check_function_calls)
def test_function_calls_for_hotfix_branch_with_hotfix_number_equal_to_one( self): def mock_get_current_branch_name(): return 'release-1.2.3' get_branch_name_swap = self.swap(common, 'get_current_branch_name', mock_get_current_branch_name) with self.verify_local_repo_swap, self.verify_branch_name_swap: with self.get_remote_alias_swap, self.check_call_swap: with self.verify_target_branch_swap, self.run_cmd_swap: with self.verify_target_version_swap, self.open_tab_swap: with self.verify_hotfix_number_swap, self.input_swap: with get_branch_name_swap: cut_release_or_hotfix_branch.execute_branch_cut( '1.2.3', 1) self.expected_check_function_calls[ 'verify_target_version_compatible_with_' 'latest_released_version_is_called'] = False self.expected_check_function_calls['run_cmd_is_called'] = True self.assertEqual(self.check_function_calls, self.expected_check_function_calls) expected_cmd_tokens = [ 'git', 'pull', 'upstream', 'develop', 'git', 'checkout', 'release-1.2.3', 'git', 'pull', 'upstream', 'release-1.2.3', 'git', 'checkout', '-b', 'release-1.2.3-hotfix-1', 'release-1.2.3' ] self.assertEqual(self.all_cmd_tokens, expected_cmd_tokens)
def test_function_calls_for_release_branch(self): with self.verify_local_repo_swap, self.verify_branch_name_swap: with self.get_remote_alias_swap, self.check_call_swap: with self.verify_target_branch_swap: with self.verify_target_version_swap, self.open_tab_swap: with self.input_swap, self.ask_user_swap: cut_release_or_hotfix_branch.execute_branch_cut( '1.2.3', 0) self.expected_check_function_calls[ 'verify_hotfix_number_is_one_ahead_of_previous_' 'hotfix_number_is_called'] = False self.assertEqual( self.check_function_calls, self.expected_check_function_calls)
def test_function_calls_for_hotfix_branch_with_hotfix_number_equal_to_one( self): with self.verify_local_repo_swap, self.verify_branch_name_swap: with self.get_remote_alias_swap, self.check_call_swap: with self.verify_target_branch_swap: with self.verify_target_version_swap, self.open_tab_swap: with self.verify_hotfix_number_swap, self.input_swap: with self.ask_user_swap: cut_release_or_hotfix_branch.execute_branch_cut( '1.2.3', 1) self.expected_check_function_calls[ 'verify_target_version_compatible_with_' 'latest_released_version_is_called'] = False self.assertEqual( self.check_function_calls, self.expected_check_function_calls)
def test_function_calls_for_hotfix_branch_with_hotfix_number_more_than_one( self): args_swap = self.swap(sys, 'argv', [ 'cut_release_or_hotfix_branch.py', '--new_version=1.2.3', '--hotfix_number=3' ]) with self.verify_local_repo_swap, self.verify_branch_name_swap: with self.get_remote_alias_swap, self.check_call_swap: with self.verify_target_branch_swap, args_swap: with self.verify_target_version_swap, self.open_tab_swap: with self.verify_hotfix_number_swap, self.input_swap: cut_release_or_hotfix_branch.execute_branch_cut() self.expected_check_function_calls[ 'verify_target_version_compatible_with_' 'latest_released_version_is_called'] = False self.assertEqual(self.check_function_calls, self.expected_check_function_calls)
def test_function_calls_for_release_branch(self): with self.verify_local_repo_swap, self.verify_branch_name_swap: with self.get_remote_alias_swap, self.check_call_swap: with self.verify_target_branch_swap: with self.verify_target_version_swap, self.open_tab_swap: with self.input_swap, self.ask_user_swap: cut_release_or_hotfix_branch.execute_branch_cut( '1.2.3', 0) self.expected_check_function_calls[ 'verify_hotfix_number_is_one_ahead_of_previous_' 'hotfix_number_is_called'] = False self.assertEqual(self.check_function_calls, self.expected_check_function_calls) expected_cmd_tokens = [ 'git', 'pull', 'upstream', 'develop', 'git', 'checkout', '-b', 'release-1.2.3', 'git', 'push', 'upstream', 'release-1.2.3' ] self.assertEqual(self.all_cmd_tokens, expected_cmd_tokens)
def test_function_calls_for_hotfix_branch_with_hotfix_number_more_than_one( self): with self.verify_local_repo_swap, self.verify_branch_name_swap: with self.get_remote_alias_swap, self.check_call_swap: with self.verify_target_branch_swap: with self.verify_target_version_swap, self.open_tab_swap: with self.verify_hotfix_number_swap, self.input_swap: with self.ask_user_swap: cut_release_or_hotfix_branch.execute_branch_cut( '1.2.3', 3) self.expected_check_function_calls[ 'verify_target_version_compatible_with_' 'latest_released_version_is_called'] = False self.assertEqual(self.check_function_calls, self.expected_check_function_calls) expected_cmd_tokens = [ 'git', 'pull', 'upstream', 'develop', 'git', 'checkout', '-b', 'release-1.2.3-hotfix-3', 'release-1.2.3-hotfix-2' ] self.assertEqual(self.all_cmd_tokens, expected_cmd_tokens)
def test_missing_release_version(self): args_swap = self.swap(sys, 'argv', ['cut_release_or_hotfix_branch.py']) with args_swap, self.assertRaisesRegexp( Exception, 'ERROR: A "release_version" arg must be specified.'): cut_release_or_hotfix_branch.execute_branch_cut()