diff --git a/SoftLayer/testing/__init__.py b/SoftLayer/testing/__init__.py index a2caa8888..d02e60f0e 100644 --- a/SoftLayer/testing/__init__.py +++ b/SoftLayer/testing/__init__.py @@ -147,7 +147,7 @@ def assert_called_with(self, service, method, **props): def assert_no_fail(self, result): """Fail when a failing click result has an error""" if result.exception: - print(result.output) + print(result.exception) raise result.exception self.assertEqual(result.exit_code, 0) diff --git a/SoftLayer/testing/xmlrpc.py b/SoftLayer/testing/xmlrpc.py index a38e85eeb..1e3bf5f1d 100644 --- a/SoftLayer/testing/xmlrpc.py +++ b/SoftLayer/testing/xmlrpc.py @@ -66,6 +66,15 @@ def do_POST(self): except UnicodeDecodeError: self.wfile.write(response_body) + except (NotImplementedError, NameError) as ex: + self.send_response(200) + self.end_headers() + response = xmlrpc.client.Fault(404, str(ex)) + response_body = xmlrpc.client.dumps(response, + allow_none=True, + methodresponse=True) + self.wfile.write(response_body.encode('utf-8')) + except SoftLayer.SoftLayerAPIError as ex: self.send_response(200) self.end_headers() diff --git a/tests/CLI/modules/call_api_tests.py b/tests/CLI/modules/call_api_tests.py index 123528607..d99c59d35 100644 --- a/tests/CLI/modules/call_api_tests.py +++ b/tests/CLI/modules/call_api_tests.py @@ -8,6 +8,7 @@ from SoftLayer.CLI import call_api from SoftLayer.CLI import exceptions +from SoftLayer import SoftLayerAPIError from SoftLayer import testing import pytest @@ -229,3 +230,37 @@ def test_parameters(self): self.assert_no_fail(result) self.assert_called_with('SoftLayer_Service', 'method', args=('arg1', '1234')) + + def test_fixture_not_implemented(self): + service = 'SoftLayer_Test' + method = 'getTest' + result = self.run_command(['call-api', service, method]) + self.assertEqual(result.exit_code, 1) + self.assert_called_with(service, method) + self.assertIsInstance(result.exception, SoftLayerAPIError) + output = '{} fixture is not implemented'.format(service) + self.assertIn(output, result.exception.faultString) + + def test_fixture_not_implemented_method(self): + call_service = 'SoftLayer_Account' + call_method = 'getTest' + result = self.run_command(['call-api', call_service, call_method]) + self.assertEqual(result.exit_code, 1) + self.assert_called_with(call_service, call_method) + self.assertIsInstance(result.exception, SoftLayerAPIError) + output = '%s::%s fixture is not implemented' % (call_service, call_method) + self.assertIn(output, result.exception.faultString) + + def test_fixture_exception(self): + call_service = 'SoftLayer_Account' + call_method = 'getTest' + result = self.run_command(['call-api', call_service, call_method]) + try: + self.assert_no_fail(result) + except Exception as ex: + print(ex) + self.assertEqual(result.exit_code, 1) + self.assert_called_with(call_service, call_method) + self.assertIsInstance(result.exception, SoftLayerAPIError) + output = '%s::%s fixture is not implemented' % (call_service, call_method) + self.assertIn(output, result.exception.faultString)