示例#1
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])
示例#2
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])
示例#3
0
    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])
示例#4
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)
示例#5
0
    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)
示例#6
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
示例#7
0
    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)
示例#8
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])
示例#9
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]))
示例#10
0
    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]))