def test_lookupRecord_success(self, mockInsert, mockLookup): testUpdater = WorkImporter({'data': {}}, 'session', {}, {}) testAction = testUpdater.lookupRecord() self.assertEqual(testAction, 'insert') self.assertEqual(testUpdater.work, None) mockLookup.assert_called_once_with('session', [], None) mockInsert.assert_called_once()
def test_getIdentifier(self): testUpdater = WorkImporter({'data': {}}, 'session', {}, {}) testWork = MagicMock() testUUID = MagicMock() testUUID.hex = 'uuidString' testWork.uuid = testUUID testUpdater.work = testWork self.assertEqual(testUpdater.identifier, 'uuidString')
def test_lookupRecord_found(self, mockLookup): mockWork = MagicMock() mockLookup.return_value = mockWork mockUUID = MagicMock() mockUUID.hex = 'testUUID' mockWork.uuid = mockUUID testImporter = WorkImporter( {'data': {}}, 'session', defaultdict(list), defaultdict(list) ) testAction = testImporter.lookupRecord() self.assertEqual(testAction, 'update') mockLookup.assert_called_once_with('session', [], None) self.assertEqual(testImporter.kinesisMsgs['test'][0]['data']['primary_identifier']['identifier'], 'testUUID')
def test_insertRecord(self, mockQuery, insert, uuid, storeCovers, storeEpubs): mockSession = MagicMock() testImporter = WorkImporter( {'data': {}}, mockSession, defaultdict(list), defaultdict(list)) insert.return_value = ['epub1'] mockQuery.return_value = ['testQueryMessage'] testImporter.insertRecord() insert.assert_called_once() mockQuery.assert_called_once() storeCovers.assert_called_once() storeEpubs.assert_called_once_with(['epub1']) self.assertEqual( testImporter.sqsMsgs['testQueue'][0], 'testQueryMessage' ) mockSession.add.assert_called_once()
def test_WorkParseData_nonNested(self): outData = WorkImporter.parseData({ 'data': { 'field1': 'jerry', 'field2': 'hello' } }) self.assertEqual(outData, {'field1': 'jerry', 'field2': 'hello'})
def test_storeCovers_dictFlags(self): testImporter = WorkImporter( {'data': {}, 'source': 'test'}, 'session', defaultdict(list), defaultdict(list)) mockWork = MagicMock() mockUUID = MagicMock() mockUUID.hex = 'test_uuid' mockWork.uuid = mockUUID mockInstance = MagicMock() mockWork.instances = [mockInstance] mockLink = MagicMock() mockInstance.links = [mockLink] mockLink.flags = {'cover': True} mockLink.url = 'testing_url' testImporter.work = mockWork testImporter.storeCovers() self.assertEqual( testImporter.sqsMsgs['test_queue'][0]['url'], 'testing_url' )
def test_storeEpubs(self): testImporter = WorkImporter( {'data': {}}, 'session', defaultdict(list), defaultdict(list)) testImporter.storeEpubs(['epub1']) self.assertEqual(testImporter.kinesisMsgs['test_stream'][0]['data'], 'epub1')
def test_ImporterInit(self, mockParser): mockParser.return_value = 'data' testImporter = WorkImporter({}, 'session', {}, {}) self.assertEqual(testImporter.data, 'data') self.assertEqual(testImporter.session, 'session')