def test_doesnt_allow_changing_schema_properties(self): schema_dict = { 'foo': 'bar', } schema = Schema(schema_dict) with pytest.raises(AttributeError): schema.foo = 'baz'
def test_to_dict_modifying_the_dict_doesnt_modify_the_schema(self): original_schema_dict = { 'foo': 'bar', } schema = Schema(original_schema_dict) schema_dict = schema.to_dict() schema_dict['bar'] = 'baz' assert 'bar' not in schema.to_dict()
def test_init_changing_the_original_schema_dict_doesnt_change_schema(self): schema_dict = { 'foo': 'bar' } schema = Schema(schema_dict) schema_dict['bar'] = 'baz' assert 'bar' not in schema.to_dict()
def test_init_loads_schema_from_dict(self): schema_dict = { 'foo': 'bar' } schema = Schema(schema_dict) assert schema.to_dict().keys() == schema_dict.keys() assert schema.to_dict()['foo'] == schema_dict['foo']
def test_validate_should_raise_when_invalid(self): schema_dict = { 'properties': { 'name': { 'type': 'string', } }, 'required': ['name'], } data = {} schema = Schema(schema_dict) with pytest.raises(datapackage_validate.exceptions.ValidationError): schema.validate(data)
def test_validate(self): schema_dict = { 'properties': { 'name': { 'type': 'string', } }, 'required': ['name'], } data = { 'name': 'Sample Package', } schema = Schema(schema_dict) schema.validate(data)
def test_to_dict_converts_schema_to_dict(self): original_schema_dict = { 'foo': 'bar', } schema = Schema(original_schema_dict) assert schema.to_dict() == original_schema_dict
def test_allow_changing_properties_not_in_schema(self): schema_dict = {} schema = Schema(schema_dict) schema.foo = 'bar' assert schema.foo == 'bar'