Merge lp:~alisonken1/openlp/pjlink2-v02 into lp:openlp

Proposed by Ken Roberts
Status: Merged
Merged at revision: 2860
Proposed branch: lp:~alisonken1/openlp/pjlink2-v02
Merge into: lp:openlp
Prerequisite: lp:~alisonken1/openlp/pjlink2-v1
Diff against target: 856 lines (+352/-385)
1 file modified
tests/openlp_core/projectors/test_projector_pjlink_base_01.py (+352/-385)
To merge this branch: bzr merge lp:~alisonken1/openlp/pjlink2-v02
Reviewer Review Type Date Requested Status
Tomas Groth Approve
Tim Bentley Approve
Review via email: mp+366554@code.launchpad.net

Commit message

PJLink2 Update V02

Description of the change

NOTE: Part 2 of a multi-part merge.
      v[2..n] merges are to fix tests

WARNING: Requires merge of lp:~alisonken1/openlp/pjlink2-v1

- Updated pjlink imports
- Added setUp() and tearDown() to pjlinkcommands.py::TestPJLinkBase to have a common
  pjlink() instance creation
- Fix tests in test_projector_pjlink_base_01.py
- Move patch.object context managers to decorators

--------------------------------------------------------------------------------
lp:~alisonken1/openlp/pjlink2-v02 (revision 2860)
https://ci.openlp.io/job/Branch-01-Pull/2720/ [SUCCESS]
https://ci.openlp.io/job/Branch-02a-Linux-Tests/2614/ [SUCCESS]
https://ci.openlp.io/job/Branch-02b-macOS-Tests/389/ [SUCCESS]
https://ci.openlp.io/job/Branch-03a-Build-Source/212/ [SUCCESS]
https://ci.openlp.io/job/Branch-03b-Build-macOS/191/ [SUCCESS]
https://ci.openlp.io/job/Branch-04a-Code-Lint/1674/ [SUCCESS]
https://ci.openlp.io/job/Branch-04b-Test-Coverage/1487/ [SUCCESS]
https://ci.openlp.io/job/Branch-05-AppVeyor-Tests/369/ [FAILURE]
Stopping after failure

To post a comment you must log in.
Revision history for this message
Raoul Snyman (raoul-snyman) wrote :

Linux tests passed!

Revision history for this message
Raoul Snyman (raoul-snyman) wrote :

Linting passed!

Revision history for this message
Raoul Snyman (raoul-snyman) wrote :

macOS tests passed!

