Creating task with invalid property crashes in py3

Currently when you are trying to set invalid additional property for
task using py3 interpreter it will fail, because function `unicode` does
not exist in py3.

Fix it by replacing `unicode` with `utils.exception_to_str` which is
used in other modules already.

Change-Id: I5897868f801467a2eaa7585b5f2d578cef358426
Closes-Bug: 1439513
This commit is contained in:
Kamil Rykowski 2015-04-02 08:15:17 +02:00
parent fd2f989cca
commit a6234d1c4e
2 changed files with 9 additions and 1 deletions

View File

@ -110,7 +110,7 @@ class Controller(object):
try:
setattr(task, key, value)
except warlock.InvalidOperation as e:
raise TypeError(unicode(e))
raise TypeError(utils.exception_to_str(e))
resp, body = self.http_client.post(url, data=task)
#NOTE(flwang): remove 'self' for now until we have an elegant

View File

@ -187,6 +187,7 @@ schema_fixtures = {
'result': {},
'message': {},
},
'additionalProperties': False,
}
)
}
@ -275,3 +276,10 @@ class TestController(testtools.TestCase):
task = self.controller.create(**properties)
self.assertEqual(task.id, '3a4560a1-e585-443e-9b39-553b46ec92d1')
self.assertEqual(task.type, 'import')
def test_create_task_invalid_property(self):
properties = {
'type': 'import',
'bad_prop': 'value',
}
self.assertRaises(TypeError, self.controller.create, **properties)