Esempio n. 1
0
    def test_entity_type_to_json(self):
        class MyModel2(Entity):
            @classmethod
            def value_to_json(cls, value):
                return value + 1

        entity_type = EntityType(MyModel2, 'title', 'description')
        self.assertEqual(entity_type.value_to_json(5), 6)
Esempio n. 2
0
    def test_entity_type_from_json(self):
        class MyModel3(Entity):
            @classmethod
            def json_to_value(cls, value):
                return value['value']

        get_definitions()['MyModel3'] = {
            'type': 'object',
            'properties': {
                'value': {
                    'type': 'integer'
                }
            }
        }

        entity_type = EntityType(MyModel3, 'title', 'description')
        self.assertEqual(entity_type.json_to_value({'value': 4}), 4)