ProjectorManager tests upd_add_port listener

This commit is contained in:
Ken Roberts 2022-01-21 21:30:51 +00:00 committed by Raoul Snyman
parent 2143d89d1d
commit caa78be00d
2 changed files with 39 additions and 3 deletions

View File

@ -34,8 +34,8 @@ from openlp.core.common.registry import Registry, RegistryBase
from openlp.core.lib.ui import create_widget_action from openlp.core.lib.ui import create_widget_action
from openlp.core.projectors import DialogSourceStyle from openlp.core.projectors import DialogSourceStyle
from openlp.core.projectors.constants import E_AUTHENTICATION, E_ERROR, E_NETWORK, E_NOT_CONNECTED, E_SOCKET_TIMEOUT,\ from openlp.core.projectors.constants import E_AUTHENTICATION, E_ERROR, E_NETWORK, E_NOT_CONNECTED, E_SOCKET_TIMEOUT,\
E_UNKNOWN_SOCKET_ERROR, QSOCKET_STATE, S_CONNECTED, S_CONNECTING, S_COOLDOWN, S_INITIALIZE, S_NOT_CONNECTED, S_OFF,\ E_UNKNOWN_SOCKET_ERROR, PJLINK_PORT, QSOCKET_STATE, S_CONNECTED, S_CONNECTING, S_COOLDOWN, S_INITIALIZE, \
S_ON, S_STANDBY, S_WARMUP, STATUS_CODE, STATUS_MSG S_NOT_CONNECTED, S_OFF, S_ON, S_STANDBY, S_WARMUP, STATUS_CODE, STATUS_MSG
from openlp.core.projectors.db import ProjectorDB from openlp.core.projectors.db import ProjectorDB
from openlp.core.projectors.editform import ProjectorEditForm from openlp.core.projectors.editform import ProjectorEditForm
@ -325,7 +325,7 @@ class ProjectorManager(QtWidgets.QWidget, RegistryBase, UiProjectorManager, LogM
self.projector_form.editProjector.connect(self.edit_projector_from_wizard) self.projector_form.editProjector.connect(self.edit_projector_from_wizard)
self.projector_list_widget.itemSelectionChanged.connect(self.update_icons) self.projector_list_widget.itemSelectionChanged.connect(self.update_icons)
def udp_listen_add(self, port): def udp_listen_add(self, port=PJLINK_PORT):
""" """
Add UDP broadcast listener Add UDP broadcast listener
""" """

View File

@ -26,6 +26,7 @@ import logging
from unittest.mock import MagicMock, patch from unittest.mock import MagicMock, patch
from openlp.core.projectors.constants import PJLINK_PORT
from openlp.core.projectors.db import ProjectorDB from openlp.core.projectors.db import ProjectorDB
from openlp.core.projectors.editform import ProjectorEditForm from openlp.core.projectors.editform import ProjectorEditForm
from openlp.core.projectors.manager import ProjectorManager from openlp.core.projectors.manager import ProjectorManager
@ -112,3 +113,38 @@ def test_bootstrap_post_set_up_autostart_projector(projector_manager_nodb, caplo
assert caplog.record_tuples[-1] == ('openlp.core.projectors.manager', 10, assert caplog.record_tuples[-1] == ('openlp.core.projectors.manager', 10,
'Delaying 1.5 seconds before loading all projectors'), \ 'Delaying 1.5 seconds before loading all projectors'), \
"Last log entry should be autoloading entry" "Last log entry should be autoloading entry"
def test_udp_listen_add_duplicate_port(projector_manager_nodb, caplog):
"""
Test adding UDP port listener to port already registered
"""
# GIVEN: Initial setup
caplog.set_level(logging.DEBUG)
projector_manager_nodb.pjlink_udp[PJLINK_PORT] = "Something to set index item"
# WHEN: udp_listen_add is called with duplicate port number
caplog.clear()
projector_manager_nodb.udp_listen_add(port=PJLINK_PORT)
# THEN: Verify log entry and registry entry not called
assert caplog.record_tuples[0] == ('openlp.core.projectors.manager', 30,
'UDP Listener for port 4352 already added - skipping')
@patch('openlp.core.projectors.manager.Registry')
def test_udp_listen_add_new(mock_registry, projector_manager_nodb, caplog):
"""
Test adding new UDP port listener
"""
# GIVEN: Initial setup
caplog.set_level(logging.DEBUG)
log_entries = [('openlp.core.projectors.manager', 10, 'Adding UDP listener on port 4352'),
('openlp.core.projectors.pjlink', 10, '(UDP:4352) PJLinkUDP() Initialized')]
# WHEN: Adding new listener
caplog.clear()
projector_manager_nodb.udp_listen_add(port=PJLINK_PORT)
# THEN: Appropriate listener and log entries
mock_registry.execute.called_with('udp_broadcast_add', port=PJLINK_PORT)
assert caplog.record_tuples == log_entries, 'Invalid log entries'