openlp/tests/openlp_core/projectors/test_projectormanager.py

93 lines
4.2 KiB
Python
Raw Normal View History

2014-10-06 19:10:03 +00:00
# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
2019-02-14 15:09:09 +00:00
# Copyright (c) 2008-2019 OpenLP Developers #
2014-10-06 19:10:03 +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 #
###############################################################################
"""
Interface tests to test the themeManager class and related methods.
"""
import os
2014-10-06 19:10:03 +00:00
from unittest import TestCase
2018-10-02 04:39:42 +00:00
from unittest.mock import MagicMock, patch
2014-10-06 19:10:03 +00:00
2017-10-07 07:05:07 +00:00
from openlp.core.common.registry import Registry
from openlp.core.projectors.db import ProjectorDB
from openlp.core.projectors.editform import ProjectorEditForm
from openlp.core.projectors.manager import ProjectorManager
from tests.helpers.testmixin import TestMixin
2017-10-07 07:05:07 +00:00
from tests.resources.projector.data import TEST_DB
2014-10-21 15:21:19 +00:00
2014-10-06 19:10:03 +00:00
class TestProjectorManager(TestCase, TestMixin):
"""
Test the functions in the ProjectorManager module
"""
def setUp(self):
"""
Create the UI and setup necessary options
"""
2014-10-24 19:17:12 +00:00
self.setup_application()
2017-11-03 22:52:24 +00:00
self.build_settings()
2014-10-06 19:10:03 +00:00
Registry.create()
2017-11-10 11:59:38 +00:00
with patch('openlp.core.projectors.db.init_url') as mocked_init_url:
2016-01-07 21:57:01 +00:00
if os.path.exists(TEST_DB):
os.unlink(TEST_DB)
mocked_init_url.return_value = 'sqlite:///%s' % TEST_DB
self.projectordb = ProjectorDB()
if not hasattr(self, 'projector_manager'):
self.projector_manager = ProjectorManager(projectordb=self.projectordb)
2014-10-06 19:10:03 +00:00
def tearDown(self):
"""
2014-10-21 15:41:09 +00:00
Remove test database.
Delete all the C++ objects at the end so that we don't have a segfault.
2014-10-06 19:10:03 +00:00
"""
2014-10-21 15:41:09 +00:00
self.projectordb.session.close()
2014-10-06 19:10:03 +00:00
self.destroy_settings()
del self.projector_manager
2014-10-06 19:10:03 +00:00
2016-05-31 21:40:13 +00:00
def test_bootstrap_initialise(self):
2014-10-06 19:10:03 +00:00
"""
Test initialize calls correct startup functions
"""
# WHEN: we call bootstrap_initialise
self.projector_manager.bootstrap_initialise()
# THEN: ProjectorDB is setup
2017-12-23 09:09:45 +00:00
assert type(self.projector_manager.projectordb) == ProjectorDB, \
'Initialization should have created a ProjectorDB() instance'
2014-10-06 19:10:03 +00:00
2016-05-31 21:40:13 +00:00
def test_bootstrap_post_set_up(self):
2014-10-06 19:10:03 +00:00
"""
Test post-initialize calls proper setups
"""
# GIVEN: setup mocks
2014-10-21 15:17:27 +00:00
self.projector_manager._load_projectors = MagicMock()
2014-10-06 19:10:03 +00:00
# WHEN: Call to initialize is run
self.projector_manager.bootstrap_initialise()
self.projector_manager.bootstrap_post_set_up()
2014-11-26 17:24:05 +00:00
# THEN: verify calls to retrieve saved projectors and edit page initialized
2017-12-23 09:09:45 +00:00
assert 1 == self.projector_manager._load_projectors.call_count, \
'Initialization should have called load_projectors()'
assert type(self.projector_manager.projector_form) == ProjectorEditForm, \
'Initialization should have created a Projector Edit Form'
assert self.projector_manager.projectordb is self.projector_manager.projector_form.projectordb, \
'ProjectorEditForm should be using same ProjectorDB() instance as ProjectorManager'