def test_process_command_future(self): """ Test command valid but no method to process yet """ # GIVEN: Test object with patch.object(openlp.core.projectors.pjlink, 'log') as mock_log, \ patch.object(openlp.core.projectors.pjlink.PJLink, 'process_clss') as mock_process_clss: pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True) pjlink.pjlink_functions = MagicMock() log_warning_text = [ call( '({ip}) Unable to process command="CLSS" (Future option?)'. format(ip=pjlink.name)) ] log_debug_text = [ call( '({ip}) Processing command "CLSS" with data "Huh?"'.format( ip=pjlink.name)) ] # WHEN: Processing a possible future command pjlink.process_command(cmd='CLSS', data="Huh?") # THEN: Appropriate log entries should have been made and methods called/not called mock_log.debug.assert_has_calls(log_debug_text) mock_log.warning.assert_has_calls(log_warning_text) assert pjlink.pjlink_functions.called is False, 'Should not have accessed pjlink_functions' assert mock_process_clss.called is False, 'Should not have called process_clss'
def test_process_command_erra(self): """ Test ERRA - Authentication Error """ # GIVEN: Test object with patch.object(openlp.core.projectors.pjlink, 'log') as mock_log, \ patch.object(openlp.core.projectors.pjlink.PJLink, 'process_pjlink') as mock_process_pjlink, \ patch.object(openlp.core.projectors.pjlink.PJLink, 'change_status') as mock_change_status, \ patch.object(openlp.core.projectors.pjlink.PJLink, 'disconnect_from_host') as mock_disconnect, \ patch.object(openlp.core.projectors.pjlink.PJLink, 'projectorAuthentication') as mock_authentication: pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True) log_error_calls = [ call('({ip}) PJLINK: {msg}'.format( ip=pjlink.name, msg=STATUS_MSG[E_AUTHENTICATION])) ] log_debug_calls = [ call('({ip}) Processing command "PJLINK" with data "ERRA"'. format(ip=pjlink.name)) ] # WHEN: process_command called with ERRA pjlink.process_command(cmd='PJLINK', data=PJLINK_ERRORS[E_AUTHENTICATION]) # THEN: Appropriate log entries should have been made and methods called/not called assert mock_disconnect.called is True, 'disconnect_from_host should have been called' mock_log.error.assert_has_calls(log_error_calls) mock_log.debug.assert_has_calls(log_debug_calls) mock_change_status.assert_called_once_with(status=E_AUTHENTICATION) mock_authentication.emit.assert_called_once_with(pjlink.name) mock_process_pjlink.assert_not_called()
def test_process_command_err4(self): """ Test ERR3 - Unavailable error """ # GIVEN: Test object with patch.object(openlp.core.projectors.pjlink, 'log') as mock_log, \ patch.object(openlp.core.projectors.pjlink.PJLink, 'process_clss') as mock_process_clss: pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True) log_error_text = [ call('({ip}) CLSS: {msg}'.format(ip=pjlink.name, msg=STATUS_MSG[E_PROJECTOR])) ] log_debug_text = [ call( '({ip}) Processing command "CLSS" with data "ERR4"'.format( ip=pjlink.name)), call('({ip}) Calling function for CLSS'.format(ip=pjlink.name)) ] # WHEN: process_command called with ERR4 pjlink.process_command(cmd='CLSS', data=PJLINK_ERRORS[E_PROJECTOR]) # THEN: Appropriate log entries should have been made and methods called mock_log.error.assert_has_calls(log_error_text) mock_log.debug.assert_has_calls(log_debug_text) mock_process_clss.assert_called_once_with( data=PJLINK_ERRORS[E_PROJECTOR])
def test_status_change(self): """ Test process_command call with ERR2 (Parameter) status """ # GIVEN: Test object with patch('openlp.core.projectors.pjlink.PJLink.changeStatus') as mock_changeStatus: pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True) # WHEN: process_command is called with "ERR2" status from projector pjlink.process_command('POWR', 'ERR2') # THEN: change_status should have called change_status with E_UNDEFINED # as first parameter mock_changeStatus.called_with(E_PARAMETER, 'change_status should have been called with "{}"'.format( STATUS_CODE[E_PARAMETER]))
def test_process_command_call_clss(self): """ Test process_command calls proper function """ # GIVEN: Test object and mocks with patch.object(openlp.core.projectors.pjlink, 'log') as mock_log, \ patch.object(openlp.core.projectors.pjlink.PJLink, 'process_clss') as mock_process_clss: pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True) log_debug_calls = [ call('({ip}) Processing command "CLSS" with data "1"'.format( ip=pjlink.name)), call('({ip}) Calling function for CLSS'.format(ip=pjlink.name)) ] # WHEN: process_command is called with valid function and data pjlink.process_command(cmd='CLSS', data='1') # THEN: Appropriate log entries should have been made and methods called mock_log.debug.assert_has_calls(log_debug_calls) mock_process_clss.assert_called_once_with(data='1')