def test_projector_change_status_connection_status_with_message( self, mock_log, mock_changeStatus): """ Test change_status with connection status """ # GIVEN: Test object pjlink = self.pjlink pjlink.projector_status = 0 pjlink.status_connect = 0 test_message = 'Different Status Message than default' log_debug_calls = [ call('({ip}) Changing status to {status} "{msg}"'.format( ip=pjlink.name, status=STATUS_CODE[S_ON], msg=test_message)), call('({ip}) status_connect: {code}: "{msg}"'.format( ip=pjlink.name, code=STATUS_CODE[S_OK], msg=test_message)), call('({ip}) projector_status: {code}: "{msg}"'.format( ip=pjlink.name, code=STATUS_CODE[S_ON], msg=test_message)), call('({ip}) error_status: {code}: "{msg}"'.format( ip=pjlink.name, code=STATUS_CODE[S_OK], msg=test_message)) ] # 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) mock_changeStatus.emit.assert_called_once_with(pjlink.ip, S_ON, test_message) assert pjlink.projector_status == S_ON, 'Projector status should be ON' assert pjlink.status_connect == S_OK, 'Status connect should not have changed'
def test_projector_change_status_connection_status_connected( self, mock_log, mock_changeStatus): """ Test change_status with connected status """ # GIVEN: Test object pjlink = self.pjlink pjlink.projector_status = 0 pjlink.status_connect = 0 log_debug_calls = [ call('({ip}) Changing status to {status} "{msg}"'.format( ip=pjlink.name, status=STATUS_CODE[S_CONNECTED], msg=STATUS_MSG[S_CONNECTED])), call('({ip}) status_connect: {code}: "{msg}"'.format( ip=pjlink.name, code=STATUS_CODE[S_CONNECTED], msg=STATUS_MSG[S_CONNECTED])), call('({ip}) projector_status: {code}: "{msg}"'.format( ip=pjlink.name, code=STATUS_CODE[S_OK], msg=STATUS_MSG[S_OK])), call('({ip}) error_status: {code}: "{msg}"'.format( ip=pjlink.name, code=STATUS_CODE[S_OK], msg=STATUS_MSG[S_OK])) ] # 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) mock_changeStatus.emit.assert_called_once_with(pjlink.ip, S_CONNECTED, 'Connected') assert pjlink.projector_status == S_OK, 'Projector status should not have changed' assert pjlink.status_connect == S_CONNECTED, 'Status connect should be CONNECTED'
def test_projector_change_status_connection_status_connected(self): """ Test change_status with connected status """ # 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 log_debug_calls = [ call('({ip}) Changing status to {status} "{msg}"'.format(ip=pjlink.name, status=STATUS_CODE[S_CONNECTED], msg=STATUS_MSG[S_CONNECTED])), call('({ip}) status_connect: {code}: "{msg}"'.format(ip=pjlink.name, code=STATUS_CODE[S_CONNECTED], msg=STATUS_MSG[S_CONNECTED])), call('({ip}) projector_status: {code}: "{msg}"'.format(ip=pjlink.name, code=STATUS_CODE[S_OK], msg=STATUS_MSG[S_OK])), call('({ip}) error_status: {code}: "{msg}"'.format(ip=pjlink.name, code=STATUS_CODE[S_OK], msg=STATUS_MSG[S_OK]))] # 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) mock_changeStatus.emit.assert_called_once_with(pjlink.ip, S_CONNECTED, 'Connected') assert pjlink.projector_status == S_OK, 'Projector status should not have changed' assert pjlink.status_connect == S_CONNECTED, 'Status connect should be CONNECTED'
def test_projector_change_status_unknown_socket_error( self, mock_log, mock_changeStatus, mock_UpdateIcons): """ Test change_status with connection error """ # GIVEN: Test object pjlink = self.pjlink pjlink.projector_status = 0 pjlink.status_connect = 0 log_debug_calls = [ call('({ip}) Changing status to {status} "{msg}"'.format( ip=pjlink.name, status=STATUS_CODE[E_UNKNOWN_SOCKET_ERROR], msg=STATUS_MSG[E_UNKNOWN_SOCKET_ERROR])), call('({ip}) status_connect: {code}: "{msg}"'.format( ip=pjlink.name, code=STATUS_CODE[E_NOT_CONNECTED], msg=STATUS_MSG[E_NOT_CONNECTED])), call('({ip}) projector_status: {code}: "{msg}"'.format( ip=pjlink.name, code=STATUS_CODE[S_OK], msg=STATUS_MSG[S_OK])), call('({ip}) error_status: {code}: "{msg}"'.format( ip=pjlink.name, code=STATUS_CODE[E_UNKNOWN_SOCKET_ERROR], msg=STATUS_MSG[E_UNKNOWN_SOCKET_ERROR])) ] # 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) assert pjlink.projector_status == S_OK, 'Projector status should not have changed' assert pjlink.status_connect == E_NOT_CONNECTED, 'Status connect should be NOT CONNECTED' assert mock_UpdateIcons.emit.called is True, 'Should have called UpdateIcons' mock_changeStatus.emit.assert_called_once_with( pjlink.ip, E_UNKNOWN_SOCKET_ERROR, STATUS_MSG[E_UNKNOWN_SOCKET_ERROR])