示例#1
0
    def process_books_test(self):
        """
        Test process books when it completes successfully
        """
        # GIVEN: An instance of CSVBible with the stop_import_flag set to False, and some sample 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='.',
                                booksfile='books.csv',
                                versefile='verse.csv')
            importer.find_and_create_book = MagicMock()
            importer.language_id = 10
            importer.stop_import_flag = False
            importer.wizard = MagicMock()

            books = [
                Book('1', '1', '1. Mosebog', '1Mos'),
                Book('2', '1', '2. Mosebog', '2Mos')
            ]

            # WHEN: Calling process_books
            result = importer.process_books(books)

            # THEN: translate and find_and_create_book should have been called with both book names.
            # 		The returned data should be a dictionary with both song's id and names.
            self.assertEqual(
                importer.find_and_create_book.mock_calls,
                [call('1. Mosebog', 2, 10),
                 call('2. Mosebog', 2, 10)])
            self.assertDictEqual(result, {1: '1. Mosebog', 2: '2. Mosebog'})
示例#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)
示例#3
0
    def test_process_books_stopped_import(self):
        """
        Test process books 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'))
            type(importer).application = PropertyMock()
            importer.stop_import_flag = True
            importer.wizard = MagicMock()

            # WHEN: Calling process_books
            result = importer.process_books(['Book 1'])

            # THEN: increment_progress_bar should not be called and the return value should be an empty dictionary
            assert importer.wizard.increment_progress_bar.called is False
            assert result == {}