예제 #1
0
    def test_file_import(self):
        """
        Test the actual import of CSV Bible file
        """
        # 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')
        books_file = TEST_PATH / 'dk1933-books.csv'
        verses_file = TEST_PATH / 'dk1933-verses.csv'
        with patch('openlp.plugins.bibles.lib.importers.csvbible.CSVBible.application'):
            mocked_manager = MagicMock()
            mocked_import_wizard = MagicMock()
            importer = CSVBible(mocked_manager, path='.', name='.', books_path=books_file, verse_path=verses_file)
            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'
            importer.get_book = MagicMock()

            # WHEN: Importing 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.get_book().id, 1, verse_tag, verse_text)
            importer.create_book.assert_any_call('1. Mosebog', importer.get_book_ref_id_by_name(), 1)
            importer.create_book.assert_any_call('1. Krønikebog', importer.get_book_ref_id_by_name(), 1)
예제 #2
0
    def test_process_verses_successful(self):
        """
        Test process_verses when the import is successful
        """
        # GIVEN: An instance of CSVBible with the application and wizard attributes mocked out, and some test data.
        mocked_manager = MagicMock()
        with patch('openlp.plugins.bibles.lib.db.BibleDB._setup'),\
                patch('openlp.plugins.bibles.lib.importers.csvbible.translate'):
            importer = CSVBible(mocked_manager, path='.', name='.', books_path=Path('books.csv'),
                                verse_path=Path('verse.csv'))
            importer.create_verse = MagicMock()
            importer.get_book = MagicMock(return_value=Book('1', '1', '1. Mosebog', '1Mos'))
            importer.get_book_name = MagicMock(return_value='1. Mosebog')
            importer.session = MagicMock()
            importer.stop_import_flag = False
            importer.wizard = MagicMock()
            verses = [Verse(1, 1, 1, 'I Begyndelsen skabte Gud Himmelen og Jorden.'),
                      Verse(1, 1, 2, 'Og Jorden var øde og tom, og der var Mørke over Verdensdybet. '
                                     'Men Guds Ånd svævede over Vandene.')]
            books = {1: '1. Mosebog'}

            # WHEN: Calling process_verses
            importer.process_verses(verses, books)

            # THEN: create_verse is called with the test data
            assert importer.get_book_name.mock_calls == [call(1, books), call(1, books)]
            importer.get_book.assert_called_once_with('1. Mosebog')
            assert importer.session.commit.call_count == 2
            assert importer.create_verse.mock_calls == \
                [call('1', 1, 1, 'I Begyndelsen skabte Gud Himmelen og Jorden.'),
                 call('1', 1, 2, 'Og Jorden var øde og tom, og der var Mørke over Verdensdybet. '
                                 'Men Guds Ånd svævede over Vandene.')]