openlp/tests/openlp_core/projectors/test_projectormanager.py

73 lines
3.3 KiB
Python
Raw Normal View History

2014-10-06 19:10:03 +00:00
# -*- coding: utf-8 -*-
2019-04-13 13:00:22 +00:00
##########################################################################
# OpenLP - Open Source Lyrics Projection #
# ---------------------------------------------------------------------- #
2020-12-30 21:42:49 +00:00
# Copyright (c) 2008-2021 OpenLP Developers #
2019-04-13 13:00:22 +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, either version 3 of the License, or #
# (at your option) any later version. #
# #
# 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, see <https://www.gnu.org/licenses/>. #
##########################################################################
2014-10-06 19:10:03 +00:00
"""
Interface tests to test the themeManager class and related methods.
"""
2020-03-19 20:04:28 +00:00
import pytest
2018-10-02 04:39:42 +00:00
from unittest.mock import MagicMock, patch
2014-10-06 19:10:03 +00:00
from openlp.core.projectors.db import ProjectorDB
from openlp.core.projectors.editform import ProjectorEditForm
from openlp.core.projectors.manager import ProjectorManager
2017-10-07 07:05:07 +00:00
from tests.resources.projector.data import TEST_DB
2014-10-21 15:21:19 +00:00
@pytest.fixture()
2020-03-19 20:04:28 +00:00
def projector_manager(settings):
with patch('openlp.core.projectors.db.init_url') as mocked_init_url:
mocked_init_url.return_value = 'sqlite:///%s' % TEST_DB
projectordb = ProjectorDB()
proj_manager = ProjectorManager(projectordb=projectordb)
yield proj_manager
projectordb.session.close()
del proj_manager
def test_bootstrap_initialise(projector_manager):
2014-10-06 19:10:03 +00:00
"""
2020-03-19 20:04:28 +00:00
Test initialize calls correct startup functions
2014-10-06 19:10:03 +00:00
"""
2020-03-19 20:04:28 +00:00
# WHEN: we call bootstrap_initialise
projector_manager.bootstrap_initialise()
# THEN: ProjectorDB is setup
assert type(projector_manager.projectordb) == ProjectorDB, \
'Initialization should have created a ProjectorDB() instance'
2014-10-06 19:10:03 +00:00
2020-03-19 20:04:28 +00:00
def test_bootstrap_post_set_up(projector_manager):
"""
Test post-initialize calls proper setups
"""
# GIVEN: setup mocks
projector_manager._load_projectors = MagicMock()
2014-10-06 19:10:03 +00:00
2020-03-19 20:04:28 +00:00
# WHEN: Call to initialize is run
projector_manager.bootstrap_initialise()
projector_manager.bootstrap_post_set_up()
2014-10-06 19:10:03 +00:00
2020-03-19 20:04:28 +00:00
# THEN: verify calls to retrieve saved projectors and edit page initialized
assert 1 == projector_manager._load_projectors.call_count, \
'Initialization should have called load_projectors()'
assert type(projector_manager.projector_form) == ProjectorEditForm, \
'Initialization should have created a Projector Edit Form'
assert projector_manager.projectordb is projector_manager.projector_form.projectordb, \
'ProjectorEditForm should be using same ProjectorDB() instance as ProjectorManager'