2014-11-07 22:24:20 +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-07 22:24:20 +00:00
|
|
|
"""
|
2016-01-07 21:36:43 +00:00
|
|
|
:mod: `tests.interfaces.openlp_core_ui.test_projectorsourceform` module
|
2014-11-07 22:24:20 +00:00
|
|
|
|
2016-01-07 21:36:43 +00:00
|
|
|
Tests for the Projector Source Select form.
|
2014-11-07 22:24:20 +00:00
|
|
|
"""
|
2020-03-19 20:04:28 +00:00
|
|
|
import pytest
|
2017-04-24 05:17:55 +00:00
|
|
|
from unittest.mock import patch
|
2016-01-07 21:36:43 +00:00
|
|
|
|
2015-11-07 00:49:40 +00:00
|
|
|
from PyQt5.QtWidgets import QDialog
|
2014-11-07 22:24:20 +00:00
|
|
|
|
2017-11-10 11:59:38 +00:00
|
|
|
from openlp.core.projectors.constants import PJLINK_DEFAULT_CODES, PJLINK_DEFAULT_SOURCES
|
2018-10-02 04:39:42 +00:00
|
|
|
from openlp.core.projectors.db import Projector, ProjectorDB
|
|
|
|
from openlp.core.projectors.sourceselectform import SourceSelectSingle, source_group
|
|
|
|
from tests.resources.projector.data import TEST1_DATA, TEST_DB
|
2017-04-24 05:17:55 +00:00
|
|
|
|
2014-11-07 22:44:40 +00:00
|
|
|
|
2020-03-19 20:04:28 +00:00
|
|
|
@pytest.yield_fixture()
|
|
|
|
def projector_env(settings):
|
|
|
|
with patch('openlp.core.projectors.db.init_url') as mocked_init_url:
|
|
|
|
mocked_init_url.return_value = 'sqlite:///{}'.format(TEST_DB)
|
|
|
|
projectordb = ProjectorDB()
|
|
|
|
# Retrieve/create a database record
|
|
|
|
projector = projectordb.get_projector_by_ip(TEST1_DATA['ip'])
|
|
|
|
if not projector:
|
|
|
|
projectordb.add_projector(projector=Projector(**TEST1_DATA))
|
|
|
|
projector = projectordb.get_projector_by_ip(TEST1_DATA['ip'])
|
|
|
|
projector.dbid = projector.id
|
|
|
|
projector.db_item = projector
|
|
|
|
yield projector, projectordb
|
|
|
|
projectordb.session.close()
|
|
|
|
del projectordb
|
|
|
|
del projector
|
|
|
|
|
|
|
|
|
2014-11-07 22:24:20 +00:00
|
|
|
def build_source_dict():
|
|
|
|
"""
|
|
|
|
Builds a source dictionary to verify source_group returns a valid dictionary of dictionary items
|
|
|
|
|
|
|
|
:returns: dictionary of valid PJLink source codes grouped by PJLink source group
|
|
|
|
"""
|
|
|
|
test_group = {}
|
|
|
|
for group in PJLINK_DEFAULT_SOURCES.keys():
|
|
|
|
test_group[group] = {}
|
|
|
|
for key in PJLINK_DEFAULT_CODES:
|
|
|
|
test_group[key[0]][key] = PJLINK_DEFAULT_CODES[key]
|
|
|
|
return test_group
|
|
|
|
|
2014-11-07 22:44:40 +00:00
|
|
|
|
2020-03-19 20:04:28 +00:00
|
|
|
def test_source_dict():
|
2014-11-07 22:24:20 +00:00
|
|
|
"""
|
2020-03-19 20:04:28 +00:00
|
|
|
Test that source list dict returned from sourceselectform module is a valid dict with proper entries
|
2014-11-07 22:24:20 +00:00
|
|
|
"""
|
2020-03-19 20:04:28 +00:00
|
|
|
# GIVEN: A list of inputs
|
|
|
|
codes = []
|
|
|
|
for item in PJLINK_DEFAULT_CODES.keys():
|
|
|
|
codes.append(item)
|
|
|
|
codes.sort()
|
|
|
|
|
|
|
|
# WHEN: projector.sourceselectform.source_select() is called
|
|
|
|
check = source_group(codes, PJLINK_DEFAULT_CODES)
|
|
|
|
|
|
|
|
# THEN: return dictionary should match test dictionary
|
|
|
|
assert check == build_source_dict(), "Source group dictionary should match test dictionary"
|
|
|
|
|
|
|
|
|
|
|
|
@patch.object(QDialog, 'exec')
|
|
|
|
def test_source_select_edit_button(mocked_qdialog, projector_env):
|
|
|
|
"""
|
|
|
|
Test source select form edit has Ok, Cancel, Reset, and Revert buttons
|
|
|
|
"""
|
|
|
|
# GIVEN: Initial setup and mocks
|
|
|
|
projector = projector_env[0]
|
|
|
|
projectordb = projector_env[1]
|
|
|
|
projector.source_available = ['11', ]
|
|
|
|
projector.source = '11'
|
|
|
|
|
|
|
|
# WHEN we create a source select widget and set edit=True
|
|
|
|
select_form = SourceSelectSingle(parent=None, projectordb=projectordb)
|
|
|
|
select_form.edit = True
|
|
|
|
select_form.exec(projector=projector)
|
|
|
|
|
|
|
|
# THEN: Verify all 4 buttons are available
|
|
|
|
assert len(select_form.button_box.buttons()) == 4, \
|
|
|
|
'SourceSelect dialog box should have "OK", "Cancel", "Rest", and "Revert" buttons available'
|
|
|
|
|
|
|
|
|
|
|
|
@patch.object(QDialog, 'exec')
|
|
|
|
def test_source_select_noedit_button(mocked_qdialog, projector_env):
|
|
|
|
"""
|
|
|
|
Test source select form view has OK and Cancel buttons only
|
|
|
|
"""
|
|
|
|
# GIVEN: Initial setup and mocks
|
|
|
|
projector = projector_env[0]
|
|
|
|
projectordb = projector_env[1]
|
|
|
|
projector.source_available = ['11', ]
|
|
|
|
projector.source = '11'
|
|
|
|
|
|
|
|
# WHEN we create a source select widget and set edit=False
|
|
|
|
select_form = SourceSelectSingle(parent=None, projectordb=projectordb)
|
|
|
|
select_form.edit = False
|
|
|
|
select_form.exec(projector=projector)
|
|
|
|
|
|
|
|
# THEN: Verify only 2 buttons are available
|
|
|
|
assert len(select_form.button_box.buttons()) == 2, \
|
|
|
|
'SourceSelect dialog box should only have "OK" and "Cancel" buttons available'
|