Ejemplo n.º 1
0
    def test_projector_avmt_status_timer_check_delete(self, mock_log,
                                                      mock_UpdateIcons):
        """
        Test avmt deletes callback in projector.status_timer_check
        """
        # GIVEN: Test object
        log_warning_text = []
        log_debug_text = [
            call('({ip}) Processing command "AVMT" with data "11"'.format(
                ip=self.pjlink.name)),
            call('({ip}) Calling function for AVMT'.format(
                ip=self.pjlink.name)),
            call(
                '({ip}) Setting shutter to closed'.format(ip=self.pjlink.name))
        ]
        self.pjlink.shutter = False
        self.pjlink.mute = True
        self.pjlink.status_timer_checks = {
            'AVMT': self.pjlink.get_av_mute_status
        }

        # WHEN: Called with setting shutter closed and mute off
        with patch.object(self.pjlink, 'status_timer') as mock_status_timer:
            process_command(projector=self.pjlink, cmd='AVMT', data='11')

            # THEN: Shutter should be True and mute should be False
            assert self.pjlink.shutter, 'Shutter should have been set to closed'
            assert self.pjlink.mute, 'Audio should not have changed'
            assert mock_UpdateIcons.emit.called, 'Update icons should have been called'
            assert 'AVMT' not in self.pjlink.status_timer_checks, 'Status timer list should not have AVMT callback'
            assert mock_status_timer.stop.called, 'Projector status_timer.stop() should have been called'
            mock_log.warning.assert_has_calls(log_warning_text)
            mock_log.debug.assert_has_calls(log_debug_text)
Ejemplo n.º 2
0
    def test_routing_command_unknown(self, mock_log, mock_functions,
                                     mock_clss):
        """
        Test process_command receiving command not in function map
        """
        # GIVEN: Test setup
        log_warning_text = [
            call('({ip}) Unable to process command="CLSS" '
                 '(Future option?)'.format(ip=self.pjlink.name))
        ]
        log_debug_text = [
            call('({ip}) Processing command "CLSS" with data "?"'.format(
                ip=self.pjlink.name))
        ]
        # Fake CLSS command is not in list
        mock_functions.__contains__.return_value = False

        # WHEN: called with unknown command
        process_command(projector=self.pjlink, cmd='CLSS', data='?')

        # THEN: Appropriate log entries should have been made and methods called/not called
        mock_log.warning.assert_has_calls(log_warning_text)
        mock_log.debug.assert_has_calls(log_debug_text)
        assert (mock_functions.__contains__.call_count == 1
                ), 'pjlink_functions should have been accessed only once'
        assert (not mock_clss.called), 'Should not have called process_clss'
Ejemplo n.º 3
0
    def test_projector_avmt_open_unmuted(self, mock_log, mock_UpdateIcons):
        """
        Test avmt status shutter open and mute off
        """
        # GIVEN: Test object
        log_warning_text = []
        log_debug_text = [
            call('({ip}) Processing command "AVMT" with data "30"'.format(
                ip=self.pjlink.name)),
            call('({ip}) Calling function for AVMT'.format(
                ip=self.pjlink.name)),
            call('({ip}) Setting shutter to open'.format(ip=self.pjlink.name)),
            call(
                '({ip}) Setting speaker to normal'.format(ip=self.pjlink.name))
        ]
        self.pjlink.shutter = True
        self.pjlink.mute = True

        # WHEN: Called with setting shutter to closed and mute on
        process_command(projector=self.pjlink, cmd='AVMT', data='30')

        # THEN: Shutter should be closed and mute should be True
        assert not self.pjlink.shutter, 'Shutter should have been set to off'
        assert not self.pjlink.mute, 'Audio should be on'
        assert mock_UpdateIcons.emit.called, 'Update icons should have been called'
        mock_log.warning.assert_has_calls(log_warning_text)
        mock_log.debug.assert_has_calls(log_debug_text)
