Ejemplo n.º 1
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.')]
Ejemplo n.º 2
0
    def do_import_success_test(self):
        """
        Test do_import when the import succeeds
        """
        # GIVEN: An instance of CSVBible
        mocked_manager = MagicMock()
        with patch('openlp.plugins.bibles.lib.db.BibleDB._setup'):
            importer = CSVBible(mocked_manager,
                                path='.',
                                name='.',
                                booksfile='books.csv',
                                versefile='verses.csv')
            importer.get_language = MagicMock(return_value=10)
            importer.parse_csv_file = MagicMock(
                side_effect=[['Book 1'], ['Verse 1']])
            importer.process_books = MagicMock(return_value=['Book 1'])
            importer.process_verses = MagicMock(return_value=['Verse 1'])
            importer.session = MagicMock()
            importer.stop_import_flag = False
            importer.wizard = MagicMock()

            # WHEN: Calling do_import
            result = importer.do_import('Bible Name')

            # THEN: parse_csv_file should be called twice,
            # and True should be returned.
            self.assertEqual(
                importer.parse_csv_file.mock_calls,
                [call('books.csv', Book),
                 call('verses.csv', Verse)])
            importer.process_books.assert_called_once_with(['Book 1'])
            importer.process_verses.assert_called_once_with(['Verse 1'],
                                                            ['Book 1'])
            self.assertTrue(result)
Ejemplo n.º 3
0
    def test_process_verses_stopped_import(self):
        """
        Test process_verses when the import is stopped
        """
        # GIVEN: An instance of CSVBible with the stop_import_flag set to True
        mocked_manager = MagicMock()
        with patch('openlp.plugins.bibles.lib.db.BibleDB._setup'):
            importer = CSVBible(mocked_manager, path='.', name='.', books_path=Path('books.csv'),
                                verse_path=Path('verse.csv'))
            importer.get_book_name = MagicMock()
            importer.session = MagicMock()
            importer.stop_import_flag = True
            importer.wizard = MagicMock()

            # WHEN: Calling process_verses
            result = importer.process_verses(['Dummy Verse'], [])

            # THEN: get_book_name should not be called and the return value should be None
            assert importer.get_book_name.called is False
            assert result is None