Exemplo n.º 1
0
 def test_custom_validation_error(self):
     data = {"name": "skame", "age": "1"}
     assert validate(self.schema, data) == (None, {
         "age": "User has to be an adult"
     })
     data = {"name": "skame", "age": ""}
     assert validate(self.schema, data) == (None, {
         "age":
         "User age must be an integer"
     })
Exemplo n.º 2
0
    def validate(self, data):
        all_errors = []
        result = super(RecursiveList, self).validate(data)

        for item in data:
            data, errors = validate(self._item_schema, item)
            if errors:
                all_errors.append(errors)

        if all_errors:
            raise SchemaErrors(all_errors)

        return result
Exemplo n.º 3
0
 def __init__(self, data: dict):
     (self.cleaned_data, self.errors) = validate(self.schema, data)
Exemplo n.º 4
0
 def validate(self, data):
     return validate(self.__schema__, data)
Exemplo n.º 5
0
 def test_custom_validation_error(self):
     data = {"name": "skame", "age": "1"}
     assert validate(self.schema, data) == (None, {"age": "User has to be an adult"})
     data = {"name": "skame", "age": ""}
     assert validate(self.schema, data) == (None, {"age": "User age must be an integer"})
Exemplo n.º 6
0
 def test_not_valid(self):
     assert validate(self.schema, {}) == (None, {'name': 'Field `name` is required.', 'age': 'Field `age` is required.'})
Exemplo n.º 7
0
 def test_valid(self):
     data = {"name": "skame", "age": "28"}
     assert validate(self.schema, data) == ({"name": "skame", "age": 28}, None)
Exemplo n.º 8
0
 def test_not_valid(self):
     assert validate(self.schema, {}) == (None, {
         'name': 'Field `name` is required.',
         'age': 'Field `age` is required.'
     })
Exemplo n.º 9
0
 def test_valid(self):
     data = {"name": "skame", "age": "28"}
     assert validate(self.schema, data) == ({
         "name": "skame",
         "age": 28
     }, None)