Merge lp:~alisonken1/openlp/bug-1734275 into lp:openlp

Proposed by Ken Roberts
Status: Superseded
Proposed branch: lp:~alisonken1/openlp/bug-1734275
Merge into: lp:openlp
Diff against target: 312 lines (+156/-98)
5 files modified
openlp/core/projectors/manager.py (+7/-5)
openlp/core/projectors/pjlink.py (+14/-11)
tests/functional/openlp_core/projectors/test_projector_bugfixes_01.py (+134/-0)
tests/functional/openlp_core/projectors/test_projector_pjlink_base.py (+1/-53)
tests/functional/openlp_core/projectors/test_projector_pjlink_commands.py (+0/-29)
To merge this branch: bzr merge lp:~alisonken1/openlp/bug-1734275
Reviewer Review Type Date Requested Status
Phill Approve
Tim Bentley Approve
Review via email: mp+334254@code.launchpad.net

This proposal supersedes a proposal from 2017-11-24.

This proposal has been superseded by a proposal from 2017-11-24.

Commit message

Bugfix 1734275 - PJLink non-standard response to LAMP command

Description of the change

- Fix non-standard LAMP response (bug 1734275)
- Moved bugfix tests to separate file
- Added test for non-standard LAMP response
- Refactor mocks
- Cleanups

--------------------------------------------------------------------------------
lp:~alisonken1/openlp/bug-1734275 (revision 2792)
https://ci.openlp.io/job/Branch-01-Pull/2311/ [SUCCESS]
https://ci.openlp.io/job/Branch-02-Functional-Tests/2212/ [SUCCESS]
https://ci.openlp.io/job/Branch-03-Interface-Tests/2088/ [SUCCESS]
https://ci.openlp.io/job/Branch-04a-Code_Analysis/1414/ [SUCCESS]
https://ci.openlp.io/job/Branch-04b-Test_Coverage/1236/ [SUCCESS]
https://ci.openlp.io/job/Branch-04c-Code_Analysis2/366/ [SUCCESS]
https://ci.openlp.io/job/Branch-05-AppVeyor-Tests/197/ [FAILURE]

To post a comment you must log in.
Revision history for this message
Phill (phill-ridout) wrote : Posted in a previous version of this proposal

A few inline comments, nothing major Sorry if it seems like I be tripping on my new status! :-p

review: Needs Fixing
Revision history for this message
Tim Bentley (trb143) :
review: Approve
Revision history for this message
Phill (phill-ridout) wrote :

You've just missed removing the pjlink instance in the test file. (see inline)

Revision history for this message
Phill (phill-ridout) :
review: Needs Fixing
lp:~alisonken1/openlp/bug-1734275 updated
2792. By Ken Roberts

Refactor mocks

