def test_process_books_completes(self): """ Test process_books when it processes all books """ # GIVEN: An instance of OpenSongBible Importer and two mocked books self.mocked_find_and_create_book.side_effect = ['db_book1', 'db_book2'] with patch.object(OpenSongBible, 'process_chapters') as mocked_process_chapters: importer = OpenSongBible(MagicMock(), path='.', name='.', file_path=None) book1 = MagicMock() book1.attrib = {'n': 'Name1'} book1.c = 'Chapter1' book2 = MagicMock() book2.attrib = {'n': 'Name2'} book2.c = 'Chapter2' importer.language_id = 10 importer.session = MagicMock() importer.stop_import_flag = False # WHEN: Calling process_books with the two books importer.process_books([book1, book2]) # THEN: find_and_create_book and process_books should be called with the details from the mocked books assert self.mocked_find_and_create_book.call_args_list == [ call('Name1', 2, 10), call('Name2', 2, 10) ] assert mocked_process_chapters.call_args_list == \ [call('db_book1', 'Chapter1'), call('db_book2', 'Chapter2')] assert importer.session.commit.call_count == 2
def process_books_stop_import_test(self): """ Test process_books when stop_import is set to True """ # GIVEN: An instance of OpenSongBible importer = OpenSongBible(MagicMock(), path='.', name='.', filename='') # WHEN: stop_import_flag is set to True importer.stop_import_flag = True importer.process_books(['Book']) # THEN: find_and_create_book should not have been called self.assertFalse(self.mocked_find_and_create_book.called)