Fix jsonschema>=2.4.0 message assertion

The jsonschema 2.4.0 release slightly changed some of the error messages
that are provided when validation fails. This patch updates the unit tests to
expect the proper string and avoid failing as a result by using regex
(.0)? instead of specific value.

Change-Id: Ifd41147fd6157038b102c78144d1f6cb16cc25e6
Closes-bug: #1359284
This commit is contained in:
Sergey Lukjanov 2014-08-21 15:37:08 +04:00
parent 55159fa4f8
commit 822c2f053f
2 changed files with 15 additions and 6 deletions

View File

@ -67,7 +67,7 @@ class TestNGTemplateCreateValidation(u.ValidationTestCase):
'node_processes': []
},
bad_req_i=(1, 'VALIDATION_ERROR',
u'[] is too short')
u'\[\] is too short')
)
def test_ng_template_create_v_names(self):
@ -142,7 +142,7 @@ class TestNGTemplateCreateValidation(u.ValidationTestCase):
'volumes_per_node': -1
},
bad_req_i=(1, 'VALIDATION_ERROR',
u'-1.0 is less than the minimum of 0')
u'-1(.0)? is less than the minimum of 0')
)
self._assert_create_object_validation(
data={
@ -154,7 +154,7 @@ class TestNGTemplateCreateValidation(u.ValidationTestCase):
'volumes_size': 0
},
bad_req_i=(1, 'VALIDATION_ERROR',
u'0.0 is less than the minimum of 1')
u'0(.0)? is less than the minimum of 1')
)
def test_ng_template_create_v_types(self):
@ -238,7 +238,7 @@ class TestNGTemplateCreateValidation(u.ValidationTestCase):
'volumes_per_node': -1
},
bad_req_i=(1, 'VALIDATION_ERROR',
u'-1.0 is less than the minimum of 0')
u'-1(.0)? is less than the minimum of 0')
)
self._assert_create_object_validation(
data={
@ -250,7 +250,7 @@ class TestNGTemplateCreateValidation(u.ValidationTestCase):
'volumes_size': 0
},
bad_req_i=(1, 'VALIDATION_ERROR',
u'0.0 is less than the minimum of 1')
u'0(.0)? is less than the minimum of 1')
)
self._assert_create_object_validation(
data={

View File

@ -13,6 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import re
import mock
import novaclient.exceptions as nova_ex
@ -255,7 +257,14 @@ class ValidationTestCase(base.SaharaTestCase):
else:
self.assertEqual(mock.call_count, call_info[0])
self.assertEqual(mock.call_args[0][0].code, call_info[1])
self.assertEqual(mock.call_args[0][0].message, call_info[2])
# Note(slukjanov): the call_info[2] is an expected validation
# message regex; regex needed because of different
# versions of jsonschema generates different
# messages.
if not re.match(call_info[2], mock.call_args[0][0].message):
self.assertEqual(call_info[2], mock.call_args[0][0].message,
"Validation message didn't match expected")
@mock.patch("sahara.utils.api.request_data")
@mock.patch("sahara.utils.api.bad_request")