コード例 #1
0
    def test_code_page_to_encoding(self):
        """
        Test the :mod:`do_import` converts the code page to the encoding correctly
        """
        # GIVEN: A mocked out SongImport class, a mocked out "manager"
        with patch('openlp.plugins.songs.lib.importers.easyworship.SongImport'), \
            patch('openlp.plugins.songs.lib.importers.easyworship.os.path') as mocked_os_path, \
            patch('builtins.open'), patch('openlp.plugins.songs.lib.importers.easyworship.struct') as mocked_struct, \
                patch('openlp.plugins.songs.lib.importers.easyworship.retrieve_windows_encoding') as \
                mocked_retrieve_windows_encoding:
            mocked_manager = MagicMock()
            importer = EasyWorshipSongImport(mocked_manager, filenames=[])
            mocked_os_path.isfile.return_value = True
            mocked_os_path.getsize.return_value = 0x800
            importer.import_source = 'Songs.DB'

            # WHEN: Unpacking the code page
            for code_page, encoding in CODE_PAGE_MAPPINGS:
                struct_unpack_return_values = [(0, 0x800, 2, 0, 0), (code_page, )]
                mocked_struct.unpack.side_effect = struct_unpack_return_values
                mocked_retrieve_windows_encoding.return_value = False

                # THEN: do_import should return None having called retrieve_windows_encoding with the correct encoding.
                self.assertIsNone(importer.do_import(), 'do_import should return None when db_size is less than 0x800')
                mocked_retrieve_windows_encoding.assert_any_call(encoding)
コード例 #2
0
ファイル: test_ewimport.py プロジェクト: crossroadchurch/paul
    def do_import_memo_validty_test(self):
        """
        Test the :mod:`do_import` module handles invalid memo files correctly
        """
        # GIVEN: A mocked out SongImport class, a mocked out "manager"
        with patch('openlp.plugins.songs.lib.importers.easyworship.SongImport'), \
            patch('openlp.plugins.songs.lib.importers.easyworship.os.path') as mocked_os_path, \
            patch('builtins.open') as mocked_open, \
                patch('openlp.plugins.songs.lib.importers.easyworship.struct') as mocked_struct:
            mocked_manager = MagicMock()
            importer = EasyWorshipSongImport(mocked_manager, filenames=[])
            mocked_os_path.isfile.return_value = True
            mocked_os_path.getsize.return_value = 0x800
            importer.import_source = 'Songs.DB'

            # WHEN: Unpacking first 35 bytes of Memo file
            struct_unpack_return_values = [(0, 0x700, 2, 0, 0), (0, 0x800, 0, 0, 0), (0, 0x800, 5, 0, 0)]
            mocked_struct.unpack.side_effect = struct_unpack_return_values

            # THEN: do_import should return None having called closed the open files db and memo files.
            for effect in struct_unpack_return_values:
                self.assertIsNone(importer.do_import(), 'do_import should return None when db_size is less than 0x800')
                self.assertEqual(mocked_open().close.call_count, 2,
                                 'The open db and memo files should have been closed')
                mocked_open().close.reset_mock()
                self.assertIs(mocked_open().seek.called, False, 'db_file.seek should not have been called.')
コード例 #3
0
    def test_do_import_memo_validty(self):
        """
        Test the :mod:`do_import` module handles invalid memo files correctly
        """
        # GIVEN: A mocked out SongImport class, a mocked out "manager"
        with patch('openlp.plugins.songs.lib.importers.easyworship.SongImport'), \
            patch('openlp.plugins.songs.lib.importers.easyworship.os.path') as mocked_os_path, \
            patch('builtins.open') as mocked_open, \
                patch('openlp.plugins.songs.lib.importers.easyworship.struct') as mocked_struct:
            mocked_manager = MagicMock()
            importer = EasyWorshipSongImport(mocked_manager, filenames=[])
            mocked_os_path.isfile.return_value = True
            mocked_os_path.getsize.return_value = 0x800
            importer.import_source = 'Songs.DB'

            # WHEN: Unpacking first 35 bytes of Memo file
            struct_unpack_return_values = [(0, 0x700, 2, 0, 0), (0, 0x800, 0, 0, 0), (0, 0x800, 5, 0, 0)]
            mocked_struct.unpack.side_effect = struct_unpack_return_values

            # THEN: do_import should return None having called closed the open files db and memo files.
            for effect in struct_unpack_return_values:
                self.assertIsNone(importer.do_import(), 'do_import should return None when db_size is less than 0x800')
                self.assertEqual(mocked_open().close.call_count, 2,
                                 'The open db and memo files should have been closed')
                mocked_open().close.reset_mock()
                self.assertIs(mocked_open().seek.called, False, 'db_file.seek should not have been called.')