Ejemplo n.º 4
0
    def test_projector_clss_invalid_no_version(self, mock_log):
        """
        Test CLSS reply has no class number
        """
        # GIVEN: Test object
        log_warning_calls = [
            call('({ip}) No numbers found in class version reply "Invalid" '
                 '- defaulting to class "1"'.format(ip=self.pjlink.name))
        ]
        log_debug_calls = [
            call('({ip}) Processing command "CLSS" with data "Invalid"'.format(
                ip=self.pjlink.name)),
            call('({ip}) Calling function for CLSS'.format(
                ip=self.pjlink.name)),
            call(
                '({ip}) Setting pjlink_class for this projector to "1"'.format(
                    ip=self.pjlink.name))
        ]

        # WHEN: Process invalid reply
        process_command(projector=self.pjlink, cmd='CLSS', data='Invalid')

        # THEN: Projector class should be set with default value
        assert self.pjlink.pjlink_class == '1', 'Invalid class reply should have set class=1'
        mock_log.warning.assert_has_calls(log_warning_calls)
        mock_log.debug.assert_has_calls(log_debug_calls)
Ejemplo n.º 5
0
    def test_projector_sver_changed(self, mock_log):
        """
        Test invalid software version information - Received different than saved
        """
        # GIVEN: Test object
        old_data = 'Test 1 Subtest 1'
        new_data = 'Test 1 Subtest 2'
        log_warning_calls = [call('({ip}) Projector software version does not match '
                                  'saved software version'.format(ip=self.pjlink.name)),
                             call('({ip}) Saved:    "{data}"'.format(ip=self.pjlink.name, data=old_data)),
                             call('({ip}) Received: "{data}"'.format(ip=self.pjlink.name, data=new_data)),
                             call('({ip}) Updating software version'.format(ip=self.pjlink.name))]
        log_debug_calls = [call('({ip}) Processing command "SVER" with data '
                                '"{data}"'.format(ip=self.pjlink.name, data=new_data)),
                           call('({ip}) Calling function for SVER'.format(ip=self.pjlink.name)),
                           call('({ip}) Setting projector software version to '
                                '"{data}"'.format(ip=self.pjlink.name, data=new_data))]
        self.pjlink.sw_version = old_data

        # WHEN: process_sver called with invalid data
        process_command(self.pjlink, cmd='SVER', data=new_data)

        # THEN: Version information should change
        assert self.pjlink.sw_version == new_data, 'Software version should have changed'
        mock_log.warning.assert_has_calls(log_warning_calls)
        mock_log.debug.assert_has_calls(log_debug_calls)
Ejemplo n.º 6
0
    def test_projector_clss_nonstandard_reply_2(self, mock_log):
        """
        Test CLSS request returns non-standard reply 1
        """
        # GIVEN: Test object
        log_warning_calls = [
            call('({ip}) Non-standard CLSS reply: "Version2"'.format(
                ip=self.pjlink.name))
        ]
        log_debug_calls = [
            call(
                '({ip}) Processing command "CLSS" with data "Version2"'.format(
                    ip=self.pjlink.name)),
            call('({ip}) Calling function for CLSS'.format(
                ip=self.pjlink.name)),
            call(
                '({ip}) Setting pjlink_class for this projector to "2"'.format(
                    ip=self.pjlink.name))
        ]

        # WHEN: Process non-standard reply
        process_command(projector=self.pjlink, cmd='CLSS', data='Version2')

        # THEN: Projector class should be set with proper value
        assert '2' == self.pjlink.pjlink_class, 'Non-standard class reply should have set class=1'
        mock_log.warning.assert_has_calls(log_warning_calls)
        mock_log.debug.assert_has_calls(log_debug_calls)
Ejemplo n.º 7
0
    def test_projector_snum_different(self, mock_log):
        """
        Test projector serial number different than saved serial number
        """
        # GIVEN: Test object
        new_data = 'Test Serial Number'
        old_data = 'Previous serial number'
        log_warning_calls = [call('({ip}) Projector serial number does not match '
                                  'saved serial number'.format(ip=self.pjlink.name)),
                             call('({ip}) Saved:    "{data}"'.format(ip=self.pjlink.name, data=old_data)),
                             call('({ip}) Received: "{data}"'.format(ip=self.pjlink.name, data=new_data)),
                             call('({ip}) NOT saving serial number'.format(ip=self.pjlink.name))]

        log_debug_calls = [call('({ip}) Processing command "SNUM" with data '
                                '"{data}"'.format(ip=self.pjlink.name, data=new_data)),
                           call('({ip}) Calling function for SNUM'.format(ip=self.pjlink.name))]
        self.pjlink.serial_no = old_data

        # WHEN: No serial number is set and we receive serial number command
        process_command(projector=self.pjlink, cmd='SNUM', data=new_data)

        # THEN: Serial number should be set
        assert self.pjlink.serial_no != new_data, 'Projector serial number should NOT have been set'
        mock_log.warning.assert_has_calls(log_warning_calls)
        mock_log.debug.assert_has_calls(log_debug_calls)
