Skip to content

Commit 29c74a8

Browse files
Merge pull request #1179 from ATGE/issue1095
#1095 Handle missing fixtures better in unit tests.
2 parents ea5536b + 479035f commit 29c74a8

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

SoftLayer/testing/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def assert_called_with(self, service, method, **props):
147147
def assert_no_fail(self, result):
148148
"""Fail when a failing click result has an error"""
149149
if result.exception:
150-
print(result.output)
150+
print(result.exception)
151151
raise result.exception
152152

153153
self.assertEqual(result.exit_code, 0)

SoftLayer/testing/xmlrpc.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,15 @@ def do_POST(self):
6666
except UnicodeDecodeError:
6767
self.wfile.write(response_body)
6868

69+
except (NotImplementedError, NameError) as ex:
70+
self.send_response(200)
71+
self.end_headers()
72+
response = xmlrpc.client.Fault(404, str(ex))
73+
response_body = xmlrpc.client.dumps(response,
74+
allow_none=True,
75+
methodresponse=True)
76+
self.wfile.write(response_body.encode('utf-8'))
77+
6978
except SoftLayer.SoftLayerAPIError as ex:
7079
self.send_response(200)
7180
self.end_headers()

tests/CLI/modules/call_api_tests.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from SoftLayer.CLI import call_api
1010
from SoftLayer.CLI import exceptions
11+
from SoftLayer import SoftLayerAPIError
1112
from SoftLayer import testing
1213

1314
import pytest
@@ -229,3 +230,37 @@ def test_parameters(self):
229230
self.assert_no_fail(result)
230231
self.assert_called_with('SoftLayer_Service', 'method',
231232
args=('arg1', '1234'))
233+
234+
def test_fixture_not_implemented(self):
235+
service = 'SoftLayer_Test'
236+
method = 'getTest'
237+
result = self.run_command(['call-api', service, method])
238+
self.assertEqual(result.exit_code, 1)
239+
self.assert_called_with(service, method)
240+
self.assertIsInstance(result.exception, SoftLayerAPIError)
241+
output = '{} fixture is not implemented'.format(service)
242+
self.assertIn(output, result.exception.faultString)
243+
244+
def test_fixture_not_implemented_method(self):
245+
call_service = 'SoftLayer_Account'
246+
call_method = 'getTest'
247+
result = self.run_command(['call-api', call_service, call_method])
248+
self.assertEqual(result.exit_code, 1)
249+
self.assert_called_with(call_service, call_method)
250+
self.assertIsInstance(result.exception, SoftLayerAPIError)
251+
output = '%s::%s fixture is not implemented' % (call_service, call_method)
252+
self.assertIn(output, result.exception.faultString)
253+
254+
def test_fixture_exception(self):
255+
call_service = 'SoftLayer_Account'
256+
call_method = 'getTest'
257+
result = self.run_command(['call-api', call_service, call_method])
258+
try:
259+
self.assert_no_fail(result)
260+
except Exception as ex:
261+
print(ex)
262+
self.assertEqual(result.exit_code, 1)
263+
self.assert_called_with(call_service, call_method)
264+
self.assertIsInstance(result.exception, SoftLayerAPIError)
265+
output = '%s::%s fixture is not implemented' % (call_service, call_method)
266+
self.assertIn(output, result.exception.faultString)

0 commit comments

Comments
 (0)