コード例 #4
0
ファイル: test_ewimport.py プロジェクト: crossroadchurch/paul
    def code_page_to_encoding_test(self):
        """
        Test the :mod:`do_import` converts the code page to the encoding correctly
        """
        # GIVEN: A mocked out SongImport class, a mocked out "manager"
        with patch('openlp.plugins.songs.lib.importers.easyworship.SongImport'), \
            patch('openlp.plugins.songs.lib.importers.easyworship.os.path') as mocked_os_path, \
            patch('builtins.open'), patch('openlp.plugins.songs.lib.importers.easyworship.struct') as mocked_struct, \
                patch('openlp.plugins.songs.lib.importers.easyworship.retrieve_windows_encoding') as \
                mocked_retrieve_windows_encoding:
            mocked_manager = MagicMock()
            importer = EasyWorshipSongImport(mocked_manager, filenames=[])
            mocked_os_path.isfile.return_value = True
            mocked_os_path.getsize.return_value = 0x800
            importer.import_source = 'Songs.DB'

            # WHEN: Unpacking the code page
            for code_page, encoding in CODE_PAGE_MAPPINGS:
                struct_unpack_return_values = [(0, 0x800, 2, 0, 0), (code_page, )]
                mocked_struct.unpack.side_effect = struct_unpack_return_values
                mocked_retrieve_windows_encoding.return_value = False

                # THEN: do_import should return None having called retrieve_windows_encoding with the correct encoding.
                self.assertIsNone(importer.do_import(), 'do_import should return None when db_size is less than 0x800')
                mocked_retrieve_windows_encoding.assert_call(encoding)
コード例 #5
0
ファイル: test_ewimport.py プロジェクト: simhnna/openlp
    def test_do_import_memo_validty(self, mocked_struct, mocked_open,
                                    mocked_stat, mocked_is_file,
                                    MockSongImport):
        """
        Test the :mod:`do_import` module handles invalid memo files correctly
        """
        # GIVEN: A mocked out SongImport class, a mocked out "manager"
        mocked_manager = MagicMock()
        importer = EasyWorshipSongImport(mocked_manager, file_paths=[])
        importer.import_source = 'Songs.DB'

        # WHEN: Unpacking first 35 bytes of Memo file
        struct_unpack_return_values = [(0, 0x700, 2, 0, 0),
                                       (0, 0x800, 0, 0, 0),
                                       (0, 0x800, 5, 0, 0)]
        mocked_struct.unpack.side_effect = struct_unpack_return_values

        # THEN: do_import should return None having called closed the open files db and memo files.
        for effect in struct_unpack_return_values:
            assert importer.do_import(
            ) is None, 'do_import should return None when db_size is less than 0x800'
            assert mocked_open(
            ).close.call_count == 2, 'The open db and memo files should have been closed'
            mocked_open().close.reset_mock()
            assert mocked_open(
            ).seek.called is False, 'db_file.seek should not have been called.'
コード例 #6
0
    def test_do_import_database_validity(self, mocked_stat, mocked_is_file, MockSongImport):
        """
        Test the :mod:`do_import` module handles invalid database files correctly
        """
        # GIVEN: A mocked out SongImport class, os.path and a mocked out "manager"
        mocked_manager = MagicMock()
        importer = EasyWorshipSongImport(mocked_manager, file_paths=[])
        importer.import_source = 'Songs.DB'

        # WHEN: DB file size is less than 0x800
        mocked_stat.return_value.st_size = 0x7FF

        # THEN: do_import should return None having called Path.stat()
        assert importer.do_import() is None, 'do_import should return None when db_size is less than 0x800'
        mocked_stat.assert_called_once_with()
