From 29547eae59d244adb681b6182b604e7085d8c1a8 Mon Sep 17 00:00:00 2001 From: Ken'ichi Ohmichi Date: Thu, 31 Oct 2013 12:16:34 +0900 Subject: [PATCH] Remove the duplicated error message from Enum If Enum validation detects invalid parameter, wsme returns a respose like the following message: {"debuginfo": null, "faultcode": "Client", "faultstring": "Invalid input for field/attribute param_enum. Value: 'hourse'. Invalid value (should be one of: dog, cat)" } In faultstring, the first message shows a invalid request. So it is not necessary to contain it in the third message. Change-Id: Ie52660fcf704551ce082f7dca2fadedadb12562a --- wsme/tests/test_api.py | 4 ++-- wsme/tests/test_types.py | 2 +- wsme/types.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/wsme/tests/test_api.py b/wsme/tests/test_api.py index 008a928..db85c51 100644 --- a/wsme/tests/test_api.py +++ b/wsme/tests/test_api.py @@ -80,7 +80,7 @@ class TestController(unittest.TestCase): self.assertTrue( res.json_body['faultstring'].startswith( "Invalid input for field/attribute number. Value: 'arf'. \ -Invalid value (should be one of:")) +Value should be one of:")) self.assertIn('v1', res.json_body['faultstring']) self.assertIn('v2', res.json_body['faultstring']) self.assertIn('None', res.json_body['faultstring']) @@ -104,7 +104,7 @@ Invalid value (should be one of:")) self.assertTrue( res.json_body['faultstring'].startswith( "Invalid input for field/attribute number. Value: '1'. \ -Invalid value (should be one of:")) +Value should be one of:")) self.assertIn('v1', res.json_body['faultstring']) self.assertIn('v2', res.json_body['faultstring']) self.assertIn('None', res.json_body['faultstring']) diff --git a/wsme/tests/test_types.py b/wsme/tests/test_types.py index 167114b..604614e 100644 --- a/wsme/tests/test_types.py +++ b/wsme/tests/test_types.py @@ -182,7 +182,7 @@ class TestTypes(unittest.TestCase): self.assertRaisesRegexp(exc.InvalidInput, "Invalid input for field/attribute a. \ -Value: 'v3'. Invalid value \(should be one of: v., v.\)", +Value: 'v3'. Value should be one of: v., v.", setattr, obj, 'a', diff --git a/wsme/types.py b/wsme/types.py index 18b032f..991450b 100644 --- a/wsme/types.py +++ b/wsme/types.py @@ -161,7 +161,7 @@ class Enum(UserType): def validate(self, value): if value not in self.values: - raise ValueError("Invalid value (should be one of: %s)" % + raise ValueError("Value should be one of: %s" % ', '.join(map(six.text_type, self.values))) return value