← Back to team overview

openlp-core team mailing list archive

Re: [Merge] lp:~alisonken1/openlp/pjlink2-n into lp:openlp

 

Review: Needs Fixing

Some questions and old style asserts remain!

Diff comments:

> === modified file 'openlp/core/projectors/constants.py'
> --- openlp/core/projectors/constants.py	2017-12-09 11:17:05 +0000
> +++ openlp/core/projectors/constants.py	2017-12-25 13:32:20 +0000
> @@ -485,3 +557,7 @@
>          label = "{source}{item}".format(source=source, item=item)
>          PJLINK_DEFAULT_CODES[label] = "{source} {item}".format(source=PJLINK_DEFAULT_SOURCES[source],
>                                                                 item=PJLINK_DEFAULT_ITEMS[item])
> +# Remove temp variables so they don't become part of the module dict

This is a bit of a hack, it seems a bad way to do things.

> +del(source)
> +del(item)
> +del(label)
> 
> === modified file 'openlp/core/projectors/pjlink.py'
> --- openlp/core/projectors/pjlink.py	2017-12-09 11:17:05 +0000
> +++ openlp/core/projectors/pjlink.py	2017-12-25 13:32:20 +0000
> @@ -794,7 +801,7 @@
>              data = decode(read, 'utf-8')
>              # Possibility of extraneous data on input when reading.
>              # Clean out extraneous characters in buffer.
> -            self.readLine(self.max_size)
> +            self.read(2048)

why 2048 will this not read over the buffer end?

