forked from openlp/openlp
- Refactor wizard pages into external page components - Refactor form labels into a central label with the alignment already set - Fix some tests - Write more tests
98 lines
4.3 KiB
Python
98 lines
4.3 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
##########################################################################
|
|
# OpenLP - Open Source Lyrics Projection #
|
|
# ---------------------------------------------------------------------- #
|
|
# Copyright (c) 2008-2019 OpenLP Developers #
|
|
# ---------------------------------------------------------------------- #
|
|
# 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/>. #
|
|
##########################################################################
|
|
"""
|
|
Package to test the openlp.core.pages package.
|
|
"""
|
|
from unittest import TestCase
|
|
from unittest.mock import MagicMock, call, patch
|
|
|
|
import pytest
|
|
|
|
from openlp.core.pages import GridLayoutPage
|
|
from tests.helpers.testmixin import TestMixin
|
|
|
|
|
|
class TestGridLayoutPage(TestCase, TestMixin):
|
|
|
|
def setUp(self):
|
|
"""Test setup"""
|
|
self.setup_application()
|
|
self.build_settings()
|
|
|
|
def tearDown(self):
|
|
"""Tear down tests"""
|
|
del self.app
|
|
|
|
@patch('openlp.core.pages.GridLayoutPage.setup_ui')
|
|
@patch('openlp.core.pages.GridLayoutPage.retranslate_ui')
|
|
def test_resize_event(self, mocked_retranslate_ui, mocked_setup_ui):
|
|
"""
|
|
Test that the `resizeEvent()` method called the `resize_columns()` method.
|
|
"""
|
|
# GIVEN: An instance of GridLayoutPage with a mocked out "resize_columns" method
|
|
instance = GridLayoutPage()
|
|
instance.resize_columns = MagicMock()
|
|
|
|
# WHEN: resizeEvent is called
|
|
instance.resizeEvent(None)
|
|
|
|
# THEN: resize_widgets should have been called
|
|
instance.resize_columns.assert_called_once()
|
|
|
|
def test_unimplemented_setup_ui(self):
|
|
"""
|
|
Test that setup_ui() throws a NotImplementedError
|
|
"""
|
|
with pytest.raises(NotImplementedError, match='Descendant pages need to implement setup_ui'):
|
|
GridLayoutPage()
|
|
|
|
@patch('openlp.core.pages.GridLayoutPage.setup_ui')
|
|
def test_unimplemented_retranslate_ui(self, mocked_setup_ui):
|
|
"""
|
|
Test that retranslate_ui() throws a NotImplementedError
|
|
"""
|
|
with pytest.raises(NotImplementedError, match='Descendant pages need to implement retranslate_ui'):
|
|
GridLayoutPage()
|
|
|
|
@patch('openlp.core.pages.GridLayoutPage.setup_ui')
|
|
@patch('openlp.core.pages.GridLayoutPage.retranslate_ui')
|
|
def test_resize_columns(self, mocked_retranslate_ui, mocked_setup_ui):
|
|
"""
|
|
Test the `resize_columns()` method with an implemented page
|
|
"""
|
|
# GIVEN: An instance of GridLayoutPage and various mocked out methods
|
|
instance = GridLayoutPage()
|
|
instance.layout.contentsRect = MagicMock(return_value=MagicMock(**{'width.return_value': 100}))
|
|
instance.layout.horizontalSpacing = MagicMock(return_value=6)
|
|
instance.layout.columnCount = MagicMock(return_value=4)
|
|
instance.layout.setColumnMinimumWidth = MagicMock()
|
|
|
|
# WHEN: `resize_columns()` is called
|
|
instance.resize_columns()
|
|
|
|
# THEN: The column widths should be set to 16
|
|
instance.layout.contentsRect.assert_called_once()
|
|
instance.layout.horizontalSpacing.assert_called_once()
|
|
instance.layout.columnCount.assert_called_once()
|
|
assert instance._column_width == 20
|
|
assert instance.layout.setColumnMinimumWidth.call_args_list == [call(0, 20), call(1, 20),
|
|
call(2, 20), call(3, 20)]
|