Revision history for this message
Phill (phill-ridout) :
review: Approve

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'openlp/core/projectors/manager.py'
--- openlp/core/projectors/manager.py 2017-11-10 11:59:38 +0000
+++ openlp/core/projectors/manager.py 2017-11-24 19:08:45 +0000
@@ -672,14 +672,16 @@
672 data=projector.model_filter)672 data=projector.model_filter)
673 count = 1673 count = 1
674 for item in projector.link.lamp:674 for item in projector.link.lamp:
675 if item['On'] is None:
676 status = translate('OpenLP.ProjectorManager', 'Unavailable')
677 elif item['On']:
678 status = translate('OpenLP.ProjectorManager', 'ON')
679 else:
680 status = translate('OpenLP.ProjectorManager', 'OFF')
675 message += '<b>{title} {count}</b> {status} '.format(title=translate('OpenLP.ProjectorManager',681 message += '<b>{title} {count}</b> {status} '.format(title=translate('OpenLP.ProjectorManager',
676 'Lamp'),682 'Lamp'),
677 count=count,683 count=count,
678 status=translate('OpenLP.ProjectorManager',684 status=status)
679 'ON')
680 if item['On']
681 else translate('OpenLP.ProjectorManager',
682 'OFF'))
683685
684 message += '<b>{title}</b>: {hours}<br />'.format(title=translate('OpenLP.ProjectorManager', 'Hours'),686 message += '<b>{title}</b>: {hours}<br />'.format(title=translate('OpenLP.ProjectorManager', 'Hours'),
685 hours=item['Hours'])687 hours=item['Hours'])
686688
=== modified file 'openlp/core/projectors/pjlink.py'
--- openlp/core/projectors/pjlink.py 2017-11-10 11:59:38 +0000
+++ openlp/core/projectors/pjlink.py 2017-11-24 19:08:45 +0000
@@ -402,17 +402,20 @@
402 :param data: Lamp(s) status.402 :param data: Lamp(s) status.
403 """403 """
404 lamps = []404 lamps = []
405 data_dict = data.split()405 lamp_list = data.split()
406 while data_dict:406 if len(lamp_list) < 2:
407 try:407 lamps.append({'Hours': int(lamp_list[0]), 'On': None})
408 fill = {'Hours': int(data_dict[0]), 'On': False if data_dict[1] == '0' else True}408 else:
409 except ValueError:409 while lamp_list:
410 # In case of invalid entry410 try:
411 log.warning('({ip}) process_lamp(): Invalid data "{data}"'.format(ip=self.ip, data=data))411 fill = {'Hours': int(lamp_list[0]), 'On': False if lamp_list[1] == '0' else True}
412 return412 except ValueError:
413 lamps.append(fill)413 # In case of invalid entry
414 data_dict.pop(0) # Remove lamp hours414 log.warning('({ip}) process_lamp(): Invalid data "{data}"'.format(ip=self.ip, data=data))
415 data_dict.pop(0) # Remove lamp on/off415 return
416 lamps.append(fill)
417 lamp_list.pop(0) # Remove lamp hours
418 lamp_list.pop(0) # Remove lamp on/off
416 self.lamp = lamps419 self.lamp = lamps
417 return420 return
418421
419422
=== added file 'tests/functional/openlp_core/projectors/test_projector_bugfixes_01.py'
--- tests/functional/openlp_core/projectors/test_projector_bugfixes_01.py 1970-01-01 00:00:00 +0000
+++ tests/functional/openlp_core/projectors/test_projector_bugfixes_01.py 2017-11-24 19:08:45 +0000
@@ -0,0 +1,134 @@
1# -*- coding: utf-8 -*-
2# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
3
4###############################################################################
5# OpenLP - Open Source Lyrics Projection #
6# --------------------------------------------------------------------------- #
7# Copyright (c) 2008-2015 OpenLP Developers #
8# --------------------------------------------------------------------------- #
9# This program is free software; you can redistribute it and/or modify it #
10# under the terms of the GNU General Public License as published by the Free #
11# Software Foundation; version 2 of the License. #
12# #
13# This program is distributed in the hope that it will be useful, but WITHOUT #
14# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
15# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
16# more details. #
17# #
18# You should have received a copy of the GNU General Public License along #
19# with this program; if not, write to the Free Software Foundation, Inc., 59 #
20# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
21###############################################################################
22"""
23Package to test the openlp.core.projectors.pjlink base package.
24"""
25from unittest import TestCase
26from unittest.mock import patch
27
28from openlp.core.projectors.db import Projector
29from openlp.core.projectors.pjlink import PJLink
30
31from tests.resources.projector.data import TEST_PIN, TEST_CONNECT_AUTHENTICATE, TEST_HASH, TEST1_DATA
32
33
34class TestPJLinkBugs(TestCase):
35 """
36 Tests for the PJLink module bugfixes
37 """
38 def setUp(self):
39 '''
40 Initialization
41 '''
42 self.pjlink_test = PJLink(Projector(**TEST1_DATA), no_poll=True)
43
44 def tearDown(self):
45 '''
46 Cleanups
47 '''
48 self.pjlink_test = None
49
50 def test_bug_1550891_process_clss_nonstandard_reply_1(self):
51 """
52 Bugfix 1550891: CLSS request returns non-standard reply with Optoma/Viewsonic projector
53 """
54 # GIVEN: Test object
55 pjlink = self.pjlink_test
56
57 # WHEN: Process non-standard reply
58 pjlink.process_clss('Class 1')
59
60 # THEN: Projector class should be set with proper value
61 self.assertEqual(pjlink.pjlink_class, '1',
62 'Non-standard class reply should have set class=1')
63
64 def test_bug_1550891_process_clss_nonstandard_reply_2(self):
65 """
66 Bugfix 1550891: CLSS request returns non-standard reply with BenQ projector
67 """
68 # GIVEN: Test object
69 pjlink = self.pjlink_test
70
71 # WHEN: Process non-standard reply
72 pjlink.process_clss('Version2')
73
74 # THEN: Projector class should be set with proper value
75 # NOTE: At this time BenQ is Class 1, but we're trying a different value to verify
76 self.assertEqual(pjlink.pjlink_class, '2',
77 'Non-standard class reply should have set class=2')
78
79 def test_bug_1593882_no_pin_authenticated_connection(self):
80 """
81 Test bug 1593882 no pin and authenticated request exception
82 """
83 # GIVEN: Test object and mocks
84 mock_socket_timer = patch.object(self.pjlink_test, 'socket_timer').start()
85 mock_timer = patch.object(self.pjlink_test, 'timer').start()
86 mock_authentication = patch.object(self.pjlink_test, 'projectorAuthentication').start()
87 mock_ready_read = patch.object(self.pjlink_test, 'waitForReadyRead').start()
88 mock_send_command = patch.object(self.pjlink_test, 'send_command').start()
89 pjlink = self.pjlink_test
90 pjlink.pin = None
91 mock_ready_read.return_value = True
92
93 # WHEN: call with authentication request and pin not set
94 pjlink.check_login(data=TEST_CONNECT_AUTHENTICATE)
95
96 # THEN: 'No Authentication' signal should have been sent
97 mock_authentication.emit.assert_called_with(pjlink.ip)
98
99 def test_bug_1593883_pjlink_authentication(self):
100 """
101 Test bugfix 1593883 pjlink authentication
102 """
103 # GIVEN: Test object and data
104 mock_socket_timer = patch.object(self.pjlink_test, 'socket_timer').start()
105 mock_timer = patch.object(self.pjlink_test, 'timer').start()
106 mock_send_command = patch.object(self.pjlink_test, 'write').start()
107 mock_state = patch.object(self.pjlink_test, 'state').start()
108 mock_waitForReadyRead = patch.object(self.pjlink_test, 'waitForReadyRead').start()
109 pjlink = self.pjlink_test
110 pjlink.pin = TEST_PIN
111 mock_state.return_value = pjlink.ConnectedState
112 mock_waitForReadyRead.return_value = True
113
114 # WHEN: Athenticated connection is called
115 pjlink.check_login(data=TEST_CONNECT_AUTHENTICATE)
116
117 # THEN: send_command should have the proper authentication
118 self.assertEqual("{test}".format(test=mock_send_command.call_args),
119 "call(b'{hash}%1CLSS ?\\r')".format(hash=TEST_HASH))
120
121 def test_bug_1734275_process_lamp_nonstandard_reply(self):
122 """
123 Test bugfix 17342785 non-standard LAMP response
124 """
125 # GIVEN: Test object
126 pjlink = self.pjlink_test
127
128 # WHEN: Process lamp command called with only hours and no lamp power state
129 pjlink.process_lamp("45")
130
131 # THEN: Lamp should show hours as 45 and lamp power as Unavailable
132 self.assertEqual(len(pjlink.lamp), 1, 'There should only be 1 lamp available')
133 self.assertEqual(pjlink.lamp[0]['Hours'], 45, 'Lamp hours should have equalled 45')
134 self.assertIsNone(pjlink.lamp[0]['On'], 'Lamp power should be "None"')
0135
=== modified file 'tests/functional/openlp_core/projectors/test_projector_pjlink_base.py'
--- tests/functional/openlp_core/projectors/test_projector_pjlink_base.py 2017-11-16 23:53:53 +0000
+++ tests/functional/openlp_core/projectors/test_projector_pjlink_base.py 2017-11-24 19:08:45 +0000
@@ -29,7 +29,7 @@
29from openlp.core.projectors.db import Projector29from openlp.core.projectors.db import Projector
30from openlp.core.projectors.pjlink import PJLink30from openlp.core.projectors.pjlink import PJLink
3131
32from tests.resources.projector.data import TEST_PIN, TEST_SALT, TEST_CONNECT_AUTHENTICATE, TEST_HASH, TEST1_DATA32from tests.resources.projector.data import TEST_PIN, TEST_SALT, TEST_CONNECT_AUTHENTICATE, TEST1_DATA
3333
34pjlink_test = PJLink(Projector(**TEST1_DATA), no_poll=True)34pjlink_test = PJLink(Projector(**TEST1_DATA), no_poll=True)
3535
@@ -79,58 +79,6 @@
79 'change_status should have been called with "{}"'.format(79 'change_status should have been called with "{}"'.format(
80 ERROR_STRING[E_PARAMETER]))80 ERROR_STRING[E_PARAMETER]))
8181
82 @patch.object(pjlink_test, 'send_command')
83 @patch.object(pjlink_test, 'waitForReadyRead')
84 @patch.object(pjlink_test, 'projectorAuthentication')
85 @patch.object(pjlink_test, 'timer')
86 @patch.object(pjlink_test, 'socket_timer')
87 def test_bug_1593882_no_pin_authenticated_connection(self,
88 mock_socket_timer,
89 mock_timer,
90 mock_authentication,
91 mock_ready_read,
92 mock_send_command):
93 """
94 Test bug 1593882 no pin and authenticated request exception
95 """
96 # GIVEN: Test object and mocks
97 pjlink = pjlink_test
98 pjlink.pin = None
99 mock_ready_read.return_value = True
100
101 # WHEN: call with authentication request and pin not set
102 pjlink.check_login(data=TEST_CONNECT_AUTHENTICATE)
103
104 # THEN: 'No Authentication' signal should have been sent
105 mock_authentication.emit.assert_called_with(pjlink.ip)
106
107 @patch.object(pjlink_test, 'waitForReadyRead')
108 @patch.object(pjlink_test, 'state')
109 @patch.object(pjlink_test, '_send_command')
110 @patch.object(pjlink_test, 'timer')
111 @patch.object(pjlink_test, 'socket_timer')
112 def test_bug_1593883_pjlink_authentication(self,
113 mock_socket_timer,
114 mock_timer,
115 mock_send_command,
116 mock_state,
117 mock_waitForReadyRead):
118 """
119 Test bugfix 1593883 pjlink authentication
120 """
121 # GIVEN: Test object and data
122 pjlink = pjlink_test
123 pjlink.pin = TEST_PIN
124 mock_state.return_value = pjlink.ConnectedState
125 mock_waitForReadyRead.return_value = True
126
127 # WHEN: Athenticated connection is called
128 pjlink.check_login(data=TEST_CONNECT_AUTHENTICATE)
129
130 # THEN: send_command should have the proper authentication
131 self.assertEqual("{test}".format(test=mock_send_command.call_args),
132 "call(data='{hash}%1CLSS ?\\r')".format(hash=TEST_HASH))
133
134 @patch.object(pjlink_test, 'disconnect_from_host')82 @patch.object(pjlink_test, 'disconnect_from_host')
135 def test_socket_abort(self, mock_disconnect):83 def test_socket_abort(self, mock_disconnect):
136 """84 """
13785
=== modified file 'tests/functional/openlp_core/projectors/test_projector_pjlink_commands.py'
--- tests/functional/openlp_core/projectors/test_projector_pjlink_commands.py 2017-11-16 23:53:53 +0000
+++ tests/functional/openlp_core/projectors/test_projector_pjlink_commands.py 2017-11-24 19:08:45 +0000
@@ -570,35 +570,6 @@
570 self.assertEqual(pjlink.pjlink_class, '2',570 self.assertEqual(pjlink.pjlink_class, '2',
571 'Projector should have set class=2')571 'Projector should have set class=2')
572572
573 def test_projector_process_clss_nonstandard_reply_optoma(self):
574 """
575 Bugfix 1550891: CLSS request returns non-standard reply with Optoma projector
576 """
577 # GIVEN: Test object
578 pjlink = pjlink_test
579
580 # WHEN: Process non-standard reply
581 pjlink.process_clss('Class 1')
582
583 # THEN: Projector class should be set with proper value
584 self.assertEqual(pjlink.pjlink_class, '1',
585 'Non-standard class reply should have set class=1')
586
587 def test_projector_process_clss_nonstandard_reply_benq(self):
588 """
589 Bugfix 1550891: CLSS request returns non-standard reply with BenQ projector
590 """
591 # GIVEN: Test object
592 pjlink = pjlink_test
593
594 # WHEN: Process non-standard reply
595 pjlink.process_clss('Version2')
596
597 # THEN: Projector class should be set with proper value
598 # NOTE: At this time BenQ is Class 1, but we're trying a different value to verify
599 self.assertEqual(pjlink.pjlink_class, '2',
600 'Non-standard class reply should have set class=2')
601
602 @patch.object(openlp.core.projectors.pjlink, 'log')573 @patch.object(openlp.core.projectors.pjlink, 'log')
603 def test_projector_process_clss_invalid_nan(self, mock_log):574 def test_projector_process_clss_invalid_nan(self, mock_log):
604 """575 """