openlp/tests/functional/openlp_core/common/test_mixins.py

99 lines
4.1 KiB
Python
Raw Normal View History

2014-07-02 18:38:10 +00:00
# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
2016-12-31 11:01:36 +00:00
# Copyright (c) 2008-2017 OpenLP Developers #
2014-07-02 18:38:10 +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 #
###############################################################################
"""
Package to test the openlp.core.common package.
"""
from unittest import TestCase
2017-10-23 22:09:57 +00:00
from unittest.mock import MagicMock, patch
2014-07-02 18:38:10 +00:00
2017-10-23 22:09:57 +00:00
from openlp.core.common.mixins import RegistryProperties
2017-10-07 07:05:07 +00:00
from openlp.core.common.registry import Registry
2014-07-02 18:38:10 +00:00
2017-10-07 07:05:07 +00:00
2017-10-23 22:09:57 +00:00
class TestRegistryProperties(TestCase, RegistryProperties):
"""
Test the functions in the ThemeManager module
"""
def setUp(self):
"""
Create the Register
"""
Registry.create()
2017-10-07 07:05:07 +00:00
2017-10-23 22:09:57 +00:00
def test_no_application(self):
"""
Test property if no registry value assigned
"""
# GIVEN an Empty Registry
# WHEN there is no Application
# THEN the application should be none
2017-12-15 16:19:42 +00:00
assert self.application is None, 'The application value should be None'
2017-10-07 07:05:07 +00:00
2017-10-23 22:09:57 +00:00
def test_application(self):
"""
Test property if registry value assigned
"""
# GIVEN an Empty Registry
application = MagicMock()
2014-07-02 18:38:10 +00:00
2017-10-23 22:09:57 +00:00
# WHEN the application is registered
Registry().register('application', application)
2014-07-02 18:38:10 +00:00
2017-10-23 22:09:57 +00:00
# THEN the application should be none
2017-12-09 16:29:58 +00:00
assert self.application == application, 'The application value should match'
2014-07-02 18:38:10 +00:00
2017-10-23 22:09:57 +00:00
@patch('openlp.core.common.mixins.is_win')
def test_application_on_windows(self, mocked_is_win):
2014-07-02 18:38:10 +00:00
"""
2017-10-23 22:09:57 +00:00
Test property if registry value assigned on Windows
2014-07-02 18:38:10 +00:00
"""
2017-10-23 22:09:57 +00:00
# GIVEN an Empty Registry and we're on Windows
application = MagicMock()
mocked_is_win.return_value = True
2014-07-02 18:38:10 +00:00
2017-10-23 22:09:57 +00:00
# WHEN the application is registered
Registry().register('application', application)
2014-07-02 18:38:10 +00:00
2017-10-23 22:09:57 +00:00
# THEN the application should be none
2017-12-09 16:29:58 +00:00
assert self.application == application, 'The application value should match'
2014-07-02 18:38:10 +00:00
2017-10-23 22:09:57 +00:00
@patch('openlp.core.common.mixins.is_win')
def test_get_application_on_windows(self, mocked_is_win):
2014-07-02 18:38:10 +00:00
"""
2017-10-23 22:09:57 +00:00
Set that getting the application object on Windows happens dynamically
2014-07-02 18:38:10 +00:00
"""
2017-10-23 22:09:57 +00:00
# GIVEN an Empty Registry and we're on Windows
mocked_is_win.return_value = True
mock_application = MagicMock()
reg_props = RegistryProperties()
registry = Registry()
2014-07-02 18:38:10 +00:00
2017-10-23 22:09:57 +00:00
# WHEN the application is accessed
with patch.object(registry, 'get') as mocked_get:
mocked_get.return_value = mock_application
actual_application = reg_props.application
2014-07-02 18:38:10 +00:00
2017-10-23 22:09:57 +00:00
# THEN the application should be the mock object, and the correct function should have been called
2017-12-09 16:29:58 +00:00
assert mock_application == actual_application, 'The application value should match'
2017-10-23 22:09:57 +00:00
mocked_is_win.assert_called_with()
mocked_get.assert_called_with('application')