From 872842e7710a630b25465fd4d4a0d0f76fa09f80 Mon Sep 17 00:00:00 2001 From: Lingxian Kong Date: Wed, 7 Sep 2016 00:56:32 +1200 Subject: [PATCH] Fix wrong error message for environment operation Change-Id: Iafdfef92bd168426be899472f3a722b7b5fcd6cf Closes-Bug: #1620618 --- .gitignore | 1 + mistralclient/api/base.py | 7 +++++-- .../tests/unit/v2/test_environments.py | 19 +++++++++++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index f7ccb59c..bebdd838 100644 --- a/.gitignore +++ b/.gitignore @@ -29,6 +29,7 @@ pip-log.txt nosetests.xml functional_creds.conf AUTHORS +ChangeLog # Translations *.mo diff --git a/mistralclient/api/base.py b/mistralclient/api/base.py index 0b6a0e3d..bef81d43 100644 --- a/mistralclient/api/base.py +++ b/mistralclient/api/base.py @@ -74,8 +74,11 @@ class ResourceManager(object): def _ensure_not_empty(self, **kwargs): for name, value in kwargs.items(): if value is None or (isinstance(value, str) and len(value) == 0): - raise APIException('%s is missing field "%s"' % - (self.resource_class.__name__, name)) + raise APIException( + 400, + '%s is missing field "%s"' % + (self.resource_class.__name__, name) + ) def _copy_if_defined(self, data, **kwargs): for name, value in kwargs.items(): diff --git a/mistralclient/tests/unit/v2/test_environments.py b/mistralclient/tests/unit/v2/test_environments.py index f2b5e041..95c3d6db 100644 --- a/mistralclient/tests/unit/v2/test_environments.py +++ b/mistralclient/tests/unit/v2/test_environments.py @@ -19,6 +19,7 @@ import pkg_resources as pkg from six.moves.urllib import parse from six.moves.urllib import request +from mistralclient.api import base as api_base from mistralclient.api.v2 import environments from mistralclient.tests.unit.v2 import base from mistralclient import utils @@ -78,6 +79,15 @@ class TestEnvironmentsV2(base.BaseClientV2Test): mock.assert_called_once_with(URL_TEMPLATE, json.dumps(expected_data)) + def test_create_without_name(self): + data = copy.deepcopy(ENVIRONMENT) + data.pop('name') + + with self.assertRaises(api_base.APIException) as cm: + self.environments.create(**data) + + self.assertEqual(400, cm.exception.error_code) + def test_update(self): data = copy.deepcopy(ENVIRONMENT) @@ -114,6 +124,15 @@ class TestEnvironmentsV2(base.BaseClientV2Test): mock.assert_called_once_with(URL_TEMPLATE, json.dumps(expected_data)) + def test_update_without_name(self): + data = copy.deepcopy(ENVIRONMENT) + data.pop('name') + + with self.assertRaises(api_base.APIException) as cm: + self.environments.update(**data) + + self.assertEqual(400, cm.exception.error_code) + def test_list(self): mock = self.mock_http_get(content={'environments': [ENVIRONMENT]})