def test_simple_properties(self):
     api_properties = {
         'property-1': {
             'type': 'string',
             'description': 'description-1.'
         },
         'property-2': {
             'type': 'integer',
             'description': 'description-2.'
         }
     }
     schema = APISchema._properties_map_to_field_list(
         api_properties, {}, {})
     schema.sort()
     self.assertEqual(schema, [{
         'name': 'property-1',
         'field_type': 'STRING',
         'description': 'description-1.',
         'mode': 'NULLABLE'
     }, {
         'name': 'property-2',
         'field_type': 'NUMERIC',
         'description': 'description-2.',
         'mode': 'NULLABLE'
     }])
Beispiel #2
0
 def test_repeated_properties(self):
     api_properties = {
         'property-1': {
             'type': 'array',
             'items': {
                 '$ref': 'NestedObject',
             },
             'description': 'description-1.'
         },
     }
     resources = {
         'NestedObject': {
             'properties': {
                 'property-2': {
                     'type': 'string',
                     'description': 'description-2.'
                 }
             }
         }
     }
     schema = APISchema._properties_map_to_field_list(api_properties,
                                                      resources, {})
     schema.sort()
     self.assertEqual(schema, [{'name': 'property-1',
                                'field_type': 'RECORD',
                                'mode': 'REPEATED',
                                'description': 'description-1.',
                                'fields': [{
                                    'name': 'property-2',
                                    'field_type': 'STRING',
                                    'description': 'description-2.',
                                    'mode': 'NULLABLE'
                                }]}])
 def test_recursive_properties(self):
     resources = {
         'Object-1': {
             'properties': {
                 'property-1': {
                     'type': 'object',
                     '$ref': 'Object-2',
                 }
             }
         },
         'Object-2': {
             'properties': {
                 'property-2': {
                     'type': 'object',
                     '$ref': 'Object-1',
                 }
             }
         }
     }
     schema = APISchema._properties_map_to_field_list(
         resources['Object-1']['properties'], resources, {})
     schema.sort()
     self.assertEqual(schema, [])
Beispiel #4
0
 def test_string_additional_properties(self):
     api_properties = {
         'property-1': {
             'type': 'object',
             'additionalProperties': {
                 'type': 'string',
                 'description': 'description-1.'
             },
             'description': 'description-1'
         },
     }
     resources = {}
     schema = APISchema._properties_map_to_field_list(
         api_properties, resources, {})
     schema.sort()
     self.assertEqual(schema, [{
         'name':
         'property-1',
         'field_type':
         'RECORD',
         'description':
         'description-1',
         'mode':
         'REPEATED',
         'fields': [{
             'name': 'name',
             'field_type': 'STRING',
             'description': 'additionalProperties name',
             'mode': 'NULLABLE'
         }, {
             'name': 'value',
             'field_type': 'STRING',
             'description': 'description-1.',
             'mode': 'NULLABLE'
         }]
     }])