def test_skip_plugin_retrieval_if_no_config_provided(self, get_plugins_info_mock): """ Verify that retrieval of information from Jenkins instance about its plugins will be skipped when run if no config file provided. """ with mock.patch("sys.stdout"): cmd.main(["test", os.path.join(self.fixtures_path, "cmd-001.yaml")]) self.assertFalse(get_plugins_info_mock.called)
def test_skip_plugin_retrieval_if_no_config_provided( self, get_plugins_info_mock): """ Verify that retrieval of information from Jenkins instance about its plugins will be skipped when run if no config file provided. """ with mock.patch('sys.stdout', new_callable=io.BytesIO): cmd.main(['test', os.path.join(self.fixtures_path, 'cmd-001.yaml')]) self.assertFalse(get_plugins_info_mock.called)
def test_console_output(self): """ Run test mode and verify that resulting XML gets sent to the console. """ console_out = io.BytesIO() with mock.patch("sys.stdout", console_out): cmd.main(["test", os.path.join(self.fixtures_path, "cmd-001.yaml")]) xml_content = codecs.open(os.path.join(self.fixtures_path, "cmd-001.xml"), "r", "utf-8").read() self.assertEqual(console_out.getvalue().decode("utf-8"), xml_content)
def test_console_output(self): """ Run test mode and verify that resulting XML gets sent to the console. """ console_out = io.BytesIO() with mock.patch('sys.stdout', console_out): cmd.main(['test', os.path.join(self.fixtures_path, 'cmd-001.yaml')]) xml_content = io.open(os.path.join(self.fixtures_path, 'cmd-001.xml'), 'r', encoding='utf-8').read() self.assertEqual(console_out.getvalue().decode('utf-8'), xml_content)
def test_skip_plugin_retrieval_if_disabled(self, get_plugins_info_mock): """ Verify that retrieval of information from Jenkins instance about its plugins will be skipped when run if a config file provided and disables querying through a config option. """ with mock.patch('sys.stdout', new_callable=io.BytesIO): cmd.main(['--conf', os.path.join(self.fixtures_path, 'disable-query-plugins.conf'), 'test', os.path.join(self.fixtures_path, 'cmd-001.yaml')]) self.assertFalse(get_plugins_info_mock.called)
def test_skip_plugin_retrieval_if_disabled(self, get_plugins_info_mock): """ Verify that retrieval of information from Jenkins instance about its plugins will be skipped when run if a config file provided and disables querying through a config option. """ with mock.patch("sys.stdout"): cmd.main( [ "--conf", os.path.join(self.fixtures_path, "disable-query-plugins.conf"), "test", os.path.join(self.fixtures_path, "cmd-001.yaml"), ] ) self.assertFalse(get_plugins_info_mock.called)
def test_stream_input_output_utf8_encoding(self): """ Run test mode simulating using pipes for input and output using utf-8 encoding """ console_out = io.BytesIO() input_file = os.path.join(self.fixtures_path, 'cmd-001.yaml') with io.open(input_file, 'r') as f: with mock.patch('sys.stdout', console_out): with mock.patch('sys.stdin', f): cmd.main(['test']) xml_content = io.open(os.path.join(self.fixtures_path, 'cmd-001.xml'), 'r', encoding='utf-8').read() value = console_out.getvalue().decode('utf-8') self.assertEqual(value, xml_content)
def test_console_output_jenkins_connection_failure_warning(self, get_plugins_info_mock): """ Run test mode and verify that failed Jenkins connection attempt exception does not bubble out of cmd.main. Ideally, we would also test that an appropriate message is logged to stderr but it's somewhat difficult to figure out how to actually enable stderr in this test suite. """ get_plugins_info_mock.side_effect = jenkins.JenkinsException("Connection refused") with mock.patch("sys.stdout"): try: cmd.main(["test", os.path.join(self.fixtures_path, "cmd-001.yaml")]) except jenkins.JenkinsException: self.fail("jenkins.JenkinsException propagated to main") except: pass # only care about jenkins.JenkinsException for now
def test_console_output_jenkins_connection_failure_warning( self, get_plugins_info_mock): """ Run test mode and verify that failed Jenkins connection attempt exception does not bubble out of cmd.main. Ideally, we would also test that an appropriate message is logged to stderr but it's somewhat difficult to figure out how to actually enable stderr in this test suite. """ get_plugins_info_mock.side_effect = \ jenkins.JenkinsException("Connection refused") with mock.patch('sys.stdout'): try: cmd.main(['test', os.path.join(self.fixtures_path, 'cmd-001.yaml')]) except jenkins.JenkinsException: self.fail("jenkins.JenkinsException propagated to main") except: pass # only care about jenkins.JenkinsException for now