Ejemplo n.º 1
0
    def test_file_import_empty_verse_tags(self):
        """
        Test the actual import of OSIS Bible file, with an empty verse tags.
        """
        # GIVEN: Test files with a mocked out "manager", "import_wizard", and mocked functions
        #        get_book_ref_id_by_name, create_verse, create_book, session and get_language.
        test_data = load_external_result_data(TEST_PATH / 'dk1933.json')
        bible_file = 'osis-dk1933-empty-verse.xml'
        with patch(
                'openlp.plugins.bibles.lib.importers.osis.OSISBible.application'
        ):
            mocked_manager = MagicMock()
            mocked_import_wizard = MagicMock()
            importer = OSISBible(mocked_manager,
                                 path='.',
                                 name='.',
                                 file_path=None)
            importer.wizard = mocked_import_wizard
            importer.get_book_ref_id_by_name = MagicMock()
            importer.create_verse = MagicMock()
            importer.create_book = MagicMock()
            importer.session = MagicMock()
            importer.get_language = MagicMock()
            importer.get_language.return_value = 'Danish'

            # WHEN: Importing bible file
            importer.file_path = TEST_PATH / bible_file
            importer.do_import()

            # THEN: The create_verse() method should have been called with each verse in the file.
            assert importer.create_verse.called is True
            for verse_tag, verse_text in test_data['verses']:
                importer.create_verse.assert_any_call(
                    importer.create_book().id, 1, verse_tag, verse_text)
Ejemplo n.º 2
0
    def test_process_books_completes(self):
        """
        Test process_books when it processes all books
        """
        # GIVEN: An instance of OSISBible Importer and two mocked books
        self.mocked_find_and_create_book.side_effect = ['db_book1', 'db_book2']
        with patch.object(OSISBible,
                          'process_chapters') as mocked_process_chapters:
            importer = OSISBible(MagicMock(),
                                 path='.',
                                 name='.',
                                 file_path=None)

            book1 = MagicMock()
            book1.get.return_value = 'Name1'
            book2 = MagicMock()
            book2.get.return_value = 'Name2'
            mocked_data = MagicMock(**{'xpath.return_value': [book1, book2]})
            importer.language_id = 10
            importer.session = MagicMock()
            importer.stop_import_flag = False

            # WHEN: Calling process_books with the two books
            importer.process_books(mocked_data)

            # 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', book1),
                call('db_book2', book2)
            ]
            assert importer.session.commit.call_count == 2
Ejemplo n.º 3
0
    def test_file_import_milestone_tags(self):
        """
        Test the actual import of OSIS Bible file, with milestone chapter and verse tags.
        """
        # GIVEN: Test files with a mocked out "manager", "import_wizard", and mocked functions
        #        get_book_ref_id_by_name, create_verse, create_book, session and get_language.
        result_file = open(os.path.join(TEST_PATH, 'web.json'), 'rb')
        test_data = json.loads(result_file.read().decode())
        bible_file = 'osis-web.xml'
        with patch(
                'openlp.plugins.bibles.lib.importers.osis.OSISBible.application'
        ):
            mocked_manager = MagicMock()
            mocked_import_wizard = MagicMock()
            importer = OSISBible(mocked_manager,
                                 path='.',
                                 name='.',
                                 filename='')
            importer.wizard = mocked_import_wizard
            importer.get_book_ref_id_by_name = MagicMock()
            importer.create_verse = MagicMock()
            importer.create_book = MagicMock()
            importer.session = MagicMock()
            importer.get_language = MagicMock()
            importer.get_language.return_value = 'English'

            # WHEN: Importing bible file
            importer.filename = os.path.join(TEST_PATH, bible_file)
            importer.do_import()

            # THEN: The create_verse() method should have been called with each verse in the file.
            self.assertTrue(importer.create_verse.called)
            for verse_tag, verse_text in test_data['verses']:
                importer.create_verse.assert_any_call(
                    importer.create_book().id, 1, verse_tag, verse_text)