Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_allow_changing_properties_not_in_schema():
schema_dict = {}
schema = Profile(schema_dict)
schema.foo = 'bar'
assert schema.foo == 'bar'
def test_to_dict_modifying_the_dict_doesnt_modify_the_schema():
original_schema_dict = {
'foo': 'bar',
}
schema = Profile(original_schema_dict)
schema_dict = schema.to_dict()
schema_dict['bar'] = 'baz'
assert 'bar' not in schema.to_dict()
def test_init_raises_if_path_isnt_a_json():
with pytest.raises(exceptions.ValidationError):
Profile('data/not_a_json')
def test_init_raises_if_url_doesnt_exist():
url = 'https://inexistent-url.com/data-package.json'
httpretty.register_uri(httpretty.GET, url, status=404)
with pytest.raises(exceptions.ValidationError):
Profile(url).to_dict()
def test_properties_are_visible_with_dir():
schema_dict = {
'foo': {}
}
schema = Profile(schema_dict)
assert 'foo' in dir(schema)
def test_validate_should_raise_when_invalid():
schema_dict = {
'properties': {
'name': {
'type': 'string',
}
},
'required': ['name'],
}
data = {}
schema = Profile(schema_dict)
with pytest.raises(exceptions.ValidationError):
schema.validate(data)
def test_schema_properties_doesnt_linger_in_class():
foo_schema_dict = {
'foo': {}
}
bar_schema_dict = {
'bar': {}
}
foo_schema = Profile(foo_schema_dict)
bar_schema = Profile(bar_schema_dict)
assert 'bar' not in dir(foo_schema)
assert 'foo' not in dir(bar_schema)
def test_init_loads_schema_from_path():
assert Profile('data/empty_schema.json').to_dict() == {}
def test_init_loads_schema_from_dict():
schema_dict = {
'foo': 'bar'
}
schema = Profile(schema_dict)
assert schema.to_dict().keys() == schema_dict.keys()
assert schema.to_dict()['foo'] == schema_dict['foo']
def test_init_raises_if_schema_is_invalid():
invalid_schema = {
'required': 51,
}
with pytest.raises(exceptions.ValidationError):
Profile(invalid_schema)