def test_set_shutdown_mode_should_kill_slave_if_slave_has_no_build(self): slave = self._create_slave() slave.set_shutdown_mode() self.mock_network.post_with_digest.assert_called_once_with( AnyStringMatching('/v1/kill'), ANY, ANY)
def test_kill_should_post_to_slave_api(self): slave = self._create_slave() slave.kill() self.mock_network.post_with_digest.assert_called_once_with( AnyStringMatching('/v1/kill'), ANY, ANY)
def test_mark_as_idle_raises_when_slave_is_in_shutdown_mode(self): slave = self._create_slave() slave._is_in_shutdown_mode = True self.assertRaises(SlaveMarkedForShutdownError, slave.mark_as_idle) self.mock_network.post_with_digest.assert_called_once_with( AnyStringMatching('/v1/kill'), ANY, ANY)
def test_fetch_project_passes_depth_parameter_for_shallow_clone_configuration( self, shallow_clone): Configuration['shallow_clones'] = shallow_clone self.os_path_isfile_mock.return_value = False self.os_path_exists_mock.return_value = False mock_popen = self._patch_popen( {'git rev-parse$': _FakePopenResult(return_code=1)}) git = Git( url='http://original-user-specified-url.test/repo-path/repo-name') git.fetch_project() git_clone_call = call(AnyStringMatching('git clone --depth=1'), start_new_session=ANY, stdout=ANY, stderr=ANY, cwd=ANY, shell=ANY) if shallow_clone: self.assertIn( git_clone_call, mock_popen.call_args_list, 'If shallow cloning, the --depth=1 parameter ' 'should be present.') else: self.assertNotIn( git_clone_call, mock_popen.call_args_list, 'If deep cloning, the --depth=1 parameter ' 'must be absent.')
def test_repo_is_cloned_if_and_only_if_rev_parse_fails( self, rev_parse_return_code, expect_git_clone_call): mock_popen = self._patch_popen({ 'git rev-parse$': _FakePopenResult(return_code=rev_parse_return_code) }) Configuration['repo_directory'] = '/repo-directory' git = Git( url='http://original-user-specified-url.test/repo-path/repo-name') git.fetch_project() git_clone_call = call(AnyStringMatching('git clone'), start_new_session=ANY, stdout=ANY, stderr=ANY, cwd=ANY, shell=ANY) if expect_git_clone_call: self.assertIn( git_clone_call, mock_popen.call_args_list, 'If "git rev-parse" returns a failing exit code, ' '"git clone" should be called.') else: self.assertNotIn( git_clone_call, mock_popen.call_args_list, 'If "git rev-parse" returns a successful exit ' 'code, "git clone" should not be called.')
def test_exceptions_in_teardown_callbacks_are_caught_and_logged(self): an_evil_callback = MagicMock(side_effect=Exception) self.exception_handler.add_teardown_callback(an_evil_callback) with suppress(SystemExit): with self.exception_handler: raise Exception self.assertEqual(an_evil_callback.call_count, 1, 'A teardown callback should be executed once.') callback_exception_was_logged = self.log_handler.has_error( AnyStringMatching('Exception raised by teardown callback.*') ) self.assertTrue(callback_exception_was_logged, 'Exception handler should log teardown callback exceptions.')
def test_execute_git_command_auto_sets_strict_host_option_correctly(self, strict_host_check_setting): Configuration['git_strict_host_key_checking'] = strict_host_check_setting popen_mock = self._patch_popen() git = Git(url='http://some-user-url.com/repo-path/repo-name') git._execute_git_command_in_repo_and_raise_on_failure('fakecmd') if strict_host_check_setting: expected_ssh_arg = '-o StrictHostKeyChecking=yes' else: expected_ssh_arg = '-o StrictHostKeyChecking=no' expected_call = call(AnyStringMatching(expected_ssh_arg), start_new_session=ANY, stdout=ANY, stderr=ANY, cwd=ANY, shell=ANY) self.assertIn(expected_call, popen_mock.call_args_list, 'Executed git command should include the correct ' 'option for StrictHostKeyChecking.')