Exemple #1
0
 def test_reusable_dot_notation(self):
     fieldset = {
         'reusable_fieldset1': {
             'name': 'reusable_fieldset1',
             'reusable': {
                 'top_level': False,
                 'expected': [
                     'test_fieldset.sub_field'
                 ]
             },
             'fields': {
                 'reusable_field': {
                     'field_details': {
                         'name': 'reusable_field',
                         'type': 'keyword',
                         'description': 'A test field'
                     }
                 }
             }
         },
         'test_fieldset': {
             'name': 'test_fieldset',
             'fields': {
                 'sub_field': {
                     'fields': {}
                 }
             }
         }
     }
     expected = {
         'sub_field': {
             'fields': {
                 'reusable_fieldset1': {
                     'name': 'reusable_fieldset1',
                     'reusable': {
                         'top_level': False,
                         'expected': [
                             'test_fieldset.sub_field'
                         ]
                     },
                     'fields': {
                         'reusable_field': {
                             'field_details': {
                                 'name': 'reusable_field',
                                 'type': 'keyword',
                                 'description': 'A test field'
                             }
                         }
                     }
                 }
             }
         }
     }
     schema_reader.duplicate_reusable_fieldsets(fieldset['reusable_fieldset1'], fieldset)
     self.assertEqual(fieldset['test_fieldset']['fields'], expected)
Exemple #2
0
 def test_improper_reusable_fails(self):
     fieldset = {
         'reusable_fieldset1': {
             'name': 'reusable_fieldset1',
             'reusable': {
                 'top_level': False,
                 'expected': [
                     'test_fieldset'
                 ]
             },
             'fields': {
                 'reusable_field': {
                     'field_details': {
                         'name': 'reusable_field',
                         'type': 'keyword',
                         'description': 'A test field'
                     }
                 }
             }
         },
         'reusable_fieldset2': {
             'name': 'reusable_fieldset2',
             'reusable': {
                 'top_level': False,
                 'expected': [
                     'test_fieldset.reusable_fieldset1'
                 ]
             },
             'fields': {
                 'reusable_field': {
                     'field_details': {
                         'name': 'reusable_field',
                         'type': 'keyword',
                         'description': 'A test field'
                     }
                 }
             }
         },
         'test_fieldset': {
             'name': 'test_fieldset',
             'fields': {}
         }
     }
     # This should fail because test_fieldset.reusable_fieldset1 doesn't exist yet
     with self.assertRaises(ValueError):
         schema_reader.duplicate_reusable_fieldsets(fieldset['reusable_fieldset2'], fieldset)
     schema_reader.duplicate_reusable_fieldsets(fieldset['reusable_fieldset1'], fieldset)
     # Then this should fail because even though test_fieldset.reusable_fieldset1 now exists, test_fieldset.reusable_fieldset1 is not
     # an allowed reusable location (it's the destination of another reusable)
     with self.assertRaises(ValueError):
         schema_reader.duplicate_reusable_fieldsets(fieldset['reusable_fieldset2'], fieldset)