Beispiel #1
0
 def test_get_model_options(self):
     data = {
         'type': 'object',
         'required': ['in', '$ref'],
         'properties': {
             'in': {
                 'type': 'string'
             },
             '$ref': {
                 'type': 'string',
                 'title': 'TITLE',
                 'description': 'DESCRIPTION'
             },
             'attr': {
                 'type': 'string'
             }
         }
     }
     schema = Schema(data)
     props = schema.get_all_properties()
     _in = props['_in']
     _ref = props['_ref']
     attr = props['attr']
     self.assertEqual(", alias='in', required=True", _in.get_model_options())
     self.assertEqual(", alias='$ref', required=True, title='TITLE', description='DESCRIPTION'", _ref.get_model_options())
     self.assertEqual("", attr.get_model_options())
Beispiel #2
0
    def test_get_all_properties(self):
        s1_data = {
            'type': 'object',
            'properties': {
                'name': {
                    'type': 'string'
                },
                'username': {
                    'type': 'string'
                },
                'password': {
                    'type': 'string'
                },
                'email': {
                    'type': 'string'
                }
            }
        }
        s2_data = {
            'allOf': [
                s1_data,
                {
                    'type': 'object',
                    'properties': {
                        'uuid': {
                            'type': 'string'
                        },
                        'state': {
                            'type': 'string'
                        },
                        'environment': {
                            'type': 'string'
                        },
                        'release': {
                            'type': 'string'
                        }
                    }
                },
                {
                    'allOf': [
                        {
                            'type': 'object',
                            'properties': {
                                'attr1': {
                                    'type': 'string'
                                },
                                'attr2': {
                                    'type': 'string'
                                }
                            }
                        },
                        {
                            'type': 'object',
                            'properties': {
                                'attr2': {
                                    'type': 'string'
                                },
                                'attr3': {
                                    'type': 'string'
                                }
                            }
                        },
                    ]
                }
            ]
        }
        s1 = Schema(s1_data)
        s2 = Schema(s2_data)
        p1s = s1.get_all_properties()
        self.assertEqual(4, len(p1s))
        self.assertTrue('name' in p1s)
        self.assertTrue(p1s['name'].is_property())
        self.assertTrue('username' in p1s)
        self.assertTrue(p1s['username'].is_property())
        self.assertTrue('password' in p1s)
        self.assertTrue(p1s['password'].is_property())
        self.assertTrue('email' in p1s)
        self.assertTrue(p1s['email'].is_property())

        p2s = s2.get_all_properties()
        self.assertEqual(11, len(p2s))
        self.assertTrue('name' in p2s)
        self.assertTrue(p2s['name'].is_property())
        self.assertTrue('username' in p2s)
        self.assertTrue(p2s['username'].is_property())
        self.assertTrue('password' in p2s)
        self.assertTrue(p2s['password'].is_property())
        self.assertTrue('email' in p2s)
        self.assertTrue(p2s['email'].is_property())
        self.assertTrue('uuid' in p2s)
        self.assertTrue(p2s['uuid'].is_property())
        self.assertTrue('state' in p2s)
        self.assertTrue(p2s['state'].is_property())
        self.assertTrue('environment' in p2s)
        self.assertTrue(p2s['environment'].is_property())
        self.assertTrue('release' in p2s)
        self.assertTrue(p2s['release'].is_property())
        self.assertTrue('attr1' in p2s)
        self.assertTrue(p2s['attr1'].is_property())
        self.assertTrue('attr2' in p2s)
        self.assertTrue(p2s['attr2'].is_property())
        self.assertTrue('attr3' in p2s)
        self.assertTrue(p2s['attr3'].is_property())