Esempio n. 1
0
 def test_invalid_on_non_list(self):
     data = {'foo': [{'a': 'b'}, {'b': 'c'}]}
     schema = (types.string, 'b')  # note how this is not normalized
     iter_validator = engine.IterableValidator(data, schema, index=0)
     with raises(Invalid) as exc:
         iter_validator.validate()
     error = exc.value.args[0]
     assert "top level did not pass validation against callable: IterableValidator" in error
Esempio n. 2
0
 def test_report_schema_errors(self):
     data = [1, 2, 3, 4]
     schema = (types.string, ('b', 'a'))
     iter_validator = engine.IterableValidator(data, schema, index=0)
     with raises(SchemaError) as exc:
         iter_validator.validate()
     error = exc.value.args[0]
     assert "iterable contains single items, schema does not" in error
Esempio n. 3
0
 def test_not_enough_items_in_data(self):
     data = {0: ('a', 'b')}
     schema = {0: ('a', 'b')}
     iter_validator = engine.IterableValidator(data, schema, index=100)
     with raises(SchemaError) as exc:
         iter_validator.validate()
     error = exc.value.args[0]
     assert '-> top level has not enough items to select from' in error
Esempio n. 4
0
    def test_validate_nested_array(self):
        data = [{'a': 'b'}, {'b': 'c'}]
        schema = (types.string, 'b')  # note how this is not normalized
        iter_validator = engine.IterableValidator(data, schema, index=0)
        with raises(Invalid) as exc:
            iter_validator.validate()

        error = exc.value.args[0]
        assert "-> list[1] -> b -> c did not match 'b'" in error