openlp/tests/interfaces/openlp_core_ui/test_projectormanager.py

102 lines
4.8 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 #
# --------------------------------------------------------------------------- #
# Copyright (c) 2008-2014 Raoul Snyman #
# Portions copyright (c) 2008-2014 Tim Bentley, Gerald Britton, Jonathan #
# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, #
# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, #
# Frode Woldsund, Martin Zibricky, Patrick Zimmermann #
# --------------------------------------------------------------------------- #
# 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.
"""
from unittest import TestCase
from openlp.core.common import Registry, Settings
from tests.functional import patch, MagicMock
from tests.helpers.testmixin import TestMixin
2014-10-16 18:22:34 +00:00
from openlp.core.ui import ProjectorManager
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'
class TestProjectorManager(TestCase, TestMixin):
"""
Test the functions in the ProjectorManager module
"""
def setUp(self):
"""
Create the UI and setup necessary options
"""
self.build_settings()
self.get_application()
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):
"""
Delete all the C++ objects at the end so that we don't have a segfault
"""
self.destroy_settings()
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
self.projector_manager.load_projectors = MagicMock()
# WHEN: Call to initialize is run
self.projector_manager.bootstrap_initialise()
self.projector_manager.bootstrap_post_set_up()
# THEN: verify calls to retrieve saved projectors
self.assertEqual(1, self.projector_manager.load_projectors.call_count,
'Initialization should have called load_projectors()')
# THEN: Verify wizard page is initialized
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')