コード例 #7
0
    def test_find_non_existing_field(self):
        """
        Test finding an non-existing field in a given list using the :mod:`db_find_field`
        """
        # GIVEN: A mocked out SongImport class, a mocked out "manager" and a list of field descriptions
        with patch('openlp.plugins.songs.lib.importers.easyworship.SongImport'):
            mocked_manager = MagicMock()
            importer = EasyWorshipSongImport(mocked_manager, file_paths=[])
            importer.field_descriptions = TEST_FIELD_DESCS

            # WHEN: Called with a field name that does not exist
            non_existing_fields = ['BK Gradient Shading', 'BK Gradient Variant', 'Favorite', 'Copyright']
            for field_name in non_existing_fields:

                # THEN: The importer object should not be None
                self.assertRaises(IndexError, importer.db_find_field, field_name)
コード例 #8
0
ファイル: test_ewimport.py プロジェクト: crossroadchurch/paul
    def find_non_existing_field_test(self):
        """
        Test finding an non-existing field in a given list using the :mod:`find_field`
        """
        # GIVEN: A mocked out SongImport class, a mocked out "manager" and a list of field descriptions
        with patch('openlp.plugins.songs.lib.importers.easyworship.SongImport'):
            mocked_manager = MagicMock()
            importer = EasyWorshipSongImport(mocked_manager, filenames=[])
            importer.field_descriptions = TEST_FIELD_DESCS

            # WHEN: Called with a field name that does not exist
            non_existing_fields = ['BK Gradient Shading', 'BK Gradient Variant', 'Favorite', 'Copyright']
            for field_name in non_existing_fields:

                # THEN: The importer object should not be None
                self.assertRaises(IndexError, importer.find_field, field_name)
コード例 #9
0
    def test_find_field_exists(self):
        """
        Test finding an existing field in a given list using the :mod:`db_find_field`
        """
        # GIVEN: A mocked out SongImport class, a mocked out "manager" and a list of field descriptions.
        with patch('openlp.plugins.songs.lib.importers.easyworship.SongImport'):
            mocked_manager = MagicMock()
            importer = EasyWorshipSongImport(mocked_manager, file_paths=[])
            importer.field_descriptions = TEST_FIELD_DESCS

            # WHEN: Called with a field name that exists
            existing_fields = ['Title', 'Text Percentage Bottom', 'RecID', 'Default Background', 'Words',
                               'BK Bitmap', 'Last Modified']
            for field_name in existing_fields:

                # THEN: The item corresponding the index returned should have the same name attribute
                assert importer.field_descriptions[importer.db_find_field(field_name)].name == field_name
コード例 #10
0
    def test_do_import_source_invalid(self, mocked_is_file, MockSongImport):
        """
        Test the :mod:`do_import` module produces an error when Songs.MB not found.
        """
        # GIVEN: A mocked out SongImport class, a mocked out "manager"
        mocked_manager = MagicMock()
        importer = EasyWorshipSongImport(mocked_manager, file_paths=[])
        with patch.object(importer, 'log_error') as mocked_log_error:

            # WHEN: do_import is supplied with an import source (Songs.MB missing)
            importer.import_source = 'Songs.DB'
            importer.do_import()

            # THEN: do_import should have logged an error that the Songs.MB file could not be found.
            mocked_log_error.assert_any_call(importer.import_source,
                                             'Could not find the "Songs.MB" file. It must be in the same folder as '
                                             'the "Songs.DB" file.')
コード例 #11
0
ファイル: test_ewimport.py プロジェクト: crossroadchurch/paul
    def find_field_exists_test(self):
        """
        Test finding an existing field in a given list using the :mod:`find_field`
        """
        # GIVEN: A mocked out SongImport class, a mocked out "manager" and a list of field descriptions.
        with patch('openlp.plugins.songs.lib.importers.easyworship.SongImport'):
            mocked_manager = MagicMock()
            importer = EasyWorshipSongImport(mocked_manager, filenames=[])
            importer.field_descriptions = TEST_FIELD_DESCS

            # WHEN: Called with a field name that exists
            existing_fields = ['Title', 'Text Percentage Bottom', 'RecID', 'Default Background', 'Words',
                               'BK Bitmap', 'Last Modified']
            for field_name in existing_fields:

                # THEN: The item corresponding the index returned should have the same name attribute
                self.assertEqual(importer.field_descriptions[importer.find_field(field_name)].name, field_name)
