예제 #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.')]
예제 #2
0
    def get_book_name_id_test(self):
        """
        Test that get_book_name() returns the correct book when called with an id
        """
        # GIVEN: A dictionary of books with their id as the keys
        books = {1: 'Book 1', 2: 'Book 2', 3: 'Book 3'}

        # WHEN: Calling get_book_name() and the name is an integer represented as a string
        test_data = [['1', 'Book 1'], ['2', 'Book 2'], ['3', 'Book 3']]
        for name, expected_result in test_data:
            actual_result = CSVBible.get_book_name(name, books)

            # THEN: get_book_name() should return the book name associated with that id from the books dictionary
            self.assertEqual(actual_result, expected_result)
예제 #3
0
    def test_get_book_name(self):
        """
        Test that get_book_name() returns the name when called with a non integer value
        """
        # GIVEN: A dictionary of books with their id as the keys
        books = {1: 'Book 1', 2: 'Book 2', 3: 'Book 3'}

        # WHEN: Calling get_book_name() and the name is not an integer represented as a string
        test_data = [['Book 4', 'Book 4'], ['Book 5', 'Book 5'], ['Book 6', 'Book 6']]
        for name, expected_result in test_data:
            actual_result = CSVBible.get_book_name(name, books)

            # THEN: get_book_name() should return the input
            assert actual_result == expected_result
예제 #4
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