2016-04-27 21:23:16 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
# OpenLP - Open Source Lyrics Projection #
|
|
|
|
# --------------------------------------------------------------------------- #
|
2017-12-29 09:15:48 +00:00
|
|
|
# Copyright (c) 2008-2018 OpenLP Developers #
|
2016-04-27 21:23:16 +00:00
|
|
|
# --------------------------------------------------------------------------- #
|
|
|
|
# This program is free software; you can redistribute it and/or modify it #
|
|
|
|
# under the terms of the GNU General Public License as published by the Free #
|
|
|
|
# Software Foundation; version 2 of the License. #
|
|
|
|
# #
|
|
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT #
|
|
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
|
|
|
|
# more details. #
|
|
|
|
# #
|
|
|
|
# You should have received a copy of the GNU General Public License along #
|
|
|
|
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
|
|
|
|
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
|
|
|
###############################################################################
|
|
|
|
"""
|
|
|
|
This module contains tests for the OpenLP song importer.
|
|
|
|
"""
|
|
|
|
from unittest import TestCase
|
2017-04-24 05:17:55 +00:00
|
|
|
from unittest.mock import patch, MagicMock
|
2016-04-27 21:23:16 +00:00
|
|
|
|
2017-10-07 07:05:07 +00:00
|
|
|
from openlp.core.common.registry import Registry
|
2017-04-24 05:17:55 +00:00
|
|
|
from openlp.plugins.songs.lib.importers.openlp import OpenLPSongImport
|
2016-04-27 21:23:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestOpenLPImport(TestCase):
|
|
|
|
"""
|
|
|
|
Test the functions in the :mod:`openlp` importer module.
|
|
|
|
"""
|
|
|
|
def setUp(self):
|
|
|
|
"""
|
|
|
|
Create the registry
|
|
|
|
"""
|
|
|
|
Registry.create()
|
|
|
|
|
2016-05-31 21:40:13 +00:00
|
|
|
def test_create_importer(self):
|
2016-04-27 21:23:16 +00:00
|
|
|
"""
|
|
|
|
Test creating an instance of the OpenLP database importer
|
|
|
|
"""
|
|
|
|
# GIVEN: A mocked out SongImport class, and a mocked out "manager"
|
|
|
|
with patch('openlp.plugins.songs.lib.importers.openlp.SongImport'):
|
|
|
|
mocked_manager = MagicMock()
|
|
|
|
|
|
|
|
# WHEN: An importer object is created
|
2017-09-30 20:16:30 +00:00
|
|
|
importer = OpenLPSongImport(mocked_manager, file_paths=[])
|
2016-04-27 21:23:16 +00:00
|
|
|
|
|
|
|
# THEN: The importer object should not be None
|
2017-12-22 22:20:04 +00:00
|
|
|
assert importer is not None, 'Import should not be none'
|
2016-04-27 21:23:16 +00:00
|
|
|
|
2016-05-31 21:40:13 +00:00
|
|
|
def test_invalid_import_source(self):
|
2016-04-27 21:23:16 +00:00
|
|
|
"""
|
|
|
|
Test OpenLPSongImport.do_import handles different invalid import_source values
|
|
|
|
"""
|
|
|
|
# GIVEN: A mocked out SongImport class, and a mocked out "manager"
|
|
|
|
with patch('openlp.plugins.songs.lib.importers.openlp.SongImport'):
|
|
|
|
mocked_manager = MagicMock()
|
|
|
|
mocked_import_wizard = MagicMock()
|
2017-09-30 20:16:30 +00:00
|
|
|
importer = OpenLPSongImport(mocked_manager, file_paths=[])
|
2016-04-27 21:23:16 +00:00
|
|
|
importer.import_wizard = mocked_import_wizard
|
|
|
|
importer.stop_import_flag = True
|
|
|
|
|
|
|
|
# WHEN: Import source is not a list
|
|
|
|
for source in ['not a list', 0]:
|
|
|
|
importer.import_source = source
|
|
|
|
|
|
|
|
# THEN: do_import should return none and the progress bar maximum should not be set.
|
2017-12-22 22:20:04 +00:00
|
|
|
assert importer.do_import() is None, 'do_import should return None when import_source is not a list'
|
2017-12-23 09:30:02 +00:00
|
|
|
assert mocked_import_wizard.progress_bar.setMaximum.called is False, \
|
2017-12-22 22:20:04 +00:00
|
|
|
'setMaximum on import_wizard.progress_bar should not have been called'
|