コード例 #12
0
    def test_get_memo_field(self, MockSongImport):
        """
        Test the :mod:`db_get_field` module
        """
        for test_results in GET_MEMO_FIELD_TEST_RESULTS:
            # GIVEN: A mocked out SongImport class, a mocked out "manager", a mocked out memo_file and an encoding
            mocked_manager = MagicMock()
            mocked_memo_file = MagicMock()
            importer = EasyWorshipSongImport(mocked_manager, file_paths=[])
            importer.memo_file = mocked_memo_file
            importer.encoding = TEST_DATA_ENCODING

            # WHEN: Supplied with test fields and test field descriptions
            importer.fields = TEST_FIELDS
            importer.field_descriptions = TEST_FIELD_DESCS
            field_index = test_results[0]
            mocked_memo_file.read.return_value = test_results[1]
            get_field_result = test_results[2]['return']
            get_field_read_calls = test_results[2]['read']
            get_field_seek_calls = test_results[2]['seek']

            # THEN: db_get_field should return the appropriate value with the appropriate mocked objects being
            # called
            assert importer.db_get_field(field_index) == get_field_result
            for call in get_field_read_calls:
                mocked_memo_file.read.assert_any_call(call)
            for call in get_field_seek_calls:
                if isinstance(call, int):
                    mocked_memo_file.seek.assert_any_call(call)
                else:
                    mocked_memo_file.seek.assert_any_call(call[0], call[1])
コード例 #13
0
    def test_get_memo_field(self):
        """
        Test the :mod:`get_field` module
        """
        for test_results in GET_MEMO_FIELD_TEST_RESULTS:
            # GIVEN: A mocked out SongImport class, a mocked out "manager", a mocked out memo_file and an encoding
            with patch('openlp.plugins.songs.lib.importers.easyworship.SongImport'):
                mocked_manager = MagicMock()
                mocked_memo_file = MagicMock()
                importer = EasyWorshipSongImport(mocked_manager, filenames=[])
                importer.memo_file = mocked_memo_file
                importer.encoding = TEST_DATA_ENCODING

                # WHEN: Supplied with test fields and test field descriptions
                importer.fields = TEST_FIELDS
                importer.field_descriptions = TEST_FIELD_DESCS
                field_index = test_results[0]
                mocked_memo_file.read.return_value = test_results[1]
                get_field_result = test_results[2]['return']
                get_field_read_calls = test_results[2]['read']
                get_field_seek_calls = test_results[2]['seek']

                # THEN: get_field should return the appropriate value with the appropriate mocked objects being called
                self.assertEqual(importer.get_field(field_index), get_field_result)
                for call in get_field_read_calls:
                    mocked_memo_file.read.assert_any_call(call)
                for call in get_field_seek_calls:
                    if isinstance(call, int):
                        mocked_memo_file.seek.assert_any_call(call)
                    else:
                        mocked_memo_file.seek.assert_any_call(call[0], call[1])
コード例 #14
0
    def test_do_import_database_validity(self):
        """
        Test the :mod:`do_import` module handles invalid database files correctly
        """
        # GIVEN: A mocked out SongImport class, os.path and a mocked out "manager"
        with patch('openlp.plugins.songs.lib.importers.easyworship.SongImport'), \
                patch('openlp.plugins.songs.lib.importers.easyworship.os.path') as mocked_os_path:
            mocked_manager = MagicMock()
            importer = EasyWorshipSongImport(mocked_manager, filenames=[])
            mocked_os_path.isfile.return_value = True
            importer.import_source = 'Songs.DB'

            # WHEN: DB file size is less than 0x800
            mocked_os_path.getsize.return_value = 0x7FF

            # THEN: do_import should return None having called os.path.isfile
            self.assertIsNone(importer.do_import(), 'do_import should return None when db_size is less than 0x800')
            mocked_os_path.getsize.assert_any_call('Songs.DB')
コード例 #15
0
ファイル: test_ewimport.py プロジェクト: crossroadchurch/paul
    def set_record_struct_test(self):
        """
        Test the :mod:`set_record_struct` module
        """
        # GIVEN: A mocked out SongImport class, a mocked out struct class, and a mocked out "manager" and a list of
        #       field descriptions
        with patch('openlp.plugins.songs.lib.importers.easyworship.SongImport'), \
                patch('openlp.plugins.songs.lib.importers.easyworship.struct') as mocked_struct:
            mocked_manager = MagicMock()
            importer = EasyWorshipSongImport(mocked_manager, filenames=[])

            # WHEN: set_record_struct is called with a list of field descriptions
            return_value = importer.set_record_struct(TEST_FIELD_DESCS)

            # THEN: set_record_struct should return None and Struct should be called with a value representing
            #       the list of field descriptions
            self.assertIsNone(return_value, 'set_record_struct should return None')
            mocked_struct.Struct.assert_called_with('>50sHIB250s250s10sQ')
