From a6234d1c4e0ba8c6bbf822cfe89473436b583acc Mon Sep 17 00:00:00 2001 From: Kamil Rykowski Date: Thu, 2 Apr 2015 08:15:17 +0200 Subject: [PATCH] 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 --- glanceclient/v2/tasks.py | 2 +- tests/v2/test_tasks.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/glanceclient/v2/tasks.py b/glanceclient/v2/tasks.py index 37801915..8ad039f3 100644 --- a/glanceclient/v2/tasks.py +++ b/glanceclient/v2/tasks.py @@ -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 diff --git a/tests/v2/test_tasks.py b/tests/v2/test_tasks.py index a5491a3b..4e1f78c4 100644 --- a/tests/v2/test_tasks.py +++ b/tests/v2/test_tasks.py @@ -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)