def test_success(self): http_method = self.respond_with(200, self.default_response) stdout = MagicMock() with patch('requests.delete', http_method), patch('sys.stdout', stdout): conduct_unload.unload(MagicMock(**self.default_args)) http_method.assert_called_with(self.default_url) self.assertEqual(self.default_output(), self.output(stdout))
def test_failure_invalid_address(self): http_method = self.raise_connection_error('test reason', self.default_url) stderr = MagicMock() with patch('requests.delete', http_method), patch('sys.stderr', stderr): conduct_unload.unload(MagicMock(**self.default_args)) http_method.assert_called_with(self.default_url) self.assertEqual( self.default_connection_error.format(self.default_url), self.output(stderr))
def test_success_verbose(self): http_method = self.respond_with(200, self.default_response) stdout = MagicMock() with patch('requests.delete', http_method), patch('sys.stdout', stdout): args = self.default_args.copy() args.update({'verbose': True}) conduct_unload.unload(MagicMock(**args)) http_method.assert_called_with(self.default_url) self.assertEqual(self.default_response + self.default_output(), self.output(stdout))
def test_failure(self): http_method = self.respond_with(404) stderr = MagicMock() with patch('requests.delete', http_method), patch('sys.stderr', stderr): conduct_unload.unload(MagicMock(**self.default_args)) http_method.assert_called_with(self.default_url) self.assertEqual( strip_margin("""|ERROR: 404 Not Found |"""), self.output(stderr))
def test_success_with_configuration(self): http_method = self.respond_with(200, self.default_response) stdout = MagicMock() cli_parameters = ' --ip 127.0.1.1 --port 9006' with patch('requests.delete', http_method), patch('sys.stdout', stdout): args = self.default_args.copy() args.update({'cli_parameters': cli_parameters}) conduct_unload.unload(MagicMock(**args)) http_method.assert_called_with(self.default_url) self.assertEqual( self.default_output(params=cli_parameters), self.output(stdout))
def test_success_quiet(self): wait_for_uninstallation_mock = MagicMock() http_method = self.respond_with(200, self.default_response) stdout = MagicMock() args = self.default_args.copy() args.update({'quiet': True}) input_args = MagicMock(**args) with patch('requests.delete', http_method), \ patch('conductr_cli.bundle_installation.wait_for_uninstallation', wait_for_uninstallation_mock): logging_setup.configure_logging(input_args, stdout) result = conduct_unload.unload(input_args) self.assertTrue(result) http_method.assert_called_with(self.default_url, auth=self.conductr_auth, verify=self.server_verification_file, timeout=DEFAULT_HTTP_TIMEOUT, headers={'Host': '127.0.0.1'}) wait_for_uninstallation_mock.assert_called_with( '45e0c477d3e5ea92aa8d85c0d8f3e25c', input_args) self.assertEqual('45e0c477d3e5ea92aa8d85c0d8f3e25c\n', self.output(stdout))
def test_success_verbose(self): request_headers_mock = MagicMock(return_value=self.mock_headers) wait_for_uninstallation_mock = MagicMock() http_method = self.respond_with(200, self.default_response) stdout = MagicMock() args = self.default_args.copy() args.update({'verbose': True}) input_args = MagicMock(**args) with patch('requests.delete', http_method), \ patch('conductr_cli.conduct_url.request_headers', request_headers_mock), \ patch('conductr_cli.bundle_installation.wait_for_uninstallation', wait_for_uninstallation_mock): logging_setup.configure_logging(input_args, stdout) result = conduct_unload.unload(input_args) self.assertTrue(result) request_headers_mock.assert_called_with(input_args) http_method.assert_called_with(self.default_url, timeout=DEFAULT_HTTP_TIMEOUT, headers=self.mock_headers) wait_for_uninstallation_mock.assert_called_with( '45e0c477d3e5ea92aa8d85c0d8f3e25c', input_args) self.assertEqual(self.default_response + self.default_output(), self.output(stdout))
def test_failure_invalid_address(self): http_method = self.raise_connection_error('test reason', self.default_url) stderr = MagicMock() with patch('requests.delete', http_method): logging_setup.configure_logging(MagicMock(**self.default_args), err_output=stderr) result = conduct_unload.unload(MagicMock(**self.default_args)) self.assertFalse(result) http_method.assert_called_with(self.default_url, timeout=DEFAULT_HTTP_TIMEOUT) self.assertEqual( self.default_connection_error.format(self.default_url), self.output(stderr))
def test_success_no_wait(self): http_method = self.respond_with(200, self.default_response) stdout = MagicMock() args = self.default_args.copy() args.update({'no_wait': True}) input_args = MagicMock(**args) with patch('requests.delete', http_method): logging_setup.configure_logging(input_args, stdout) result = conduct_unload.unload(input_args) self.assertTrue(result) http_method.assert_called_with(self.default_url, timeout=DEFAULT_HTTP_TIMEOUT) self.assertEqual(self.default_output(), self.output(stdout))
def test_failure(self): http_method = self.respond_with(404) stderr = MagicMock() with patch('requests.delete', http_method): logging_setup.configure_logging(MagicMock(**self.default_args), err_output=stderr) result = conduct_unload.unload(MagicMock(**self.default_args)) self.assertFalse(result) http_method.assert_called_with(self.default_url, timeout=DEFAULT_HTTP_TIMEOUT) self.assertEqual( as_error(strip_margin("""|Error: 404 Not Found |""")), self.output(stderr))
def test_success(self): wait_for_uninstallation_mock = MagicMock() http_method = self.respond_with(200, self.default_response) stdout = MagicMock() input_args = MagicMock(**self.default_args) with patch('requests.delete', http_method), \ patch('conductr_cli.bundle_installation.wait_for_uninstallation', wait_for_uninstallation_mock): logging_setup.configure_logging(input_args, stdout) result = conduct_unload.unload(input_args) self.assertTrue(result) http_method.assert_called_with(self.default_url, timeout=DEFAULT_HTTP_TIMEOUT) wait_for_uninstallation_mock.assert_called_with('45e0c477d3e5ea92aa8d85c0d8f3e25c', input_args) self.assertEqual(self.default_output(), self.output(stdout))
def test_failure_invalid_address(self): http_method = self.raise_connection_error('test reason', self.default_url) stderr = MagicMock() input_args = MagicMock(**self.default_args) with patch('requests.delete', http_method): logging_setup.configure_logging(input_args, err_output=stderr) result = conduct_unload.unload(input_args) self.assertFalse(result) http_method.assert_called_with(self.default_url, auth=self.conductr_auth, verify=self.server_verification_file, timeout=DEFAULT_HTTP_TIMEOUT, headers={'Host': '127.0.0.1'}) self.assertEqual( self.default_connection_error.format(self.default_url), self.output(stderr))
def test_failure(self): http_method = self.respond_with(404) stderr = MagicMock() input_args = MagicMock(**self.default_args) with patch('requests.delete', http_method): logging_setup.configure_logging(input_args, err_output=stderr) result = conduct_unload.unload(input_args) self.assertFalse(result) http_method.assert_called_with(self.default_url, auth=self.conductr_auth, verify=self.server_verification_file, timeout=DEFAULT_HTTP_TIMEOUT, headers={'Host': '127.0.0.1'}) self.assertEqual( as_error(strip_margin("""|Error: 404 Not Found |""")), self.output(stderr))
def test_success_no_wait(self): http_method = self.respond_with(200, self.default_response) stdout = MagicMock() args = self.default_args.copy() args.update({'no_wait': True}) input_args = MagicMock(**args) with patch('requests.delete', http_method): logging_setup.configure_logging(input_args, stdout) result = conduct_unload.unload(input_args) self.assertTrue(result) http_method.assert_called_with(self.default_url, auth=self.conductr_auth, verify=self.server_verification_file, timeout=DEFAULT_HTTP_TIMEOUT, headers={'Host': '127.0.0.1'}) self.assertEqual(self.default_output(), self.output(stdout))
def test_failure(self): http_method = self.respond_with(404) stderr = MagicMock() input_args = MagicMock(**self.default_args) with patch('requests.delete', http_method): logging_setup.configure_logging(input_args, err_output=stderr) result = conduct_unload.unload(input_args) self.assertFalse(result) http_method.assert_called_with(self.default_url, auth=self.conductr_auth, verify=self.server_verification_file, timeout=DEFAULT_HTTP_TIMEOUT, headers={'Host': '127.0.0.1'}) self.assertEqual( as_error( strip_margin("""|Error: 404 Not Found |""")), self.output(stderr))
def test_success_quiet(self): wait_for_uninstallation_mock = MagicMock() http_method = self.respond_with(200, self.default_response) stdout = MagicMock() args = self.default_args.copy() args.update({'quiet': True}) input_args = MagicMock(**args) with patch('requests.delete', http_method), \ patch('conductr_cli.bundle_installation.wait_for_uninstallation', wait_for_uninstallation_mock): logging_setup.configure_logging(input_args, stdout) result = conduct_unload.unload(input_args) self.assertTrue(result) http_method.assert_called_with(self.default_url, auth=self.conductr_auth, verify=self.server_verification_file, timeout=DEFAULT_HTTP_TIMEOUT, headers={'Host': '127.0.0.1'}) wait_for_uninstallation_mock.assert_called_with('45e0c477d3e5ea92aa8d85c0d8f3e25c', input_args) self.assertEqual('45e0c477d3e5ea92aa8d85c0d8f3e25c\n', self.output(stdout))
def test_success_no_wait(self): request_headers_mock = MagicMock(return_value=self.mock_headers) http_method = self.respond_with(200, self.default_response) stdout = MagicMock() args = self.default_args.copy() args.update({'no_wait': True}) input_args = MagicMock(**args) with patch('requests.delete', http_method), \ patch('conductr_cli.conduct_url.request_headers', request_headers_mock): logging_setup.configure_logging(input_args, stdout) result = conduct_unload.unload(input_args) self.assertTrue(result) request_headers_mock.assert_called_with(input_args) http_method.assert_called_with(self.default_url, timeout=DEFAULT_HTTP_TIMEOUT, headers=self.mock_headers) self.assertEqual(self.default_output(), self.output(stdout))
def test_failure(self): request_headers_mock = MagicMock(return_value=self.mock_headers) http_method = self.respond_with(404) stderr = MagicMock() input_args = MagicMock(**self.default_args) with patch('requests.delete', http_method), \ patch('conductr_cli.conduct_url.request_headers', request_headers_mock): logging_setup.configure_logging(input_args, err_output=stderr) result = conduct_unload.unload(input_args) self.assertFalse(result) request_headers_mock.assert_called_with(input_args) http_method.assert_called_with(self.default_url, timeout=DEFAULT_HTTP_TIMEOUT, headers=self.mock_headers) self.assertEqual( as_error( strip_margin("""|Error: 404 Not Found |""")), self.output(stderr))
def test_failure_invalid_address(self): request_headers_mock = MagicMock(return_value=self.mock_headers) http_method = self.raise_connection_error('test reason', self.default_url) stderr = MagicMock() input_args = MagicMock(**self.default_args) with patch('requests.delete', http_method), \ patch('conductr_cli.conduct_url.request_headers', request_headers_mock): logging_setup.configure_logging(input_args, err_output=stderr) result = conduct_unload.unload(input_args) self.assertFalse(result) request_headers_mock.assert_called_with(input_args) http_method.assert_called_with(self.default_url, timeout=DEFAULT_HTTP_TIMEOUT, headers=self.mock_headers) self.assertEqual( self.default_connection_error.format(self.default_url), self.output(stderr))
def test_success_with_configuration(self): wait_for_uninstallation_mock = MagicMock() http_method = self.respond_with(200, self.default_response) stdout = MagicMock() args = self.default_args.copy() cli_parameters = ' --ip 127.0.1.1 --port 9006' args.update({'cli_parameters': cli_parameters}) input_args = MagicMock(**args) with patch('requests.delete', http_method), \ patch('conductr_cli.bundle_installation.wait_for_uninstallation', wait_for_uninstallation_mock): logging_setup.configure_logging(input_args, stdout) result = conduct_unload.unload(input_args) self.assertTrue(result) http_method.assert_called_with(self.default_url, timeout=DEFAULT_HTTP_TIMEOUT) wait_for_uninstallation_mock.assert_called_with('45e0c477d3e5ea92aa8d85c0d8f3e25c', input_args) self.assertEqual( self.default_output(params=cli_parameters), self.output(stdout))