示例#1
0
 def testLoadDataIntoDictMovesRequiredIfApplicableMetadata(self):
     """Verify that load_data_into_dict() moves all entries matching required metadata from value of extras key to
     be (key:value) pairs of the dict."""
     original = {
         'aardvark':
         'foo',
         'extras': [{
             'key': 'spatial',
             'value': 'wayoutthere'
         }, {
             'key': 'foo',
             'value': 'bar'
         }, {
             'key': 'publisher',
             'value': 'usda'
         }]
     }
     expected = {
         'aardvark': 'foo',
         'common_core': {
             'publisher': 'usda',
             'spatial': 'wayoutthere'
         },
         'extras': [{
             'key': 'foo',
             'value': 'bar'
         }]
     }
     actual = plugin.CommonCoreMetadataFormPlugin().get_helpers(
     )['load_data_into_dict'](original)
     MetadataPluginTest.__check_dicts_match__(expected, actual)
示例#2
0
 def testLoadDataIntoDictFailsGracefully(self):
     """Verify that load_data_into_dict() doesn't generate an error if extras not found"""
     original = {
         'aardvark':
         'foo',
         '__extras': [{
             'key': 'foo',
             'value': 'bar'
         }, {
             'key': 'publisher',
             'value': 'usda'
         }]
     }
     expected = {
         'aardvark':
         'foo',
         'common_core': {},
         '__extras': [{
             'key': 'foo',
             'value': 'bar'
         }, {
             'key': 'publisher',
             'value': 'usda'
         }]
     }
     actual = plugin.CommonCoreMetadataFormPlugin().get_helpers(
     )['load_data_into_dict'](original)
     MetadataPluginTest.__check_dicts_match__(expected, actual)
示例#3
0
 def testLoadDataIntoDictMovesSingleValuedExtrasEntry(self):
     """Verify that load_data_into_dict() moves all entries matching required metadata from value of extras key to
     be (key:value) pairs of the dict."""
     original = {
         'hi': 'there',
         'extras': [{
             'key': 'publisher',
             'value': 'USGS'
         }]
     }
     expected = {
         'hi': 'there',
         'common_core': {
             'publisher': 'USGS'
         },
         'extras': []
     }
     actual = plugin.CommonCoreMetadataFormPlugin().get_helpers(
     )['load_data_into_dict'](original)
     MetadataPluginTest.__check_dicts_match__(expected, actual)
示例#4
0
 def testLoadDataIntoDictLarge(self):
     original = {
         'aardvark':
         'foo',
         'extras': [{
             u'value': u'daily',
             u'key': u'accrual_periodicity',
             '__extras': {
                 u'package_id': u'154dc150-bba6-4201-b4ff-1a684121e27e',
                 u'revision_id': u'0fe96ac4-bac5-4ee5-a7e6-224f58897575'
             }
         }, {
             u'value': u'asdfa',
             u'key': u'category',
             '__extras': {
                 u'revision_id': u'0fe96ac4-bac5-4ee5-a7e6-224f58897575',
                 u'package_id': u'154dc150-bba6-4201-b4ff-1a684121e27e'
             }
         }, {
             u'value': u'contactmyemailaddr',
             u'key': u'contact_email',
             '__extras': {
                 u'package_id': u'154dc150-bba6-4201-b4ff-1a684121e27e',
                 u'revision_id': u'43774ce1-7b28-45d3-95cb-b98bc3860f6f'
             }
         }]
     }
     expected = {
         'aardvark': 'foo',
         'common_core': {
             u'accrual_periodicity': u'value',
             u'category': 'asdfa',
             u'contact_email': 'contactmyemailaddr'
         },
         'extras': []
     }
     actual = plugin.CommonCoreMetadataFormPlugin().get_helpers(
     )['load_data_into_dict'](original)
     MetadataPluginTest.__check_dicts_match__(expected, actual)
示例#5
0
    def testLoadDataIntoDictNoExtra(self):
        """Verify that when no '__extras' key exist, load_data_into_dict() will move any common core metadata in key value pairs into a dict under
        the key 'common_core'"""
        original = {
            'foo': 'bar',
            'publisher': 'somename',
            'foo2': 'bar2',
            'data_dictionary': 'something',
            'system_of_records': 'somesystem'
        }
        expected = {
            'foo': 'bar',
            'common_core': {
                'data_dictionary': 'something',
                'publisher': 'somename',
                'system_of_records': 'somesystem'
            },
            'foo2': 'bar2'
        }
        actual = plugin.CommonCoreMetadataFormPlugin().get_helpers(
        )['load_data_into_dict'](original)

        log.debug('actual: {0}'.format(actual))
        MetadataPluginTest.__check_dicts_match__(expected, actual)