def zefania_import_error_test(self):
        """
        Test that we give an error message if trying to import a zefania bible
        """
        # GIVEN: A mocked out "manager" and mocked out critical_error_message_box and an import
        with patch('openlp.plugins.bibles.lib.opensong.critical_error_message_box') as \
                mocked_critical_error_message_box:
            mocked_manager = MagicMock()
            importer = OpenSongBible(mocked_manager, path='.', name='.', filename='')

            # WHEN: An trying to import a zefania bible
            importer.filename = os.path.join(TEST_PATH, 'zefania-dk1933.xml')
            importer.do_import()

            # THEN: The importer should have "shown" an error message
            mocked_critical_error_message_box.assert_called_with(message='Incorrect Bible file type supplied. '
                                                                 'This looks like a Zefania XML bible, '
                                                                 'please use the Zefania import option.')
示例#2
0
    def zefania_import_error_test(self):
        """
        Test that we give an error message if trying to import a zefania bible
        """
        # GIVEN: A mocked out "manager" and mocked out critical_error_message_box and an import
        with patch('openlp.plugins.bibles.lib.opensong.critical_error_message_box') as \
                mocked_critical_error_message_box:
            mocked_manager = MagicMock()
            importer = OpenSongBible(mocked_manager,
                                     path='.',
                                     name='.',
                                     filename='')

            # WHEN: An trying to import a zefania bible
            importer.filename = os.path.join(TEST_PATH, 'zefania-dk1933.xml')
            importer.do_import()

            # THEN: The importer should have "shown" an error message
            mocked_critical_error_message_box.assert_called_with(
                message='Incorrect Bible file type supplied. '
                'This looks like a Zefania XML bible, '
                'please use the Zefania import option.')
示例#3
0
    def create_importer_test(self):
        """
        Test creating an instance of the OpenSong file importer
        """
        # GIVEN: A mocked out "manager"
        mocked_manager = MagicMock()

        # WHEN: An importer object is created
        importer = OpenSongBible(mocked_manager,
                                 path='.',
                                 name='.',
                                 filename='')

        # THEN: The importer should be an instance of BibleDB
        self.assertIsInstance(importer, BibleDB)
    def file_import_test(self):
        """
        Test the actual import of OpenSong 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.
        result_file = open(os.path.join(TEST_PATH, 'dk1933.json'), 'rb')
        test_data = json.loads(result_file.read().decode())
        bible_file = 'opensong-dk1933.xml'
        with patch('openlp.plugins.bibles.lib.opensong.OpenSongBible.application'):
            mocked_manager = MagicMock()
            mocked_import_wizard = MagicMock()
            importer = OpenSongBible(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 = 'Danish'

            # 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, int(verse_tag), verse_text)
示例#5
0
    def file_import_test(self):
        """
        Test the actual import of OpenSong 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.
        result_file = open(os.path.join(TEST_PATH, 'dk1933.json'), 'rb')
        test_data = json.loads(result_file.read().decode())
        bible_file = 'opensong-dk1933.xml'
        with patch(
                'openlp.plugins.bibles.lib.opensong.OpenSongBible.application'
        ):
            mocked_manager = MagicMock()
            mocked_import_wizard = MagicMock()
            importer = OpenSongBible(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 = 'Danish'

            # 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, int(verse_tag), verse_text)