Ejemplo n.º 8
0
    def test_projector_avmt_audio_muted(self, mock_log, mock_UpdateIcons):
        """
        Test avmt status shutter unchanged and mute on
        """
        # GIVEN: Test setup
        log_warning_text = []
        log_debug_text = [
            call('({ip}) Processing command "AVMT" with data "21"'.format(
                ip=self.pjlink.name)),
            call('({ip}) Calling function for AVMT'.format(
                ip=self.pjlink.name)),
            call('({ip}) Setting speaker to muted'.format(ip=self.pjlink.name))
        ]
        self.pjlink.shutter = True
        self.pjlink.mute = False

        # WHEN: Called with setting shutter closed and mute on
        process_command(projector=self.pjlink, cmd='AVMT', data='21')

        # THEN: Shutter should be closed and mute should be True
        assert self.pjlink.shutter, 'Shutter should not have changed'
        assert self.pjlink.mute, 'Audio should be off'
        assert mock_UpdateIcons.emit.called, 'Update icons should have been called'
        mock_log.warning.assert_has_calls(log_warning_text)
        mock_log.debug.assert_has_calls(log_debug_text)
Ejemplo n.º 9
0
    def test_projector_erst_data_invalid_nan(self, mock_log):
        """
        Test ERST called with invalid data
        """
        # GIVEN: Test object
        chk_data = 'Z' + ('0' * (PJLINK_ERST_DATA['DATA_LENGTH'] - 1))
        log_warn_calls = [
            call('({ip}) Invalid error status response "{data}"'.format(
                ip=self.pjlink.name, data=chk_data))
        ]
        log_debug_calls = [
            call('({ip}) Processing command "ERST" with data "{data}"'.format(
                ip=self.pjlink.name, data=chk_data)),
            call(
                '({ip}) Calling function for ERST'.format(ip=self.pjlink.name))
        ]
        self.pjlink.projector_errors = None

        # WHEN: process_erst called with invalid data (too many values
        process_command(self.pjlink, cmd='ERST', data=chk_data)

        # THEN: pjlink.projector_errors should be empty and warning logged
        assert not self.pjlink.projector_errors, 'There should be no errors'
        mock_log.warning.assert_has_calls(log_warn_calls)
        mock_log.debug.assert_has_calls(log_debug_calls)
Ejemplo n.º 10
0
    def test_projector_erst_warn_cover_only(self, mock_log):
        """
        Test test_projector_process_erst_warn_cover_only
        """
        # GIVEN: Test object
        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}
        log_warn_calls = []
        log_debug_calls = [
            call('({ip}) Processing command "ERST" with data "{data}"'.format(
                ip=self.pjlink.name, data=chk_data)),
            call(
                '({ip}) Calling function for ERST'.format(ip=self.pjlink.name))
        ]
        self.pjlink.projector_errors = None

        # WHEN: process_erst with status set to WARN
        process_command(projector=self.pjlink, cmd='ERST', data=chk_data)

        # THEN: PJLink instance errors should match only cover warning
        assert 1 == len(
            self.pjlink.projector_errors
        ), 'There should only be 1 error listed in projector_errors'
        assert 'Cover' in self.pjlink.projector_errors, '"Cover" should be the only error listed'
        assert self.pjlink.projector_errors[
            'Cover'] == E_WARN, '"Cover" should have E_WARN listed as error'
        assert chk_test == self.pjlink.projector_errors, 'projector_errors should match test errors'
        mock_log.warning.assert_has_calls(log_warn_calls)
        mock_log.debug.assert_has_calls(log_debug_calls)