コード例 #16
0
ファイル: test_ewimport.py プロジェクト: crossroadchurch/paul
    def do_import_source_test(self):
        """
        Test the :mod:`do_import` module opens the correct files
        """
        # GIVEN: A mocked out SongImport class, a mocked out "manager"
        with patch('openlp.plugins.songs.lib.importers.easyworship.SongImport'), \
                patch('openlp.plugins.songs.lib.importers.easyworship.os.path') as mocked_os_path:
            mocked_manager = MagicMock()
            importer = EasyWorshipSongImport(mocked_manager, filenames=[])
            mocked_os_path.isfile.side_effect = [True, False]

            # WHEN: Supplied with an import source
            importer.import_source = 'Songs.DB'

            # THEN: do_import should return None having called os.path.isfile
            self.assertIsNone(importer.do_import(), 'do_import should return None')
            mocked_os_path.isfile.assert_any_call('Songs.DB')
            mocked_os_path.isfile.assert_any_call('Songs.MB')
コード例 #17
0
ファイル: test_ewimport.py プロジェクト: crossroadchurch/paul
    def do_import_database_validity_test(self):
        """
        Test the :mod:`do_import` module handles invalid database files correctly
        """
        # GIVEN: A mocked out SongImport class, os.path and a mocked out "manager"
        with patch('openlp.plugins.songs.lib.importers.easyworship.SongImport'), \
                patch('openlp.plugins.songs.lib.importers.easyworship.os.path') as mocked_os_path:
            mocked_manager = MagicMock()
            importer = EasyWorshipSongImport(mocked_manager, filenames=[])
            mocked_os_path.isfile.return_value = True
            importer.import_source = 'Songs.DB'

            # WHEN: DB file size is less than 0x800
            mocked_os_path.getsize.return_value = 0x7FF

            # THEN: do_import should return None having called os.path.isfile
            self.assertIsNone(importer.do_import(), 'do_import should return None when db_size is less than 0x800')
            mocked_os_path.getsize.assert_any_call('Songs.DB')
コード例 #18
0
    def test_do_import_source(self):
        """
        Test the :mod:`do_import` module opens the correct files
        """
        # GIVEN: A mocked out SongImport class, a mocked out "manager"
        with patch('openlp.plugins.songs.lib.importers.easyworship.SongImport'), \
                patch('openlp.plugins.songs.lib.importers.easyworship.os.path') as mocked_os_path:
            mocked_manager = MagicMock()
            importer = EasyWorshipSongImport(mocked_manager, filenames=[])
            mocked_os_path.isfile.side_effect = [True, False]

            # WHEN: Supplied with an import source
            importer.import_source = 'Songs.DB'

            # THEN: do_import should return None having called os.path.isfile
            self.assertIsNone(importer.do_import(), 'do_import should return None')
            mocked_os_path.isfile.assert_any_call('Songs.DB')
            mocked_os_path.isfile.assert_any_call('Songs.MB')
コード例 #19
0
    def test_set_record_struct(self):
        """
        Test the :mod:`db_set_record_struct` module
        """
        # GIVEN: A mocked out SongImport class, a mocked out struct class, and a mocked out "manager" and a list of
        #       field descriptions
        with patch('openlp.plugins.songs.lib.importers.easyworship.SongImport'), \
                patch('openlp.plugins.songs.lib.importers.easyworship.struct') as mocked_struct:
            mocked_manager = MagicMock()
            importer = EasyWorshipSongImport(mocked_manager, file_paths=[])

            # WHEN: db_set_record_struct is called with a list of field descriptions
            return_value = importer.db_set_record_struct(TEST_FIELD_DESCS)

            # THEN: db_set_record_struct should return None and Struct should be called with a value representing
            #       the list of field descriptions
            assert return_value is None, 'db_set_record_struct should return None'
            mocked_struct.Struct.assert_called_with('>50sHIB250s250s10sQ')
