openlp/tests/interfaces/openlp_core_ui/test_projectormanager.py

98 lines
4.4 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 #
# --------------------------------------------------------------------------- #
2015-01-18 13:39:21 +00:00
# Copyright (c) 2008-2015 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
from openlp.core.common import Registry, Settings
from tests.functional import patch, MagicMock
from tests.helpers.testmixin import TestMixin
from openlp.core.ui import ProjectorManager, ProjectorEditForm
2014-10-06 21:19:08 +00:00
from openlp.core.lib.projector.db import Projector, ProjectorDB
2014-10-06 19:10:03 +00:00
from tests.resources.projector.data import TEST1_DATA, TEST2_DATA, TEST3_DATA
tmpfile = '/tmp/openlp-test-projectormanager.sql'
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
"""
self.build_settings()
2014-10-24 19:17:12 +00:00
self.setup_application()
2014-10-06 19:10:03 +00:00
Registry.create()
if not hasattr(self, 'projector_manager'):
2014-10-06 21:19:08 +00:00
with patch('openlp.core.lib.projector.db.init_url') as mocked_init_url:
2014-10-06 19:10:03 +00:00
mocked_init_url.start()
mocked_init_url.return_value = 'sqlite:///%s' % tmpfile
self.projectordb = ProjectorDB()
if not hasattr(self, 'projector_manager'):
self.projector_manager = ProjectorManager(projectordb=self.projectordb)
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
def bootstrap_initialise_test(self):
"""
Test initialize calls correct startup functions
"""
# WHEN: we call bootstrap_initialise
self.projector_manager.bootstrap_initialise()
# THEN: ProjectorDB is setup
self.assertEqual(type(self.projector_manager.projectordb), ProjectorDB,
'Initialization should have created a ProjectorDB() instance')
def bootstrap_post_set_up_test(self):
"""
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
2014-10-21 15:15:20 +00:00
self.assertEqual(1, self.projector_manager._load_projectors.call_count,
2014-10-06 19:10:03 +00:00
'Initialization should have called load_projectors()')
2014-10-16 18:22:34 +00:00
self.assertEqual(type(self.projector_manager.projector_form), ProjectorEditForm,
'Initialization should have created a Projector Edit Form')
2014-10-06 19:10:03 +00:00
self.assertIs(self.projector_manager.projectordb,
2014-10-16 18:22:34 +00:00
self.projector_manager.projector_form.projectordb,
'ProjectorEditForm should be using same ProjectorDB() instance as ProjectorManager')