def test_build_instance(self): testInstanceRow = { 'title': 'Instance Test', 'language': 'en', 'copyright_date': '2019', 'publisher_pub_date': 'New York [2019]', 'pub_place': 'nyu' } instanceTest = HathiRecord(testInstanceRow) instanceTest.parseIdentifiers = MagicMock() instanceTest.parsePubInfo = MagicMock() instanceTest.parsePubPlace = MagicMock() instanceTest.buildInstance({}) self.assertIsInstance(instanceTest.instance, InstanceRecord) self.assertEqual(instanceTest.instance.language, 'en') self.assertEqual(instanceTest.instance.title, 'Instance Test')
def test_build_instance_no_cover(self, mockCover): testInstanceRow = { 'htid': 'test.1', 'title': 'Instance Test', 'language': 'en', 'copyright_date': '2019', 'publisher_pub_date': 'New York [2019]', 'pub_place': 'nyu', 'description': 'testing' } instanceTest = HathiRecord(testInstanceRow) instanceTest.parseIdentifiers = MagicMock() instanceTest.parsePubInfo = MagicMock() instanceTest.parsePubPlace = MagicMock() instanceTest.buildInstance({}) mockCover.assert_called_once_with() self.assertIsInstance(instanceTest.instance, InstanceRecord) self.assertEqual(instanceTest.instance.language, 'en') self.assertEqual(instanceTest.instance.title, 'Instance Test')
def test_build_instance_cover(self, mockAddItem, mockCover): testInstanceRow = { 'htid': 'test.1', 'title': 'Instance Test', 'language': 'en', 'copyright_date': '2019', 'publisher_pub_date': 'New York [2019]', 'pub_place': 'nyu', 'description': 'testing' } instanceTest = HathiRecord(testInstanceRow) instanceTest.parseIdentifiers = MagicMock() instanceTest.parsePubInfo = MagicMock() instanceTest.parsePubPlace = MagicMock() instanceTest.buildInstance({}) mockCover.assert_called_once() mockAddItem.assert_has_calls([ call( 'dates', Date, **{ 'display_date': '2019', 'date_range': '2019', 'date_type': 'copyright_date' }), call( 'links', Link, **{ 'url': 'test_url', 'media_type': 'image/jpeg', 'flags': { 'cover': True, 'temporary': True } }) ]) self.assertIsInstance(instanceTest.instance, InstanceRecord) self.assertEqual(instanceTest.instance.language, 'en')
def test_build_data_model(self): testRow = { 'title': 'Work Test', 'description': '1st of 4', 'bib_key': '0000000', 'htid': 'test.000000000', 'gov_doc': 'f', 'author': 'Author, Test', 'copyright_date': '2019', 'rights': 'test_rights' } workTest = HathiRecord(testRow) workTest.buildWork = MagicMock() workTest.buildInstance = MagicMock() workTest.buildItem = MagicMock() workTest.createRights = MagicMock() workTest.buildDataModel('countryCodes') self.assertIsInstance(workTest, HathiRecord)