Ejemplo n.º 1
0
    def test_publicationDateCheck3(self):
        testEdition3 = SFRRecordManager.createEmptyEditionRecord()

        testEdition3['publication_date'] = datetime(1488, 1, 1)
        testPubDateCheck3 = SFRRecordManager.publicationDateCheck(testEdition3)
        assert testPubDateCheck3.year == 1488

        testEdition3['publication_date'] = 'December 1488'
        testPubDateCheck3 = SFRRecordManager.publicationDateCheck(testEdition3)
        assert testPubDateCheck3.year == 1488
Ejemplo n.º 2
0
    def test_publicationDateCheck1(self):
        testEdition = SFRRecordManager.createEmptyEditionRecord()

        testEdition['publication_date'] = datetime(1900, 1, 1)
        testPubDateCheck = SFRRecordManager.publicationDateCheck(testEdition)
        assert testPubDateCheck.year == 1900

        testEdition['publication_date'] = '1900'
        testPubDateCheck = SFRRecordManager.publicationDateCheck(testEdition)
        assert testPubDateCheck.year == 1900
Ejemplo n.º 3
0
    def test_publicationDateCheck5(self):
        testEdition5 = SFRRecordManager.createEmptyEditionRecord()

        testEdition5['publication_date'] = datetime.utcnow() + timedelta(1)
        testPubDateCheck5 = SFRRecordManager.publicationDateCheck(testEdition5)
        assert testPubDateCheck5 == None

        testEdition5['publication_date'] = (datetime.utcnow() +
                                            timedelta(1)).strftime('%Y-%m-%d')
        testPubDateCheck5 = SFRRecordManager.publicationDateCheck(testEdition5)
        assert testPubDateCheck5 == None
Ejemplo n.º 4
0
    def test_publicationDateCheck4(self):
        #Tests for incorrect date ranges
        testEdition4 = SFRRecordManager.createEmptyEditionRecord()

        testEdition4['publication_date'] = datetime(1300, 1, 1)
        testPubDateCheck4 = SFRRecordManager.publicationDateCheck(testEdition4)
        assert testPubDateCheck4 == None

        testEdition4['publication_date'] = '1300'
        testPubDateCheck4 = SFRRecordManager.publicationDateCheck(testEdition4)
        assert testPubDateCheck4 == None
Ejemplo n.º 5
0
    def test_publicationDateCheck2(self):
        testEdition2 = SFRRecordManager.createEmptyEditionRecord()

        testEdition2['publication_date'] = datetime.utcnow()
        testPubDateCheck2 = SFRRecordManager.publicationDateCheck(testEdition2)
        assert testPubDateCheck2.year == datetime.utcnow().year

        testEdition2['publication_date'] = datetime.utcnow().strftime(
            '%Y-%m-%d')
        testPubDateCheck2 = SFRRecordManager.publicationDateCheck(testEdition2)
        assert testPubDateCheck2.year == datetime.utcnow().year
Ejemplo n.º 6
0
    def test_parseDelimitedEntry_custom_function_custom_type(self, mocker):
        mockParser = mocker.MagicMock()
        mockParser.return_value = {'tests': [1, 2, 3]}
        parsedData = SFRRecordManager.parseDelimitedEntry(
            '1|2|3', ['f1', 'f2', 'f3'],
            dType=mocker.MagicMock,
            dParser=mockParser)

        assert parsedData.tests == [1, 2, 3]
