def process_chapters_completes_test(self, mocked_parse_chapter_number):
        """
        Test process_chapters when it completes
        """
        # GIVEN: An instance of OpenSongBible
        importer = OpenSongBible(MagicMock(), path='.', name='.', filename='')
        importer.wizard = MagicMock()

        # WHEN: called with some valid data
        book = MagicMock()
        book.name = "Book"
        chapter1 = MagicMock()
        chapter1.attrib = {'n': '1'}
        chapter1.c = 'Chapter1'
        chapter1.v = ['Chapter1 Verses']
        chapter2 = MagicMock()
        chapter2.attrib = {'n': '2'}
        chapter2.c = 'Chapter2'
        chapter2.v = ['Chapter2 Verses']

        importer.process_verses = MagicMock()
        importer.stop_import_flag = False
        importer.process_chapters(book, [chapter1, chapter2])

        # THEN: parse_chapter_number, process_verses and increment_process_bar should have been called
        self.assertEqual(mocked_parse_chapter_number.call_args_list,
                         [call('1', 0), call('2', 1)])
        self.assertEqual(importer.process_verses.call_args_list, [
            call(book, 1, ['Chapter1 Verses']),
            call(book, 2, ['Chapter2 Verses'])
        ])
        self.assertEqual(
            importer.wizard.increment_progress_bar.call_args_list,
            [call('Importing Book 1...'),
             call('Importing Book 2...')])
    def process_books_completes_test(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='.',
                                     filename='')

            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
            self.assertEqual(self.mocked_find_and_create_book.call_args_list,
                             [call('Name1', 2, 10),
                              call('Name2', 2, 10)])
            self.assertEqual(
                mocked_process_chapters.call_args_list,
                [call('db_book1', 'Chapter1'),
                 call('db_book2', 'Chapter2')])
            self.assertEqual(importer.session.commit.call_count, 2)
    def process_verses_completes_test(self):
        """
        Test process_verses when it completes
        """
        with patch('openlp.plugins.bibles.lib.importers.opensong.get_text',
                   **{'side_effect': ['Verse1 Text', 'Verse2 Text']}) as mocked_get_text, \
                patch.object(OpenSongBible, 'parse_verse_number',
                             **{'side_effect': [1, 2]}) as mocked_parse_verse_number:
            # GIVEN: An instance of OpenSongBible
            importer = OpenSongBible(MagicMock(),
                                     path='.',
                                     name='.',
                                     filename='')
            importer.wizard = MagicMock()

            # WHEN: called with some valid data
            book = MagicMock()
            book.id = 1
            verse1 = MagicMock()
            verse1.attrib = {'n': '1'}
            verse1.c = 'Chapter1'
            verse1.v = ['Chapter1 Verses']
            verse2 = MagicMock()
            verse2.attrib = {'n': '2'}
            verse2.c = 'Chapter2'
            verse2.v = ['Chapter2 Verses']

            importer.create_verse = MagicMock()
            importer.stop_import_flag = False
            importer.process_verses(book, 1, [verse1, verse2])

            # THEN: parse_chapter_number, process_verses and increment_process_bar should have been called
            self.assertEqual(mocked_parse_verse_number.call_args_list,
                             [call('1', 0), call('2', 1)])
            self.assertEqual(mocked_get_text.call_args_list,
                             [call(verse1), call(verse2)])
            self.assertEqual(
                importer.create_verse.call_args_list,
                [call(1, 1, 1, 'Verse1 Text'),
                 call(1, 1, 2, 'Verse2 Text')])