Beispiel #1
0
    def test_shape_with_validation(self):
        schema = {
            "type": "object",
            "properties": {
                "number": {
                    "type": "integer"
                },
                "obj": {
                    "type": "object",
                    "properties": {
                        "number": {
                            "type": "integer"
                        }
                    }
                }
            }
        }

        validator = Draft4Validator(schema=schema, format_checker=FormatChecker())
        data = {
            "number": "a",
            "obj": {
                "number": "c"
            }
        }

        s1 = Shape(schema=schema, data=data, validator=validator)
        self.assertListEqual([{'message': "'a' is not of type 'integer'"}, {'message': "'c' is not of type 'integer'"}],
                             s1.validate())
Beispiel #2
0
    def test_shape_extras_with_validation(self):
        schema = {
            "type": "object",
            "properties": {
                "number": {
                    "type": "integer"
                }
            }
        }

        validator = Draft4Validator(schema=schema, format_checker=FormatChecker())
        data = {
            "number": "a"
        }
        e = Shape(schema=schema, data=data, validator=validator)
        extras = {"e": e}
        s1 = Shape(schema=schema, data=data, validator=validator, extras=extras)

        self.assertListEqual([{'message': "'a' is not of type 'integer'", 'name': 'e'}, {'message': "'a' is not of type 'integer'"}],
                             s1.validate(True))