Revision history for this message
Tim Bentley (trb143) :
review: Approve
Revision history for this message
Tomas Groth (tomasgroth) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'tests/openlp_core/projectors/test_projector_pjlink_base_01.py'
--- tests/openlp_core/projectors/test_projector_pjlink_base_01.py 2019-04-26 07:51:13 +0000
+++ tests/openlp_core/projectors/test_projector_pjlink_base_01.py 2019-04-26 07:51:13 +0000
@@ -22,10 +22,11 @@
22"""22"""
23Package to test the openlp.core.projectors.pjlink base package.23Package to test the openlp.core.projectors.pjlink base package.
24"""24"""
25from unittest import TestCase, skip25from unittest import TestCase
26from unittest.mock import MagicMock, call, patch26from unittest.mock import MagicMock, call, patch
2727
28import openlp.core.projectors.pjlink28import openlp.core.projectors.pjlink
29from openlp.core.projectors.pjlinkcommands import process_command
29from openlp.core.projectors.constants import E_NOT_CONNECTED, E_PARAMETER, E_UNKNOWN_SOCKET_ERROR, QSOCKET_STATE, \30from openlp.core.projectors.constants import E_NOT_CONNECTED, E_PARAMETER, E_UNKNOWN_SOCKET_ERROR, QSOCKET_STATE, \
30 S_CONNECTED, S_CONNECTING, S_NOT_CONNECTED, S_OK, S_ON, STATUS_CODE, STATUS_MSG31 S_CONNECTED, S_CONNECTING, S_NOT_CONNECTED, S_OK, S_ON, STATUS_CODE, STATUS_MSG
31from openlp.core.projectors.db import Projector32from openlp.core.projectors.db import Projector
@@ -37,47 +38,56 @@
37 """38 """
38 Tests for the PJLink module39 Tests for the PJLink module
39 """40 """
40 @skip('Needs update to new setup')41 def setUp(self):
41 def test_status_change(self):42 """
43 Initialize test state(s)
44 """
45 # Default PJLink instance for tests
46 self.pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
47
48 def tearDown(self):
49 """
50 Cleanup test state(s)
51 """
52 del(self.pjlink)
53
54 @patch.object(openlp.core.projectors.pjlink.PJLink, 'changeStatus')
55 def test_status_change(self, mock_changeStatus):
42 """56 """
43 Test process_command call with ERR2 (Parameter) status57 Test process_command call with ERR2 (Parameter) status
44 """58 """
45 # GIVEN: Test object59 # GIVEN: Test object
46 with patch('openlp.core.projectors.pjlink.PJLink.changeStatus') as mock_changeStatus:60 pjlink = self.pjlink
4761
48 pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)62 # WHEN: process_command is called with "ERR2" status from projector
4963 process_command(projector=pjlink, cmd='POWR', data='ERR2')
50 # WHEN: process_command is called with "ERR2" status from projector64
51 pjlink.process_command('POWR', 'ERR2')65 # THEN: change_status should have called change_status with E_UNDEFINED
5266 # as first parameter
53 # THEN: change_status should have called change_status with E_UNDEFINED67 mock_changeStatus.called_with(E_PARAMETER,
54 # as first parameter68 'change_status should have been called '
55 mock_changeStatus.called_with(E_PARAMETER,69 'with "{}"'.format(STATUS_CODE[E_PARAMETER]))
56 'change_status should have been called with "{}"'.format(70
57 STATUS_CODE[E_PARAMETER]))71 @patch.object(openlp.core.projectors.pjlink.PJLink, 'disconnect_from_host')
5872 def test_socket_abort(self, mock_disconnect):
59 @skip('Needs update to new setup')
60 def test_socket_abort(self):
61 """73 """
62 Test PJLink.socket_abort calls disconnect_from_host74 Test PJLink.socket_abort calls disconnect_from_host
63 """75 """
64 # GIVEN: Test object76 # GIVEN: Test object
65 with patch('openlp.core.projectors.pjlink.PJLink.disconnect_from_host') as mock_disconnect:77 pjlink = self.pjlink
66 pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)78
6779 # WHEN: Calling socket_abort
68 # WHEN: Calling socket_abort80 pjlink.socket_abort()
69 pjlink.socket_abort()81
7082 # THEN: disconnect_from_host should be called
71 # THEN: disconnect_from_host should be called83 assert mock_disconnect.called is True, 'Should have called disconnect_from_host'
72 assert mock_disconnect.called is True, 'Should have called disconnect_from_host'84
73
74 @skip('Needs update to new setup')
75 def test_poll_loop_not_connected(self):85 def test_poll_loop_not_connected(self):
76 """86 """
77 Test PJLink.poll_loop not connected return87 Test PJLink.poll_loop not connected return
78 """88 """
79 # GIVEN: Test object and mocks89 # GIVEN: Test object
80 pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)90 pjlink = self.pjlink
81 pjlink.state = MagicMock()91 pjlink.state = MagicMock()
82 pjlink.timer = MagicMock()92 pjlink.timer = MagicMock()
83 pjlink.state.return_value = False93 pjlink.state.return_value = False
@@ -89,412 +99,371 @@
89 # THEN: poll_loop should exit without calling any other method99 # THEN: poll_loop should exit without calling any other method
90 assert pjlink.timer.called is False, 'Should have returned without calling any other method'100 assert pjlink.timer.called is False, 'Should have returned without calling any other method'
91101
92 @skip('Needs update to new setup')102 @patch.object(openlp.core.projectors.pjlink.PJLink, 'send_command')
93 def test_poll_loop_set_interval(self):103 def test_poll_loop_set_interval(self, mock_send_command):
94 """104 """
95 Test PJLink.poll_loop makes correct calls105 Test PJLink.poll_loop makes correct calls
96 """106 """
97 # GIVEN: Mocks and test data107 # GIVEN: Test object and data
98 with patch('openlp.core.projectors.pjlink.PJLink.send_command') as mock_send_command:108 pjlink = self.pjlink
99109 pjlink.state = MagicMock()
100 pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)110 pjlink.state.return_value = QSOCKET_STATE[S_CONNECTED]
101 pjlink.state = MagicMock()111 pjlink.poll_timer = MagicMock()
102 pjlink.state.return_value = QSOCKET_STATE[S_CONNECTED]112 pjlink.poll_timer.interval.return_value = 10
103 pjlink.poll_timer = MagicMock()113
104 pjlink.poll_timer.interval.return_value = 10114 pjlink.poll_time = 20
105115 pjlink.power = S_ON
106 pjlink.poll_time = 20116 pjlink.source_available = None
107 pjlink.power = S_ON117 pjlink.other_info = None
108 pjlink.source_available = None118 pjlink.manufacturer = None
109 pjlink.other_info = None119 pjlink.model = None
110 pjlink.manufacturer = None120 pjlink.pjlink_name = None
111 pjlink.model = None121 call_list = [
112 pjlink.pjlink_name = None122 call('POWR'),
113 call_list = [123 call('ERST'),
114 call('POWR'),124 call('LAMP'),
115 call('ERST'),125 call('AVMT'),
116 call('LAMP'),126 call('INPT'),
117 call('AVMT'),127 call('INST'),
118 call('INPT'),128 call('INFO'),
119 call('INST'),129 call('INF1'),
120 call('INFO'),130 call('INF2'),
121 call('INF1'),131 call('NAME'),
122 call('INF2'),132 ]
123 call('NAME'),133
124 ]134 # WHEN: PJLink.poll_loop is called
125135 pjlink.poll_loop()
126 # WHEN: PJLink.poll_loop is called136
127 pjlink.poll_loop()137 # THEN: proper calls were made to retrieve projector data
128138 # First, call to update the timer with the next interval
129 # THEN: proper calls were made to retrieve projector data139 assert pjlink.poll_timer.setInterval.called is True, 'Timer update interval should have been called'
130 # First, call to update the timer with the next interval140 # Finally, should have called send_command with a list of projetctor status checks
131 assert pjlink.poll_timer.setInterval.called is True, 'Timer update interval should have been called'141 mock_send_command.assert_has_calls(call_list, 'Should have queued projector queries')
132 # Finally, should have called send_command with a list of projetctor status checks142
133 mock_send_command.assert_has_calls(call_list, 'Should have queued projector queries')143 @patch.object(openlp.core.projectors.pjlink.PJLink, 'projectorUpdateIcons')
134144 @patch.object(openlp.core.projectors.pjlink.PJLink, 'changeStatus')
135 @skip('Needs update to new setup')145 @patch.object(openlp.core.projectors.pjlink, 'log')
136 def test_projector_change_status_unknown_socket_error(self):146 def test_projector_change_status_unknown_socket_error(self, mock_log, mock_changeStatus, mock_UpdateIcons):
137 """147 """
138 Test change_status with connection error148 Test change_status with connection error
139 """149 """
140 # GIVEN: Test object and mocks150 # GIVEN: Test object
141 with patch.object(openlp.core.projectors.pjlink, 'log') as mock_log, \151 pjlink = self.pjlink
142 patch.object(openlp.core.projectors.pjlink.PJLink, 'changeStatus') as mock_changeStatus, \152 pjlink.projector_status = 0
143 patch.object(openlp.core.projectors.pjlink.PJLink, 'projectorUpdateIcons') as mock_UpdateIcons:153 pjlink.status_connect = 0
144154 log_debug_calls = [
145 pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)155 call('({ip}) Changing status to {status} "{msg}"'.format(ip=pjlink.name,
146 pjlink.projector_status = 0156 status=STATUS_CODE[E_UNKNOWN_SOCKET_ERROR],
147 pjlink.status_connect = 0157 msg=STATUS_MSG[E_UNKNOWN_SOCKET_ERROR])),
148 log_debug_calls = [158 call('({ip}) status_connect: {code}: "{msg}"'.format(ip=pjlink.name,
149 call('({ip}) Changing status to {status} "{msg}"'.format(ip=pjlink.name,159 code=STATUS_CODE[E_NOT_CONNECTED],
150 status=STATUS_CODE[E_UNKNOWN_SOCKET_ERROR],160 msg=STATUS_MSG[E_NOT_CONNECTED])),
151 msg=STATUS_MSG[E_UNKNOWN_SOCKET_ERROR])),161 call('({ip}) projector_status: {code}: "{msg}"'.format(ip=pjlink.name,
152 call('({ip}) status_connect: {code}: "{msg}"'.format(ip=pjlink.name,162 code=STATUS_CODE[S_OK],
153 code=STATUS_CODE[E_NOT_CONNECTED],163 msg=STATUS_MSG[S_OK])),
154 msg=STATUS_MSG[E_NOT_CONNECTED])),164 call('({ip}) error_status: {code}: "{msg}"'.format(ip=pjlink.name,
155 call('({ip}) projector_status: {code}: "{msg}"'.format(ip=pjlink.name,165 code=STATUS_CODE[E_UNKNOWN_SOCKET_ERROR],
156 code=STATUS_CODE[S_OK],166 msg=STATUS_MSG[E_UNKNOWN_SOCKET_ERROR]))]
157 msg=STATUS_MSG[S_OK])),167
158 call('({ip}) error_status: {code}: "{msg}"'.format(ip=pjlink.name,168 # WHEN: change_status called with unknown socket error
159 code=STATUS_CODE[E_UNKNOWN_SOCKET_ERROR],169 pjlink.change_status(status=E_UNKNOWN_SOCKET_ERROR)
160 msg=STATUS_MSG[E_UNKNOWN_SOCKET_ERROR]))]170
161171 # THEN: Proper settings should change and signals sent
162 # WHEN: change_status called with unknown socket error172 mock_log.debug.assert_has_calls(log_debug_calls)
163 pjlink.change_status(status=E_UNKNOWN_SOCKET_ERROR)173 assert pjlink.projector_status == S_OK, 'Projector status should not have changed'
164174 assert pjlink.status_connect == E_NOT_CONNECTED, 'Status connect should be NOT CONNECTED'
165 # THEN: Proper settings should change and signals sent175 assert mock_UpdateIcons.emit.called is True, 'Should have called UpdateIcons'
166 mock_log.debug.assert_has_calls(log_debug_calls)176 mock_changeStatus.emit.assert_called_once_with(pjlink.ip, E_UNKNOWN_SOCKET_ERROR,
167 assert pjlink.projector_status == S_OK, 'Projector status should not have changed'177 STATUS_MSG[E_UNKNOWN_SOCKET_ERROR])
168 assert pjlink.status_connect == E_NOT_CONNECTED, 'Status connect should be NOT CONNECTED'178
169 assert mock_UpdateIcons.emit.called is True, 'Should have called UpdateIcons'179 @patch.object(openlp.core.projectors.pjlink.PJLink, 'projectorUpdateIcons')
170 mock_changeStatus.emit.assert_called_once_with(pjlink.ip, E_UNKNOWN_SOCKET_ERROR,180 @patch.object(openlp.core.projectors.pjlink.PJLink, 'changeStatus')
171 STATUS_MSG[E_UNKNOWN_SOCKET_ERROR])181 @patch.object(openlp.core.projectors.pjlink, 'log')
172182 def test_projector_change_status_connection_status_connecting(self, mock_log, mock_changeStatus, mock_UpdateIcons):
173 @skip('Needs update to new setup')
174 def test_projector_change_status_connection_status_connecting(self):
175 """183 """
176 Test change_status with connecting status184 Test change_status with connecting status
177 """185 """
178 # GIVEN: Test object and mocks186 # GIVEN: Test object
179 with patch.object(openlp.core.projectors.pjlink, 'log') as mock_log, \187 pjlink = self.pjlink
180 patch.object(openlp.core.projectors.pjlink.PJLink, 'changeStatus') as mock_changeStatus, \188 pjlink.projector_status = 0
181 patch.object(openlp.core.projectors.pjlink.PJLink, 'projectorUpdateIcons') as mock_UpdateIcons:189 pjlink.status_connect = 0
182190 log_debug_calls = [
183 pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)191 call('({ip}) Changing status to {status} "{msg}"'.format(ip=pjlink.name,
184 pjlink.projector_status = 0192 status=STATUS_CODE[S_CONNECTING],
185 pjlink.status_connect = 0
186 log_debug_calls = [
187 call('({ip}) Changing status to {status} "{msg}"'.format(ip=pjlink.name,
188 status=STATUS_CODE[S_CONNECTING],
189 msg=STATUS_MSG[S_CONNECTING])),
190 call('({ip}) status_connect: {code}: "{msg}"'.format(ip=pjlink.name,
191 code=STATUS_CODE[S_CONNECTING],
192 msg=STATUS_MSG[S_CONNECTING])),193 msg=STATUS_MSG[S_CONNECTING])),
193 call('({ip}) projector_status: {code}: "{msg}"'.format(ip=pjlink.name,194 call('({ip}) status_connect: {code}: "{msg}"'.format(ip=pjlink.name,
194 code=STATUS_CODE[S_OK],195 code=STATUS_CODE[S_CONNECTING],
195 msg=STATUS_MSG[S_OK])),196 msg=STATUS_MSG[S_CONNECTING])),
196 call('({ip}) error_status: {code}: "{msg}"'.format(ip=pjlink.name,197 call('({ip}) projector_status: {code}: "{msg}"'.format(ip=pjlink.name,
197 code=STATUS_CODE[S_OK],198 code=STATUS_CODE[S_OK],
198 msg=STATUS_MSG[S_OK]))]199 msg=STATUS_MSG[S_OK])),
199200 call('({ip}) error_status: {code}: "{msg}"'.format(ip=pjlink.name,
200 # WHEN: change_status called with CONNECTING201 code=STATUS_CODE[S_OK],
201 pjlink.change_status(status=S_CONNECTING)202 msg=STATUS_MSG[S_OK]))]
202203
203 # THEN: Proper settings should change and signals sent204 # WHEN: change_status called with CONNECTING
204 mock_log.debug.assert_has_calls(log_debug_calls)205 pjlink.change_status(status=S_CONNECTING)
205 mock_changeStatus.emit.assert_called_once_with(pjlink.ip, S_CONNECTING, STATUS_MSG[S_CONNECTING])206
206 assert pjlink.projector_status == S_OK, 'Projector status should not have changed'207 # THEN: Proper settings should change and signals sent
207 assert pjlink.status_connect == S_CONNECTING, 'Status connect should be CONNECTING'208 mock_log.debug.assert_has_calls(log_debug_calls)
208 assert mock_UpdateIcons.emit.called is True, 'Should have called UpdateIcons'209 mock_changeStatus.emit.assert_called_once_with(pjlink.ip, S_CONNECTING, STATUS_MSG[S_CONNECTING])
209210 assert pjlink.projector_status == S_OK, 'Projector status should not have changed'
210 @skip('Needs update to new setup')211 assert pjlink.status_connect == S_CONNECTING, 'Status connect should be CONNECTING'
211 def test_projector_change_status_connection_status_connected(self):212 assert mock_UpdateIcons.emit.called is True, 'Should have called UpdateIcons'
213
214 @patch.object(openlp.core.projectors.pjlink.PJLink, 'changeStatus')
215 @patch.object(openlp.core.projectors.pjlink, 'log')
216 def test_projector_change_status_connection_status_connected(self, mock_log, mock_changeStatus):
212 """217 """
213 Test change_status with connected status218 Test change_status with connected status
214 """219 """
215 # GIVEN: Test object and mocks220 # GIVEN: Test object
216 with patch.object(openlp.core.projectors.pjlink, 'log') as mock_log, \221 pjlink = self.pjlink
217 patch.object(openlp.core.projectors.pjlink.PJLink, 'changeStatus') as mock_changeStatus:222 pjlink.projector_status = 0
218223 pjlink.status_connect = 0
219 pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)224 log_debug_calls = [
220 pjlink.projector_status = 0225 call('({ip}) Changing status to {status} "{msg}"'.format(ip=pjlink.name,
221 pjlink.status_connect = 0226 status=STATUS_CODE[S_CONNECTED],
222 log_debug_calls = [
223 call('({ip}) Changing status to {status} "{msg}"'.format(ip=pjlink.name,
224 status=STATUS_CODE[S_CONNECTED],
225 msg=STATUS_MSG[S_CONNECTED])),
226 call('({ip}) status_connect: {code}: "{msg}"'.format(ip=pjlink.name,
227 code=STATUS_CODE[S_CONNECTED],
228 msg=STATUS_MSG[S_CONNECTED])),227 msg=STATUS_MSG[S_CONNECTED])),
229 call('({ip}) projector_status: {code}: "{msg}"'.format(ip=pjlink.name,228 call('({ip}) status_connect: {code}: "{msg}"'.format(ip=pjlink.name,
230 code=STATUS_CODE[S_OK],229 code=STATUS_CODE[S_CONNECTED],
231 msg=STATUS_MSG[S_OK])),230 msg=STATUS_MSG[S_CONNECTED])),
232 call('({ip}) error_status: {code}: "{msg}"'.format(ip=pjlink.name,231 call('({ip}) projector_status: {code}: "{msg}"'.format(ip=pjlink.name,
233 code=STATUS_CODE[S_OK],232 code=STATUS_CODE[S_OK],
234 msg=STATUS_MSG[S_OK]))]233 msg=STATUS_MSG[S_OK])),
235234 call('({ip}) error_status: {code}: "{msg}"'.format(ip=pjlink.name,
236 # WHEN: change_status called with CONNECTED235 code=STATUS_CODE[S_OK],
237 pjlink.change_status(status=S_CONNECTED)236 msg=STATUS_MSG[S_OK]))]
238237
239 # THEN: Proper settings should change and signals sent238 # WHEN: change_status called with CONNECTED
240 mock_log.debug.assert_has_calls(log_debug_calls)239 pjlink.change_status(status=S_CONNECTED)
241 mock_changeStatus.emit.assert_called_once_with(pjlink.ip, S_CONNECTED, 'Connected')240
242 assert pjlink.projector_status == S_OK, 'Projector status should not have changed'241 # THEN: Proper settings should change and signals sent
243 assert pjlink.status_connect == S_CONNECTED, 'Status connect should be CONNECTED'242 mock_log.debug.assert_has_calls(log_debug_calls)
244243 mock_changeStatus.emit.assert_called_once_with(pjlink.ip, S_CONNECTED, 'Connected')
245 @skip('Needs update to new setup')244 assert pjlink.projector_status == S_OK, 'Projector status should not have changed'
246 def test_projector_change_status_connection_status_with_message(self):245 assert pjlink.status_connect == S_CONNECTED, 'Status connect should be CONNECTED'
246
247 @patch.object(openlp.core.projectors.pjlink.PJLink, 'changeStatus')
248 @patch.object(openlp.core.projectors.pjlink, 'log')
249 def test_projector_change_status_connection_status_with_message(self, mock_log, mock_changeStatus):
247 """250 """
248 Test change_status with connection status251 Test change_status with connection status
249 """252 """
250 # GIVEN: Test object and mocks253 # GIVEN: Test object
251 with patch.object(openlp.core.projectors.pjlink, 'log') as mock_log, \254 pjlink = self.pjlink
252 patch.object(openlp.core.projectors.pjlink.PJLink, 'changeStatus') as mock_changeStatus:255 pjlink.projector_status = 0
253256 pjlink.status_connect = 0
254 pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)257 test_message = 'Different Status Message than default'
255 pjlink.projector_status = 0258 log_debug_calls = [
256 pjlink.status_connect = 0259 call('({ip}) Changing status to {status} "{msg}"'.format(ip=pjlink.name,
257 test_message = 'Different Status Message than default'260 status=STATUS_CODE[S_ON],
258 log_debug_calls = [
259 call('({ip}) Changing status to {status} "{msg}"'.format(ip=pjlink.name,
260 status=STATUS_CODE[S_ON],
261 msg=test_message)),
262 call('({ip}) status_connect: {code}: "{msg}"'.format(ip=pjlink.name,
263 code=STATUS_CODE[S_OK],
264 msg=test_message)),261 msg=test_message)),
265 call('({ip}) projector_status: {code}: "{msg}"'.format(ip=pjlink.name,262 call('({ip}) status_connect: {code}: "{msg}"'.format(ip=pjlink.name,
266 code=STATUS_CODE[S_ON],263 code=STATUS_CODE[S_OK],
267 msg=test_message)),264 msg=test_message)),
268 call('({ip}) error_status: {code}: "{msg}"'.format(ip=pjlink.name,265 call('({ip}) projector_status: {code}: "{msg}"'.format(ip=pjlink.name,
269 code=STATUS_CODE[S_OK],266 code=STATUS_CODE[S_ON],
270 msg=test_message))]267 msg=test_message)),
271268 call('({ip}) error_status: {code}: "{msg}"'.format(ip=pjlink.name,
272 # WHEN: change_status called with projector ON status269 code=STATUS_CODE[S_OK],
273 pjlink.change_status(status=S_ON, msg=test_message)270 msg=test_message))]
274271
275 # THEN: Proper settings should change and signals sent272 # WHEN: change_status called with projector ON status
276 mock_log.debug.assert_has_calls(log_debug_calls)273 pjlink.change_status(status=S_ON, msg=test_message)
277 mock_changeStatus.emit.assert_called_once_with(pjlink.ip, S_ON, test_message)274
278 assert pjlink.projector_status == S_ON, 'Projector status should be ON'275 # THEN: Proper settings should change and signals sent
279 assert pjlink.status_connect == S_OK, 'Status connect should not have changed'276 mock_log.debug.assert_has_calls(log_debug_calls)
280277 mock_changeStatus.emit.assert_called_once_with(pjlink.ip, S_ON, test_message)
281 @skip('Needs update to new setup')278 assert pjlink.projector_status == S_ON, 'Projector status should be ON'
282 def test_projector_get_av_mute_status(self):279 assert pjlink.status_connect == S_OK, 'Status connect should not have changed'
280
281 @patch.object(openlp.core.projectors.pjlink.PJLink, 'send_command')
282 @patch.object(openlp.core.projectors.pjlink, 'log')
283 def test_projector_get_av_mute_status(self, mock_log, mock_send_command):
283 """284 """
284 Test sending command to retrieve shutter/audio state285 Test sending command to retrieve shutter/audio state
285 """286 """
286 # GIVEN: Test object and mocks287 # GIVEN: Test object
287 with patch.object(openlp.core.projectors.pjlink, 'log') as mock_log, \288 pjlink = self.pjlink
288 patch.object(openlp.core.projectors.pjlink.PJLink, 'send_command') as mock_send_command:289 test_data = 'AVMT'
289 pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)290 log_debug_calls = [call('({ip}) Sending {cmd} command'.format(ip=pjlink.name, cmd=test_data))]
290 test_data = 'AVMT'291
291 log_debug_calls = [call('({ip}) reset_information() connect status is '292 # WHEN: get_av_mute_status is called
292 '{state}'.format(ip=pjlink.name, state=STATUS_CODE[S_NOT_CONNECTED])),293 pjlink.get_av_mute_status()
293 call('({ip}) Sending {cmd} command'.format(ip=pjlink.name, cmd=test_data))]294
294295 # THEN: log data and send_command should have been called
295 # WHEN: get_av_mute_status is called296 mock_log.debug.assert_has_calls(log_debug_calls)
296 pjlink.get_av_mute_status()297 mock_send_command.assert_called_once_with(cmd=test_data, priority=False)
297298
298 # THEN: log data and send_command should have been called299 @patch.object(openlp.core.projectors.pjlink.PJLink, 'send_command')
299 mock_log.debug.assert_has_calls(log_debug_calls)300 @patch.object(openlp.core.projectors.pjlink, 'log')
300 mock_send_command.assert_called_once_with(cmd=test_data, priority=False)301 def test_projector_get_available_inputs(self, mock_log, mock_send_command):
301
302 @skip('Needs update to new setup')
303 def test_projector_get_available_inputs(self):
304 """302 """
305 Test sending command to retrieve avaliable inputs303 Test sending command to retrieve avaliable inputs
306 """304 """
307 # GIVEN: Test object and mocks305 # GIVEN: Test object
308 with patch.object(openlp.core.projectors.pjlink, 'log') as mock_log, \306 pjlink = self.pjlink
309 patch.object(openlp.core.projectors.pjlink.PJLink, 'send_command') as mock_send_command:307 test_data = 'INST'
310 pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)308 log_debug_calls = [call('({ip}) Sending {cmd} command'.format(ip=pjlink.name, cmd=test_data))]
311 test_data = 'INST'309
312 log_debug_calls = [call('({ip}) reset_information() connect status is '310 # WHEN: get_available_inputs is called
313 '{state}'.format(ip=pjlink.name, state=STATUS_CODE[S_NOT_CONNECTED])),311 pjlink.get_available_inputs()
314 call('({ip}) Sending {cmd} command'.format(ip=pjlink.name, cmd=test_data))]312
315313 # THEN: log data and send_command should have been called
316 # WHEN: get_available_inputs is called314 mock_log.debug.assert_has_calls(log_debug_calls)
317 pjlink.get_available_inputs()315 mock_send_command.assert_called_once_with(cmd=test_data)
318316
319 # THEN: log data and send_command should have been called317 @patch.object(openlp.core.projectors.pjlink.PJLink, 'send_command')
320 mock_log.debug.assert_has_calls(log_debug_calls)318 @patch.object(openlp.core.projectors.pjlink, 'log')
321 mock_send_command.assert_called_once_with(cmd=test_data)319 def test_projector_get_error_status(self, mock_log, mock_send_command):
322
323 @skip('Needs update to new setup')
324 def test_projector_get_error_status(self):
325 """320 """
326 Test sending command to retrieve projector error status321 Test sending command to retrieve projector error status
327 """322 """
328 # GIVEN: Test object and mocks323 # GIVEN: Test object
329 with patch.object(openlp.core.projectors.pjlink, 'log') as mock_log, \324 pjlink = self.pjlink
330 patch.object(openlp.core.projectors.pjlink.PJLink, 'send_command') as mock_send_command:325 test_data = 'ERST'
331 pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)326 log_debug_calls = [call('({ip}) Sending {cmd} command'.format(ip=pjlink.name, cmd=test_data))]
332 test_data = 'ERST'327
333 log_debug_calls = [call('({ip}) reset_information() connect status is '328 # WHEN: get_error_status is called
334 '{state}'.format(ip=pjlink.name, state=STATUS_CODE[S_NOT_CONNECTED])),329 pjlink.get_error_status()
335 call('({ip}) Sending {cmd} command'.format(ip=pjlink.name, cmd=test_data))]330
336331 # THEN: log data and send_command should have been called
337 # WHEN: get_error_status is called332 mock_log.debug.assert_has_calls(log_debug_calls)
338 pjlink.get_error_status()333 mock_send_command.assert_called_once_with(cmd=test_data)
339334
340 # THEN: log data and send_command should have been called335 @patch.object(openlp.core.projectors.pjlink.PJLink, 'send_command')
341 mock_log.debug.assert_has_calls(log_debug_calls)336 @patch.object(openlp.core.projectors.pjlink, 'log')
342 mock_send_command.assert_called_once_with(cmd=test_data)337 def test_projector_get_input_source(self, mock_log, mock_send_command):
343
344 @skip('Needs update to new setup')
345 def test_projector_get_input_source(self):
346 """338 """
347 Test sending command to retrieve current input339 Test sending command to retrieve current input
348 """340 """
349 # GIVEN: Test object and mocks341 # GIVEN: Test object
350 with patch.object(openlp.core.projectors.pjlink, 'log') as mock_log, \342 pjlink = self.pjlink
351 patch.object(openlp.core.projectors.pjlink.PJLink, 'send_command') as mock_send_command:343 test_data = 'INPT'
352 pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)344 log_debug_calls = [call('({ip}) Sending {cmd} command'.format(ip=pjlink.name, cmd=test_data))]
353 test_data = 'INPT'345
354 log_debug_calls = [call('({ip}) reset_information() connect status is '346 # WHEN: get_input_source is called
355 '{state}'.format(ip=pjlink.name, state=STATUS_CODE[S_NOT_CONNECTED])),347 pjlink.get_input_source()
356 call('({ip}) Sending {cmd} command'.format(ip=pjlink.name, cmd=test_data))]348
357349 # THEN: log data and send_command should have been called
358 # WHEN: get_input_source is called350 mock_log.debug.assert_has_calls(log_debug_calls)
359 pjlink.get_input_source()351 mock_send_command.assert_called_once_with(cmd=test_data)
360352
361 # THEN: log data and send_command should have been called353 @patch.object(openlp.core.projectors.pjlink.PJLink, 'send_command')
362 mock_log.debug.assert_has_calls(log_debug_calls)354 @patch.object(openlp.core.projectors.pjlink, 'log')
363 mock_send_command.assert_called_once_with(cmd=test_data)355 def test_projector_get_lamp_status(self, mock_log, mock_send_command):
364
365 @skip('Needs update to new setup')
366 def test_projector_get_lamp_status(self):
367 """356 """
368 Test sending command to retrieve lamp(s) status357 Test sending command to retrieve lamp(s) status
369 """358 """
370 # GIVEN: Test object and mocks359 # GIVEN: Test object
371 with patch.object(openlp.core.projectors.pjlink, 'log') as mock_log, \360 pjlink = self.pjlink
372 patch.object(openlp.core.projectors.pjlink.PJLink, 'send_command') as mock_send_command:361 test_data = 'LAMP'
373 pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)362 log_debug_calls = [call('({ip}) Sending {cmd} command'.format(ip=pjlink.name, cmd=test_data))]
374 test_data = 'LAMP'363
375 log_debug_calls = [call('({ip}) reset_information() connect status is '364 # WHEN: get_input_source is called
376 '{state}'.format(ip=pjlink.name, state=STATUS_CODE[S_NOT_CONNECTED])),365 pjlink.get_lamp_status()
377 call('({ip}) Sending {cmd} command'.format(ip=pjlink.name, cmd=test_data))]366
378367 # THEN: log data and send_command should have been called
379 # WHEN: get_input_source is called368 mock_log.debug.assert_has_calls(log_debug_calls)
380 pjlink.get_lamp_status()369 mock_send_command.assert_called_once_with(cmd=test_data)
381370
382 # THEN: log data and send_command should have been called371 @patch.object(openlp.core.projectors.pjlink.PJLink, 'send_command')
383 mock_log.debug.assert_has_calls(log_debug_calls)372 @patch.object(openlp.core.projectors.pjlink, 'log')
384 mock_send_command.assert_called_once_with(cmd=test_data)373 def test_projector_get_manufacturer(self, mock_log, mock_send_command):
385
386 @skip('Needs update to new setup')
387 def test_projector_get_manufacturer(self):
388 """374 """
389 Test sending command to retrieve manufacturer name375 Test sending command to retrieve manufacturer name
390 """376 """
391 # GIVEN: Test object and mocks377 # GIVEN: Test object
392 with patch.object(openlp.core.projectors.pjlink, 'log') as mock_log, \378 pjlink = self.pjlink
393 patch.object(openlp.core.projectors.pjlink.PJLink, 'send_command') as mock_send_command:379 test_data = 'INF1'
394 pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)380 log_debug_calls = [call('({ip}) Sending {cmd} command'.format(ip=pjlink.name, cmd=test_data))]
395 test_data = 'INF1'381
396 log_debug_calls = [call('({ip}) reset_information() connect status is '382 # WHEN: get_input_source is called
397 '{state}'.format(ip=pjlink.name, state=STATUS_CODE[S_NOT_CONNECTED])),383 pjlink.get_manufacturer()
398 call('({ip}) Sending {cmd} command'.format(ip=pjlink.name, cmd=test_data))]384
399385 # THEN: log data and send_command should have been called
400 # WHEN: get_input_source is called386 mock_log.debug.assert_has_calls(log_debug_calls)
401 pjlink.get_manufacturer()387 mock_send_command.assert_called_once_with(cmd=test_data)
402388
403 # THEN: log data and send_command should have been called389 @patch.object(openlp.core.projectors.pjlink.PJLink, 'send_command')
404 mock_log.debug.assert_has_calls(log_debug_calls)390 @patch.object(openlp.core.projectors.pjlink, 'log')
405 mock_send_command.assert_called_once_with(cmd=test_data)391 def test_projector_get_model(self, mock_log, mock_send_command):
406
407 @skip('Needs update to new setup')
408 def test_projector_get_model(self):
409 """392 """
410 Test sending command to get model information393 Test sending command to get model information
411 """394 """
412 # GIVEN: Test object and mocks395 # GIVEN: Test object
413 with patch.object(openlp.core.projectors.pjlink, 'log') as mock_log, \396 pjlink = self.pjlink
414 patch.object(openlp.core.projectors.pjlink.PJLink, 'send_command') as mock_send_command:397 test_data = 'INF2'
415 pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)398 log_debug_calls = [call('({ip}) Sending {cmd} command'.format(ip=pjlink.name, cmd=test_data))]
416 test_data = 'INF2'399
417 log_debug_calls = [call('({ip}) reset_information() connect status is '400 # WHEN: get_input_source is called
418 '{state}'.format(ip=pjlink.name, state=STATUS_CODE[S_NOT_CONNECTED])),401 pjlink.get_model()
419 call('({ip}) Sending {cmd} command'.format(ip=pjlink.name, cmd=test_data))]402
420403 # THEN: log data and send_command should have been called
421 # WHEN: get_input_source is called404 mock_log.debug.assert_has_calls(log_debug_calls)
422 pjlink.get_model()405 mock_send_command.assert_called_once_with(cmd=test_data)
423406
424 # THEN: log data and send_command should have been called407 @patch.object(openlp.core.projectors.pjlink.PJLink, 'send_command')
425 mock_log.debug.assert_has_calls(log_debug_calls)408 @patch.object(openlp.core.projectors.pjlink, 'log')
426 mock_send_command.assert_called_once_with(cmd=test_data)409 def test_projector_get_name(self, mock_log, mock_send_command):
427
428 @skip('Needs update to new setup')
429 def test_projector_get_name(self):
430 """410 """
431 Test sending command to get user-assigned name411 Test sending command to get user-assigned name
432 """412 """
433 # GIVEN: Test object and mocks413 # GIVEN: Test object
434 with patch.object(openlp.core.projectors.pjlink, 'log') as mock_log, \414 pjlink = self.pjlink
435 patch.object(openlp.core.projectors.pjlink.PJLink, 'send_command') as mock_send_command:415 test_data = 'NAME'
436 pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)416 log_debug_calls = [call('({ip}) Sending {cmd} command'.format(ip=pjlink.name, cmd=test_data))]
437 test_data = 'NAME'417
438 log_debug_calls = [call('({ip}) reset_information() connect status is '418 # WHEN: get_input_source is called
439 '{state}'.format(ip=pjlink.name, state=STATUS_CODE[S_NOT_CONNECTED])),419 pjlink.get_name()
440 call('({ip}) Sending {cmd} command'.format(ip=pjlink.name, cmd=test_data))]420
441421 # THEN: log data and send_command should have been called
442 # WHEN: get_input_source is called422 mock_log.debug.assert_has_calls(log_debug_calls)
443 pjlink.get_name()423 mock_send_command.assert_called_once_with(cmd=test_data)
444424
445 # THEN: log data and send_command should have been called425 @patch.object(openlp.core.projectors.pjlink.PJLink, 'send_command')
446 mock_log.debug.assert_has_calls(log_debug_calls)426 @patch.object(openlp.core.projectors.pjlink, 'log')
447 mock_send_command.assert_called_once_with(cmd=test_data)427 def test_projector_get_other_info(self, mock_log, mock_send_command):
448
449 @skip('Needs update to new setup')
450 def test_projector_get_other_info(self):
451 """428 """
452 Test sending command to retrieve other information429 Test sending command to retrieve other information
453 """430 """
454 # GIVEN: Test object and mocks431 # GIVEN: Test object
455 with patch.object(openlp.core.projectors.pjlink, 'log') as mock_log, \432 pjlink = self.pjlink
456 patch.object(openlp.core.projectors.pjlink.PJLink, 'send_command') as mock_send_command:433 test_data = 'INFO'
457 pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)434 log_debug_calls = [call('({ip}) Sending {cmd} command'.format(ip=pjlink.name, cmd=test_data))]
458 test_data = 'INFO'435
459 log_debug_calls = [call('({ip}) reset_information() connect status is '436 # WHEN: get_input_source is called
460 '{state}'.format(ip=pjlink.name, state=STATUS_CODE[S_NOT_CONNECTED])),437 pjlink.get_other_info()
461 call('({ip}) Sending {cmd} command'.format(ip=pjlink.name, cmd=test_data))]438
462439 # THEN: log data and send_command should have been called
463 # WHEN: get_input_source is called440 mock_log.debug.assert_has_calls(log_debug_calls)
464 pjlink.get_other_info()441 mock_send_command.assert_called_once_with(cmd=test_data)
465442
466 # THEN: log data and send_command should have been called443 @patch.object(openlp.core.projectors.pjlink.PJLink, 'send_command')
467 mock_log.debug.assert_has_calls(log_debug_calls)444 @patch.object(openlp.core.projectors.pjlink, 'log')
468 mock_send_command.assert_called_once_with(cmd=test_data)445 def test_projector_get_power_status(self, mock_log, mock_send_command):
469
470 @skip('Needs update to new setup')
471 def test_projector_get_power_status(self):
472 """446 """
473 Test sending command to retrieve current power state447 Test sending command to retrieve current power state
474 """448 """
475 # GIVEN: Test object and mocks449 # GIVEN: Test object
476 with patch.object(openlp.core.projectors.pjlink, 'log') as mock_log, \450 pjlink = self.pjlink
477 patch.object(openlp.core.projectors.pjlink.PJLink, 'send_command') as mock_send_command:451 test_data = 'POWR'
478 pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)452 log_debug_calls = [call('({ip}) Sending {cmd} command'.format(ip=pjlink.name, cmd=test_data))]
479 test_data = 'POWR'453
480 log_debug_calls = [call('({ip}) reset_information() connect status is '454 # WHEN: get_input_source is called
481 '{state}'.format(ip=pjlink.name, state=STATUS_CODE[S_NOT_CONNECTED])),455 pjlink.get_power_status()
482 call('({ip}) Sending {cmd} command'.format(ip=pjlink.name, cmd=test_data))]456
483457 # THEN: log data and send_command should have been called
484 # WHEN: get_input_source is called458 mock_log.debug.assert_has_calls(log_debug_calls)
485 pjlink.get_power_status()459 mock_send_command.assert_called_once_with(cmd=test_data, priority=False)
486460
487 # THEN: log data and send_command should have been called
488 mock_log.debug.assert_has_calls(log_debug_calls)
489 mock_send_command.assert_called_once_with(cmd=test_data, priority=False)
490
491 @skip('Needs update to new setup')
492 def test_projector_get_status_invalid(self):461 def test_projector_get_status_invalid(self):
493 """462 """
494 Test to check returned information for error code463 Test to check returned information for error code
495 """464 """
496 # GIVEN: Test object465 # GIVEN: Test object
497 pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)466 pjlink = self.pjlink
498 test_string = 'NaN test'467 test_string = 'NaN test'
499468
500 # WHEN: get_status called469 # WHEN: get_status called
@@ -504,14 +473,13 @@
504 assert code == -1, 'Should have returned -1 as a bad status check'473 assert code == -1, 'Should have returned -1 as a bad status check'
505 assert message is None, 'Invalid code type should have returned None for message'474 assert message is None, 'Invalid code type should have returned None for message'
506475
507 @skip('Needs update to new setup')
508 def test_projector_get_status_valid(self):476 def test_projector_get_status_valid(self):
509 """477 """
510 Test to check returned information for status codes478 Test to check returned information for status codes
511 """479 """
512 # GIVEN: Test object480 # GIVEN: Test object
513 test_message = 'Not Connected'481 test_message = 'Not Connected'
514 pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)482 pjlink = self.pjlink
515483
516 # WHEN: get_status called484 # WHEN: get_status called
517 code, message = pjlink._get_status(status=S_NOT_CONNECTED)485 code, message = pjlink._get_status(status=S_NOT_CONNECTED)
@@ -520,13 +488,12 @@
520 assert code == 'S_NOT_CONNECTED', 'Code returned should have been the same code that was sent'488 assert code == 'S_NOT_CONNECTED', 'Code returned should have been the same code that was sent'
521 assert message == test_message, 'Description of code should have been returned'489 assert message == test_message, 'Description of code should have been returned'
522490
523 @skip('Needs update to new setup')
524 def test_projector_get_status_unknown(self):491 def test_projector_get_status_unknown(self):
525 """492 """
526 Test to check returned information for unknown code493 Test to check returned information for unknown code
527 """494 """
528 # GIVEN: Test object495 # GIVEN: Test object
529 pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)496 pjlink = self.pjlink
530497
531 # WHEN: get_status called498 # WHEN: get_status called
532 code, message = pjlink._get_status(status=9999)499 code, message = pjlink._get_status(status=9999)