2014-11-01 10:59:45 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2019-04-13 13:00:22 +00:00
|
|
|
##########################################################################
|
|
|
|
# OpenLP - Open Source Lyrics Projection #
|
|
|
|
# ---------------------------------------------------------------------- #
|
2020-01-01 02:53:08 +00:00
|
|
|
# Copyright (c) 2008-2020 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-11-01 10:59:45 +00:00
|
|
|
"""
|
|
|
|
This module contains tests for the lib submodule of the Images plugin.
|
|
|
|
"""
|
2020-03-04 06:06:47 +00:00
|
|
|
import pytest
|
2017-10-07 07:05:07 +00:00
|
|
|
from unittest.mock import MagicMock
|
2014-11-01 10:59:45 +00:00
|
|
|
|
2017-10-07 07:05:07 +00:00
|
|
|
from openlp.core.common.registry import Registry
|
2018-10-26 23:15:31 +00:00
|
|
|
from openlp.plugins.images.lib.imagetab import ImageTab
|
2014-11-01 10:59:45 +00:00
|
|
|
|
2018-10-02 04:39:42 +00:00
|
|
|
|
2020-03-04 06:06:47 +00:00
|
|
|
@pytest.fixture()
|
|
|
|
def form(settings):
|
|
|
|
Registry().register('settings_form', MagicMock())
|
|
|
|
frm = ImageTab(None, 'Images', None, None)
|
|
|
|
frm.settings_form.register_post_process = MagicMock()
|
|
|
|
return frm
|
2014-11-01 10:59:45 +00:00
|
|
|
|
|
|
|
|
2020-03-04 06:06:47 +00:00
|
|
|
def test_save_tab_nochange(form):
|
2014-11-01 10:59:45 +00:00
|
|
|
"""
|
2020-03-04 06:06:47 +00:00
|
|
|
Test no changes does not trigger post processing
|
2014-11-01 10:59:45 +00:00
|
|
|
"""
|
2020-03-04 06:06:47 +00:00
|
|
|
# GIVEN: No changes on the form.
|
|
|
|
# WHEN: the save is invoked
|
|
|
|
form.save()
|
|
|
|
# THEN: the post process should not be requested
|
|
|
|
assert 0 == form.settings_form.register_post_process.call_count, \
|
|
|
|
'Image Post processing should not have been requested'
|
2014-11-01 10:59:45 +00:00
|
|
|
|
|
|
|
|
2020-03-04 06:06:47 +00:00
|
|
|
def test_save_tab_change(form):
|
|
|
|
"""
|
|
|
|
Test a color change is applied and triggers post processing.
|
|
|
|
"""
|
|
|
|
# GIVEN: Apply a change to the form.
|
|
|
|
form.on_background_color_changed('#999999')
|
|
|
|
# WHEN: the save is invoked
|
|
|
|
form.save()
|
|
|
|
# THEN: the post process should be requested
|
|
|
|
assert 1 == form.settings_form.register_post_process.call_count, \
|
|
|
|
'Image Post processing should have been requested'
|
|
|
|
# THEN: The color should be set
|
|
|
|
assert form.background_color == '#999999', 'The updated color should have been saved'
|