Exemple #1
0
    def test_entity_type(self):
        s = Schema()

        e = EntityType('MyEntity', s, attributes={
            'foo': {'type':'string', 'default':'FOO'},
            'req': {'type':'integer', 'required':True},
            'e': {'type':['x', 'y']}})

        e.init()
        self.assertRaises(ValidationError, e.validate, {}) # Missing required 'req'
        self.assertEqual(e.validate({'req':42}), {'foo': 'FOO', 'req': 42})
Exemple #2
0
    def test_entity_type(self):
        s = Schema()

        e = EntityType('MyEntity', s, attributes={
            'foo': {'type': 'string', 'default': 'FOO'},
            'req': {'type': 'integer', 'required': True},
            'e': {'type': ['x', 'y']}})

        e.init()
        self.assertRaises(ValidationError, e.validate, {})  # Missing required 'req'
        self.assertEqual(e.validate({'req': 42}), {'foo': 'FOO', 'req': 42})
Exemple #3
0
    def test_entity_type(self):
        s = Schema(
            annotations={
                'i1': {
                    'attributes': {
                        'foo1': {
                            'type': 'string',
                            'default': 'FOO1'
                        }
                    }
                },
                'i2': {
                    'attributes': {
                        'foo2': {
                            'type': 'string',
                            'default': 'FOO2'
                        }
                    }
                }
            })

        e = EntityType('MyEntity',
                       s,
                       attributes={
                           'foo': {
                               'type': 'string',
                               'default': 'FOO'
                           },
                           'req': {
                               'type': 'integer',
                               'required': True
                           },
                           'e': {
                               'type': ['x', 'y']
                           }
                       })
        e.init()
        self.assertRaises(ValidationError, e.validate,
                          {})  # Missing required 'req'
        self.assertEqual(e.validate({'req': 42}), {'foo': 'FOO', 'req': 42})
        # Try with an annotation
        e = EntityType('e2',
                       s,
                       attributes={'x': {
                           'type': 'integer'
                       }},
                       annotations=['i1', 'i2'])
        e.init()
        self.assertEqual(e.validate({'x': 1}), {
            'x': 1,
            'foo1': 'FOO1',
            'foo2': 'FOO2'
        })
Exemple #4
0
    def test_entity_type(self):
        s = Schema(annotations={
            'i1':{'attributes': { 'foo1': {'type':'string', 'default':'FOO1'}}},
            'i2':{'attributes': { 'foo2': {'type':'string', 'default':'FOO2'}}}})

        e = EntityType('MyEntity', s, attributes={
            'foo': {'type':'string', 'default':'FOO'},
            'req': {'type':'integer', 'required':True},
            'e': {'type':['x', 'y']}})
        e.init()
        self.assertRaises(ValidationError, e.validate, {}) # Missing required 'req'
        self.assertEqual(e.validate({'req':42}), {'foo': 'FOO', 'req': 42})
        # Try with an annotation
        e = EntityType('e2', s, attributes={'x':{'type':'integer'}}, annotations=['i1', 'i2'])
        e.init()
        self.assertEqual(e.validate({'x':1}), {'x':1, 'foo1': 'FOO1', 'foo2': 'FOO2'})
Exemple #5
0
    def test_entity_type(self):
        s = Schema()

        e = EntityType(
            "MyEntity",
            s,
            attributes={
                "foo": {"type": "string", "default": "FOO"},
                "req": {"type": "integer", "required": True},
                "e": {"type": ["x", "y"]},
            },
        )

        e.init()
        self.assertRaises(ValidationError, e.validate, {})  # Missing required 'req'
        self.assertEqual(e.validate({"req": 42}), {"foo": "FOO", "req": 42})
Exemple #6
0
    def test_entity_annotation_refs(self):
        s = Schema(
            annotations={
                "i1": {
                    "attributes": {
                        "name": {"type": "string", "default": "$identity"},
                        "identity": {"type": "string", "default": "$name", "required": True},
                    }
                }
            }
        )

        e = EntityType("MyEntity", s, attributes={}, annotations=["i1"])
        e.init()
        self.assertEqual({"identity": "x", "name": "x"}, e.validate({"identity": "x"}))
        self.assertEqual({"identity": "x", "name": "x"}, e.validate({"name": "x"}))
        self.assertEqual({"identity": "x", "name": "y"}, e.validate({"identity": "x", "name": "y"}))
        self.assertRaises(ValidationError, e.validate, {})
Exemple #7
0
    def test_entity_annotation_refs(self):
        s = Schema(
            annotations={
                'i1': {
                    'attributes': {
                        'name': {
                            'type': 'string',
                            'default': '$identity'
                        },
                        'identity': {
                            'type': 'string',
                            'default': '$name',
                            "required": True
                        }
                    }
                }
            })

        e = EntityType('MyEntity', s, attributes={}, annotations=['i1'])
        e.init()
        self.assertEqual({
            'identity': 'x',
            'name': 'x'
        }, e.validate({'identity': 'x'}))
        self.assertEqual({
            'identity': 'x',
            'name': 'x'
        }, e.validate({'name': 'x'}))
        self.assertEqual({
            'identity': 'x',
            'name': 'y'
        }, e.validate({
            'identity': 'x',
            'name': 'y'
        }))
        self.assertRaises(ValidationError, e.validate, {})
Exemple #8
0
    def test_entity_type(self):
        s = Schema(
            annotations={
                "i1": {"attributes": {"foo1": {"type": "string", "default": "FOO1"}}},
                "i2": {"attributes": {"foo2": {"type": "string", "default": "FOO2"}}},
            }
        )

        e = EntityType(
            "MyEntity",
            s,
            attributes={
                "foo": {"type": "string", "default": "FOO"},
                "req": {"type": "integer", "required": True},
                "e": {"type": ["x", "y"]},
            },
        )
        e.init()
        self.assertRaises(ValidationError, e.validate, {})  # Missing required 'req'
        self.assertEqual(e.validate({"req": 42}), {"foo": "FOO", "req": 42})
        # Try with an annotation
        e = EntityType("e2", s, attributes={"x": {"type": "integer"}}, annotations=["i1", "i2"])
        e.init()
        self.assertEqual(e.validate({"x": 1}), {"x": 1, "foo1": "FOO1", "foo2": "FOO2"})