>              log.debug('({ip}) check_login() read "{data}"'.format(ip=self.ip, data=data.strip()))
>          # At this point, we should only have the initial login prompt with
>          # possible authentication
> 
> === modified file 'tests/functional/openlp_core/projectors/test_projector_pjlink_cmd_routing.py'
> --- tests/functional/openlp_core/projectors/test_projector_pjlink_cmd_routing.py	2017-12-09 11:17:05 +0000
> +++ tests/functional/openlp_core/projectors/test_projector_pjlink_cmd_routing.py	2017-12-25 13:32:20 +0000
> @@ -24,209 +24,222 @@
>  """
>  
>  from unittest import TestCase
> -from unittest.mock import patch, MagicMock
> +from unittest.mock import MagicMock, call, patch
>  
>  import openlp.core.projectors.pjlink
> -from openlp.core.projectors.constants import PJLINK_ERRORS, \
> +from openlp.core.projectors.constants import PJLINK_ERRORS, PJLINK_PREFIX, STATUS_MSG, \
>      E_AUTHENTICATION, E_PARAMETER, E_PROJECTOR, E_UNAVAILABLE, E_UNDEFINED
>  from openlp.core.projectors.db import Projector
>  from openlp.core.projectors.pjlink import PJLink
>  
> -'''
> -from openlp.core.projectors.constants import ERROR_STRING, PJLINK_ERST_DATA, PJLINK_ERST_STATUS, \
> -    PJLINK_POWR_STATUS, PJLINK_VALID_CMD, E_WARN, E_ERROR, S_OFF, S_STANDBY, S_ON
> -'''
> -from tests.resources.projector.data import TEST_PIN, TEST1_DATA
> -
> -pjlink_test = PJLink(Projector(**TEST1_DATA), pin=TEST_PIN, no_poll=True)
> -pjlink_test.ip = '127.0.0.1'
> +from tests.resources.projector.data import TEST1_DATA
>  
>  
>  class TestPJLinkRouting(TestCase):
>      """
>      Tests for the PJLink module command routing
>      """
> -    def setUp(self):
> -        '''
> -        TestPJLinkCommands part 2 initialization
> -        '''
> -        self.pjlink_test = PJLink(Projector(**TEST1_DATA), no_poll=True)
> -
> -    def tearDown(self):
> -        '''
> -        TestPJLinkCommands part 2 cleanups
> -        '''
> -        self.pjlink_test = None
> -
> -    @patch.object(openlp.core.projectors.pjlink, 'log')
> -    def test_process_command_call_clss(self, mock_log):
> +    def test_get_data_unknown_command(self):
> +        """
> +        Test not a valid command
> +        """
> +        # GIVEN: Test object
> +        log_warning_text = [call('(111.111.111.111) get_data(): Invalid packet - unknown command "UNK"')]
> +        log_debug_text = [call('(111.111.111.111) get_data(ip="111.111.111.111" buffer="b\'%1UNK=Huh?\'"'),
> +                          call('(111.111.111.111) get_data(): Checking new data "%1UNK=Huh?"')]
> +
> +        with patch.object(openlp.core.projectors.pjlink, 'log') as mock_log, \
> +                patch.object(openlp.core.projectors.pjlink.PJLink, '_trash_buffer') as mock_buffer:
> +
> +            pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
> +            pjlink.pjlink_functions = MagicMock()
> +
> +            # WHEN: get_data called with an unknown command
> +            pjlink.get_data(buff='{prefix}1UNK=Huh?'.format(prefix=PJLINK_PREFIX).encode('utf-8'))
> +
> +            # 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)
> +            self.assertFalse(pjlink.pjlink_functions.called, 'Should not have accessed pjlink_functions')

should be assert x is False

> +            self.assertTrue(mock_buffer.called, 'Should have called _trash_buffer')
> +
> +    def test_process_command_call_clss(self):
>          """
>          Test process_command calls proper function
>          """
> +        # GIVEN: Test object and mocks
> +        log_debug_calls = [call('(111.111.111.111) Processing command "CLSS" with data "1"'),
> +                           call('(111.111.111.111) Calling function for CLSS')]
> +
> +        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)
> +
> +            # 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')
> +
> +    def test_process_command_erra(self):
> +        """
> +        Test ERRA - Authentication Error
> +        """
>          # GIVEN: Test object
> -        pjlink = pjlink_test
> -        log_text = '(127.0.0.1) Calling function for CLSS'
> -        mock_log.reset_mock()
> -        mock_process_clss = MagicMock()
> -        pjlink.pjlink_functions['CLSS'] = mock_process_clss
> -
> -        # WHEN: process_command is called with valid function and data
> -        pjlink.process_command(cmd='CLSS', data='1')
> -
> -        # THEN: Process method should have been called properly
> -        mock_log.debug.assert_called_with(log_text)
> -        mock_process_clss.assert_called_with('1')
> -
> -    @patch.object(pjlink_test, 'change_status')
> -    @patch.object(openlp.core.projectors.pjlink, 'log')
> -    def test_process_command_err1(self, mock_log, mock_change_status):
> +        log_error_calls = [call('(111.111.111.111) PJLINK: {msg}'.format(msg=STATUS_MSG[E_AUTHENTICATION]))]
> +        log_debug_calls = [call('(111.111.111.111) Processing command "PJLINK" with data "ERRA"')]
> +
> +        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)
> +
> +            # 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
> +            mock_log.error.assert_has_calls(log_error_calls)
> +            mock_log.debug.assert_has_calls(log_debug_calls)
> +            self.assertTrue(mock_disconnect.called, 'disconnect_from_host should have been called')
> +            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_err1(self):
>          """
>          Test ERR1 - Undefined projector function
>          """
>          # GIVEN: Test object
> -        pjlink = pjlink_test
> -        log_text = '(127.0.0.1) Projector returned error "ERR1"'
> -        mock_change_status.reset_mock()
> -        mock_log.reset_mock()
> -
> -        # WHEN: process_command called with ERR1
> -        pjlink.process_command(cmd='CLSS', data=PJLINK_ERRORS[E_UNDEFINED])
> -
> -        # THEN: Error should be logged and status_change should be called
> -        mock_change_status.assert_called_once_with(E_UNDEFINED, 'Undefined Command: "CLSS"')
> -        mock_log.error.assert_called_with(log_text)
> -
> -    @patch.object(pjlink_test, 'change_status')
> -    @patch.object(openlp.core.projectors.pjlink, 'log')
> -    def test_process_command_err2(self, mock_log, mock_change_status):
> +        log_error_text = [call('(111.111.111.111) CLSS: {msg}'.format(msg=STATUS_MSG[E_UNDEFINED]))]
> +        log_debug_text = [call('(111.111.111.111) Processing command "CLSS" with data "ERR1"'),
> +                          call('(111.111.111.111) Calling function for CLSS')]
> +
> +        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)
> +
> +            # WHEN: process_command called with ERR1
> +            pjlink.process_command(cmd='CLSS', data=PJLINK_ERRORS[E_UNDEFINED])
> +
> +            # 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_UNDEFINED])
> +
> +    def test_process_command_err2(self):
>          """
>          Test ERR2 - Parameter Error
>          """
>          # GIVEN: Test object
> -        pjlink = pjlink_test
> -        log_text = '(127.0.0.1) Projector returned error "ERR2"'
> -        mock_change_status.reset_mock()
> -        mock_log.reset_mock()
> -
> -        # WHEN: process_command called with ERR2
> -        pjlink.process_command(cmd='CLSS', data=PJLINK_ERRORS[E_PARAMETER])
> -
> -        # THEN: Error should be logged and status_change should be called
> -        mock_change_status.assert_called_once_with(E_PARAMETER)
> -        mock_log.error.assert_called_with(log_text)
> -
> -    @patch.object(pjlink_test, 'change_status')
> -    @patch.object(openlp.core.projectors.pjlink, 'log')
> -    def test_process_command_err3(self, mock_log, mock_change_status):
> -        """
> -        Test ERR3 - Unavailable error
> -        """
> -        # GIVEN: Test object
> -        pjlink = pjlink_test
> -        log_text = '(127.0.0.1) Projector returned error "ERR3"'
> -        mock_change_status.reset_mock()
> -        mock_log.reset_mock()
> -
> -        # WHEN: process_command called with ERR3
> -        pjlink.process_command(cmd='CLSS', data=PJLINK_ERRORS[E_UNAVAILABLE])
> -
> -        # THEN: Error should be logged and status_change should be called
> -        mock_change_status.assert_called_once_with(E_UNAVAILABLE)
> -        mock_log.error.assert_called_with(log_text)
> -
> -    @patch.object(pjlink_test, 'change_status')
> -    @patch.object(openlp.core.projectors.pjlink, 'log')
> -    def test_process_command_err4(self, mock_log, mock_change_status):
> -        """
> -        Test ERR3 - Unavailable error
> -        """
> -        # GIVEN: Test object
> -        pjlink = pjlink_test
> -        log_text = '(127.0.0.1) Projector returned error "ERR4"'
> -        mock_change_status.reset_mock()
> -        mock_log.reset_mock()
> -
> -        # WHEN: process_command called with ERR3
> -        pjlink.process_command(cmd='CLSS', data=PJLINK_ERRORS[E_PROJECTOR])
> -
> -        # THEN: Error should be logged and status_change should be called
> -        mock_change_status.assert_called_once_with(E_PROJECTOR)
> -        mock_log.error.assert_called_with(log_text)
> -
> -    @patch.object(pjlink_test, 'projectorAuthentication')
> -    @patch.object(pjlink_test, 'change_status')
> -    @patch.object(pjlink_test, 'disconnect_from_host')
> -    @patch.object(openlp.core.projectors.pjlink, 'log')
> -    def test_process_command_erra(self, mock_log, mock_disconnect, mock_change_status, mock_err_authenticate):
> -        """
> -        Test ERRA - Authentication Error
> -        """
> -        # GIVEN: Test object
> -        pjlink = pjlink_test
> -        log_text = '(127.0.0.1) Projector returned error "ERRA"'
> -        mock_change_status.reset_mock()
> -        mock_log.reset_mock()
> -
> -        # WHEN: process_command called with ERRA
> -        pjlink.process_command(cmd='CLSS', data=PJLINK_ERRORS[E_AUTHENTICATION])
> -
> -        # THEN: Error should be logged and several methods should be called
> -        self.assertTrue(mock_disconnect.called, 'disconnect_from_host should have been called')
> -        mock_change_status.assert_called_once_with(E_AUTHENTICATION)
> -        mock_log.error.assert_called_with(log_text)
> +        log_error_text = [call('(111.111.111.111) CLSS: {msg}'.format(msg=STATUS_MSG[E_PARAMETER]))]
> +        log_debug_text = [call('(111.111.111.111) Processing command "CLSS" with data "ERR2"'),
> +                          call('(111.111.111.111) Calling function for CLSS')]
> +
> +        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)
> +
> +            # WHEN: process_command called with ERR2
> +            pjlink.process_command(cmd='CLSS', data=PJLINK_ERRORS[E_PARAMETER])
> +
> +            # THEN: Appropriate log entries should have been made and methods called/not 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_PARAMETER])
> +
> +    def test_process_command_err3(self):
> +        """
> +        Test ERR3 - Unavailable error
> +        """
> +        # GIVEN: Test object
> +        log_error_text = [call('(111.111.111.111) CLSS: {msg}'.format(msg=STATUS_MSG[E_UNAVAILABLE]))]
> +        log_debug_text = [call('(111.111.111.111) Processing command "CLSS" with data "ERR3"'),
> +                          call('(111.111.111.111) Calling function for CLSS')]
> +
> +        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)
> +
> +            # WHEN: process_command called with ERR3
> +            pjlink.process_command(cmd='CLSS', data=PJLINK_ERRORS[E_UNAVAILABLE])
> +
> +            # 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_UNAVAILABLE])
> +
> +    def test_process_command_err4(self):
> +        """
> +        Test ERR3 - Unavailable error
> +        """
> +        # GIVEN: Test object
> +        log_error_text = [call('(111.111.111.111) CLSS: {msg}'.format(msg=STATUS_MSG[E_PROJECTOR]))]
> +        log_debug_text = [call('(111.111.111.111) Processing command "CLSS" with data "ERR4"'),
> +                          call('(111.111.111.111) Calling function for CLSS')]
> +
> +        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)
> +
> +            # 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_process_command_future(self):
>          """
>          Test command valid but no method to process yet
>          """
> -        # GIVEN: Initial mocks and data
> -        mock_log = patch.object(openlp.core.projectors.pjlink, 'log').start()
> -        mock_functions = patch.object(self.pjlink_test, 'pjlink_functions').start()
> -        mock_functions.return_value = []
> -
> -        pjlink = self.pjlink_test
> -        log_text = '(111.111.111.111) Unable to process command="CLSS" (Future option?)'
> -
> -        # WHEN: process_command called with an unknown command
> -        pjlink.process_command(cmd='CLSS', data='DONT CARE')
> -
> -        # THEN: Error should be logged and no command called
> -        self.assertFalse(mock_functions.called, 'Should not have gotten to the end of the method')
> -        mock_log.warning.assert_called_once_with(log_text)
> -
> -    @patch.object(pjlink_test, 'pjlink_functions')
> -    @patch.object(openlp.core.projectors.pjlink, 'log')
> -    def test_process_command_invalid(self, mock_log, mock_functions):
> -        """
> -        Test not a valid command
> -        """
>          # GIVEN: Test object
> -        pjlink = pjlink_test
> -        mock_functions.reset_mock()
> -        mock_log.reset_mock()
> -
> -        # WHEN: process_command called with an unknown command
> -        pjlink.process_command(cmd='Unknown', data='Dont Care')
> -        log_text = '(127.0.0.1) Ignoring command="Unknown" (Invalid/Unknown)'
> -
> -        # THEN: Error should be logged and no command called
> -        self.assertFalse(mock_functions.called, 'Should not have gotten to the end of the method')
> -        mock_log.error.assert_called_once_with(log_text)
> +        log_warning_text = [call('(111.111.111.111) Unable to process command="CLSS" (Future option?)')]
> +        log_debug_text = [call('(111.111.111.111) Processing command "CLSS" with data "Huh?"')]
> +
> +        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()
> +
> +            # 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)
> +            self.assertFalse(pjlink.pjlink_functions.called, 'Should not have accessed pjlink_functions')

self.assert

> +            self.assertFalse(mock_process_clss.called, 'Should not have called process_clss')
>  
>      def test_process_command_ok(self):
>          """
>          Test command returned success
>          """
>          # GIVEN: Initial mocks and data
> -        mock_log = patch.object(openlp.core.projectors.pjlink, 'log').start()
> -        mock_send_command = patch.object(self.pjlink_test, 'send_command').start()
> -
> -        pjlink = self.pjlink_test
> -        log_text = '(111.111.111.111) Command "POWR" returned OK'
> -
> -        # WHEN: process_command called with a command that returns OK
> -        pjlink.process_command(cmd='POWR', data='OK')
> -
> -        # THEN: Appropriate calls should have been made
> -        mock_log.debug.assert_called_with(log_text)
> -        mock_send_command.assert_called_once_with(cmd='POWR')
> +        # GIVEN: Test object and mocks
> +        log_debug_calls = [call('(111.111.111.111) Processing command "CLSS" with data "OK"'),
> +                           call('(111.111.111.111) Command "CLSS" returned OK')]
> +
> +        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, 'process_clss') as mock_process_clss:
> +
> +            pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
> +
> +            # WHEN: process_command is called with valid function and data
> +            pjlink.process_command(cmd='CLSS', data='OK')
> +
> +            # THEN: Appropriate log entries should have been made and methods called
> +            mock_log.debug.assert_has_calls(log_debug_calls)
> +            mock_send_command.assert_called_once_with(cmd='CLSS')
> +            mock_process_clss.assert_not_called()
> 
> === modified file 'tests/functional/openlp_core/projectors/test_projector_pjlink_commands_01.py'
> --- tests/functional/openlp_core/projectors/test_projector_pjlink_commands_01.py	2017-12-09 11:17:05 +0000
> +++ tests/functional/openlp_core/projectors/test_projector_pjlink_commands_01.py	2017-12-25 13:32:20 +0000
> @@ -23,372 +23,402 @@
>  Package to test the openlp.core.projectors.pjlink commands package.
>  """
>  from unittest import TestCase
> -from unittest.mock import patch
> +from unittest.mock import call, patch
>  
>  import openlp.core.projectors.pjlink
> -from openlp.core.projectors.constants import ERROR_STRING, PJLINK_ERST_DATA, PJLINK_ERST_STATUS, \
> -    PJLINK_POWR_STATUS, \
> -    E_ERROR, E_NOT_CONNECTED, E_SOCKET_ADDRESS_NOT_AVAILABLE, E_UNKNOWN_SOCKET_ERROR, E_WARN, \
> -    S_CONNECTED, S_OFF, S_ON, S_NOT_CONNECTED, S_CONNECTING, S_STANDBY
> +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
>  
> -from tests.resources.projector.data import TEST_PIN, TEST1_DATA
> -
> -pjlink_test = PJLink(Projector(**TEST1_DATA), pin=TEST_PIN, no_poll=True)
> -pjlink_test.ip = '127.0.0.1'
> -
> -# Create a list of ERST positional data so we don't have to redo the same buildup multiple times
> -PJLINK_ERST_POSITIONS = []
> -for pos in range(0, len(PJLINK_ERST_DATA)):
> -    if pos in PJLINK_ERST_DATA:
> -        PJLINK_ERST_POSITIONS.append(PJLINK_ERST_DATA[pos])
> +from tests.resources.projector.data import TEST1_DATA
>  
>  
>  class TestPJLinkCommands(TestCase):
>      """
>      Tests for the PJLinkCommands class part 1
>      """
> -    @patch.object(pjlink_test, 'changeStatus')
> -    @patch.object(openlp.core.projectors.pjlink, 'log')
> -    def test_projector_change_status_connection_error(self, mock_log, mock_change_status):
> +    def test_projector_change_status_unknown_socket_error(self):
>          """
>          Test change_status with connection error
>          """
> -        # GIVEN: Test object
> -        pjlink = pjlink_test
> -        pjlink.projector_status = 0
> -        pjlink.status_connect = 0
> -        test_code = E_UNKNOWN_SOCKET_ERROR
> -        mock_change_status.reset_mock()
> -        mock_log.reset_mock()
> -
> -        # WHEN: change_status called with unknown socket error
> -        pjlink.change_status(status=test_code, msg=None)
> -
> -        # THEN: Proper settings should change and signals sent
> -        self.assertEqual(pjlink.projector_status, E_NOT_CONNECTED, 'Projector status should be NOT CONNECTED')
> -        self.assertEqual(pjlink.status_connect, E_NOT_CONNECTED, 'Status connect should be NOT CONNECTED')
> -        mock_change_status.emit.assert_called_once_with(pjlink.ip, E_UNKNOWN_SOCKET_ERROR,
> -                                                        'An unidentified error occurred')
> -        self.assertEqual(mock_log.debug.call_count, 3, 'Debug log should have been called 3 times')
> -
> -    @patch.object(pjlink_test, 'changeStatus')
> -    @patch.object(openlp.core.projectors.pjlink, 'log')
> -    def test_projector_change_status_connection_status_connecting(self, mock_log, mock_change_status):
> -        """
> -        Test change_status with connection status
> -        """
> -        # GIVEN: Test object
> -        pjlink = pjlink_test
> -        pjlink.projector_status = 0
> -        pjlink.status_connect = 0
> -        test_code = S_CONNECTING
> -        mock_change_status.reset_mock()
> -        mock_log.reset_mock()
> -
> -        # WHEN: change_status called with unknown socket error
> -        pjlink.change_status(status=test_code, msg=None)
> -
> -        # THEN: Proper settings should change and signals sent
> -        self.assertEqual(pjlink.projector_status, S_NOT_CONNECTED, 'Projector status should be NOT CONNECTED')
> -        self.assertEqual(pjlink.status_connect, S_CONNECTING, 'Status connect should be CONNECTING')
> -        mock_change_status.emit.assert_called_once_with(pjlink.ip, S_CONNECTING, 'Connecting')
> -        self.assertEqual(mock_log.debug.call_count, 3, 'Debug log should have been called 3 times')
> -
> -    @patch.object(pjlink_test, 'changeStatus')
> -    @patch.object(openlp.core.projectors.pjlink, 'log')
> -    def test_projector_change_status_connection_status_connected(self, mock_log, mock_change_status):
> -        """
> -        Test change_status with connection status
> -        """
> -        # GIVEN: Test object
> -        pjlink = pjlink_test
> -        pjlink.projector_status = 0
> -        pjlink.status_connect = 0
> -        test_code = S_ON
> -        mock_change_status.reset_mock()
> -        mock_log.reset_mock()
> -
> -        # WHEN: change_status called with unknown socket error
> -        pjlink.change_status(status=test_code, msg=None)
> -
> -        # THEN: Proper settings should change and signals sent
> -        self.assertEqual(pjlink.projector_status, S_ON, 'Projector status should be ON')
> -        self.assertEqual(pjlink.status_connect, S_CONNECTED, 'Status connect should be CONNECTED')
> -        mock_change_status.emit.assert_called_once_with(pjlink.ip, S_ON, 'Power is on')
> -        self.assertEqual(mock_log.debug.call_count, 3, 'Debug log should have been called 3 times')
> -
> -    @patch.object(pjlink_test, 'changeStatus')
> -    @patch.object(openlp.core.projectors.pjlink, 'log')
> -    def test_projector_change_status_connection_status_with_message(self, mock_log, mock_change_status):
> -        """
> -        Test change_status with connection status
> -        """
> -        # GIVEN: Test object
> -        pjlink = pjlink_test
> -        pjlink.projector_status = 0
> -        pjlink.status_connect = 0
> +        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.assert

