def test_validate_custom_items(self):
        data = {'a': {'b': 'b', 'c': 'c', 'd': 'd'}}
        picky = cherry_pick((('b' ,'b')))
        picky.must_validate = ('b',)
        schema = ('a', picky)

        # should not raise invalid, because 'c' never got validated
        assert validate(data, schema) is None
    def test_validate_custom_items(self):
        data = {"a": {"b": "b", "c": "c", "d": "d"}}
        picky = cherry_pick((("b", "b")))
        picky.must_validate = ("b",)
        schema = ("a", picky)

        # should not raise invalid, because 'c' never got validated
        assert validate(data, schema) is None
    def test_top_level_cherry_pick_with_optionals_passes(self):
        data = {'b': 'b', 'c': 'c', 'd': 'd'}
        schema = cherry_pick((
            ('b', types.string),
            (optional('optional'), types.string))
        )

        assert validate(data, schema) is None
    def test_validate_custom_items(self):
        data = {'a': {'b': 'b', 'c': 'c', 'd': 'd'}}
        picky = cherry_pick((('b', 'b'), ('c', 'd')))
        picky.must_validate = ('b', )
        schema = ('a', picky)

        # should not raise invalid, because 'c' never got validated
        assert validate(data, schema) is None
    def test_validate_only_one_item(self):
        data = {"a": {"b": "b", "c": "c", "d": "d"}}
        schema = ("a", cherry_pick(("b", "a")))

        with raises(Invalid) as exc:
            validate(data, schema)

        error = exc.value.args[0]
        assert "-> a -> b -> b did not match 'a'" in error
    def test_validate_only_one_item(self):
        data = {'a': {'b': 'b', 'c': 'c', 'd': 'd'}}
        schema = ('a', cherry_pick(('b', 'a')))

        with raises(Invalid) as exc:
            validate(data, schema)

        error = exc.value.args[0]
        assert  "-> a -> b -> b did not match 'a'" in error
Exemple #7
0
    def test_top_level_cherry_pick_with_optionals_complains(self):
        data = {'b': 'b', 'optional': 1}
        schema = (cherry_pick(
            ('b', types.string), ), (optional('optional'), types.string))

        with raises(Invalid) as exc:
            validate(data, schema)
        error = exc.value.args[0]
        assert '1 did not pass validation against callable: string' in error
    def test_validate_only_one_item(self):
        data = {'a': {'b': 'b', 'c': 'c', 'd': 'd'}}
        schema = ('a', cherry_pick(('b', 'a')))

        with raises(Invalid) as exc:
            validate(data, schema)

        error = exc.value.args[0]
        assert "-> a -> b -> b  did not match 'a'" in error
    def test_top_level_cherry_pick_with_optionals_complains(self):
        data = {'b': 'b', 'optional': 1}
        schema = (cherry_pick(
            ('b', types.string),),
            (optional('optional'), types.string)
        )

        with raises(Invalid) as exc:
            validate(data, schema)
        error = exc.value.args[0]
        assert '1 did not pass validation against callable: string' in error
    def test_complain_about_empty_must_validate(self):
        data = {"a": {"b": "b", "c": "c", "d": "d"}}
        picky = cherry_pick((("b", "b"), ("c", "d")))
        picky.must_validate = ()
        schema = ("a", picky)

        # should not raise invalid, because 'c' never got validated
        with raises(SchemaError) as exc:
            validate(data, schema)

        error = exc.value.args[0]
        assert "-> a  must_validate attribute must not be empty" in error
    def test_complain_about_empty_must_validate(self):
        data = {'a': {'b': 'b', 'c': 'c', 'd': 'd'}}
        picky = cherry_pick((('b' ,'b'), ('c', 'd')))
        picky.must_validate = ()
        schema = ('a', picky)

        # should not raise invalid, because 'c' never got validated
        with raises(SchemaError) as exc:
            validate(data, schema)

        error = exc.value.args[0]
        assert  "-> a  must_validate attribute must not be empty" in error
    def test_complain_about_empty_must_validate(self):
        data = {'a': {'b': 'b', 'c': 'c', 'd': 'd'}}
        picky = cherry_pick((('b', 'b'), ('c', 'd')))
        picky.must_validate = ()
        schema = ('a', picky)

        # should not raise invalid, because 'c' never got validated
        with raises(SchemaError) as exc:
            validate(data, schema)

        error = exc.value.args[0]
        assert "-> a  must_validate attribute must not be empty" in error
Exemple #13
0
 def test_single_pair_tuple(self):
     result = validators.cherry_pick(('a', 'b'))
     assert result.must_validate == ('a',)
Exemple #14
0
 def test_empty_tuple(self):
     result = validators.cherry_pick(())
     assert result.must_validate == ()
Exemple #15
0
 def test_single_items_tuples(self):
     result = validators.cherry_pick(('a', 'b', 'c', 'd'))
     assert result.must_validate == ()
Exemple #16
0
 def __init__(self, data, schema, defined_keys=None):
     if defined_keys:
         schema = cherry_pick(schema)
     self.data = Data(data, schema).normalized()
     self.schema = Schema(data, schema).normalized()
Exemple #17
0
 def test_single_items_tuples(self):
     result = validators.cherry_pick(('a', 'b', 'c', 'd'))
     assert result.must_validate == ()
Exemple #18
0
 def test_single_pair_tuple(self):
     result = validators.cherry_pick(('a', 'b'))
     assert result.must_validate == ('a', )
Exemple #19
0
    def test_top_level_cherry_pick_with_optionals_passes(self):
        data = {'b': 'b', 'c': 'c', 'd': 'd'}
        schema = cherry_pick(
            (('b', types.string), (optional('optional'), types.string)))

        assert validate(data, schema) is None
Exemple #20
0
 def test_empty_tuple(self):
     result = validators.cherry_pick(())
     assert result.must_validate == ()
Exemple #21
0
 def __init__(self, data, schema, defined_keys=None):
     if defined_keys:
         schema = cherry_pick(schema)
     self.data = Data(data, schema).normalized()
     self.schema = Schema(data, schema).normalized()