Ejemplo n.º 7
0
    def test_parseInstance(self, testInstance, testDCDWRecord, mocker):
        mockItemBuild = mocker.patch.object(SFRRecordManager, 'buildItems')
        mockNormalizeDates = mocker.patch.object(SFRRecordManager,
                                                 'normalizeDates')
        mockNormalizeDates.return_value = ['Date 1', 'Date 2']
        testWork = SFRRecordManager.createEmptyWorkRecord()
        testEdition = SFRRecordManager.createEmptyEditionRecord()

        testInstance.parseInstance(testWork, testEdition, testDCDWRecord)

        assert list(testWork['title'].elements()) == ['Test Title']
        assert list(
            testWork['alt_titles'].elements()) == ['Test Alt 1', 'Test Alt 2']
        assert list(testEdition['alt_titles'].elements()) == [
            'Test Alt 1', 'Test Alt 2'
        ]
        assert list(testWork['medium'].elements()) == ['testing']
        assert list(
            testWork['series_data'].elements()) == ['test ser|1|series']
        assert list(
            testEdition['volume_data'].elements()) == ['test vol|1|volume']
        assert list(testEdition['edition_data'].elements()) == ['testVersion']
        assert list(testWork['authors']) == ['Test Author']
        assert list(testEdition['publishers']) == ['Test Publisher']
        assert list(testEdition['publication_place'].elements()) == [
            'Test Publication Place'
        ]
        assert list(testEdition['contributors']) == ['Contrib 1|printer']
        assert list(testWork['contributors']) == ['Contrib 3|||translator']
        assert testWork['subjects'] == set(
            ['Subject 1', 'Subject 2', 'Subject 3'])
        assert testEdition['dates'] == set(['Date 1', 'Date 2'])
        assert testEdition['languages'] == set(['Language 1'])
        assert testWork['languages'] == set(['Language 1'])
        assert list(testEdition['summary'].elements()) == ['Test Abstract']
        assert list(
            testEdition['table_of_contents'].elements()) == ['Test TOC']
        assert list(testEdition['extent'].elements()) == ['Test Extent']
        assert testWork['measurements'] == set(['true|government_doc'])
        assert testEdition['measurements'] == set(['test|other'])
        assert testEdition['dcdw_uuids'] == ['testUUID']
        mockItemBuild.assert_called_once_with(testEdition, testDCDWRecord,
                                              set(['Contrib 2|||provider']))
        mockNormalizeDates.assert_called_once_with(['Date 1', 'Date 2'])
Ejemplo n.º 8
0
    def test_addWorkInstanceMetadata(self, testInstance, testDCDWRecord):
        testWork = SFRRecordManager.createEmptyWorkRecord()

        testInstance.addWorkInstanceMetadata(testWork, testDCDWRecord)

        assert list(testWork['title'].elements()) == ['Test Title']
        assert testWork['identifiers'] == set(['1|test', '2|isbn', '3|owi'])
        assert list(testWork['authors']) == ['Test Author']
        assert testWork['subjects'] == set(
            ['Subject 1', 'Subject 2', 'Subject 3'])
Ejemplo n.º 9
0
    def createWorkFromEditions(self, editions, instances):
        recordManager = SFRRecordManager(self.session, self.statics['iso639'])
        logger.debug('BUILDING WORK')
        workData = recordManager.buildWork(instances, editions)
        logger.debug('SAVING WORK')

        recordManager.saveWork(workData)

        logger.debug('MERGING RECORDS')
        deletedRecordUUIDs = recordManager.mergeRecords()

        return recordManager.work, deletedRecordUUIDs
Ejemplo n.º 10
0
    def test_setPipeDelimitedData(self, mocker):
        mockParse = mocker.patch.object(SFRRecordManager,
                                        'parseDelimitedEntry')
        mockParse.side_effect = [1, None, 2, None, 3]

        testParsedData = SFRRecordManager.setPipeDelimitedData(
            [1, 2, 3, 4, 5],
            'testFields',
            dType='testType',
            dParser='testFunction')

        assert testParsedData == [1, 2, 3]
        mockParse.assert_has_calls([
            mocker.call(1, 'testFields', 'testType', 'testFunction'),
            mocker.call(2, 'testFields', 'testType', 'testFunction'),
            mocker.call(3, 'testFields', 'testType', 'testFunction'),
            mocker.call(4, 'testFields', 'testType', 'testFunction'),
            mocker.call(5, 'testFields', 'testType', 'testFunction')
        ])
Ejemplo n.º 11
0
 def testInstance(self, mocker):
     mocker.patch('managers.sfrRecord.Work')
     return SFRRecordManager(mocker.MagicMock(), {'2b': {'ger': 'deu'}})
Ejemplo n.º 12
0
 def test_parseLinkFlags(self):
     assert (
         SFRRecordManager.parseLinkFlags({'flags': '{"testing": true}', 'key': 'value'})\
             ==\
         {'flags': {'testing': True}, 'key': 'value'}
     )
Ejemplo n.º 13
0
    def test_parseDelimitedEntry_no_function_no_type(self):
        parsedData = SFRRecordManager.parseDelimitedEntry(
            '1|2|3', ['f1', 'f2', 'f3'], None, None)

        assert parsedData == {'f1': '1', 'f2': '2', 'f3': '3'}