> +            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'
> -        test_code = S_ON
> -        mock_change_status.reset_mock()
> -        mock_log.reset_mock()
> -
> -        # WHEN: change_status called with unknown socket error
> -        pjlink.change_status(status=test_code, msg=test_message)
> -
> -        # THEN: Proper settings should change and signals sent
> -        self.assertEqual(pjlink.projector_status, S_ON, 'Projector status should be ON')
> -        self.assertEqual(pjlink.status_connect, S_CONNECTED, 'Status connect should be CONNECTED')
> -        mock_change_status.emit.assert_called_once_with(pjlink.ip, S_ON, test_message)
> -        self.assertEqual(mock_log.debug.call_count, 3, 'Debug log should have been called 3 times')
> -
> -    @patch.object(pjlink_test, 'send_command')
> -    @patch.object(openlp.core.projectors.pjlink, 'log')
> -    def test_projector_get_av_mute_status(self, mock_log, mock_send_command):
> +        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
>          """
> -        # GIVEN: Test object
> -        pjlink = pjlink_test
> -        mock_log.reset_mock()
> -        mock_send_command.reset_mock()
>          test_data = 'AVMT'
> -        test_log = '(127.0.0.1) Sending AVMT command'
> -
> -        # WHEN: get_av_mute_status is called
> -        pjlink.get_av_mute_status()
> -
> -        # THEN: log data and send_command should have been called
> -        mock_log.debug.assert_called_once_with(test_log)
> -        mock_send_command.assert_called_once_with(cmd=test_data)
> -
> -    @patch.object(pjlink_test, 'send_command')
> -    @patch.object(openlp.core.projectors.pjlink, 'log')
> -    def test_projector_get_available_inputs(self, mock_log, mock_send_command):
> +        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)
> +
> +            # WHEN: get_av_mute_status is called
> +            pjlink.get_av_mute_status()
> +
> +            # 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
>          """
> -        # GIVEN: Test object
> -        pjlink = pjlink_test
> -        mock_log.reset_mock()
> -        mock_send_command.reset_mock()
>          test_data = 'INST'
> -        test_log = '(127.0.0.1) Sending INST command'
> -
> -        # WHEN: get_available_inputs is called
> -        pjlink.get_available_inputs()
> -
> -        # THEN: log data and send_command should have been called
> -        mock_log.debug.assert_called_once_with(test_log)
> -        mock_send_command.assert_called_once_with(cmd=test_data)
> -
> -    @patch.object(pjlink_test, 'send_command')
> -    @patch.object(openlp.core.projectors.pjlink, 'log')
> -    def test_projector_get_error_status(self, mock_log, mock_send_command):
> +        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)
> +
> +            # WHEN: get_available_inputs is called
> +            pjlink.get_available_inputs()
> +
> +            # 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
>          """
> -        # GIVEN: Test object
> -        pjlink = pjlink_test
> -        mock_log.reset_mock()
> -        mock_send_command.reset_mock()
>          test_data = 'ERST'
> -        test_log = '(127.0.0.1) Sending ERST command'
> -
> -        # WHEN: get_error_status is called
> -        pjlink.get_error_status()
> -
> -        # THEN: log data and send_command should have been called
> -        mock_log.debug.assert_called_once_with(test_log)
> -        mock_send_command.assert_called_once_with(cmd=test_data)
> -
> -    @patch.object(pjlink_test, 'send_command')
> -    @patch.object(openlp.core.projectors.pjlink, 'log')
> -    def test_projector_get_input_source(self, mock_log, mock_send_command):
> +        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)
> +
> +            # WHEN: get_error_status is called
> +            pjlink.get_error_status()
> +
> +            # 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_input_source(self):
>          """
>          Test sending command to retrieve current input
>          """
> -        # GIVEN: Test object
> -        pjlink = pjlink_test
> -        mock_log.reset_mock()
> -        mock_send_command.reset_mock()
>          test_data = 'INPT'
> -        test_log = '(127.0.0.1) Sending INPT command'
> -
> -        # WHEN: get_input_source is called
> -        pjlink.get_input_source()
> -
> -        # THEN: log data and send_command should have been called
> -        mock_log.debug.assert_called_once_with(test_log)
> -        mock_send_command.assert_called_once_with(cmd=test_data)
> -
> -    @patch.object(pjlink_test, 'send_command')
> -    @patch.object(openlp.core.projectors.pjlink, 'log')
> -    def test_projector_get_lamp_status(self, mock_log, mock_send_command):
> +        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)
> +
> +            # WHEN: get_input_source is called
> +            pjlink.get_input_source()
> +
> +            # 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
>          """
> -        # GIVEN: Test object
> -        pjlink = pjlink_test
> -        mock_log.reset_mock()
> -        mock_send_command.reset_mock()
>          test_data = 'LAMP'
> -        test_log = '(127.0.0.1) Sending LAMP command'
> -
> -        # WHEN: get_lamp_status is called
> -        pjlink.get_lamp_status()
> -
> -        # THEN: log data and send_command should have been called
> -        mock_log.debug.assert_called_once_with(test_log)
> -        mock_send_command.assert_called_once_with(cmd=test_data)
> -
> -    @patch.object(pjlink_test, 'send_command')
> -    @patch.object(openlp.core.projectors.pjlink, 'log')
> -    def test_projector_get_manufacturer(self, mock_log, mock_send_command):
> +        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)
> +
> +            # WHEN: get_input_source is called
> +            pjlink.get_lamp_status()
> +
> +            # 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
>          """
> -        # GIVEN: Test object
> -        pjlink = pjlink_test
> -        mock_log.reset_mock()
> -        mock_send_command.reset_mock()
>          test_data = 'INF1'
> -        test_log = '(127.0.0.1) Sending INF1 command'
> -
> -        # WHEN: get_manufacturer is called
> -        pjlink.get_manufacturer()
> -
> -        # THEN: log data and send_command should have been called
> -        mock_log.debug.assert_called_once_with(test_log)
> -        mock_send_command.assert_called_once_with(cmd=test_data)
> -
> -    @patch.object(pjlink_test, 'send_command')
> -    @patch.object(openlp.core.projectors.pjlink, 'log')
> -    def test_projector_get_model(self, mock_log, mock_send_command):
> +        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)
> +
> +            # WHEN: get_input_source is called
> +            pjlink.get_manufacturer()
> +
> +            # 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
>          """
> -        # GIVEN: Test object
> -        pjlink = pjlink_test
> -        mock_log.reset_mock()
> -        mock_send_command.reset_mock()
>          test_data = 'INF2'
> -        test_log = '(127.0.0.1) Sending INF2 command'
> -
> -        # WHEN: get_model is called
> -        pjlink.get_model()
> -
> -        # THEN: log data and send_command should have been called
> -        mock_log.debug.assert_called_once_with(test_log)
> -        mock_send_command.assert_called_once_with(cmd=test_data)
> -
> -    @patch.object(pjlink_test, 'send_command')
> -    @patch.object(openlp.core.projectors.pjlink, 'log')
> -    def test_projector_get_name(self, mock_log, mock_send_command):
> +        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)
> +
> +            # WHEN: get_input_source is called
> +            pjlink.get_model()
> +
> +            # 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
>          """
> -        # GIVEN: Test object
> -        pjlink = pjlink_test
> -        mock_log.reset_mock()
> -        mock_send_command.reset_mock()
>          test_data = 'NAME'
> -        test_log = '(127.0.0.1) Sending NAME command'
> -
> -        # WHEN: get_name is called
> -        pjlink.get_name()
> -
> -        # THEN: log data and send_command should have been called
> -        mock_log.debug.assert_called_once_with(test_log)
> -        mock_send_command.assert_called_once_with(cmd=test_data)
> -
> -    @patch.object(pjlink_test, 'send_command')
> -    @patch.object(openlp.core.projectors.pjlink, 'log')
> -    def test_projector_get_other_info(self, mock_log, mock_send_command):
> +        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)
> +
> +            # WHEN: get_input_source is called
> +            pjlink.get_name()
> +
> +            # 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
>          """
> -        # GIVEN: Test object
> -        pjlink = pjlink_test
> -        mock_log.reset_mock()
> -        mock_send_command.reset_mock()
>          test_data = 'INFO'
> -        test_log = '(127.0.0.1) Sending INFO command'
> -
> -        # WHEN: get_other_info is called
> -        pjlink.get_other_info()
> -
> -        # THEN: log data and send_command should have been called
> -        mock_log.debug.assert_called_once_with(test_log)
> -        mock_send_command.assert_called_once_with(cmd=test_data)
> -
> -    @patch.object(pjlink_test, 'send_command')
> -    @patch.object(openlp.core.projectors.pjlink, 'log')
> -    def test_projector_get_power_status(self, mock_log, mock_send_command):
> +        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)
> +
> +            # WHEN: get_input_source is called
> +            pjlink.get_other_info()
> +
> +            # 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
>          """
> -        # GIVEN: Test object
> -        pjlink = pjlink_test
> -        mock_log.reset_mock()
> -        mock_send_command.reset_mock()
>          test_data = 'POWR'
> -        test_log = '(127.0.0.1) Sending POWR command'
> -
> -        # WHEN: get_power_status called
> -        pjlink.get_power_status()
> -
> -        # THEN: log data and send_command should have been called
> -        mock_log.debug.assert_called_once_with(test_log)
> -        mock_send_command.assert_called_once_with(cmd=test_data)
> -
> -    def test_projector_get_status_error(self):
> -        """
> -        Test to check returned information for error code
> -        """
> -        # GIVEN: Test object
> -        pjlink = pjlink_test
> -        test_string = 'E_SOCKET_ADDRESS_NOT_AVAILABLE'
> -        test_message = 'The address specified to socket.bind() does not belong to the host'
> -
> -        # WHEN: get_status called
> -        string, message = pjlink._get_status(status=E_SOCKET_ADDRESS_NOT_AVAILABLE)
> -
> -        # THEN: Proper strings should have been returned
> -        self.assertEqual(string, test_string, 'Code as string should have been returned')
> -        self.assertEqual(message, test_message, 'Description of code should have been returned')
> +        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)
> +
> +            # WHEN: get_input_source is called
> +            pjlink.get_power_status()
> +
> +            # 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
> -        pjlink = pjlink_test
> -        test_string = 'Test string since get_status will only work with int'
> -        test_message = 'Invalid status code'
> +        pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
> +        test_string = 'NaN test'
>  
>          # WHEN: get_status called
> -        string, message = pjlink._get_status(status=test_string)
> -
> -        # THEN: Proper strings should have been returned
> -        self.assertEqual(string, -1, 'Should have returned -1 as a bad status check')
> -        self.assertEqual(message, test_message, 'Error message should have been returned')
> -
> -    def test_projector_get_status_status(self):
> +        code, message = pjlink._get_status(status=test_string)
> +
> +        # 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')
> +
> +    def test_projector_get_status_valid(self):
>          """
>          Test to check returned information for status codes
>          """
>          # GIVEN: Test object
> -        pjlink = pjlink_test
> -        test_string = 'S_NOT_CONNECTED'
> -        test_message = 'Not connected'
> +        test_message = 'Not Connected'
> +        pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
>  
>          # WHEN: get_status called
> -        string, message = pjlink._get_status(status=S_NOT_CONNECTED)
> +        code, message = pjlink._get_status(status=S_NOT_CONNECTED)
>  
>          # THEN: Proper strings should have been returned
> -        self.assertEqual(string, test_string, 'Code as string should have been returned')
> +        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):


-- 
https://code.launchpad.net/~alisonken1/openlp/pjlink2-n/+merge/335588
Your team OpenLP Core is subscribed to branch lp:openlp.


References