コード例 #1
0
 def test_validate_length_equality_returns(self):
     data = {0:('a', 1)}
     class _Schema(object):
         __validator_leaf__ = True
     schema = {0:_Schema()}
     validator = engine.Validator({}, {})
     result = validator.length_equality(data, schema, 0, [])
     assert result is None
コード例 #2
0
ファイル: test_engine.py プロジェクト: ktdreyer/notario
    def test_validate_value_nested_dictionaries(self):
        data = {'a': 1, 'b': {'a': 2, 'b': 1}}
        schema = (('a', 1), ('b', (('a', 2), ('b', 2))))
        with raises(Invalid) as exc:
            validator = engine.Validator(data, schema)
            validator.validate()

        error = exc.value.args[0]
        assert '-> b -> b -> 1 did not match 2' in error
コード例 #3
0
ファイル: test_engine.py プロジェクト: ktdreyer/notario
    def test_validate_top_level_values(self):
        data = {'a': 1, 'b': 2}
        schema = (('a', 1), ('b', 1))
        with raises(Invalid) as exc:
            validator = engine.Validator(data, schema)
            validator.validate()

        error = exc.value.args[0]
        assert '-> b -> 2 did not match 1' in error
コード例 #4
0
ファイル: test_engine.py プロジェクト: ktdreyer/notario
    def test_validate_length_equality_less_items(self):
        data = {'a': 1, 'b': 2, 'c': 'c'}
        schema = (('a', 1), ('b', 2))
        with raises(Invalid) as exc:
            validator = engine.Validator(data, schema)
            validator.validate()

        error = exc.value.args[0]
        assert "top level has unexpected item in data: ('c', 'c')" in error
コード例 #5
0
ファイル: test_engine.py プロジェクト: ktdreyer/notario
    def test_validate_length_equality(self):
        data = {'a': 1, 'b': 2}
        schema = (('a', 1, 2), ('c', 2))
        with raises(SchemaError) as exc:
            validator = engine.Validator(data, schema)
            validator.validate()

        error = exc.value.args[0]
        assert '-> top level length did not match schema' in error
コード例 #6
0
ファイル: test_engine.py プロジェクト: ktdreyer/notario
    def test_validate_top_level_keys(self):
        data = {'a': 1, 'b': 2}
        schema = (('a', 1), ('c', 2))
        with raises(Invalid) as exc:
            validator = engine.Validator(data, schema)
            validator.validate()

        error = exc.value.args[0]
        assert "-> b key did not match 'c'" in error
コード例 #7
0
ファイル: test_engine.py プロジェクト: ktdreyer/notario
 def test_optional_key_raises(self):
     data = {'a': 1, 'b': 3, 'c': 3}
     schema = (('a', 1), (optional('b'), 2), ('c', 3))
     validator = engine.Validator(data, schema)
     with raises(Invalid) as exc:
         validator.validate()
     exc_msg = str(exc.value)
     assert '3 did not match 2' in exc_msg
     assert 'b -> 3' in exc_msg
コード例 #8
0
ファイル: test_engine.py プロジェクト: ktdreyer/notario
    def test_traverser_returns_the_recursive_leaf_if_seen(self):
        data = {'a': {'b': [1, 1, 1, 1]}}
        schema = ('a', recursive.AllObjects(('b', [1, 1, 1, 2])))
        with raises(Invalid) as exc:
            validator = engine.Validator(data, schema)
            validator.validate()

        error = exc.value.args[0]
        assert '-> a -> b -> [1, 1, 1, 1] did not match [1, 1, 1, 2]' in error
コード例 #9
0
ファイル: test_engine.py プロジェクト: ktdreyer/notario
    def test_traverser_returns_the_iterable_leaf_if_seen(self):
        data = {'a': {'b': [1, 1, 1, 1]}}
        schema = ('a', ('b', iterables.AllItems(2)))
        with raises(Invalid) as exc:
            validator = engine.Validator(data, schema)
            validator.validate()

        error = exc.value.args[0]
        assert '-> a -> b -> list[0] item did not match 2' in error
コード例 #10
0
ファイル: test_engine.py プロジェクト: ktdreyer/notario
    def test_validate_multiple_items_as_values(self):
        data = {'a': 1, 'b': {'a': 2, 'b': 1, 'd': 1, 'c': 2}}
        schema = (('a', 1), ('b', (('a', 2), ('b', 1), ('c', 2), ('d', 2))))
        with raises(Invalid) as exc:
            validator = engine.Validator(data, schema)
            validator.validate()

        error = exc.value.args[0]
        assert '-> b -> d -> 1 did not match 2' in error in error
コード例 #11
0
ファイル: test_engine.py プロジェクト: ktdreyer/notario
    def test_validate_key_nested_arrays(self):
        data = {'a': 1, 'b': {'a': 2, 'b': [1, 2, 3]}}
        schema = (('a', 1), ('b', (('a', 2), ('b', [1, 1, 3]))))
        with raises(Invalid) as exc:
            validator = engine.Validator(data, schema)
            validator.validate()

        error = exc.value.args[0]
        assert '-> b -> b -> [1, 2, 3] did not match [1, 1, 3]' in error
コード例 #12
0
ファイル: test_engine.py プロジェクト: ktdreyer/notario
    def test_validate_key_doubly_nested_dictionaries(self):
        data = {'a': 1, 'b': {'a': 2, 'b': {'a': 'a'}}}
        schema = (('a', 1), ('b', (('a', 2), ('b', ('a', 'b')))))
        with raises(Invalid) as exc:
            validator = engine.Validator(data, schema)
            validator.validate()

        error = exc.value.args[0]
        assert "-> b -> b -> a -> a did not match 'b'" in error
コード例 #13
0
    def test_deal_with_recursion(self):
        data = {'a': {'a': 'a', 'b': {'a': 'b', 'c': 'c', 'd': 1}}}
        schema = ('a', (('a', 'a'), ('b', recursive.AllObjects((types.string, types.string)))))
        with raises(Invalid) as exc:
            validator = engine.Validator(data, schema)
            validator.validate()

        error = exc.value.args[0]
        assert '1  did not pass validation against callable: string' in error
        assert 'not of type string' in error
コード例 #14
0
ファイル: test_engine.py プロジェクト: ktdreyer/notario
 def test_optional_key_passes(self):
     data = {'a': 1, 'c': 3}
     schema = (('a', 1), (optional('b'), 2), ('c', 3))
     validator = engine.Validator(data, schema)
     assert validator.validate() is None