Ejemplo n.º 11
0
    def test_projector_avmt_bad_data(self, mock_log, mock_UpdateIcons):
        """
        Test avmt bad data fail
        """
        # GIVEN: Test object
        log_warning_text = [
            call('({ip}) Invalid av mute response: 36'.format(
                ip=self.pjlink.name))
        ]
        log_debug_text = [
            call('({ip}) Processing command "AVMT" with data "36"'.format(
                ip=self.pjlink.name)),
            call(
                '({ip}) Calling function for AVMT'.format(ip=self.pjlink.name))
        ]
        self.pjlink.shutter = True
        self.pjlink.mute = True

        # WHEN: Called with an invalid setting
        process_command(projector=self.pjlink, cmd='AVMT', data='36')

        # THEN: Shutter should be closed and mute should be True
        assert self.pjlink.shutter, 'Shutter should changed'
        assert self.pjlink.mute, 'Audio should not have changed'
        assert not mock_UpdateIcons.emit.called, 'Update icons should NOT have been called'
        mock_log.warning.assert_has_calls(log_warning_text)
        mock_log.debug.assert_has_calls(log_debug_text)
Ejemplo n.º 12
0
    def test_status_change(self, mock_changeStatus):
        """
        Test process_command call with ERR2 (Parameter) status
        """
        # GIVEN: Test object
        pjlink = self.pjlink

        # WHEN: process_command is called with "ERR2" status from projector
        process_command(projector=pjlink, cmd='POWR', data='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]))
Ejemplo n.º 13
0
    def test_routing_pjink_errA(self, mock_log):
        """
        Test rouing when PJLink ERRA received
        """
        # GIVEN: Test setup
        err_code = E_AUTHENTICATION
        err_msg = STATUS_MSG[err_code]
        err_str = PJLINK_ERRORS[err_code]

        log_error_text = [
            call('({ip}) CLSS: {err}'.format(ip=self.pjlink.name, err=err_msg))
        ]
        log_debug_text = [
            call('({ip}) Processing command "CLSS" with data "{err}"'.format(
                ip=self.pjlink.name, err=err_str))
        ]

        # WHEN: routing called
        chk = process_command(projector=self.pjlink, cmd='CLSS', data=err_str)

        # 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)
        assert (chk == err_code), 'Should have returned {err}'.format(
            err=PJLINK_ERRORS[err_code])
Ejemplo n.º 14
0
    def test_process_pjlink_authenticate_token_length(self, mock_log):
        """
        Test initial connection prompt with authentication and bad token
        """
        # GIVEN: Initial mocks and data
        bad_token = '1234abcde'  # Length should be 8, this is 9
        log_error_calls = [
            call('({ip}) Authentication token invalid (size) - '
                 'aborting'.format(ip=self.pjlink.name))
        ]
        log_warning_calls = []
        log_debug_calls = [
            call('({ip}) Processing command "PJLINK" with data '
                 '"1 {data}"'.format(ip=self.pjlink.name, data=bad_token)),
            call('({ip}) Calling function for PJLINK'.format(
                ip=self.pjlink.name)),
            call(
                '({ip}) Processing PJLINK command'.format(ip=self.pjlink.name))
        ]
        self.pjlink.pin = TEST_SALT

        # WHEN: process_pjlink called with bad token
        chk = process_command(projector=self.pjlink,
                              cmd='PJLINK',
                              data='1 {data}'.format(data=bad_token))

        # THEN: proper processing should have occured
        mock_log.error.assert_has_calls(log_error_calls)
        mock_log.warning.assert_has_calls(log_warning_calls)
        mock_log.debug.assert_has_calls(log_debug_calls)
        assert chk == E_NO_AUTHENTICATION, \
            'Should have returned {data}'.format(data=STATUS_CODE[E_NO_AUTHENTICATION])
Ejemplo n.º 15
0
    def test_process_pjlink_authenticate_pin_not_set_error(self, mock_log):
        """
        Test initial connection prompt with authentication and no pin set
        """
        # GIVEN: Initial mocks and data
        log_error_calls = [
            call('({ip}) Authenticate connection but no PIN - aborting'.format(
                ip=self.pjlink.name))
        ]
        log_warning_calls = []
        log_debug_calls = [
            call('({ip}) Processing command "PJLINK" with data "1 {data}"'.
                 format(ip=self.pjlink.name, data=TEST_SALT)),
            call('({ip}) Calling function for PJLINK'.format(
                ip=self.pjlink.name)),
            call(
                '({ip}) Processing PJLINK command'.format(ip=self.pjlink.name))
        ]

        self.pjlink.pin = None

        # WHEN: process_pjlink called with no authentication required
        chk = process_command(projector=self.pjlink,
                              cmd='PJLINK',
                              data='1 {salt}'.format(salt=TEST_SALT))

        # THEN: proper processing should have occured
        mock_log.error.assert_has_calls(log_error_calls)
        mock_log.warning.assert_has_calls(log_warning_calls)
        mock_log.debug.assert_has_calls(log_debug_calls)
        assert chk == E_NO_AUTHENTICATION, \
            'Should have returned {data}'.format(data=STATUS_CODE[E_NO_AUTHENTICATION])
Ejemplo n.º 16
0
    def test_process_pjlink_normal_with_token(self, mock_log):
        """
        Test process_pjlinnk called with no authentication but pin is set
        """
        # GIVEN: Initial mocks and data
        log_error_calls = [
            call('({ip}) Normal connection with extra information - '
                 'aborting'.format(ip=self.pjlink.name))
        ]
        log_warning_calls = []
        log_debug_calls = [
            call('({ip}) Processing command "PJLINK" with data '
                 '"0 {data}"'.format(ip=self.pjlink.name, data=TEST_SALT)),
            call('({ip}) Calling function for PJLINK'.format(
                ip=self.pjlink.name)),
            call(
                '({ip}) Processing PJLINK command'.format(ip=self.pjlink.name))
        ]
        self.pjlink.pin = TEST_PIN

        # WHEN: process_pjlink called with invalid authentication scheme
        chk = process_command(projector=self.pjlink,
                              cmd='PJLINK',
                              data='0 {data}'.format(data=TEST_SALT))

        # THEN: Proper calls should be made
        mock_log.error.assert_has_calls(log_error_calls)
        mock_log.warning.assert_has_calls(log_warning_calls)
        mock_log.debug.assert_has_calls(log_debug_calls)
        assert chk == E_NO_AUTHENTICATION, \
            'Should have returned {data}'.format(data=STATUS_CODE[E_NO_AUTHENTICATION])
Ejemplo n.º 17
0
    def test_process_pjlink_normal(self, mock_log):
        """
        Test processing PJLINK initial prompt
        """
        # GIVEN: Mocks and data
        log_error_calls = []
        log_warning_calls = []
        log_debug_calls = [
            call('({ip}) Processing command "PJLINK" with data "0"'.format(
                ip=self.pjlink.name)),
            call('({ip}) Calling function for PJLINK'.format(
                ip=self.pjlink.name)),
            call('({ip}) Processing PJLINK command'.format(
                ip=self.pjlink.name)),
            call('({ip}) PJLINK: Returning {data}'.format(
                ip=self.pjlink.name, data=STATUS_CODE[S_CONNECT]))
        ]

        self.pjlink.pin = None

        # WHEN: process_pjlink called with no authentication required
        chk = process_command(projector=self.pjlink, cmd='PJLINK', data="0")

        # THEN: proper processing should have occured
        mock_log.error.assert_has_calls(log_error_calls)
        mock_log.warning.assert_has_calls(log_warning_calls)
        mock_log.debug.assert_has_calls(log_debug_calls)
        assert chk == S_CONNECT, 'Should have returned {data}'.format(
            data=STATUS_CODE[S_CONNECT])
Ejemplo n.º 18
0
    def test_process_pjlink_authenticate_token_missing(self, mock_log):
        """
        Test initial connection prompt with authentication and missing token
        """
        # GIVEN: Initial mocks and data
        log_error_calls = [
            call('({ip}) Authenticated connection but not enough info - '
                 'aborting'.format(ip=self.pjlink.name))
        ]
        log_warning_calls = []
        log_debug_calls = [
            call('({ip}) Processing command "PJLINK" with data "1"'.format(
                ip=self.pjlink.name)),
            call('({ip}) Calling function for PJLINK'.format(
                ip=self.pjlink.name)),
            call(
                '({ip}) Processing PJLINK command'.format(ip=self.pjlink.name))
        ]

        self.pjlink.pin = TEST_SALT

        # WHEN: process_pjlink called with bad token
        chk = process_command(projector=self.pjlink, cmd='PJLINK', data='1')

        # THEN: proper processing should have occured
        mock_log.error.assert_has_calls(log_error_calls)
        mock_log.warning.assert_has_calls(log_warning_calls)
        mock_log.debug.assert_has_calls(log_debug_calls)
        assert chk == E_NO_AUTHENTICATION, \
            'Should have returned {data}'.format(data=STATUS_CODE[E_NO_AUTHENTICATION])
Ejemplo n.º 19
0
    def test_projector_lamp_invalid_missing_data(self, mock_log):
        """
        Test process lamp with 1 lamp reply hours only and no on/off status
        """
        # GIVEN: Test object
        log_warning_calls = [call('({ip}) process_lamp(): Invalid data "45" - '
                                  'Missing data'.format(ip=self.pjlink.name))]
        log_debug_calls = [call('({ip}) Processing command "LAMP" with data "45"'.format(ip=self.pjlink.name)),
                           call('({ip}) Calling function for LAMP'.format(ip=self.pjlink.name))]
        self.pjlink.lamp = None

        # WHEN: Call process_command with 3 lamps
        process_command(projector=self.pjlink, cmd='LAMP', data='45')

        # THEN: Lamp should have been set with proper lamp status
        mock_log.warning.assert_has_calls(log_warning_calls)
        mock_log.debug.assert_has_calls(log_debug_calls)
        assert not self.pjlink.lamp, 'Projector lamp info should not have changed'
Ejemplo n.º 20
0
    def test_projector_rlmp_save(self, mock_log):
        """
        Test saving lamp type
        """
        # GIVEN: Test object
        new_data = 'Lamp Type Test'
        log_warning_calls = []
        log_debug_calls = [call('({ip}) Processing command "RLMP" with data '
                                '"{data}"'.format(ip=self.pjlink.name, data=new_data)),
                           call('({ip}) Calling function for RLMP'.format(ip=self.pjlink.name))]
        self.pjlink.model_lamp = None

        # WHEN: Filter model is received
        process_command(projector=self.pjlink, cmd='RLMP', data=new_data)

        # THEN: Filter model number should be saved
        mock_log.warning.assert_has_calls(log_warning_calls)
        mock_log.debug.assert_has_calls(log_debug_calls)
        assert self.pjlink.model_lamp == new_data, 'Lamp model should have been saved'
Ejemplo n.º 21
0
    def test_projector_inpt_invalid(self, mock_log):
        """
        Test input source returned not valid according to standard
        """
        # GIVEN: Test object
        log_warning_calls = [call('({ip}) Input source not listed as a PJLink valid source - '
                                  'ignoring'.format(ip=self.pjlink.name))]
        log_debug_calls = [call('({ip}) Processing command "INPT" with data "91"'.format(ip=self.pjlink.name)),
                           call('({ip}) Calling function for INPT'.format(ip=self.pjlink.name))]
        self.pjlink.source = None
        self.pjlink.source_available = None

        # WHEN: Called with input source
        process_command(projector=self.pjlink, cmd='INPT', data='91')

        # THEN: Input selected should reflect current input
        assert not self.pjlink.source, 'Input source should not have changed'
        mock_log.warning.assert_has_calls(log_warning_calls)
        mock_log.debug.assert_has_calls(log_debug_calls)
Ejemplo n.º 22
0
    def test_projector_lamp_single(self, mock_log):
        """
        Test status lamp on/off and hours
        """
        # GIVEN: Test object
        log_warning_calls = []
        log_debug_calls = [call('({ip}) Processing command "LAMP" with data "11111 1"'.format(ip=self.pjlink.name)),
                           call('({ip}) Calling function for LAMP'.format(ip=self.pjlink.name))]
        self.pjlink.lamp = None

        # WHEN: Call process_command with 3 lamps
        process_command(projector=self.pjlink, cmd='LAMP', data='11111 1')

        # THEN: Lamp should have been set with proper lamp status
        mock_log.warning.assert_has_calls(log_warning_calls)
        mock_log.debug.assert_has_calls(log_debug_calls)
        assert 1 == len(self.pjlink.lamp), 'Projector should have 1 lamp specified'
        assert self.pjlink.lamp[0]['On'], 'Lamp 1 power status should have been set to TRUE'
        assert 11111 == self.pjlink.lamp[0]['Hours'], 'Lamp 1 hours should have been set to 11111'
Ejemplo n.º 23
0
    def test_projector_name(self, mock_log):
        """
        Test saving NAME data from projector
        """
        # GIVEN: Test object
        chk_data = "Some Name the End-User Set IN Projector"
        log_warning_calls = []
        log_debug_calls = [call('({ip}) Processing command "NAME" with data '
                                '"Some Name the End-User Set IN Projector"'.format(ip=self.pjlink.name)),
                           call('({ip}) Calling function for NAME'.format(ip=self.pjlink.name)),
                           call('({ip}) Setting projector PJLink name to '
                                '"Some Name the End-User Set IN Projector"'.format(ip=self.pjlink.name))]

        # WHEN: process_name called with test data
        process_command(projector=self.pjlink, cmd='NAME', data=chk_data)

        # THEN: name should be set and logged
        mock_log.warning.assert_has_calls(log_warning_calls)
        mock_log.debug.assert_has_calls(log_debug_calls)
        assert self.pjlink.pjlink_name == chk_data, 'Name test data should have been saved'
Ejemplo n.º 24
0
    def test_projector_inpt_good(self, mock_log):
        """
        Test input source status shows current input
        """
        # GIVEN: Test object
        self.pjlink.source = '11'
        log_warning_calls = []
        log_debug_calls = [call('({ip}) Processing command "INPT" with data "21"'.format(ip=self.pjlink.name)),
                           call('({ip}) Calling function for INPT'.format(ip=self.pjlink.name)),
                           call('({ip}) Setting current source to "21"'.format(ip=self.pjlink.name))]
        chk_source_available = ['11', '12', '21', '22', '31', '32']
        self.pjlink.source_available = chk_source_available

        # WHEN: Called with input source
        process_command(projector=self.pjlink, cmd='INPT', data='21')

        # THEN: Input selected should reflect current input
        assert '21' == self.pjlink.source, 'Input source should be set to "21"'
        mock_log.warning.assert_has_calls(log_warning_calls)
        mock_log.debug.assert_has_calls(log_debug_calls)
Ejemplo n.º 25
0
    def test_projector_inpt_not_in_list(self, mock_log):
        """
        Test input source not listed in available sources
        """
        # GIVEN: Test object
        log_warning_calls = [call('({ip}) Input source not listed in available sources - '
                                  'ignoring'.format(ip=self.pjlink.name))]
        log_debug_calls = [call('({ip}) Processing command "INPT" with data "25"'.format(ip=self.pjlink.name)),
                           call('({ip}) Calling function for INPT'.format(ip=self.pjlink.name))]
        self.pjlink.source = '11'
        chk_source_available = ['11', '12', '21', '22', '31', '32']
        self.pjlink.source_available = chk_source_available

        # WHEN: Called with input source
        process_command(projector=self.pjlink, cmd='INPT', data='25')

        # THEN: Input selected should reflect current input
        assert '11' == self.pjlink.source, 'Input source should not have changed'
        mock_log.warning.assert_has_calls(log_warning_calls)
        mock_log.debug.assert_has_calls(log_debug_calls)
Ejemplo n.º 26
0
    def test_projector_powr_invalid(self, mock_log, mock_UpdateIcons, mock_change_status, mock_send_command):
        """
        Test process_powr invalid call
        """
        # GIVEN: Test object
        self.pjlink.power = S_STANDBY
        log_warning_calls = [call('({ip}) Unknown power response: "99"'.format(ip=self.pjlink.name))]
        log_debug_calls = [call('({ip}) Processing command "POWR" with data "99"'.format(ip=self.pjlink.name)),
                           call('({ip}) Calling function for POWR'.format(ip=self.pjlink.name)),
                           call('({ip}) Processing POWR command'.format(ip=self.pjlink.name))]

        # WHEN: process_command called with test data
        process_command(projector=self.pjlink, cmd='POWR', data='99')

        # THEN: Projector power should not have changed
        mock_log.warning.assert_has_calls(log_warning_calls)
        mock_log.debug.assert_has_calls(log_debug_calls)
        assert S_STANDBY == self.pjlink.power, 'Power should not have changed'
        mock_UpdateIcons.emit.assert_not_called()
        mock_change_status.assert_not_called()
        mock_send_command.assert_not_called()
Ejemplo n.º 27
0
    def test_projector_powr_on(self, mock_log, mock_UpdateIcons, mock_change_status, mock_send_command):
        """
        Test status power to ON
        """
        # GIVEN: Test object
        log_warning_calls = []
        log_debug_calls = [call('({ip}) Processing command "POWR" with data "1"'.format(ip=self.pjlink.name)),
                           call('({ip}) Calling function for POWR'.format(ip=self.pjlink.name)),
                           call('({ip}) Processing POWR command'.format(ip=self.pjlink.name))]
        self.pjlink.power = S_STANDBY

        # WHEN: process_name called with test data
        process_command(projector=self.pjlink, cmd='POWR', data=PJLINK_POWR_STATUS[S_ON])

        # THEN: Power should be set to ON
        mock_log.warning.assert_has_calls(log_warning_calls)
        mock_log.debug.assert_has_calls(log_debug_calls)
        assert S_ON == self.pjlink.power, 'Power should have been set to ON'
        assert mock_UpdateIcons.emit.called, 'projectorUpdateIcons should have been called'
        mock_send_command.assert_called_once_with('INST')
        mock_change_status.assert_called_once_with(S_ON)
Ejemplo n.º 28
0
    def test_projector_erst_all_ok(self, mock_log):
        """
        Test to verify pjlink.projector_errors is set to None when no errors
        """
        # GIVEN: Test object
        chk_data = '0' * PJLINK_ERST_DATA['DATA_LENGTH']
        log_warning_calls = []
        log_debug_calls = [
            call('({ip}) Processing command "ERST" with data "{chk}"'.format(
                ip=self.pjlink.name, chk=chk_data)),
            call(
                '({ip}) Calling function for ERST'.format(ip=self.pjlink.name))
        ]

        # WHEN: process_erst with no errors
        process_command(projector=self.pjlink, cmd='ERST', data=chk_data)

        # THEN: PJLink instance errors should be None
        assert self.pjlink.projector_errors is None, 'projector_errors should have been set to None'
        mock_log.warning.assert_has_calls(log_warning_calls)
        mock_log.debug.assert_has_calls(log_debug_calls)
Ejemplo n.º 29
0
    def test_projector_snum_set(self, mock_log):
        """
        Test saving serial number from projector
        """
        # GIVEN: Test object
        new_data = 'Test Serial Number'
        self.pjlink.serial_no = None
        log_warning_calls = []
        log_debug_calls = [call('({ip}) Processing command "SNUM" with data "{data}"'.format(ip=self.pjlink.name,
                                                                                             data=new_data)),
                           call('({ip}) Calling function for SNUM'.format(ip=self.pjlink.name)),
                           call('({ip}) Setting projector serial number to '
                                '"{data}"'.format(ip=self.pjlink.name, data=new_data))]

        # WHEN: No serial number is set and we receive serial number command
        process_command(projector=self.pjlink, cmd='SNUM', data=new_data)

        # THEN: Serial number should be set
        assert self.pjlink.serial_no == new_data, 'Projector serial number should have been set'
        mock_log.warning.assert_has_calls(log_warning_calls)
        mock_log.debug.assert_has_calls(log_debug_calls)
Ejemplo n.º 30
0
    def test_projector_sver_invalid(self, mock_log):
        """
        Test invalid software version information - too long
        """
        # GIVEN: Test object
        new_data = 'This is a test software version line that is too long based on PJLink version 2 specs'
        log_warning_calls = [call('Invalid software version - too long')]
        log_debug_calls = [call('({ip}) Processing command "SVER" with data "{data}"'.format(ip=self.pjlink.name,
                                                                                             data=new_data)),
                           call('({ip}) Calling function for SVER'.format(ip=self.pjlink.name))]
        self.pjlink.sw_version = None
        self.pjlink.sw_version_received = None

        # WHEN: process_sver called with invalid data
        process_command(projector=self.pjlink, cmd='SVER', data=new_data)

        # THEN: Version information should not change
        assert not self.pjlink.sw_version, 'Software version should not have changed'
        assert not self.pjlink.sw_version_received, 'Received software version should not have changed'
        mock_log.warning.assert_has_calls(log_warning_calls)
        mock_log.debug.assert_has_calls(log_debug_calls)