コード例 #20
0
    def test_code_page_to_encoding(self, mocked_retrieve_windows_encoding, mocked_struct, mocked_open, mocked_path_open,
                                   mocked_path_stat, mocked_path_is_file, MockSongImport):
        """
        Test the :mod:`do_import` converts the code page to the encoding correctly
        """
        # GIVEN: A mocked out SongImport class, a mocked out "manager"
        mocked_manager = MagicMock()
        importer = EasyWorshipSongImport(mocked_manager, file_paths=[])
        importer.import_source = 'Songs.DB'

        # WHEN: Unpacking the code page
        for code_page, encoding in CODE_PAGE_MAPPINGS:
            struct_unpack_return_values = [(0, 0x800, 2, 0, 0), (code_page, )]
            mocked_struct.unpack.side_effect = struct_unpack_return_values
            mocked_retrieve_windows_encoding.return_value = False

            # THEN: do_import should return None having called retrieve_windows_encoding with the correct encoding.
            assert importer.do_import() is None, 'do_import should return None when db_size is less than 0x800'
            mocked_retrieve_windows_encoding.assert_any_call(encoding)
コード例 #21
0
ファイル: test_ewimport.py プロジェクト: crossroadchurch/paul
    def do_import_source_invalid_test(self):
        """
        Test the :mod:`do_import` module produces an error when Songs.MB not found.
        """
        # GIVEN: A mocked out SongImport class, a mocked out "manager"
        with patch('openlp.plugins.songs.lib.importers.easyworship.SongImport'), \
                patch('openlp.plugins.songs.lib.importers.easyworship.os.path') as mocked_os_path:
            mocked_manager = MagicMock()
            importer = EasyWorshipSongImport(mocked_manager, filenames=[])
            importer.log_error = MagicMock()
            mocked_os_path.isfile.side_effect = [True, False]

            # WHEN: do_import is supplied with an import source (Songs.MB missing)
            importer.import_source = 'Songs.DB'
            importer.do_import()

            # THEN: do_import should have logged an error that the Songs.MB file could not be found.
            importer.log_error.assert_any_call(importer.import_source, 'Could not find the "Songs.MB" file. It must be '
                                                                       'in the same folder as the "Songs.DB" file.')
コード例 #22
0
ファイル: test_ewimport.py プロジェクト: crossroadchurch/paul
    def get_field_test(self):
        """
        Test the :mod:`get_field` module
        """
        # GIVEN: A mocked out SongImport class, a mocked out "manager", an encoding and some test data and known results
        with patch('openlp.plugins.songs.lib.importers.easyworship.SongImport'):
            mocked_manager = MagicMock()
            importer = EasyWorshipSongImport(mocked_manager, filenames=[])
            importer.encoding = TEST_DATA_ENCODING
            importer.fields = TEST_FIELDS
            importer.field_descriptions = TEST_FIELD_DESCS
            field_results = [(0, b'A Heart Like Thine'), (1, 100), (2, 102), (3, True), (6, None), (7, None)]

            # WHEN: Called with test data
            for field_index, result in field_results:
                return_value = importer.get_field(field_index)

                # THEN: get_field should return the known results
                self.assertEqual(return_value, result,
                                 'get_field should return "%s" when called with "%s"' %
                                 (result, TEST_FIELDS[field_index]))
コード例 #23
0
ファイル: test_ewimport.py プロジェクト: crossroadchurch/paul
    def get_memo_field_test(self):
        """
        Test the :mod:`get_field` module
        """
        for test_results in GET_MEMO_FIELD_TEST_RESULTS:
            # GIVEN: A mocked out SongImport class, a mocked out "manager", a mocked out memo_file and an encoding
            with patch('openlp.plugins.songs.lib.importers.easyworship.SongImport'):
                mocked_manager = MagicMock()
                mocked_memo_file = MagicMock()
                importer = EasyWorshipSongImport(mocked_manager, filenames=[])
                importer.memo_file = mocked_memo_file
                importer.encoding = TEST_DATA_ENCODING

                # WHEN: Supplied with test fields and test field descriptions
                importer.fields = TEST_FIELDS
                importer.field_descriptions = TEST_FIELD_DESCS
                field_index = test_results[0]
                mocked_memo_file.read.return_value = test_results[1]
                get_field_result = test_results[2]['return']
                get_field_read_calls = test_results[2]['read']
                get_field_seek_calls = test_results[2]['seek']

                # THEN: get_field should return the appropriate value with the appropriate mocked objects being called
                self.assertEqual(importer.get_field(field_index), get_field_result)
                for call in get_field_read_calls:
                    mocked_memo_file.read.assert_any_call(call)
                for call in get_field_seek_calls:
                    if isinstance(call, int):
                        mocked_memo_file.seek.assert_any_call(call)
                    else:
                        mocked_memo_file.seek.assert_any_call(call[0], call[1])
