PR revision: test build_dict_conforming... arg for schema type

Raise an error if it's not a schema.Object instance (not just
if it's not a schema.Schema instance).

Also adds a test for this.

Signed-off-by: Sebastien Awwad <sebastien.awwad@gmail.com>
This commit is contained in:
Sebastien Awwad 2019-04-03 10:30:42 -04:00
parent 9aa22466c0
commit 25aa71d4c6
No known key found for this signature in database
GPG key ID: BC0C6DEDD5E5CC03
2 changed files with 9 additions and 2 deletions

View file

@ -292,6 +292,13 @@ def test_build_dict_conforming_to_schema(self):
# Test construction of a few metadata formats using
# build_dict_conforming_to_schema().
# Try the wrong type of schema object.
STRING_SCHEMA = securesystemslib.schema.AnyString()
with self.assertRaises(ValueError):
tuf.formats.build_dict_conforming_to_schema(
STRING_SCHEMA, string='some string')
# Try building Timestamp metadata.
spec_version = tuf.SPECIFICATION_VERSION
version = 8

View file

@ -516,9 +516,9 @@ def build_dict_conforming_to_schema(schema, **kwargs):
"""
# Check the schema argument type (must provide check_match and _required).
if not isinstance(schema, SCHEMA.Schema):
if not isinstance(schema, SCHEMA.Object):
raise ValueError(
'The first argument must be a schema.Schema object, but is not. '
'The first argument must be a schema.Object instance, but is not. '
'Given schema: ' + repr(schema))
# Make a copy of the provided fields so that the caller's provided values