Tolerate jsonschema==2.6.0

Latest jsonschema changes the exception messages. In this
changeset, we assert that the exception message should be
either the one generated by the old library or one from the
new library. Ideally, we should not be string comparing the
error messages at all.

Upper-Constraints:
https://github.com/openstack/requirements/blob/master/upper-constraints.txt#L198

Change-Id: I6610b2e436aef808e1c318d6e82008095ed0e1d3
This commit is contained in:
Dinesh Bhor 2017-02-16 10:00:15 +05:30
parent 00bc5612a8
commit 37af37a0fd
1 changed files with 21 additions and 8 deletions

View File

@ -100,7 +100,10 @@ class APIValidationTestCase(test.NoDBTestCase):
method(body=body, req=req,)
except exception.ValidationError as ex:
self.assertEqual(http.BAD_REQUEST, ex.kwargs['code'])
if not re.match(expected_detail, ex.kwargs['detail']):
if isinstance(expected_detail, list):
self.assertIn(ex.kwargs['detail'], expected_detail,
'Exception details did not match expected')
elif not re.match(expected_detail, ex.kwargs['detail']):
self.assertEqual(expected_detail, ex.kwargs['detail'],
'Exception details did not match expected')
except Exception as ex:
@ -244,18 +247,28 @@ class PatternPropertiesTestCase(APIValidationTestCase):
self.post(body={'foo': 'bar'}, req=FakeRequest()))
def test_validate_patternProperties_fails(self):
detail = "Additional properties are not allowed ('__' was unexpected)"
details = [
"Additional properties are not allowed ('__' was unexpected)",
"'__' does not match any of the regexes: '^[a-zA-Z0-9]{1,10}$'"
]
self.check_validation_error(self.post, body={'__': 'bar'},
expected_detail=detail)
expected_detail=details)
detail = "Additional properties are not allowed ('' was unexpected)"
details = [
"'' does not match any of the regexes: '^[a-zA-Z0-9]{1,10}$'",
"Additional properties are not allowed ('' was unexpected)"
]
self.check_validation_error(self.post, body={'': 'bar'},
expected_detail=detail)
expected_detail=details)
detail = ("Additional properties are not allowed ('0123456789a' was"
" unexpected)")
details = [
("'0123456789a' does not match any of the regexes: "
"'^[a-zA-Z0-9]{1,10}$'"),
("Additional properties are not allowed ('0123456789a' was"
" unexpected)")
]
self.check_validation_error(self.post, body={'0123456789a': 'bar'},
expected_detail=detail)
expected_detail=details)
if sys.version[:3] == '3.5':
detail = "expected string or bytes-like object"