コード例 #24
0
    def test_create_importer(self):
        """
        Test creating an instance of the EasyWorship file importer
        """
        # GIVEN: A mocked out SongImport class, and a mocked out "manager"
        with patch('openlp.plugins.songs.lib.importers.easyworship.SongImport'):
            mocked_manager = MagicMock()

            # WHEN: An importer object is created
            importer = EasyWorshipSongImport(mocked_manager, file_paths=[])

            # THEN: The importer object should not be None
            assert importer is not None, 'Import should not be none'
コード例 #25
0
    def test_get_field(self, MockSongImport):
        """
        Test the :mod:`db_get_field` module
        """
        # GIVEN: A mocked out SongImport class, a mocked out "manager", an encoding and some test data and known results
        mocked_manager = MagicMock()
        importer = EasyWorshipSongImport(mocked_manager, file_paths=[])
        importer.encoding = TEST_DATA_ENCODING
        importer.fields = TEST_FIELDS
        importer.field_descriptions = TEST_FIELD_DESCS
        field_results = [(0, b'A Heart Like Thine'), (1, 100), (2, 102), (3, True), (6, None), (7, None)]

        # WHEN: Called with test data
        for field_index, result in field_results:
            return_value = importer.db_get_field(field_index)

            # THEN: db_get_field should return the known results
            assert return_value == result, 'db_get_field should return "%s" when called with "%s"' % \
                (result, TEST_FIELDS[field_index])
コード例 #26
0
    def test_do_import_source_invalid(self):
        """
        Test the :mod:`do_import` module produces an error when Songs.MB not found.
        """
        # GIVEN: A mocked out SongImport class, a mocked out "manager"
        with patch('openlp.plugins.songs.lib.importers.easyworship.SongImport'), \
                patch('openlp.plugins.songs.lib.importers.easyworship.os.path') as mocked_os_path:
            mocked_manager = MagicMock()
            importer = EasyWorshipSongImport(mocked_manager, filenames=[])
            importer.log_error = MagicMock()
            mocked_os_path.isfile.side_effect = [True, False]

            # WHEN: do_import is supplied with an import source (Songs.MB missing)
            importer.import_source = 'Songs.DB'
            importer.do_import()

            # THEN: do_import should have logged an error that the Songs.MB file could not be found.
            importer.log_error.assert_any_call(importer.import_source, 'Could not find the "Songs.MB" file. It must be '
                                                                       'in the same folder as the "Songs.DB" file.')
コード例 #27
0
    def test_get_field(self):
        """
        Test the :mod:`get_field` module
        """
        # GIVEN: A mocked out SongImport class, a mocked out "manager", an encoding and some test data and known results
        with patch('openlp.plugins.songs.lib.importers.easyworship.SongImport'):
            mocked_manager = MagicMock()
            importer = EasyWorshipSongImport(mocked_manager, filenames=[])
            importer.encoding = TEST_DATA_ENCODING
            importer.fields = TEST_FIELDS
            importer.field_descriptions = TEST_FIELD_DESCS
            field_results = [(0, b'A Heart Like Thine'), (1, 100), (2, 102), (3, True), (6, None), (7, None)]

            # WHEN: Called with test data
            for field_index, result in field_results:
                return_value = importer.get_field(field_index)

                # THEN: get_field should return the known results
                self.assertEqual(return_value, result,
                                 'get_field should return "%s" when called with "%s"' %
                                 (result, TEST_FIELDS[field_index]))
コード例 #28
0
 def __init__(self, manager):
     EasyWorshipSongImport.__init__(self, manager, file_paths=[])
コード例 #29
0
ファイル: test_ewimport.py プロジェクト: crossroadchurch/paul
 def __init__(self, manager):
     EasyWorshipSongImport.__init__(self, manager, filenames=[])