openlp/tests/functional/openlp_core/projectors/test_projector_pjlink_comma...

1221 lines
57 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
# Copyright (c) 2008-2015 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; 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 #
###############################################################################
"""
2017-11-10 11:59:38 +00:00
Package to test the openlp.core.projectors.pjlink commands package.
"""
from unittest import TestCase
2017-12-25 08:44:30 +00:00
from unittest.mock import call, patch
2017-11-10 11:59:38 +00:00
import openlp.core.projectors.pjlink
2017-12-25 08:44:30 +00:00
from openlp.core.projectors.constants import PJLINK_ERST_DATA, PJLINK_ERST_STATUS, PJLINK_POWR_STATUS, \
STATUS_CODE, STATUS_MSG, E_ERROR, E_NOT_CONNECTED, E_UNKNOWN_SOCKET_ERROR, E_WARN, \
S_CONNECTED, S_CONNECTING, S_OFF, S_OK, S_ON, S_NOT_CONNECTED, S_STANDBY
from openlp.core.projectors.db import Projector
from openlp.core.projectors.pjlink import PJLink
2017-12-25 08:44:30 +00:00
from tests.resources.projector.data import TEST1_DATA
2016-05-28 05:55:54 +00:00
2017-08-06 07:23:26 +00:00
class TestPJLinkCommands(TestCase):
"""
2017-12-04 00:24:47 +00:00
Tests for the PJLinkCommands class part 1
"""
2017-12-25 08:44:30 +00:00
def test_projector_change_status_unknown_socket_error(self):
2017-06-25 02:21:07 +00:00
"""
Test change_status with connection error
2017-06-25 02:21:07 +00:00
"""
2017-12-25 08:44:30 +00:00
log_debug_calls = [
call('(111.111.111.111) Changing status to '
'{status} "{msg}"'.format(status=STATUS_CODE[E_UNKNOWN_SOCKET_ERROR],
msg=STATUS_MSG[E_UNKNOWN_SOCKET_ERROR])),
call('(111.111.111.111) status_connect: '
'{code}: "{msg}"'.format(code=STATUS_CODE[E_NOT_CONNECTED],
msg=STATUS_MSG[E_NOT_CONNECTED])),
call('(111.111.111.111) projector_status: '
'{code}: "{msg}"'.format(code=STATUS_CODE[S_OK],
msg=STATUS_MSG[S_OK])),
call('(111.111.111.111) error_status: '
'{code}: "{msg}"'.format(code=STATUS_CODE[E_UNKNOWN_SOCKET_ERROR],
msg=STATUS_MSG[E_UNKNOWN_SOCKET_ERROR]))]
# GIVEN: Test object and mocks
with patch.object(openlp.core.projectors.pjlink, 'log') as mock_log, \
patch.object(openlp.core.projectors.pjlink.PJLink, 'changeStatus') as mock_changeStatus, \
patch.object(openlp.core.projectors.pjlink.PJLink, 'projectorUpdateIcons') as mock_UpdateIcons:
pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
pjlink.projector_status = 0
pjlink.status_connect = 0
# WHEN: change_status called with unknown socket error
pjlink.change_status(status=E_UNKNOWN_SOCKET_ERROR)
# THEN: Proper settings should change and signals sent
mock_log.debug.assert_has_calls(log_debug_calls)
self.assertEqual(pjlink.projector_status, S_OK, 'Projector status should not have changed')
self.assertEqual(pjlink.status_connect, E_NOT_CONNECTED,
'Status connect should be NOT CONNECTED')
self.assertTrue(mock_UpdateIcons.emit.called, 'Should have called UpdateIcons')
mock_changeStatus.emit.assert_called_once_with(pjlink.ip, E_UNKNOWN_SOCKET_ERROR,
STATUS_MSG[E_UNKNOWN_SOCKET_ERROR])
def test_projector_change_status_connection_status_connecting(self):
"""
Test change_status with connecting status
"""
log_debug_calls = [
call('(111.111.111.111) Changing status to '
'{status} "{msg}"'.format(status=STATUS_CODE[S_CONNECTING],
msg=STATUS_MSG[S_CONNECTING])),
call('(111.111.111.111) status_connect: '
'{code}: "{msg}"'.format(code=STATUS_CODE[S_CONNECTING],
msg=STATUS_MSG[S_CONNECTING])),
call('(111.111.111.111) projector_status: '
'{code}: "{msg}"'.format(code=STATUS_CODE[S_OK],
msg=STATUS_MSG[S_OK])),
call('(111.111.111.111) error_status: '
'{code}: "{msg}"'.format(code=STATUS_CODE[S_OK],
msg=STATUS_MSG[S_OK]))]
# GIVEN: Test object and mocks
with patch.object(openlp.core.projectors.pjlink, 'log') as mock_log, \
patch.object(openlp.core.projectors.pjlink.PJLink, 'changeStatus') as mock_changeStatus, \
patch.object(openlp.core.projectors.pjlink.PJLink, 'projectorUpdateIcons') as mock_UpdateIcons:
pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
pjlink.projector_status = 0
pjlink.status_connect = 0
# WHEN: change_status called with CONNECTING
pjlink.change_status(status=S_CONNECTING)
# THEN: Proper settings should change and signals sent
mock_log.debug.assert_has_calls(log_debug_calls)
self.assertEqual(pjlink.projector_status, S_OK, 'Projector status should not have changed')
self.assertEqual(pjlink.status_connect, S_CONNECTING, 'Status connect should be CONNECTING')
self.assertTrue(mock_UpdateIcons.emit.called, 'Should have called UpdateIcons')
mock_changeStatus.emit.assert_called_once_with(pjlink.ip, S_CONNECTING, STATUS_MSG[S_CONNECTING])
def test_projector_change_status_connection_status_connected(self):
"""
Test change_status with connected status
"""
log_debug_calls = [
call('(111.111.111.111) Changing status to '
'{status} "{msg}"'.format(status=STATUS_CODE[S_CONNECTED],
msg=STATUS_MSG[S_CONNECTED])),
call('(111.111.111.111) status_connect: '
'{code}: "{msg}"'.format(code=STATUS_CODE[S_CONNECTED],
msg=STATUS_MSG[S_CONNECTED])),
call('(111.111.111.111) projector_status: '
'{code}: "{msg}"'.format(code=STATUS_CODE[S_OK],
msg=STATUS_MSG[S_OK])),
call('(111.111.111.111) error_status: '
'{code}: "{msg}"'.format(code=STATUS_CODE[S_OK],
msg=STATUS_MSG[S_OK]))]
# GIVEN: Test object and mocks
with patch.object(openlp.core.projectors.pjlink, 'log') as mock_log, \
patch.object(openlp.core.projectors.pjlink.PJLink, 'changeStatus') as mock_changeStatus:
pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
pjlink.projector_status = 0
pjlink.status_connect = 0
# WHEN: change_status called with CONNECTED
pjlink.change_status(status=S_CONNECTED)
# THEN: Proper settings should change and signals sent
mock_log.debug.assert_has_calls(log_debug_calls)
self.assertEqual(pjlink.projector_status, S_OK, 'Projector status should not have changed')
self.assertEqual(pjlink.status_connect, S_CONNECTED, 'Status connect should be CONNECTED')
mock_changeStatus.emit.assert_called_once_with(pjlink.ip, S_CONNECTED, 'Connected')
def test_projector_change_status_connection_status_with_message(self):
"""
Test change_status with connection status
"""
test_message = 'Different Status Message than default'
2017-12-25 08:44:30 +00:00
log_debug_calls = [
call('(111.111.111.111) Changing status to {status} "{msg}"'.format(status=STATUS_CODE[S_ON],
msg=test_message)),
call('(111.111.111.111) status_connect: {code}: "{msg}"'.format(code=STATUS_CODE[S_OK],
msg=test_message)),
call('(111.111.111.111) projector_status: {code}: "{msg}"'.format(code=STATUS_CODE[S_ON],
msg=test_message)),
call('(111.111.111.111) error_status: {code}: "{msg}"'.format(code=STATUS_CODE[S_OK],
msg=test_message))]
# GIVEN: Test object and mocks
with patch.object(openlp.core.projectors.pjlink, 'log') as mock_log, \
patch.object(openlp.core.projectors.pjlink.PJLink, 'changeStatus') as mock_changeStatus:
pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
pjlink.projector_status = 0
pjlink.status_connect = 0
# WHEN: change_status called with projector ON status
pjlink.change_status(status=S_ON, msg=test_message)
# THEN: Proper settings should change and signals sent
mock_log.debug.assert_has_calls(log_debug_calls)
self.assertEqual(pjlink.projector_status, S_ON, 'Projector status should be ON')
self.assertEqual(pjlink.status_connect, S_OK, 'Status connect should not have changed')
mock_changeStatus.emit.assert_called_once_with(pjlink.ip, S_ON, test_message)
def test_projector_get_av_mute_status(self):
"""
Test sending command to retrieve shutter/audio state
"""
test_data = 'AVMT'
2017-12-25 08:44:30 +00:00
log_debug_calls = [call('(111.111.111.111) reset_information() connect status is '
'{state}'.format(state=STATUS_CODE[S_NOT_CONNECTED])),
call('(111.111.111.111) Sending {cmd} command'.format(cmd=test_data))]
2017-06-25 02:21:07 +00:00
2017-12-25 08:44:30 +00:00
# GIVEN: Test object and mocks
with patch.object(openlp.core.projectors.pjlink, 'log') as mock_log, \
patch.object(openlp.core.projectors.pjlink.PJLink, 'send_command') as mock_send_command:
pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
2017-12-25 08:44:30 +00:00
# WHEN: get_av_mute_status is called
pjlink.get_av_mute_status()
2017-12-25 08:44:30 +00:00
# THEN: log data and send_command should have been called
mock_log.debug.assert_has_calls(log_debug_calls)
mock_send_command.assert_called_once_with(cmd=test_data)
def test_projector_get_available_inputs(self):
"""
Test sending command to retrieve avaliable inputs
"""
test_data = 'INST'
2017-12-25 08:44:30 +00:00
log_debug_calls = [call('(111.111.111.111) reset_information() connect status is '
'{state}'.format(state=STATUS_CODE[S_NOT_CONNECTED])),
call('(111.111.111.111) Sending {cmd} command'.format(cmd=test_data))]
2017-12-25 08:44:30 +00:00
# GIVEN: Test object and mocks
with patch.object(openlp.core.projectors.pjlink, 'log') as mock_log, \
patch.object(openlp.core.projectors.pjlink.PJLink, 'send_command') as mock_send_command:
pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
2017-12-25 08:44:30 +00:00
# WHEN: get_available_inputs is called
pjlink.get_available_inputs()
2017-12-25 08:44:30 +00:00
# THEN: log data and send_command should have been called
mock_log.debug.assert_has_calls(log_debug_calls)
mock_send_command.assert_called_once_with(cmd=test_data)
def test_projector_get_error_status(self):
"""
Test sending command to retrieve projector error status
"""
test_data = 'ERST'
2017-12-25 08:44:30 +00:00
log_debug_calls = [call('(111.111.111.111) reset_information() connect status is '
'{state}'.format(state=STATUS_CODE[S_NOT_CONNECTED])),
call('(111.111.111.111) Sending {cmd} command'.format(cmd=test_data))]
# GIVEN: Test object and mocks
with patch.object(openlp.core.projectors.pjlink, 'log') as mock_log, \
patch.object(openlp.core.projectors.pjlink.PJLink, 'send_command') as mock_send_command:
pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
2017-12-25 08:44:30 +00:00
# WHEN: get_error_status is called
pjlink.get_error_status()
2017-12-25 08:44:30 +00:00
# THEN: log data and send_command should have been called
mock_log.debug.assert_has_calls(log_debug_calls)
mock_send_command.assert_called_once_with(cmd=test_data)
2017-12-25 08:44:30 +00:00
def test_projector_get_input_source(self):
"""
Test sending command to retrieve current input
"""
test_data = 'INPT'
2017-12-25 08:44:30 +00:00
log_debug_calls = [call('(111.111.111.111) reset_information() connect status is '
'{state}'.format(state=STATUS_CODE[S_NOT_CONNECTED])),
call('(111.111.111.111) Sending {cmd} command'.format(cmd=test_data))]
2017-12-25 08:44:30 +00:00
# GIVEN: Test object and mocks
with patch.object(openlp.core.projectors.pjlink, 'log') as mock_log, \
patch.object(openlp.core.projectors.pjlink.PJLink, 'send_command') as mock_send_command:
pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
2017-12-25 08:44:30 +00:00
# WHEN: get_input_source is called
pjlink.get_input_source()
2017-12-25 08:44:30 +00:00
# THEN: log data and send_command should have been called
mock_log.debug.assert_has_calls(log_debug_calls)
mock_send_command.assert_called_once_with(cmd=test_data)
def test_projector_get_lamp_status(self):
"""
Test sending command to retrieve lamp(s) status
"""
test_data = 'LAMP'
2017-12-25 08:44:30 +00:00
log_debug_calls = [call('(111.111.111.111) reset_information() connect status is '
'{state}'.format(state=STATUS_CODE[S_NOT_CONNECTED])),
call('(111.111.111.111) Sending {cmd} command'.format(cmd=test_data))]
2017-12-25 08:44:30 +00:00
# GIVEN: Test object and mocks
with patch.object(openlp.core.projectors.pjlink, 'log') as mock_log, \
patch.object(openlp.core.projectors.pjlink.PJLink, 'send_command') as mock_send_command:
pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
2017-12-25 08:44:30 +00:00
# WHEN: get_input_source is called
pjlink.get_lamp_status()
2017-12-25 08:44:30 +00:00
# THEN: log data and send_command should have been called
mock_log.debug.assert_has_calls(log_debug_calls)
mock_send_command.assert_called_once_with(cmd=test_data)
def test_projector_get_manufacturer(self):
"""
Test sending command to retrieve manufacturer name
"""
test_data = 'INF1'
2017-12-25 08:44:30 +00:00
log_debug_calls = [call('(111.111.111.111) reset_information() connect status is '
'{state}'.format(state=STATUS_CODE[S_NOT_CONNECTED])),
call('(111.111.111.111) Sending {cmd} command'.format(cmd=test_data))]
2017-12-25 08:44:30 +00:00
# GIVEN: Test object and mocks
with patch.object(openlp.core.projectors.pjlink, 'log') as mock_log, \
patch.object(openlp.core.projectors.pjlink.PJLink, 'send_command') as mock_send_command:
pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
2017-12-25 08:44:30 +00:00
# WHEN: get_input_source is called
pjlink.get_manufacturer()
2017-12-25 08:44:30 +00:00
# THEN: log data and send_command should have been called
mock_log.debug.assert_has_calls(log_debug_calls)
mock_send_command.assert_called_once_with(cmd=test_data)
def test_projector_get_model(self):
"""
Test sending command to get model information
"""
test_data = 'INF2'
2017-12-25 08:44:30 +00:00
log_debug_calls = [call('(111.111.111.111) reset_information() connect status is '
'{state}'.format(state=STATUS_CODE[S_NOT_CONNECTED])),
call('(111.111.111.111) Sending {cmd} command'.format(cmd=test_data))]
2017-12-25 08:44:30 +00:00
# GIVEN: Test object and mocks
with patch.object(openlp.core.projectors.pjlink, 'log') as mock_log, \
patch.object(openlp.core.projectors.pjlink.PJLink, 'send_command') as mock_send_command:
pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
2017-12-25 08:44:30 +00:00
# WHEN: get_input_source is called
pjlink.get_model()
2017-12-25 08:44:30 +00:00
# THEN: log data and send_command should have been called
mock_log.debug.assert_has_calls(log_debug_calls)
mock_send_command.assert_called_once_with(cmd=test_data)
def test_projector_get_name(self):
"""
Test sending command to get user-assigned name
"""
test_data = 'NAME'
2017-12-25 08:44:30 +00:00
log_debug_calls = [call('(111.111.111.111) reset_information() connect status is '
'{state}'.format(state=STATUS_CODE[S_NOT_CONNECTED])),
call('(111.111.111.111) Sending {cmd} command'.format(cmd=test_data))]
2017-12-25 08:44:30 +00:00
# GIVEN: Test object and mocks
with patch.object(openlp.core.projectors.pjlink, 'log') as mock_log, \
patch.object(openlp.core.projectors.pjlink.PJLink, 'send_command') as mock_send_command:
pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
2017-12-25 08:44:30 +00:00
# WHEN: get_input_source is called
pjlink.get_name()
2017-12-25 08:44:30 +00:00
# THEN: log data and send_command should have been called
mock_log.debug.assert_has_calls(log_debug_calls)
mock_send_command.assert_called_once_with(cmd=test_data)
def test_projector_get_other_info(self):
"""
Test sending command to retrieve other information
"""
test_data = 'INFO'
2017-12-25 08:44:30 +00:00
log_debug_calls = [call('(111.111.111.111) reset_information() connect status is '
'{state}'.format(state=STATUS_CODE[S_NOT_CONNECTED])),
call('(111.111.111.111) Sending {cmd} command'.format(cmd=test_data))]
2017-12-25 08:44:30 +00:00
# GIVEN: Test object and mocks
with patch.object(openlp.core.projectors.pjlink, 'log') as mock_log, \
patch.object(openlp.core.projectors.pjlink.PJLink, 'send_command') as mock_send_command:
pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
2017-12-25 08:44:30 +00:00
# WHEN: get_input_source is called
pjlink.get_other_info()
2017-12-25 08:44:30 +00:00
# THEN: log data and send_command should have been called
mock_log.debug.assert_has_calls(log_debug_calls)
mock_send_command.assert_called_once_with(cmd=test_data)
def test_projector_get_power_status(self):
"""
Test sending command to retrieve current power state
"""
test_data = 'POWR'
2017-12-25 08:44:30 +00:00
log_debug_calls = [call('(111.111.111.111) reset_information() connect status is '
'{state}'.format(state=STATUS_CODE[S_NOT_CONNECTED])),
call('(111.111.111.111) Sending {cmd} command'.format(cmd=test_data))]
2017-12-25 08:44:30 +00:00
# GIVEN: Test object and mocks
with patch.object(openlp.core.projectors.pjlink, 'log') as mock_log, \
patch.object(openlp.core.projectors.pjlink.PJLink, 'send_command') as mock_send_command:
pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
2017-12-25 08:44:30 +00:00
# WHEN: get_input_source is called
pjlink.get_power_status()
2017-12-25 08:44:30 +00:00
# THEN: log data and send_command should have been called
mock_log.debug.assert_has_calls(log_debug_calls)
mock_send_command.assert_called_once_with(cmd=test_data)
def test_projector_get_status_invalid(self):
"""
Test to check returned information for error code
"""
# GIVEN: Test object
2017-12-25 08:44:30 +00:00
pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
test_string = 'NaN test'
# WHEN: get_status called
2017-12-25 08:44:30 +00:00
code, message = pjlink._get_status(status=test_string)
2017-12-25 08:44:30 +00:00
# THEN: Proper data should have been returned
self.assertEqual(code, -1, 'Should have returned -1 as a bad status check')
self.assertIsNone(message, 'Invalid code type should have returned None for message')
2017-12-25 08:44:30 +00:00
def test_projector_get_status_valid(self):
"""
Test to check returned information for status codes
"""
# GIVEN: Test object
2017-12-25 08:44:30 +00:00
test_message = 'Not Connected'
pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
# WHEN: get_status called
2017-12-25 08:44:30 +00:00
code, message = pjlink._get_status(status=S_NOT_CONNECTED)
# THEN: Proper strings should have been returned
2017-12-25 08:44:30 +00:00
self.assertEqual(code, 'S_NOT_CONNECTED', 'Code returned should have been the same code that was sent')
self.assertEqual(message, test_message, 'Description of code should have been returned')
def test_projector_get_status_unknown(self):
"""
Test to check returned information for unknown code
"""
# GIVEN: Test object
2017-12-25 08:44:30 +00:00
pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
# WHEN: get_status called
2017-12-25 08:44:30 +00:00
code, message = pjlink._get_status(status=9999)
# THEN: Proper strings should have been returned
2017-12-25 08:44:30 +00:00
self.assertIsNone(code, 'Code returned should have been the same code that was sent')
self.assertIsNone(message, 'Should have returned None as message')
def test_projector_process_inf1(self):
"""
Test saving INF1 data (manufacturer)
"""
2017-12-25 08:44:30 +00:00
test_data = 'TEst INformation MultiCase'
# GIVEN: Test object
2017-12-25 08:44:30 +00:00
pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
pjlink.manufacturer = None
# WHEN: process_inf called with test data
pjlink.process_inf1(data=test_data)
# THEN: Data should be saved
self.assertEqual(pjlink.manufacturer, test_data, 'Test data should have been saved')
def test_projector_process_inf2(self):
"""
Test saving INF2 data (model)
"""
2017-12-25 08:44:30 +00:00
test_data = 'TEst moDEl MultiCase'
# GIVEN: Test object
2017-12-25 08:44:30 +00:00
pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
pjlink.model = None
# WHEN: process_inf called with test data
pjlink.process_inf2(data=test_data)
# THEN: Data should be saved
self.assertEqual(pjlink.model, test_data, 'Test data should have been saved')
def test_projector_process_info(self):
"""
Test saving INFO data (other information)
"""
2017-12-25 08:44:30 +00:00
test_data = 'TEst ExtrANEous MultiCase INformatoin that MFGR might Set'
# GIVEN: Test object
2017-12-25 08:44:30 +00:00
pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
pjlink.other_info = None
# WHEN: process_inf called with test data
pjlink.process_info(data=test_data)
# THEN: Data should be saved
self.assertEqual(pjlink.other_info, test_data, 'Test data should have been saved')
2017-06-25 02:21:07 +00:00
2017-12-25 08:44:30 +00:00
def test_projector_process_avmt_bad_data(self):
"""
Test avmt bad data fail
"""
# GIVEN: Test object
2017-12-25 08:44:30 +00:00
with patch.object(openlp.core.projectors.pjlink.PJLink, 'projectorUpdateIcons') as mock_UpdateIcons:
pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
pjlink.shutter = True
pjlink.mute = True
2017-12-25 08:44:30 +00:00
# WHEN: Called with an invalid setting
pjlink.process_avmt('36')
2017-12-25 08:44:30 +00:00
# THEN: Shutter should be closed and mute should be True
self.assertTrue(pjlink.shutter, 'Shutter should changed')
self.assertTrue(pjlink.mute, 'Audio should not have changed')
self.assertFalse(mock_UpdateIcons.emit.called, 'Update icons should NOT have been called')
2017-12-25 08:44:30 +00:00
def test_projector_process_avmt_closed_muted(self):
2017-06-25 02:21:07 +00:00
"""
2017-08-06 07:23:26 +00:00
Test avmt status shutter closed and mute off
2017-06-25 02:21:07 +00:00
"""
# GIVEN: Test object
2017-12-25 08:44:30 +00:00
with patch.object(openlp.core.projectors.pjlink.PJLink, 'projectorUpdateIcons') as mock_UpdateIcons:
pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
pjlink.shutter = False
pjlink.mute = False
2017-06-25 02:21:07 +00:00
2017-12-25 08:44:30 +00:00
# WHEN: Called with setting shutter to closed and mute on
pjlink.process_avmt('31')
2017-06-25 02:21:07 +00:00
2017-12-25 08:44:30 +00:00
# THEN: Shutter should be closed and mute should be True
self.assertTrue(pjlink.shutter, 'Shutter should have been set to closed')
self.assertTrue(pjlink.mute, 'Audio should be muted')
self.assertTrue(mock_UpdateIcons.emit.called, 'Update icons should have been called')
2017-06-25 02:21:07 +00:00
2017-12-25 08:44:30 +00:00
def test_projector_process_avmt_shutter_closed(self):
2017-06-25 02:21:07 +00:00
"""
Test avmt status shutter closed and audio unchanged
2017-06-25 02:21:07 +00:00
"""
# GIVEN: Test object
2017-12-25 08:44:30 +00:00
with patch.object(openlp.core.projectors.pjlink.PJLink, 'projectorUpdateIcons') as mock_UpdateIcons:
pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
pjlink.shutter = False
pjlink.mute = True
2017-06-25 02:21:07 +00:00
2017-12-25 08:44:30 +00:00
# WHEN: Called with setting shutter closed and mute off
pjlink.process_avmt('11')
2017-06-25 02:21:07 +00:00
2017-12-25 08:44:30 +00:00
# THEN: Shutter should be True and mute should be False
self.assertTrue(pjlink.shutter, 'Shutter should have been set to closed')
self.assertTrue(pjlink.mute, 'Audio should not have changed')
self.assertTrue(mock_UpdateIcons.emit.called, 'Update icons should have been called')
2017-06-25 02:21:07 +00:00
2017-12-25 08:44:30 +00:00
def test_projector_process_avmt_audio_muted(self):
2017-06-25 02:21:07 +00:00
"""
Test avmt status shutter unchanged and mute on
2017-06-25 02:21:07 +00:00
"""
# GIVEN: Test object
2017-12-25 08:44:30 +00:00
with patch.object(openlp.core.projectors.pjlink.PJLink, 'projectorUpdateIcons') as mock_UpdateIcons:
pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
pjlink.shutter = True
pjlink.mute = False
2017-06-25 02:21:07 +00:00
2017-12-25 08:44:30 +00:00
# WHEN: Called with setting shutter closed and mute on
pjlink.process_avmt('21')
2017-06-25 02:21:07 +00:00
2017-12-25 08:44:30 +00:00
# THEN: Shutter should be closed and mute should be True
self.assertTrue(pjlink.shutter, 'Shutter should not have changed')
self.assertTrue(pjlink.mute, 'Audio should be off')
self.assertTrue(mock_UpdateIcons.emit.called, 'Update icons should have been called')
2017-06-25 02:21:07 +00:00
2017-12-25 08:44:30 +00:00
def test_projector_process_avmt_open_unmuted(self):
2017-06-25 02:21:07 +00:00
"""
Test avmt status shutter open and mute off
2017-06-25 02:21:07 +00:00
"""
# GIVEN: Test object
2017-12-25 08:44:30 +00:00
with patch.object(openlp.core.projectors.pjlink.PJLink, 'projectorUpdateIcons') as mock_UpdateIcons:
pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
pjlink.shutter = True
pjlink.mute = True
2017-06-25 02:21:07 +00:00
2017-12-25 08:44:30 +00:00
# WHEN: Called with setting shutter to closed and mute on
pjlink.process_avmt('30')
2017-06-25 02:21:07 +00:00
2017-12-25 08:44:30 +00:00
# THEN: Shutter should be closed and mute should be True
self.assertFalse(pjlink.shutter, 'Shutter should have been set to open')
self.assertFalse(pjlink.mute, 'Audio should be on')
self.assertTrue(mock_UpdateIcons.emit.called, 'Update icons should have been called')
2017-06-25 02:21:07 +00:00
2017-08-06 07:23:26 +00:00
def test_projector_process_clss_one(self):
2017-06-25 02:21:07 +00:00
"""
Test class 1 sent from projector
"""
# GIVEN: Test object
2017-12-25 08:44:30 +00:00
pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
# WHEN: Process class response
pjlink.process_clss('1')
# THEN: Projector class should be set to 1
2017-12-25 08:44:30 +00:00
self.assertEqual(pjlink.pjlink_class, '1', 'Projector should have set class=1')
2017-08-06 07:23:26 +00:00
def test_projector_process_clss_two(self):
2017-06-25 02:21:07 +00:00
"""
Test class 2 sent from projector
"""
# GIVEN: Test object
2017-12-25 08:44:30 +00:00
pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
2017-06-25 02:21:07 +00:00
# WHEN: Process class response
pjlink.process_clss('2')
# THEN: Projector class should be set to 1
2017-12-25 08:44:30 +00:00
self.assertEqual(pjlink.pjlink_class, '2', 'Projector should have set class=2')
2017-06-25 02:21:07 +00:00
2017-12-25 08:44:30 +00:00
def test_projector_process_clss_invalid_nan(self):
"""
Test CLSS reply has no class number
"""
2017-12-25 08:44:30 +00:00
log_debug_calls = [call('(111.111.111.111) reset_information() connect status is '
'{state}'.format(state=STATUS_CODE[S_NOT_CONNECTED])),
call('(111.111.111.111) Setting pjlink_class for this projector to "1"')]
log_error_calls = [call('(111.111.111.111) NAN CLSS version reply "Z" - defaulting to class "1"')]
# GIVEN: Test object
2017-12-25 08:44:30 +00:00
with patch.object(openlp.core.projectors.pjlink, 'log') as mock_log:
pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
2017-12-25 08:44:30 +00:00
# WHEN: Process invalid reply
pjlink.process_clss('Z')
2017-12-25 08:44:30 +00:00
# THEN: Projector class should be set with default value
self.assertEqual(pjlink.pjlink_class, '1', 'Invalid NaN class reply should have set class=1')
mock_log.error.assert_has_calls(log_error_calls)
mock_log.debug.assert_has_calls(log_debug_calls)
2017-12-25 08:44:30 +00:00
def test_projector_process_clss_invalid_no_version(self):
"""
Test CLSS reply has no class number
"""
2017-12-25 08:44:30 +00:00
log_debug_calls = [call('(111.111.111.111) reset_information() connect status is '
'{state}'.format(state=STATUS_CODE[S_NOT_CONNECTED])),
call('(111.111.111.111) Setting pjlink_class for this projector to "1"')]
log_error_calls = [call('(111.111.111.111) No numbers found in class version reply "Invalid" '
'- defaulting to class "1"')]
# GIVEN: Test object
2017-12-25 08:44:30 +00:00
with patch.object(openlp.core.projectors.pjlink, 'log') as mock_log:
pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
2017-12-25 08:44:30 +00:00
# WHEN: Process invalid reply
pjlink.process_clss('Invalid')
2017-12-25 08:44:30 +00:00
# THEN: Projector class should be set with default value
self.assertEqual(pjlink.pjlink_class, '1', 'Invalid class reply should have set class=1')
mock_log.error.assert_has_calls(log_error_calls)
mock_log.debug.assert_has_calls(log_debug_calls)
2017-08-06 07:23:26 +00:00
def test_projector_process_erst_all_ok(self):
2016-03-03 18:19:42 +00:00
"""
2017-12-25 08:44:30 +00:00
Test to verify pjlink.projector_errors is set to None when no errors
2016-03-03 18:19:42 +00:00
"""
2017-12-25 08:44:30 +00:00
chk_data = '0' * PJLINK_ERST_DATA['DATA_LENGTH']
2016-03-03 18:19:42 +00:00
# GIVEN: Test object
2017-12-25 08:44:30 +00:00
pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
2016-03-03 18:19:42 +00:00
2017-08-06 07:23:26 +00:00
# WHEN: process_erst with no errors
2017-12-25 08:44:30 +00:00
pjlink.process_erst(chk_data)
# THEN: PJLink instance errors should be None
2017-08-06 07:23:26 +00:00
self.assertIsNone(pjlink.projector_errors, 'projector_errors should have been set to None')
2017-12-25 08:44:30 +00:00
def test_projector_process_erst_data_invalid_length(self):
"""
Test test_projector_process_erst_data_invalid_length
"""
2017-12-25 08:44:30 +00:00
chk_data = '0' * (PJLINK_ERST_DATA['DATA_LENGTH'] + 1)
log_debug_calls = [call('(111.111.111.111) reset_information() connect status is '
'{state}'.format(state=STATUS_CODE[S_NOT_CONNECTED]))]
log_warn_calls = [call('111.111.111.111) Invalid error status response "0000000": '
'length != {chk}'.format(chk=PJLINK_ERST_DATA['DATA_LENGTH']))]
# GIVEN: Test object
2017-12-25 08:44:30 +00:00
with patch.object(openlp.core.projectors.pjlink, 'log') as mock_log:
pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
pjlink.projector_errors = None
2017-12-25 08:44:30 +00:00
# WHEN: process_erst called with invalid data (too many values
pjlink.process_erst(chk_data)
2017-12-25 08:44:30 +00:00
# THEN: pjlink.projector_errors should be empty and warning logged
self.assertIsNone(pjlink.projector_errors, 'There should be no errors')
mock_log.debug.assert_has_calls(log_debug_calls)
mock_log.warning.assert_has_calls(log_warn_calls)
2017-12-25 08:44:30 +00:00
def test_projector_process_erst_data_invalid_nan(self):
"""
Test test_projector_process_erst_data_invalid_nan
"""
2017-12-25 08:44:30 +00:00
chk_data = 'Z' + ('0' * (PJLINK_ERST_DATA['DATA_LENGTH'] - 1))
log_debug_calls = [call('(111.111.111.111) reset_information() connect status is '
'{state}'.format(state=STATUS_CODE[S_NOT_CONNECTED]))]
log_warn_calls = [call('(111.111.111.111) Invalid error status response "Z00000"')]
# GIVEN: Test object
2017-12-25 08:44:30 +00:00
with patch.object(openlp.core.projectors.pjlink, 'log') as mock_log:
pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
pjlink.projector_errors = None
2017-12-25 08:44:30 +00:00
# WHEN: process_erst called with invalid data (too many values
pjlink.process_erst(chk_data)
2017-12-25 08:44:30 +00:00
# THEN: pjlink.projector_errors should be empty and warning logged
self.assertIsNone(pjlink.projector_errors, 'There should be no errors')
mock_log.debug.assert_has_calls(log_debug_calls)
mock_log.warning.assert_has_calls(log_warn_calls)
2017-08-06 07:23:26 +00:00
def test_projector_process_erst_all_warn(self):
"""
Test test_projector_process_erst_all_warn
"""
2017-12-25 08:44:30 +00:00
chk_data = '{fan}{lamp}{temp}{cover}{filt}{other}'.format(fan=PJLINK_ERST_STATUS[E_WARN],
lamp=PJLINK_ERST_STATUS[E_WARN],
temp=PJLINK_ERST_STATUS[E_WARN],
cover=PJLINK_ERST_STATUS[E_WARN],
filt=PJLINK_ERST_STATUS[E_WARN],
other=PJLINK_ERST_STATUS[E_WARN])
chk_test = {'Fan': E_WARN,
'Lamp': E_WARN,
'Temperature': E_WARN,
'Cover': E_WARN,
'Filter': E_WARN,
'Other': E_WARN}
2017-08-06 07:23:26 +00:00
# GIVEN: Test object
2017-12-25 08:44:30 +00:00
pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
pjlink.projector_errors = None
2017-08-06 07:23:26 +00:00
# WHEN: process_erst with status set to WARN
2017-12-25 08:44:30 +00:00
pjlink.process_erst(chk_data)
2017-08-06 07:23:26 +00:00
# THEN: PJLink instance errors should match chk_value
2017-12-25 08:44:30 +00:00
self.assertEqual(pjlink.projector_errors, chk_test, 'Projector errors should be all E_WARN')
2017-08-06 07:23:26 +00:00
def test_projector_process_erst_all_error(self):
"""
Test test_projector_process_erst_all_error
"""
2017-12-25 08:44:30 +00:00
chk_data = '{fan}{lamp}{temp}{cover}{filt}{other}'.format(fan=PJLINK_ERST_STATUS[E_ERROR],
lamp=PJLINK_ERST_STATUS[E_ERROR],
temp=PJLINK_ERST_STATUS[E_ERROR],
cover=PJLINK_ERST_STATUS[E_ERROR],
filt=PJLINK_ERST_STATUS[E_ERROR],
other=PJLINK_ERST_STATUS[E_ERROR])
chk_test = {'Fan': E_ERROR,
'Lamp': E_ERROR,
'Temperature': E_ERROR,
'Cover': E_ERROR,
'Filter': E_ERROR,
'Other': E_ERROR}
2017-08-06 07:23:26 +00:00
# GIVEN: Test object
2017-12-25 08:44:30 +00:00
pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
pjlink.projector_errors = None
# WHEN: process_erst with status set to WARN
2017-12-25 08:44:30 +00:00
pjlink.process_erst(chk_data)
# THEN: PJLink instance errors should match chk_value
2017-12-25 08:44:30 +00:00
self.assertEqual(pjlink.projector_errors, chk_test, 'Projector errors should be all E_ERROR')
def test_projector_process_erst_warn_cover_only(self):
"""
Test test_projector_process_erst_warn_cover_only
"""
2017-12-25 08:44:30 +00:00
chk_data = '{fan}{lamp}{temp}{cover}{filt}{other}'.format(fan=PJLINK_ERST_STATUS[S_OK],
lamp=PJLINK_ERST_STATUS[S_OK],
temp=PJLINK_ERST_STATUS[S_OK],
cover=PJLINK_ERST_STATUS[E_WARN],
filt=PJLINK_ERST_STATUS[S_OK],
other=PJLINK_ERST_STATUS[S_OK])
chk_test = {'Cover': E_WARN}
# GIVEN: Test object
2017-12-25 08:44:30 +00:00
pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
pjlink.projector_errors = None
# WHEN: process_erst with status set to WARN
pjlink.process_erst(chk_data)
# THEN: PJLink instance errors should match only cover warning
assert 1 == len(pjlink.projector_errors), 'There should only be 1 error listed in projector_errors'
assert 'Cover' in pjlink.projector_errors, '"Cover" should be the only error listed'
assert pjlink.projector_errors['Cover'] == E_WARN, '"Cover" should have E_WARN listed as error'
assert chk_test == pjlink.projector_errors, 'projector_errors should match test errors'
def test_projector_process_inpt_valid(self):
2017-08-06 07:23:26 +00:00
"""
Test input source status shows current input
"""
2017-12-25 08:44:30 +00:00
log_debug_calls = [call('(111.111.111.111) reset_information() connect status is S_NOT_CONNECTED')]
chk_source_available = ['11', '12', '21', '22', '31', '32']
# GIVEN: Test object
2017-12-25 08:44:30 +00:00
with patch.object(openlp.core.projectors.pjlink, 'log') as mock_log:
pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
pjlink.source_available = chk_source_available
pjlink.source = '11'
# WHEN: Called with input source
pjlink.process_inpt('21')
2017-12-25 08:44:30 +00:00
# THEN: Input selected should reflect current input
assert pjlink.source == '21', 'Input source should be set to "21"'
mock_log.debug.assert_has_calls(log_debug_calls)
2017-12-25 08:44:30 +00:00
def test_projector_process_input_not_in_list(self):
"""
Test setting input outside of available inputs
TODO: Future test
"""
pass
2016-04-17 09:30:30 +00:00
2017-12-25 08:44:30 +00:00
def test_projector_process_input_not_in_default(self):
"""
Test setting input with no sources available
TODO: Future test
"""
pass
def test_projector_process_input_invalid(self):
"""
Test setting input with an invalid value
TODO: Future test
"""
def test_projector_process_inst_class_1(self):
2016-04-16 08:08:45 +00:00
"""
Test saving video source available information
2016-04-16 08:08:45 +00:00
"""
2017-12-25 08:44:30 +00:00
log_debug_calls = [call('(111.111.111.111) Setting projector sources_available to '
'"[\'11\', \'12\', \'21\', \'22\', \'31\', \'32\']"')]
chk_data = '21 12 11 22 32 31' # Although they should already be sorted, use unsorted to verify method
chk_test = ['11', '12', '21', '22', '31', '32']
2016-04-16 08:08:45 +00:00
# GIVEN: Test object
2017-12-25 08:44:30 +00:00
with patch.object(openlp.core.projectors.pjlink, 'log') as mock_log:
pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
pjlink.source_available = []
# WHEN: process_inst called with test data
pjlink.process_inst(data=chk_data)
# THEN: Data should have been sorted and saved properly
assert pjlink.source_available == chk_test, "Sources should have been sorted and saved"
mock_log.debug.assert_has_calls(log_debug_calls)
def test_projector_process_lamp_invalid(self):
"""
Test status multiple lamp on/off and hours
"""
2017-12-25 08:44:30 +00:00
log_data = [call('(111.111.111.111) process_lamp(): Invalid data "11111 1 22222 0 333A3 1"')]
2016-04-16 08:08:45 +00:00
2017-12-25 08:44:30 +00:00
# GIVEN: Test object
with patch.object(openlp.core.projectors.pjlink, 'log') as mock_log:
pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
pjlink.lamp = [{'Hours': 00000, 'On': True},
{'Hours': 11111, 'On': False}]
# WHEN: Call process_command with invalid lamp data
pjlink.process_lamp('11111 1 22222 0 333A3 1')
# THEN: lamps should not have changed
assert 2 == len(pjlink.lamp), 'Projector should have kept 2 lamps specified'
assert pjlink.lamp[0]['On'] is True, 'Lamp 1 power status should have stayed TRUE'
assert 00000 == pjlink.lamp[0]['Hours'], 'Lamp 1 hours should have been left at 00000'
assert pjlink.lamp[1]['On'] is False, 'Lamp 2 power status should have stayed FALSE'
assert 11111 == pjlink.lamp[1]['Hours'], 'Lamp 2 hours should have been left at 11111'
mock_log.warning.assert_has_calls(log_data)
2016-04-22 11:41:29 +00:00
def test_projector_process_lamp_multiple(self):
2016-04-17 09:30:30 +00:00
"""
Test status multiple lamp on/off and hours
2016-04-17 09:30:30 +00:00
"""
# GIVEN: Test object
2017-12-25 08:44:30 +00:00
pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
pjlink.lamp = []
2016-04-17 09:30:30 +00:00
2017-12-25 08:44:30 +00:00
# WHEN: Call process_command with invalid lamp data
pjlink.process_lamp('11111 1 22222 0 33333 1')
2016-04-17 09:30:30 +00:00
2016-04-17 09:33:48 +00:00
# THEN: Lamp should have been set with proper lamp status
2017-12-25 08:44:30 +00:00
assert 3 == len(pjlink.lamp), 'Projector should have 3 lamps specified'
assert pjlink.lamp[0]['On'] is True, 'Lamp 1 power status should have been set to TRUE'
assert 11111 == pjlink.lamp[0]['Hours'], 'Lamp 1 hours should have been set to 11111'
assert pjlink.lamp[1]['On'] is False, 'Lamp 2 power status should have been set to FALSE'
assert 22222 == pjlink.lamp[1]['Hours'], 'Lamp 2 hours should have been set to 22222'
assert pjlink.lamp[2]['On'] is True, 'Lamp 3 power status should have been set to TRUE'
assert 33333 == pjlink.lamp[2]['Hours'], 'Lamp 3 hours should have been set to 33333'
2016-04-23 19:55:47 +00:00
def test_projector_process_lamp_single(self):
"""
Test status lamp on/off and hours
"""
2017-12-25 08:44:30 +00:00
# GIVEN: Test object
2017-12-25 08:44:30 +00:00
pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
pjlink.lamp = []
2017-12-25 08:44:30 +00:00
# WHEN: Call process_command with invalid lamp data
pjlink.process_lamp('22222 1')
# THEN: Lamp should have been set with status=ON and hours=22222
2017-12-25 08:44:30 +00:00
assert 1 == len(pjlink.lamp), 'Projector should have only 1 lamp'
assert pjlink.lamp[0]['On'] is True, 'Lamp power status should have been set to TRUE'
assert 22222 == pjlink.lamp[0]['Hours'], 'Lamp hours should have been set to 22222'
2017-12-25 08:44:30 +00:00
def test_projector_process_name(self):
"""
Test saving NAME data from projector
"""
2017-12-25 08:44:30 +00:00
chk_data = "Some Name the End-User Set IN Projector"
log_debug_calls = [call('(111.111.111.111) Setting projector PJLink name to '
'"Some Name the End-User Set IN Projector"')]
2017-12-25 08:44:30 +00:00
# GIVEN: Test object
with patch.object(openlp.core.projectors.pjlink, 'log') as mock_log:
pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
# WHEN: process_name called with test data
pjlink.process_name(data=chk_data)
2017-12-25 08:44:30 +00:00
# THEN: name should be set and logged
assert pjlink.pjlink_name == chk_data, 'Name test data should have been saved'
mock_log.debug.assert_has_calls(log_debug_calls)
2017-12-25 08:44:30 +00:00
def test_projector_process_powr_on(self):
2016-04-23 19:55:47 +00:00
"""
Test status power to ON
2016-04-23 19:55:47 +00:00
"""
2017-12-25 08:44:30 +00:00
# GIVEN: Test object
with patch.object(openlp.core.projectors.pjlink.PJLink, 'send_command') as mock_send_command, \
patch.object(openlp.core.projectors.pjlink.PJLink, 'change_status') as mock_change_status, \
patch.object(openlp.core.projectors.pjlink.PJLink, 'projectorUpdateIcons') as mock_UpdateIcons:
pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
pjlink.power = S_STANDBY
2016-04-23 19:55:47 +00:00
2017-12-25 08:44:30 +00:00
# WHEN: process_name called with test data
pjlink.process_powr(data=PJLINK_POWR_STATUS[S_ON])
2016-04-23 19:55:47 +00:00
2017-12-25 08:44:30 +00:00
# THEN: Power should be set to ON
assert pjlink.power == S_ON, 'Power should have been set to ON'
assert mock_UpdateIcons.emit.called is True, 'projectorUpdateIcons should have been called'
mock_send_command.assert_called_once_with('INST')
mock_change_status.assert_called_once_with(S_ON)
2016-04-23 19:55:47 +00:00
2017-12-25 08:44:30 +00:00
def test_projector_process_powr_invalid(self):
"""
Test process_powr invalid call
"""
2017-12-25 08:44:30 +00:00
log_warn_calls = [call('(111.111.111.111) Unknown power response: "99"')]
2017-12-25 08:44:30 +00:00
# GIVEN: Test object
with patch.object(openlp.core.projectors.pjlink, 'log') as mock_log, \
patch.object(openlp.core.projectors.pjlink.PJLink, 'send_command') as mock_send_command, \
patch.object(openlp.core.projectors.pjlink.PJLink, 'change_status') as mock_change_status, \
patch.object(openlp.core.projectors.pjlink.PJLink, 'projectorUpdateIcons') as mock_UpdateIcons:
pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
pjlink.power = S_STANDBY
2017-12-25 08:44:30 +00:00
# WHEN: process_name called with test data
pjlink.process_powr(data='99')
2017-12-25 08:44:30 +00:00
# THEN: Power should be set to ON
assert pjlink.power == S_STANDBY, 'Power should not have changed'
assert mock_UpdateIcons.emit.called is False, 'projectorUpdateIcons() should not have been called'
mock_change_status.called is False, 'change_status() should not have been called'
mock_send_command.called is False, 'send_command() should not have been called'
mock_log.warning.assert_has_calls(log_warn_calls)
def test_projector_process_powr_off(self):
2016-04-23 19:55:47 +00:00
"""
Test status power to STANDBY
2016-04-23 19:55:47 +00:00
"""
2017-12-25 08:44:30 +00:00
# GIVEN: Test object
with patch.object(openlp.core.projectors.pjlink.PJLink, 'send_command') as mock_send_command, \
patch.object(openlp.core.projectors.pjlink.PJLink, 'change_status') as mock_change_status, \
patch.object(openlp.core.projectors.pjlink.PJLink, 'projectorUpdateIcons') as mock_UpdateIcons:
2016-04-23 19:55:47 +00:00
2017-12-25 08:44:30 +00:00
pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
pjlink.power = S_ON
2016-04-23 19:55:47 +00:00
2017-12-25 08:44:30 +00:00
# WHEN: process_name called with test data
pjlink.process_powr(data=PJLINK_POWR_STATUS[S_STANDBY])
# THEN: Power should be set to ON
assert pjlink.power == S_STANDBY, 'Power should have changed to S_STANDBY'
assert mock_UpdateIcons.emit.called is True, 'projectorUpdateIcons should have been called'
mock_change_status.called is True, 'change_status should have been called'
mock_send_command.called is False, 'send_command should not have been called'
2017-08-06 07:23:26 +00:00
def test_projector_process_rfil_save(self):
"""
2017-08-06 07:23:26 +00:00
Test saving filter type
"""
2017-12-25 08:44:30 +00:00
filter_model = 'Filter Type Test'
# GIVEN: Test object
2017-12-25 08:44:30 +00:00
pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
2017-08-06 07:23:26 +00:00
pjlink.model_filter = None
2017-08-06 07:23:26 +00:00
# WHEN: Filter model is received
pjlink.process_rfil(data=filter_model)
2017-08-06 07:23:26 +00:00
# THEN: Filter model number should be saved
2017-12-25 08:44:30 +00:00
assert pjlink.model_filter == filter_model, 'Filter type should have been saved'
2017-08-06 07:23:26 +00:00
def test_projector_process_rfil_nosave(self):
"""
2017-08-06 07:23:26 +00:00
Test saving filter type previously saved
"""
2017-08-06 07:23:26 +00:00
filter_model = 'Filter Type Test'
2017-12-25 08:44:30 +00:00
log_warn_calls = [call('(111.111.111.111) Filter model already set'),
call('(111.111.111.111) Saved model: "Old filter type"'),
call('(111.111.111.111) New model: "Filter Type Test"')]
2017-12-25 08:44:30 +00:00
# GIVEN: Test object
with patch.object(openlp.core.projectors.pjlink, 'log') as mock_log:
2017-12-25 08:44:30 +00:00
pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
pjlink.model_filter = 'Old filter type'
# WHEN: Filter model is received
pjlink.process_rfil(data=filter_model)
# THEN: Filter model number should be saved
assert pjlink.model_filter != filter_model, 'Filter type should NOT have been saved'
mock_log.warning.assert_has_calls(log_warn_calls)
2017-08-06 07:23:26 +00:00
def test_projector_process_rlmp_save(self):
"""
2017-08-06 07:23:26 +00:00
Test saving lamp type
"""
# GIVEN: Test object
2017-12-25 08:44:30 +00:00
# GIVEN: Test object
pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
2017-08-06 07:23:26 +00:00
pjlink.model_lamp = None
lamp_model = 'Lamp Type Test'
2017-08-06 07:23:26 +00:00
# WHEN: Filter model is received
pjlink.process_rlmp(data=lamp_model)
2017-08-06 07:23:26 +00:00
# THEN: Filter model number should be saved
self.assertEqual(pjlink.model_lamp, lamp_model, 'Lamp type should have been saved')
2017-08-06 07:23:26 +00:00
def test_projector_process_rlmp_nosave(self):
"""
2017-08-06 07:23:26 +00:00
Test saving lamp type previously saved
"""
2017-12-25 08:44:30 +00:00
lamp_model = 'Lamp Type Test'
log_warn_calls = [call('(111.111.111.111) Lamp model already set'),
call('(111.111.111.111) Saved lamp: "Old lamp type"'),
call('(111.111.111.111) New lamp: "Lamp Type Test"')]
# GIVEN: Test object
2017-12-25 08:44:30 +00:00
with patch.object(openlp.core.projectors.pjlink, 'log') as mock_log:
2017-12-25 08:44:30 +00:00
pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
pjlink.model_lamp = 'Old lamp type'
2017-12-25 08:44:30 +00:00
# WHEN: Filter model is received
pjlink.process_rlmp(data=lamp_model)
# THEN: Filter model number should be saved
assert pjlink.model_lamp != lamp_model, 'Lamp type should NOT have been saved'
mock_log.warning.assert_has_calls(log_warn_calls)
2016-05-21 18:19:18 +00:00
2017-08-06 07:23:26 +00:00
def test_projector_process_snum_set(self):
2016-05-21 18:19:18 +00:00
"""
2017-08-06 07:23:26 +00:00
Test saving serial number from projector
2016-05-21 18:19:18 +00:00
"""
2017-12-25 08:44:30 +00:00
log_debug_calls = [call('(111.111.111.111) Setting projector serial number to "Test Serial Number"')]
2017-08-06 07:23:26 +00:00
test_number = 'Test Serial Number'
2017-12-25 08:44:30 +00:00
# GIVEN: Test object
with patch.object(openlp.core.projectors.pjlink, 'log') as mock_log:
pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
pjlink.serial_no = None
2017-12-25 08:44:30 +00:00
# WHEN: No serial number is set and we receive serial number command
pjlink.process_snum(data=test_number)
# THEN: Serial number should be set
assert pjlink.serial_no == test_number, 'Projector serial number should have been set'
mock_log.debug.assert_has_calls(log_debug_calls)
2017-05-12 09:51:56 +00:00
2017-08-06 07:23:26 +00:00
def test_projector_process_snum_different(self):
2017-05-13 09:00:29 +00:00
"""
2017-08-06 07:23:26 +00:00
Test projector serial number different than saved serial number
2017-05-13 09:00:29 +00:00
"""
2017-12-25 08:44:30 +00:00
log_warn_calls = [call('(111.111.111.111) Projector serial number does not match saved serial number'),
call('(111.111.111.111) Saved: "Previous serial number"'),
call('(111.111.111.111) Received: "Test Serial Number"'),
call('(111.111.111.111) NOT saving serial number')]
2017-08-06 07:23:26 +00:00
test_number = 'Test Serial Number'
2017-05-13 09:00:29 +00:00
2017-12-25 08:44:30 +00:00
# GIVEN: Test object
with patch.object(openlp.core.projectors.pjlink, 'log') as mock_log:
pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
pjlink.serial_no = 'Previous serial number'
2017-05-13 09:00:29 +00:00
2017-12-25 08:44:30 +00:00
# WHEN: No serial number is set and we receive serial number command
pjlink.process_snum(data=test_number)
2017-12-25 08:44:30 +00:00
# THEN: Serial number should be set
assert pjlink.serial_no != test_number, 'Projector serial number should NOT have been set'
mock_log.warning.assert_has_calls(log_warn_calls)
def test_projector_process_sver(self):
"""
Test invalid software version information - too long
"""
test_data = 'Test 1 Subtest 1'
2017-12-25 08:44:30 +00:00
log_debug_calls = [call('(111.111.111.111) Setting projector software version to "Test 1 Subtest 1"')]
2017-12-25 08:44:30 +00:00
# GIVEN: Test object
with patch.object(openlp.core.projectors.pjlink, 'log') as mock_log:
pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
pjlink.sw_version = None
pjlink.sw_version_received = None
# WHEN: process_sver called with invalid data
pjlink.process_sver(data=test_data)
2017-12-25 08:44:30 +00:00
# THEN: Version information should not change
assert pjlink.sw_version == test_data, 'Software version should have been updated'
mock_log.debug.assert_has_calls(log_debug_calls)
2017-12-25 08:44:30 +00:00
def test_projector_process_sver_changed(self):
"""
Test invalid software version information - Received different than saved
"""
test_data_old = 'Test 1 Subtest 1'
2017-12-25 08:44:30 +00:00
test_data_new = 'Test 1 Subtest 2'
log_warn_calls = [call('(111.111.111.111) Projector software version does not match saved software version'),
call('(111.111.111.111) Saved: "Test 1 Subtest 1"'),
call('(111.111.111.111) Received: "Test 1 Subtest 2"'),
call('(111.111.111.111) Updating software version')]
# GIVEN: Test object
with patch.object(openlp.core.projectors.pjlink, 'log') as mock_log:
pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
pjlink.sw_version = test_data_old
2017-12-25 08:44:30 +00:00
# WHEN: process_sver called with invalid data
pjlink.process_sver(data=test_data_new)
2017-12-25 08:44:30 +00:00
# THEN: Version information should not change
assert pjlink.sw_version == test_data_new, 'Software version should have changed'
mock_log.warning.assert_has_calls(log_warn_calls)
2017-12-25 08:44:30 +00:00
def test_projector_process_sver_invalid(self):
"""
Test invalid software version information - too long
"""
test_data = 'This is a test software version line that is too long based on PJLink version 2 specs'
2017-12-25 08:44:30 +00:00
log_warn_calls = [call('Invalid software version - too long')]
2017-12-25 08:44:30 +00:00
# GIVEN: Test object
with patch.object(openlp.core.projectors.pjlink, 'log') as mock_log:
pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
pjlink.sw_version = None
# WHEN: process_sver called with invalid data
pjlink.process_sver(data=test_data)
2017-12-25 08:44:30 +00:00
# THEN: Version information should not change
assert pjlink.sw_version is None, 'Software version should not have changed'
assert pjlink.sw_version_received is None, 'Received software version should not have changed'
mock_log.warning.assert_has_calls(log_warn_calls)
def test_projector_reset_information(self):
"""
Test reset_information() resets all information and stops timers
"""
2017-12-25 08:44:30 +00:00
log_debug_calls = [call('(111.111.111.111): Calling timer.stop()'),
call('(111.111.111.111): Calling socket_timer.stop()')]
# GIVEN: Test object
with patch.object(openlp.core.projectors.pjlink, 'log') as mock_log:
pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
# timer and socket_timer not available until instantiation, so mock here
with patch.object(pjlink, 'socket_timer') as mock_socket_timer, \
patch.object(pjlink, 'timer') as mock_timer:
pjlink.power = S_ON
pjlink.pjlink_name = 'OPENLPTEST'
pjlink.manufacturer = 'PJLINK'
pjlink.model = '1'
pjlink.shutter = True
pjlink.mute = True
pjlink.lamp = True
pjlink.fan = True
pjlink.source_available = True
pjlink.other_info = 'ANOTHER TEST'
pjlink.send_queue = True
pjlink.send_busy = True
# WHEN: reset_information() is called
pjlink.reset_information()
2017-12-25 08:44:30 +00:00
# THEN: All information should be reset and timers stopped
assert pjlink.power == S_OFF, 'Projector power should be OFF'
assert pjlink.pjlink_name is None, 'Projector pjlink_name should be None'
assert pjlink.manufacturer is None, 'Projector manufacturer should be None'
assert pjlink.model is None, 'Projector model should be None'
assert pjlink.shutter is None, 'Projector shutter should be None'
assert pjlink.mute is None, 'Projector shuttter should be None'
assert pjlink.lamp is None, 'Projector lamp should be None'
assert pjlink.fan is None, 'Projector fan should be None'
assert pjlink.source_available is None, 'Projector source_available should be None'
assert pjlink.source is None, 'Projector source should be None'
assert pjlink.other_info is None, 'Projector other_info should be None'
assert pjlink.send_queue == [], 'Projector send_queue should be an empty list'
assert pjlink.send_busy is False, 'Projector send_busy should be False'
assert mock_timer.stop.called is True, 'Projector timer.stop() should have been called'
assert mock_socket_timer.stop.called is True, 'Projector socket_timer.stop() should have been called'
mock_log.debug.assert_has_calls(log_debug_calls)