From a903bdf133f718bbc0489d6ecae104312c46c64a Mon Sep 17 00:00:00 2001 From: kyle Date: Tue, 1 Oct 2024 17:52:22 -0400 Subject: [PATCH 1/7] SFR-2217 Cleanup OCLC no prefix --- mappings/muse.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/mappings/muse.py b/mappings/muse.py index 6f1c6472b4a..fccfe4bec19 100644 --- a/mappings/muse.py +++ b/mappings/muse.py @@ -68,6 +68,8 @@ def applyFormatting(self): # Take first title as they are in order of preference self.record.title = self.record.title[0] + self.record.id = [self.clean_identifier(id) for id in self.record.identifiers] + # Extract language code from 008 fixed data field self.record.languages = [self.extractLanguage(l) for l in self.record.languages] @@ -119,3 +121,11 @@ def addHasPartLink(self, url, mediaType, flags): self.record.has_part.append( '{}|{}|muse|{}|{}'.format(lastItemNo, url, mediaType, flags) ) + + def clean_identifier(self, identifier): + oclc_number_prefix = '(OCoLC)' + + if identifier.startswith(oclc_number_prefix): + return identifier[len(oclc_number_prefix):] + + return identifier From 9d0f05f045d4c31e9d14c98b2fdf4814d2b4a9a0 Mon Sep 17 00:00:00 2001 From: kyle Date: Wed, 2 Oct 2024 09:55:59 -0400 Subject: [PATCH 2/7] using snake case --- mappings/muse.py | 52 +++++++++++++++------------------ tests/unit/test_muse_mapping.py | 16 +++++----- 2 files changed, 32 insertions(+), 36 deletions(-) diff --git a/mappings/muse.py b/mappings/muse.py index fccfe4bec19..2acb95d419e 100644 --- a/mappings/muse.py +++ b/mappings/muse.py @@ -68,61 +68,57 @@ def applyFormatting(self): # Take first title as they are in order of preference self.record.title = self.record.title[0] - self.record.id = [self.clean_identifier(id) for id in self.record.identifiers] + self.record.id = [self.cleanup_identifier(id) for id in self.record.identifiers] # Extract language code from 008 fixed data field - self.record.languages = [self.extractLanguage(l) for l in self.record.languages] + self.record.languages = [self.extract_language(language) for language in self.record.languages] # Extract publication date from 008 fixed field if 264 field is missing if len(self.record.dates) < 1: - pubDate = self.source['008'].data[11:15] - self.record.dates.append('{}|publication_date'.format(pubDate)) + publication_date = self.source['008'].data[11:15] + self.record.dates.append('{}|publication_date'.format(publication_date)) # If publisher missing, assume JHU if len(self.record.publisher) < 1: self.record.publisher.append('John Hopkins University Press||') - # Clean up subjects to remove spots for missing subheadings - self.record.subjects = [ - self.cleanUpSubjectHead(s) - for s in self.record.subjects - ] + self.record.subjects = [self.clean_up_subject_head(subject) for subject in self.record.subjects] - # Add Rights statement self.record.rights = '{}|{}||{}|'.format( - 'muse', 'https://creativecommons.org/licenses/by-nc/4.0/', + 'muse', + 'https://creativecommons.org/licenses/by-nc/4.0/', 'Creative Commons Attribution-NonCommercial 4.0 International' ) - def cleanUpSubjectHead(self, subject): - subjectStr, *subjectMeta = subject.split('|') - subjectParts = subjectStr.split('--') + def clean_up_subject_head(self, subject): + subject_str, *subject_metadata = subject.split('|') + subject_parts = subject_str.split('--') - outParts = [] + out_parts = [] - for part in subjectParts: - cleanPart = part.strip(' .') + for part in subject_parts: + clean_parts = part.strip(' .') - if cleanPart == '': continue + if clean_parts == '': continue - outParts.append(cleanPart) + out_parts.append(clean_parts) - cleanSubject = ' -- '.join([p for p in outParts]) + cleaned_subject = ' -- '.join([part for part in out_parts]) - return '|'.join([cleanSubject] + subjectMeta) + return '|'.join([cleaned_subject] + subject_metadata) - def extractLanguage(self, language): - _, _, marcData, *_ = language.split('|') - return '||{}'.format(marcData[35:38]) + def extract_language(self, language): + _, _, marc_data, *_ = language.split('|') + return '||{}'.format(marc_data[35:38]) - def addHasPartLink(self, url, mediaType, flags): - lastItemNo = int(self.record.has_part[-1][0]) + def add_has_part_link(self, url, media_type, flags): + last_item_no = int(self.record.has_part[-1][0]) self.record.has_part.append( - '{}|{}|muse|{}|{}'.format(lastItemNo, url, mediaType, flags) + '{}|{}|muse|{}|{}'.format(last_item_no, url, media_type, flags) ) - def clean_identifier(self, identifier): + def cleanup_identifier(self, identifier): oclc_number_prefix = '(OCoLC)' if identifier.startswith(oclc_number_prefix): diff --git a/tests/unit/test_muse_mapping.py b/tests/unit/test_muse_mapping.py index 5bec22824bb..851ce303a5b 100644 --- a/tests/unit/test_muse_mapping.py +++ b/tests/unit/test_muse_mapping.py @@ -39,10 +39,10 @@ def test_createMapping(self, testMapping): def test_applyFormatting(self, testMapping, mocker): - mockCleanSubject = mocker.patch.object(MUSEMapping, 'cleanUpSubjectHead') + mockCleanSubject = mocker.patch.object(MUSEMapping, 'clean_up_subject_head') mockCleanSubject.side_effect = [1, 2, 3] - mockExtractLanguage = mocker.patch.object(MUSEMapping, 'extractLanguage') + mockExtractLanguage = mocker.patch.object(MUSEMapping, 'extract_language') mockExtractLanguage.side_effect = ['lng1', 'lng2'] testMapping.applyFormatting() @@ -54,15 +54,15 @@ def test_applyFormatting(self, testMapping, mocker): assert testMapping.record.languages == ['lng1', 'lng2'] assert testMapping.record.dates[0] == '2000|publication_date' - def test_cleanUpSubjectHead(self, testMapping): - cleanSubject = testMapping.cleanUpSubjectHead('first -- second. -- -- |||') + def test_clean_up_subject_head(self, testMapping): + cleanSubject = testMapping.clean_up_subject_head('first -- second. -- -- |||') assert cleanSubject == 'first -- second|||' - def test_extractLanguage(self, testMapping): - assert testMapping.extractLanguage('||100607s2011 mdu o 00 0 eng d z ') == '||eng' + def test_extract_language(self, testMapping): + assert testMapping.extract_language('||100607s2011 mdu o 00 0 eng d z ') == '||eng' - def test_addHasPartLink(self, testMapping): - testMapping.addHasPartLink('newURL', 'pdf+json', 'pdfFlags') + def test_add_has_part_link(self, testMapping): + testMapping.add_has_part_link('newURL', 'pdf+json', 'pdfFlags') assert testMapping.record.has_part[1] == '1|newURL|muse|pdf+json|pdfFlags' From d5ccee223203aff7d1cc985a6dd7dbf52aa06d95 Mon Sep 17 00:00:00 2001 From: kyle Date: Wed, 2 Oct 2024 10:52:28 -0400 Subject: [PATCH 3/7] rewriting unit tests --- mappings/muse.py | 15 ++--- tests/unit/test_muse_mapping.py | 100 ++++++++++++++++---------------- 2 files changed, 59 insertions(+), 56 deletions(-) diff --git a/mappings/muse.py b/mappings/muse.py index 2acb95d419e..3e82b3e7b88 100644 --- a/mappings/muse.py +++ b/mappings/muse.py @@ -1,5 +1,8 @@ from mappings.marc import MARCMapping +DEFAULT_PUBLISHER = 'John Hopkins University Press||' + + class MUSEMapping(MARCMapping): def __init__(self, source): super(MUSEMapping, self).__init__(source, {}) @@ -69,18 +72,15 @@ def applyFormatting(self): self.record.title = self.record.title[0] self.record.id = [self.cleanup_identifier(id) for id in self.record.identifiers] - - # Extract language code from 008 fixed data field + self.record.languages = [self.extract_language(language) for language in self.record.languages] - # Extract publication date from 008 fixed field if 264 field is missing if len(self.record.dates) < 1: publication_date = self.source['008'].data[11:15] self.record.dates.append('{}|publication_date'.format(publication_date)) - - # If publisher missing, assume JHU + if len(self.record.publisher) < 1: - self.record.publisher.append('John Hopkins University Press||') + self.record.publisher.append(DEFAULT_PUBLISHER) self.record.subjects = [self.clean_up_subject_head(subject) for subject in self.record.subjects] @@ -109,7 +109,8 @@ def clean_up_subject_head(self, subject): def extract_language(self, language): _, _, marc_data, *_ = language.split('|') - return '||{}'.format(marc_data[35:38]) + print(marc_data) + return '||{}'.format(marc_data[35:38] or marc_data) def add_has_part_link(self, url, media_type, flags): last_item_no = int(self.record.has_part[-1][0]) diff --git a/tests/unit/test_muse_mapping.py b/tests/unit/test_muse_mapping.py index 851ce303a5b..c7ce37b823a 100644 --- a/tests/unit/test_muse_mapping.py +++ b/tests/unit/test_muse_mapping.py @@ -1,68 +1,70 @@ import pytest from mappings.muse import MUSEMapping +from model import Record +test_source = { + '008': type('data-object', (object,), { 'data' : 'testingdate2000pla' }) +} -class TestMUSEMapping: - @pytest.fixture - def testRecord(self, mocker): - mockRecord = mocker.MagicMock() - mockRecord.identifiers = ['1|muse', '2|test', '3|other'] - mockRecord.title = ['Main Title', 'Secondary Title'] - mockRecord.subjects = ['subj1', 'subj2', 'subj3'] - mockRecord.has_part = ['1|testURL|muse|testType|testFlags'] - mockRecord.languages = ['||lang1', '||lang2'] - mockRecord.dates = [] +def test_create_mapping(): + muse_mapping = MUSEMapping(test_source) + + assert set([ + 'identifiers', 'authors', 'title', 'alternative', 'has_version', + 'publisher', 'spatial', 'dates', 'languages', 'extent', + 'table_of_contents', 'abstract', 'subjects', 'contributors', + 'is_part_of', 'has_part' + ]).issubset(set(muse_mapping.mapping.keys())) + assert muse_mapping.mapping['is_part_of'] == ('490', '{a}|{v}|volume') - return mockRecord +def test_apply_formatting(): + muse_mapping = MUSEMapping(test_source) + record = Record() + record.identifiers = ['1|muse', '2|test', '3|other'] + record.title = ['Main Title', 'Secondary Title'] + record.subjects = ['subj1', 'subj2', 'subj3'] + record.has_part = ['1|testURL|muse|testType|testFlags'] + record.languages = ['||lng1', '||lng2'] + record.publisher = [] + record.dates = [] + muse_mapping.record = record - @pytest.fixture - def testMapping(self, testRecord, mocker): - class TestMapping(MUSEMapping): - def __init__(self): - self.mapping = None - self.record = testRecord - self.source = {'008': mocker.MagicMock(data='testingdate2000pla')} - - return TestMapping() + muse_mapping.applyFormatting() - def test_createMapping(self, testMapping): - recordMapping = testMapping.createMapping() + assert muse_mapping.record.source == 'muse' + assert muse_mapping.record.source_id == '1' + assert muse_mapping.record.title == 'Main Title' + assert muse_mapping.record.subjects == ['subj1', 'subj2', 'subj3'] + assert muse_mapping.record.languages == ['||lng1', '||lng2'] + assert muse_mapping.record.dates[0] == '2000|publication_date' - assert list(recordMapping.keys()) == [ - 'identifiers', 'authors', 'title', 'alternative', 'has_version', - 'publisher', 'spatial', 'dates', 'languages', 'extent', - 'table_of_contents', 'abstract', 'subjects', 'contributors', - 'is_part_of', 'has_part' - ] - assert recordMapping['is_part_of'] == ('490', '{a}|{v}|volume') +def test_clean_up_subject_head(): + muse_mapping = MUSEMapping(test_source) + + cleanSubject = muse_mapping.clean_up_subject_head('first -- second. -- -- |||') - def test_applyFormatting(self, testMapping, mocker): + assert cleanSubject == 'first -- second|||' - mockCleanSubject = mocker.patch.object(MUSEMapping, 'clean_up_subject_head') - mockCleanSubject.side_effect = [1, 2, 3] +def test_extract_language(): + muse_mapping = MUSEMapping(test_source) - mockExtractLanguage = mocker.patch.object(MUSEMapping, 'extract_language') - mockExtractLanguage.side_effect = ['lng1', 'lng2'] + extracted_language = muse_mapping.extract_language('||100607s2011 mdu o 00 0 eng d z ') - testMapping.applyFormatting() + assert extracted_language == '||eng' - assert testMapping.record.source == 'muse' - assert testMapping.record.source_id == '1' - assert testMapping.record.title == 'Main Title' - assert testMapping.record.subjects == [1, 2, 3] - assert testMapping.record.languages == ['lng1', 'lng2'] - assert testMapping.record.dates[0] == '2000|publication_date' +def test_cleanup_identifier(): + muse_mapping = MUSEMapping(test_source) - def test_clean_up_subject_head(self, testMapping): - cleanSubject = testMapping.clean_up_subject_head('first -- second. -- -- |||') + cleaned_identifier = muse_mapping.cleanup_identifier('(OCoLC)12235') - assert cleanSubject == 'first -- second|||' + assert cleaned_identifier == '12235' - def test_extract_language(self, testMapping): - assert testMapping.extract_language('||100607s2011 mdu o 00 0 eng d z ') == '||eng' +def test_add_has_part_link(): + muse_mapping = MUSEMapping(test_source) + muse_mapping.record = Record() + muse_mapping.record.has_part = ['1|test_url|muse|epub|flags'] - def test_add_has_part_link(self, testMapping): - testMapping.add_has_part_link('newURL', 'pdf+json', 'pdfFlags') + muse_mapping.add_has_part_link('newURL', 'pdf+json', 'pdfFlags') - assert testMapping.record.has_part[1] == '1|newURL|muse|pdf+json|pdfFlags' + assert muse_mapping.record.has_part[1] == '1|newURL|muse|pdf+json|pdfFlags' From e188e1097087ded03085d571bf12c2a9f0bd6c37 Mon Sep 17 00:00:00 2001 From: kyle Date: Wed, 2 Oct 2024 10:57:37 -0400 Subject: [PATCH 4/7] fixing test --- mappings/muse.py | 7 ++++--- tests/unit/test_muse_mapping.py | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/mappings/muse.py b/mappings/muse.py index 3e82b3e7b88..d92d916c038 100644 --- a/mappings/muse.py +++ b/mappings/muse.py @@ -71,7 +71,7 @@ def applyFormatting(self): # Take first title as they are in order of preference self.record.title = self.record.title[0] - self.record.id = [self.cleanup_identifier(id) for id in self.record.identifiers] + self.record.identifiers = [self.cleanup_identifier(id) for id in self.record.identifiers] self.record.languages = [self.extract_language(language) for language in self.record.languages] @@ -121,8 +121,9 @@ def add_has_part_link(self, url, media_type, flags): def cleanup_identifier(self, identifier): oclc_number_prefix = '(OCoLC)' + id_type, id = identifier.split('|') - if identifier.startswith(oclc_number_prefix): - return identifier[len(oclc_number_prefix):] + if id.startswith(oclc_number_prefix): + return f'{id_type}|{id[len(oclc_number_prefix):]}' return identifier diff --git a/tests/unit/test_muse_mapping.py b/tests/unit/test_muse_mapping.py index c7ce37b823a..b8052bfb266 100644 --- a/tests/unit/test_muse_mapping.py +++ b/tests/unit/test_muse_mapping.py @@ -21,7 +21,7 @@ def test_create_mapping(): def test_apply_formatting(): muse_mapping = MUSEMapping(test_source) record = Record() - record.identifiers = ['1|muse', '2|test', '3|other'] + record.identifiers = ['1|muse', '2|test', '3|other', '4|(OCoLC)123'] record.title = ['Main Title', 'Secondary Title'] record.subjects = ['subj1', 'subj2', 'subj3'] record.has_part = ['1|testURL|muse|testType|testFlags'] @@ -35,6 +35,7 @@ def test_apply_formatting(): assert muse_mapping.record.source == 'muse' assert muse_mapping.record.source_id == '1' assert muse_mapping.record.title == 'Main Title' + assert muse_mapping.record.identifiers == ['1|muse', '2|test', '3|other', '4|123'] assert muse_mapping.record.subjects == ['subj1', 'subj2', 'subj3'] assert muse_mapping.record.languages == ['||lng1', '||lng2'] assert muse_mapping.record.dates[0] == '2000|publication_date' @@ -56,9 +57,9 @@ def test_extract_language(): def test_cleanup_identifier(): muse_mapping = MUSEMapping(test_source) - cleaned_identifier = muse_mapping.cleanup_identifier('(OCoLC)12235') + cleaned_identifier = muse_mapping.cleanup_identifier('4|(OCoLC)12235') - assert cleaned_identifier == '12235' + assert cleaned_identifier == '4|12235' def test_add_has_part_link(): muse_mapping = MUSEMapping(test_source) From 231f16beba9f3962da4dfb2da35211db5a78c409 Mon Sep 17 00:00:00 2001 From: kyle Date: Wed, 2 Oct 2024 11:49:01 -0400 Subject: [PATCH 5/7] renaming var --- tests/unit/test_muse_mapping.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit/test_muse_mapping.py b/tests/unit/test_muse_mapping.py index b8052bfb266..2b5a6ddb79f 100644 --- a/tests/unit/test_muse_mapping.py +++ b/tests/unit/test_muse_mapping.py @@ -43,9 +43,9 @@ def test_apply_formatting(): def test_clean_up_subject_head(): muse_mapping = MUSEMapping(test_source) - cleanSubject = muse_mapping.clean_up_subject_head('first -- second. -- -- |||') + cleaned_subject = muse_mapping.clean_up_subject_head('first -- second. -- -- |||') - assert cleanSubject == 'first -- second|||' + assert cleaned_subject == 'first -- second|||' def test_extract_language(): muse_mapping = MUSEMapping(test_source) From c8bab01a98b7131b159634af7a8209883763b7a4 Mon Sep 17 00:00:00 2001 From: kyle Date: Thu, 3 Oct 2024 11:55:52 -0400 Subject: [PATCH 6/7] formatting tests --- tests/unit/test_muse_mapping.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/unit/test_muse_mapping.py b/tests/unit/test_muse_mapping.py index 2b5a6ddb79f..cbab9df5c8c 100644 --- a/tests/unit/test_muse_mapping.py +++ b/tests/unit/test_muse_mapping.py @@ -18,6 +18,7 @@ def test_create_mapping(): ]).issubset(set(muse_mapping.mapping.keys())) assert muse_mapping.mapping['is_part_of'] == ('490', '{a}|{v}|volume') + def test_apply_formatting(): muse_mapping = MUSEMapping(test_source) record = Record() @@ -40,6 +41,7 @@ def test_apply_formatting(): assert muse_mapping.record.languages == ['||lng1', '||lng2'] assert muse_mapping.record.dates[0] == '2000|publication_date' + def test_clean_up_subject_head(): muse_mapping = MUSEMapping(test_source) @@ -47,6 +49,7 @@ def test_clean_up_subject_head(): assert cleaned_subject == 'first -- second|||' + def test_extract_language(): muse_mapping = MUSEMapping(test_source) @@ -54,6 +57,7 @@ def test_extract_language(): assert extracted_language == '||eng' + def test_cleanup_identifier(): muse_mapping = MUSEMapping(test_source) @@ -61,6 +65,7 @@ def test_cleanup_identifier(): assert cleaned_identifier == '4|12235' + def test_add_has_part_link(): muse_mapping = MUSEMapping(test_source) muse_mapping.record = Record() From 4bbd1392e2673517f3e492c6fc67f25b4ec2c410 Mon Sep 17 00:00:00 2001 From: kyle Date: Thu, 3 Oct 2024 13:46:34 -0400 Subject: [PATCH 7/7] fixing language mapping --- managers/muse.py | 8 ++++---- mappings/muse.py | 22 ++++++++++++++++------ tests/unit/test_muse_manager.py | 6 +++--- tests/unit/test_muse_mapping.py | 12 ++++++------ 4 files changed, 29 insertions(+), 19 deletions(-) diff --git a/managers/muse.py b/managers/muse.py index f15470f6af5..851a3502ae1 100644 --- a/managers/muse.py +++ b/managers/muse.py @@ -68,7 +68,7 @@ def identifyReadableVersions(self): def addReadableLinks(self): if self.pdfDownloadURL: - self.record.addHasPartLink( + self.record.add_has_part_link( self.pdfDownloadURL, 'application/pdf', json.dumps({'download': True, 'reader': False, 'catalog': False}) @@ -76,14 +76,14 @@ def addReadableLinks(self): if self.epubURL: self.s3EpubPath = 'epubs/muse/{}.epub'.format(self.museID) - self.record.addHasPartLink( + self.record.add_has_part_link( self.constructS3Link(self.s3EpubPath), 'application/epub+zip', json.dumps({'download': True, 'reader': False, 'catalog': False}) ) self.epubReadPath = 'epubs/muse/{}/manifest.json'.format(self.museID) - self.record.addHasPartLink( + self.record.add_has_part_link( self.constructS3Link(self.epubReadPath), 'application/webpub+json', json.dumps({'download': False, 'reader': True, 'catalog': False}) @@ -92,7 +92,7 @@ def addReadableLinks(self): self.constructWebpubManifest() if self.pdfWebpubManifest: self.s3PDFReadPath = 'manifests/muse/{}.json'.format(self.museID) - self.record.addHasPartLink( + self.record.add_has_part_link( self.createManifestInS3(self.s3PDFReadPath), 'application/webpub+json', json.dumps({'reader': True, 'download': False, 'catalog': False}) diff --git a/mappings/muse.py b/mappings/muse.py index d92d916c038..0d06c503fda 100644 --- a/mappings/muse.py +++ b/mappings/muse.py @@ -73,7 +73,11 @@ def applyFormatting(self): self.record.identifiers = [self.cleanup_identifier(id) for id in self.record.identifiers] - self.record.languages = [self.extract_language(language) for language in self.record.languages] + self.record.languages = [ + extracted_langauge + for language in self.record.languages + if (extracted_langauge := self.extract_language(language)) + ] if len(self.record.dates) < 1: publication_date = self.source['008'].data[11:15] @@ -109,8 +113,13 @@ def clean_up_subject_head(self, subject): def extract_language(self, language): _, _, marc_data, *_ = language.split('|') - print(marc_data) - return '||{}'.format(marc_data[35:38] or marc_data) + marc_data = marc_data.split(' ') + + # MARC data example: 100607s2011 mdu o 00 0 eng d + if len(marc_data) >= 7: + return f'||{marc_data[5]}' + + return None def add_has_part_link(self, url, media_type, flags): last_item_no = int(self.record.has_part[-1][0]) @@ -121,9 +130,10 @@ def add_has_part_link(self, url, media_type, flags): def cleanup_identifier(self, identifier): oclc_number_prefix = '(OCoLC)' - id_type, id = identifier.split('|') + id, id_type = identifier.split('|') + id = id.strip() if id.startswith(oclc_number_prefix): - return f'{id_type}|{id[len(oclc_number_prefix):]}' + return f'{id[len(oclc_number_prefix):]}|{id_type}' - return identifier + return f'{id}|{id_type}' diff --git a/tests/unit/test_muse_manager.py b/tests/unit/test_muse_manager.py index ee624a62b3d..843e3b8b2e6 100644 --- a/tests/unit/test_muse_manager.py +++ b/tests/unit/test_muse_manager.py @@ -116,7 +116,7 @@ def test_addReadableLinks_pdf(self, testManager, mocker): testManager.addReadableLinks() - testManager.record.addHasPartLink.assert_called_once_with( + testManager.record.add_has_part_link.assert_called_once_with( 'testPDFURL', 'application/pdf', '{"download": true, "reader": false, "catalog": false}' ) mockConstruct.assert_called_once() @@ -130,7 +130,7 @@ def test_addReadableLinks_epub(self, testManager, mocker): testManager.addReadableLinks() - testManager.record.addHasPartLink.assert_has_calls([ + testManager.record.add_has_part_link.assert_has_calls([ mocker.call('epubDownloadURL', 'application/epub+zip', '{"download": true, "reader": false, "catalog": false}'), mocker.call('epubReadURL', 'application/webpub+json', '{"download": false, "reader": true, "catalog": false}') ]) @@ -149,7 +149,7 @@ def test_addReadableLinks_manifest(self, testManager, mocker): testManager.addReadableLinks() - testManager.record.addHasPartLink.assert_called_once_with( + testManager.record.add_has_part_link.assert_called_once_with( 'webpubReadURL', 'application/webpub+json', '{"reader": true, "download": false, "catalog": false}' ) mockS3.assert_called_once_with('manifests/muse/1.json') diff --git a/tests/unit/test_muse_mapping.py b/tests/unit/test_muse_mapping.py index cbab9df5c8c..c80191f014a 100644 --- a/tests/unit/test_muse_mapping.py +++ b/tests/unit/test_muse_mapping.py @@ -22,11 +22,11 @@ def test_create_mapping(): def test_apply_formatting(): muse_mapping = MUSEMapping(test_source) record = Record() - record.identifiers = ['1|muse', '2|test', '3|other', '4|(OCoLC)123'] + record.identifiers = ['1|muse', '2|test', '3|other', '(OCoLC)123|oclc'] record.title = ['Main Title', 'Secondary Title'] record.subjects = ['subj1', 'subj2', 'subj3'] record.has_part = ['1|testURL|muse|testType|testFlags'] - record.languages = ['||lng1', '||lng2'] + record.languages = ['||100607s2011 mdu o 00 0 lng1 d', '||100607s2011 mdu o 00 0 lng2 d'] record.publisher = [] record.dates = [] muse_mapping.record = record @@ -36,7 +36,7 @@ def test_apply_formatting(): assert muse_mapping.record.source == 'muse' assert muse_mapping.record.source_id == '1' assert muse_mapping.record.title == 'Main Title' - assert muse_mapping.record.identifiers == ['1|muse', '2|test', '3|other', '4|123'] + assert muse_mapping.record.identifiers == ['1|muse', '2|test', '3|other', '123|oclc'] assert muse_mapping.record.subjects == ['subj1', 'subj2', 'subj3'] assert muse_mapping.record.languages == ['||lng1', '||lng2'] assert muse_mapping.record.dates[0] == '2000|publication_date' @@ -53,7 +53,7 @@ def test_clean_up_subject_head(): def test_extract_language(): muse_mapping = MUSEMapping(test_source) - extracted_language = muse_mapping.extract_language('||100607s2011 mdu o 00 0 eng d z ') + extracted_language = muse_mapping.extract_language('||100607s2011 mdu o 00 0 eng d') assert extracted_language == '||eng' @@ -61,9 +61,9 @@ def test_extract_language(): def test_cleanup_identifier(): muse_mapping = MUSEMapping(test_source) - cleaned_identifier = muse_mapping.cleanup_identifier('4|(OCoLC)12235') + cleaned_identifier = muse_mapping.cleanup_identifier('(OCoLC)1223|oclc') - assert cleaned_identifier == '4|12235' + assert cleaned_identifier == '1223|oclc' def test_add_has_part_link():