Skip to content

Commit bcac437

Browse files
committed
1101 unit test
1 parent 3acc5b9 commit bcac437

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

SoftLayer/managers/user.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,13 +246,12 @@ def create_user(self, user_object, password):
246246

247247
try:
248248
return self.user_service.createObject(user_object, password, None)
249-
except exceptions.SoftLayerAPIError as err:
250-
if err.faultCode != "SoftLayer_Exception_User_Customer_DelegateIamIdInvitationToPaas":
251-
raise
252-
else:
249+
except exceptions.SoftLayerAPIError as ex:
250+
if ex.faultCode == "SoftLayer_Exception_User_Customer_DelegateIamIdInvitationToPaas":
253251
raise exceptions.SoftLayerError("Your request for a new user was received, but it needs to be "
254252
"processed by the Platform Services API first. Barring any errors on "
255253
"the Platform Services side, your new user should be created shortly.")
254+
raise
256255

257256
def edit_user(self, user_id, user_object):
258257
"""Blindly sends user_object to SoftLayer_User_Customer::editObject

tests/managers/user_tests.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,3 +191,33 @@ def test_get_current_user_mask(self):
191191
result = self.manager.get_current_user(objectmask="mask[id]")
192192
self.assert_called_with('SoftLayer_Account', 'getCurrentUser', mask="mask[id]")
193193
self.assertEqual(result['id'], 12345)
194+
195+
def test_create_user_handle_paas_exception(self):
196+
user_template = {"username": "foobar", "email": "foobar@example.com"}
197+
198+
self.manager.user_service = mock.Mock()
199+
200+
# FaultCode IS NOT SoftLayer_Exception_User_Customer_DelegateIamIdInvitationToPaas
201+
any_error = exceptions.SoftLayerAPIError("SoftLayer_Exception_User_Customer",
202+
"This exception indicates an error")
203+
204+
self.manager.user_service.createObject.side_effect = any_error
205+
206+
try:
207+
self.manager.create_user(user_template, "Pass@123")
208+
except exceptions.SoftLayerAPIError as ex:
209+
self.assertEqual(ex.faultCode, "SoftLayer_Exception_User_Customer")
210+
self.assertEqual(ex.faultString, "This exception indicates an error")
211+
212+
# FaultCode is SoftLayer_Exception_User_Customer_DelegateIamIdInvitationToPaas
213+
paas_error = exceptions.SoftLayerAPIError("SoftLayer_Exception_User_Customer_DelegateIamIdInvitationToPaas",
214+
"This exception does NOT indicate an error")
215+
216+
self.manager.user_service.createObject.side_effect = paas_error
217+
218+
try:
219+
self.manager.create_user(user_template, "Pass@123")
220+
except exceptions.SoftLayerError as ex:
221+
self.assertEqual(ex.args[0], "Your request for a new user was received, but it needs to be processed by "
222+
"the Platform Services API first. Barring any errors on the Platform Services "
223+
"side, your new user should be created shortly.")

0 commit comments

Comments
 (0)