Fix fake_init_exception() to better handle Neutron exceptions

Neutron often declares exceptions by overriding the message attribute
and possibly adding additional information later, like a 'reason' for
the failure, rather than passing the code and message around as
arguments.  We should handle this appropriately and display the correct
message, instead of failing with "TypeError: fake_init_exception()
takes exactly 3 arguments (1 given)"

Change-Id: Ib838704cb9ca968ddfc6e3bfed3af7d0ea08f384
Closes-Bug: #1315035
This commit is contained in:
Julie Pichon
2014-05-01 15:41:01 +01:00
parent 53eb11604b
commit b04d26a51a

View File

@@ -27,9 +27,16 @@ from openstack_dashboard.test.test_data import utils
def create_stubbed_exception(cls, status_code=500):
msg = "Expected failure."
def fake_init_exception(self, code, message, **kwargs):
def fake_init_exception(self, code=None, message=None, **kwargs):
self.code = code
self.message = message
self.message = message or self.__class__.message
try:
# Neutron sometimes updates the message with additional
# information, like a reason.
self.message = self.message % kwargs
except Exception:
pass # We still have the main error message.
def fake_str(self):
return str(self.message)