diff --git a/CHANGELOG.md b/CHANGELOG.md index ae592d7..af00b80 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,13 @@ Change Log ========== + +1.2.1 +----- + +* Fixed bug which could raise KeyError when looking up transcription files for records with no resourceType. + + 1.2.0 ----- diff --git a/aubreylib/resource.py b/aubreylib/resource.py index bf4ed39..d5de51e 100644 --- a/aubreylib/resource.py +++ b/aubreylib/resource.py @@ -189,7 +189,7 @@ def __init__(self, identifier, metadataLocations, staticFileLocations, # Get transcriptions data self.transcriptions = get_transcriptions_data( meta_id=self.meta_id, - resource_type=self.desc_MD['resourceType'][0]['content'], + resource_type=self.desc_MD.get('resourceType', [{}])[0].get('content'), transcriptions_server_url=kwargs.get('transcriptions_server_url'), ) # Get the fileSets within the fileSec diff --git a/setup.py b/setup.py index f8477ec..8df4ea9 100644 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ setup( name='aubreylib', - version='1.2.0', + version='1.2.1', description='A helper library for the Aubrey access system.', author='University of North Texas Libraries', author_email='mark.phillips@unt.edu', diff --git a/tests/test_resource.py b/tests/test_resource.py index 9f53e0d..357bed8 100644 --- a/tests/test_resource.py +++ b/tests/test_resource.py @@ -66,8 +66,13 @@ def test_get_dimensions_data_absent(self, mock_exists): class TestGetTranscriptionsData: - def test_get_transcriptions_data_wrong_resource_type(self): - result = resource.get_transcriptions_data('metadc123', 'text', 'http://example.com') + @pytest.mark.parametrize('resource_type', [ + '', + None, + 'text', + ]) + def test_get_transcriptions_data_wrong_resource_type(self, resource_type): + result = resource.get_transcriptions_data('metadc123', resource_type, 'http://example.com') assert result == {} @pytest.mark.parametrize('url', [ @@ -196,3 +201,18 @@ def testResourceObjectTranscriptions(self, mocked_fileSet_file, assert not ro.manifestation_dict[1][1]['has_vtt_chapters'] assert not ro.manifestation_dict[1][1]['has_vtt_thumbnails'] assert not ro.manifestation_dict[1][1]['has_vtt_metadata'] + + @patch.object(resource.ResourceObject, 'get_fileSet_file') + @patch('aubreylib.resource.get_desc_metadata') + def testResourceObjectEmptyDescMD(self, mocked_get_desc_metadata, mocked_fileSet_file): + """Tests that a ResourceObject can instantiate with missing descriptive metadata keys.""" + mocked_get_desc_metadata.return_value = {} + mocked_fileSet_file.return_value = {'file_mimetype': '', + 'file_name': '', + 'files_system': ''} + current_directory = os.path.dirname(os.path.abspath(__file__)) + mets_path = '{0}/data/metapth12434.mets.xml'.format(current_directory) + + resource.ResourceObject(identifier=mets_path, metadataLocations=[], + staticFileLocations=[], mimetypeIconsPath='', use=USE, + transcriptions_server_url='http://example.com')