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
1=== modified file 'tests/openlp_core/projectors/test_projector_pjlink_base_01.py'
2--- tests/openlp_core/projectors/test_projector_pjlink_base_01.py 2019-04-26 07:51:13 +0000
3+++ tests/openlp_core/projectors/test_projector_pjlink_base_01.py 2019-04-26 07:51:13 +0000
4@@ -22,10 +22,11 @@
5 """
6 Package to test the openlp.core.projectors.pjlink base package.
7 """
8-from unittest import TestCase, skip
9+from unittest import TestCase
10 from unittest.mock import MagicMock, call, patch
11
12 import openlp.core.projectors.pjlink
13+from openlp.core.projectors.pjlinkcommands import process_command
14 from openlp.core.projectors.constants import E_NOT_CONNECTED, E_PARAMETER, E_UNKNOWN_SOCKET_ERROR, QSOCKET_STATE, \
15 S_CONNECTED, S_CONNECTING, S_NOT_CONNECTED, S_OK, S_ON, STATUS_CODE, STATUS_MSG
16 from openlp.core.projectors.db import Projector
17@@ -37,47 +38,56 @@
18 """
19 Tests for the PJLink module
20 """
21- @skip('Needs update to new setup')
22- def test_status_change(self):
23+ def setUp(self):
24+ """
25+ Initialize test state(s)
26+ """
27+ # Default PJLink instance for tests
28+ self.pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
29+
30+ def tearDown(self):
31+ """
32+ Cleanup test state(s)
33+ """
34+ del(self.pjlink)
35+
36+ @patch.object(openlp.core.projectors.pjlink.PJLink, 'changeStatus')
37+ def test_status_change(self, mock_changeStatus):
38 """
39 Test process_command call with ERR2 (Parameter) status
40 """
41 # GIVEN: Test object
42- with patch('openlp.core.projectors.pjlink.PJLink.changeStatus') as mock_changeStatus:
43-
44- pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
45-
46- # WHEN: process_command is called with "ERR2" status from projector
47- pjlink.process_command('POWR', 'ERR2')
48-
49- # THEN: change_status should have called change_status with E_UNDEFINED
50- # as first parameter
51- mock_changeStatus.called_with(E_PARAMETER,
52- 'change_status should have been called with "{}"'.format(
53- STATUS_CODE[E_PARAMETER]))
54-
55- @skip('Needs update to new setup')
56- def test_socket_abort(self):
57+ pjlink = self.pjlink
58+
59+ # WHEN: process_command is called with "ERR2" status from projector
60+ process_command(projector=pjlink, cmd='POWR', data='ERR2')
61+
62+ # THEN: change_status should have called change_status with E_UNDEFINED
63+ # as first parameter
64+ mock_changeStatus.called_with(E_PARAMETER,
65+ 'change_status should have been called '
66+ 'with "{}"'.format(STATUS_CODE[E_PARAMETER]))
67+
68+ @patch.object(openlp.core.projectors.pjlink.PJLink, 'disconnect_from_host')
69+ def test_socket_abort(self, mock_disconnect):
70 """
71 Test PJLink.socket_abort calls disconnect_from_host
72 """
73 # GIVEN: Test object
74- with patch('openlp.core.projectors.pjlink.PJLink.disconnect_from_host') as mock_disconnect:
75- pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
76-
77- # WHEN: Calling socket_abort
78- pjlink.socket_abort()
79-
80- # THEN: disconnect_from_host should be called
81- assert mock_disconnect.called is True, 'Should have called disconnect_from_host'
82-
83- @skip('Needs update to new setup')
84+ pjlink = self.pjlink
85+
86+ # WHEN: Calling socket_abort
87+ pjlink.socket_abort()
88+
89+ # THEN: disconnect_from_host should be called
90+ assert mock_disconnect.called is True, 'Should have called disconnect_from_host'
91+
92 def test_poll_loop_not_connected(self):
93 """
94 Test PJLink.poll_loop not connected return
95 """
96- # GIVEN: Test object and mocks
97- pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
98+ # GIVEN: Test object
99+ pjlink = self.pjlink
100 pjlink.state = MagicMock()
101 pjlink.timer = MagicMock()
102 pjlink.state.return_value = False
103@@ -89,412 +99,371 @@
104 # THEN: poll_loop should exit without calling any other method
105 assert pjlink.timer.called is False, 'Should have returned without calling any other method'
106
107- @skip('Needs update to new setup')
108- def test_poll_loop_set_interval(self):
109+ @patch.object(openlp.core.projectors.pjlink.PJLink, 'send_command')
110+ def test_poll_loop_set_interval(self, mock_send_command):
111 """
112 Test PJLink.poll_loop makes correct calls
113 """
114- # GIVEN: Mocks and test data
115- with patch('openlp.core.projectors.pjlink.PJLink.send_command') as mock_send_command:
116-
117- pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
118- pjlink.state = MagicMock()
119- pjlink.state.return_value = QSOCKET_STATE[S_CONNECTED]
120- pjlink.poll_timer = MagicMock()
121- pjlink.poll_timer.interval.return_value = 10
122-
123- pjlink.poll_time = 20
124- pjlink.power = S_ON
125- pjlink.source_available = None
126- pjlink.other_info = None
127- pjlink.manufacturer = None
128- pjlink.model = None
129- pjlink.pjlink_name = None
130- call_list = [
131- call('POWR'),
132- call('ERST'),
133- call('LAMP'),
134- call('AVMT'),
135- call('INPT'),
136- call('INST'),
137- call('INFO'),
138- call('INF1'),
139- call('INF2'),
140- call('NAME'),
141- ]
142-
143- # WHEN: PJLink.poll_loop is called
144- pjlink.poll_loop()
145-
146- # THEN: proper calls were made to retrieve projector data
147- # First, call to update the timer with the next interval
148- assert pjlink.poll_timer.setInterval.called is True, 'Timer update interval should have been called'
149- # Finally, should have called send_command with a list of projetctor status checks
150- mock_send_command.assert_has_calls(call_list, 'Should have queued projector queries')
151-
152- @skip('Needs update to new setup')
153- def test_projector_change_status_unknown_socket_error(self):
154+ # GIVEN: Test object and data
155+ pjlink = self.pjlink
156+ pjlink.state = MagicMock()
157+ pjlink.state.return_value = QSOCKET_STATE[S_CONNECTED]
158+ pjlink.poll_timer = MagicMock()
159+ pjlink.poll_timer.interval.return_value = 10
160+
161+ pjlink.poll_time = 20
162+ pjlink.power = S_ON
163+ pjlink.source_available = None
164+ pjlink.other_info = None
165+ pjlink.manufacturer = None
166+ pjlink.model = None
167+ pjlink.pjlink_name = None
168+ call_list = [
169+ call('POWR'),
170+ call('ERST'),
171+ call('LAMP'),
172+ call('AVMT'),
173+ call('INPT'),
174+ call('INST'),
175+ call('INFO'),
176+ call('INF1'),
177+ call('INF2'),
178+ call('NAME'),
179+ ]
180+
181+ # WHEN: PJLink.poll_loop is called
182+ pjlink.poll_loop()
183+
184+ # THEN: proper calls were made to retrieve projector data
185+ # First, call to update the timer with the next interval
186+ assert pjlink.poll_timer.setInterval.called is True, 'Timer update interval should have been called'
187+ # Finally, should have called send_command with a list of projetctor status checks
188+ mock_send_command.assert_has_calls(call_list, 'Should have queued projector queries')
189+
190+ @patch.object(openlp.core.projectors.pjlink.PJLink, 'projectorUpdateIcons')
191+ @patch.object(openlp.core.projectors.pjlink.PJLink, 'changeStatus')
192+ @patch.object(openlp.core.projectors.pjlink, 'log')
193+ def test_projector_change_status_unknown_socket_error(self, mock_log, mock_changeStatus, mock_UpdateIcons):
194 """
195 Test change_status with connection error
196 """
197- # GIVEN: Test object and mocks
198- with patch.object(openlp.core.projectors.pjlink, 'log') as mock_log, \
199- patch.object(openlp.core.projectors.pjlink.PJLink, 'changeStatus') as mock_changeStatus, \
200- patch.object(openlp.core.projectors.pjlink.PJLink, 'projectorUpdateIcons') as mock_UpdateIcons:
201-
202- pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
203- pjlink.projector_status = 0
204- pjlink.status_connect = 0
205- log_debug_calls = [
206- call('({ip}) Changing status to {status} "{msg}"'.format(ip=pjlink.name,
207- status=STATUS_CODE[E_UNKNOWN_SOCKET_ERROR],
208- msg=STATUS_MSG[E_UNKNOWN_SOCKET_ERROR])),
209- call('({ip}) status_connect: {code}: "{msg}"'.format(ip=pjlink.name,
210- code=STATUS_CODE[E_NOT_CONNECTED],
211- msg=STATUS_MSG[E_NOT_CONNECTED])),
212- call('({ip}) projector_status: {code}: "{msg}"'.format(ip=pjlink.name,
213- code=STATUS_CODE[S_OK],
214- msg=STATUS_MSG[S_OK])),
215- call('({ip}) error_status: {code}: "{msg}"'.format(ip=pjlink.name,
216- code=STATUS_CODE[E_UNKNOWN_SOCKET_ERROR],
217- msg=STATUS_MSG[E_UNKNOWN_SOCKET_ERROR]))]
218-
219- # WHEN: change_status called with unknown socket error
220- pjlink.change_status(status=E_UNKNOWN_SOCKET_ERROR)
221-
222- # THEN: Proper settings should change and signals sent
223- mock_log.debug.assert_has_calls(log_debug_calls)
224- assert pjlink.projector_status == S_OK, 'Projector status should not have changed'
225- assert pjlink.status_connect == E_NOT_CONNECTED, 'Status connect should be NOT CONNECTED'
226- assert mock_UpdateIcons.emit.called is True, 'Should have called UpdateIcons'
227- mock_changeStatus.emit.assert_called_once_with(pjlink.ip, E_UNKNOWN_SOCKET_ERROR,
228- STATUS_MSG[E_UNKNOWN_SOCKET_ERROR])
229-
230- @skip('Needs update to new setup')
231- def test_projector_change_status_connection_status_connecting(self):
232+ # GIVEN: Test object
233+ pjlink = self.pjlink
234+ pjlink.projector_status = 0
235+ pjlink.status_connect = 0
236+ log_debug_calls = [
237+ call('({ip}) Changing status to {status} "{msg}"'.format(ip=pjlink.name,
238+ status=STATUS_CODE[E_UNKNOWN_SOCKET_ERROR],
239+ msg=STATUS_MSG[E_UNKNOWN_SOCKET_ERROR])),
240+ call('({ip}) status_connect: {code}: "{msg}"'.format(ip=pjlink.name,
241+ code=STATUS_CODE[E_NOT_CONNECTED],
242+ msg=STATUS_MSG[E_NOT_CONNECTED])),
243+ call('({ip}) projector_status: {code}: "{msg}"'.format(ip=pjlink.name,
244+ code=STATUS_CODE[S_OK],
245+ msg=STATUS_MSG[S_OK])),
246+ call('({ip}) error_status: {code}: "{msg}"'.format(ip=pjlink.name,
247+ code=STATUS_CODE[E_UNKNOWN_SOCKET_ERROR],
248+ msg=STATUS_MSG[E_UNKNOWN_SOCKET_ERROR]))]
249+
250+ # WHEN: change_status called with unknown socket error
251+ pjlink.change_status(status=E_UNKNOWN_SOCKET_ERROR)
252+
253+ # THEN: Proper settings should change and signals sent
254+ mock_log.debug.assert_has_calls(log_debug_calls)
255+ assert pjlink.projector_status == S_OK, 'Projector status should not have changed'
256+ assert pjlink.status_connect == E_NOT_CONNECTED, 'Status connect should be NOT CONNECTED'
257+ assert mock_UpdateIcons.emit.called is True, 'Should have called UpdateIcons'
258+ mock_changeStatus.emit.assert_called_once_with(pjlink.ip, E_UNKNOWN_SOCKET_ERROR,
259+ STATUS_MSG[E_UNKNOWN_SOCKET_ERROR])
260+
261+ @patch.object(openlp.core.projectors.pjlink.PJLink, 'projectorUpdateIcons')
262+ @patch.object(openlp.core.projectors.pjlink.PJLink, 'changeStatus')
263+ @patch.object(openlp.core.projectors.pjlink, 'log')
264+ def test_projector_change_status_connection_status_connecting(self, mock_log, mock_changeStatus, mock_UpdateIcons):
265 """
266 Test change_status with connecting status
267 """
268- # GIVEN: Test object and mocks
269- with patch.object(openlp.core.projectors.pjlink, 'log') as mock_log, \
270- patch.object(openlp.core.projectors.pjlink.PJLink, 'changeStatus') as mock_changeStatus, \
271- patch.object(openlp.core.projectors.pjlink.PJLink, 'projectorUpdateIcons') as mock_UpdateIcons:
272-
273- pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
274- pjlink.projector_status = 0
275- pjlink.status_connect = 0
276- log_debug_calls = [
277- call('({ip}) Changing status to {status} "{msg}"'.format(ip=pjlink.name,
278- status=STATUS_CODE[S_CONNECTING],
279- msg=STATUS_MSG[S_CONNECTING])),
280- call('({ip}) status_connect: {code}: "{msg}"'.format(ip=pjlink.name,
281- code=STATUS_CODE[S_CONNECTING],
282+ # GIVEN: Test object
283+ pjlink = self.pjlink
284+ pjlink.projector_status = 0
285+ pjlink.status_connect = 0
286+ log_debug_calls = [
287+ call('({ip}) Changing status to {status} "{msg}"'.format(ip=pjlink.name,
288+ status=STATUS_CODE[S_CONNECTING],
289 msg=STATUS_MSG[S_CONNECTING])),
290- call('({ip}) projector_status: {code}: "{msg}"'.format(ip=pjlink.name,
291- code=STATUS_CODE[S_OK],
292- msg=STATUS_MSG[S_OK])),
293- call('({ip}) error_status: {code}: "{msg}"'.format(ip=pjlink.name,
294+ call('({ip}) status_connect: {code}: "{msg}"'.format(ip=pjlink.name,
295+ code=STATUS_CODE[S_CONNECTING],
296+ msg=STATUS_MSG[S_CONNECTING])),
297+ call('({ip}) projector_status: {code}: "{msg}"'.format(ip=pjlink.name,
298 code=STATUS_CODE[S_OK],
299- msg=STATUS_MSG[S_OK]))]
300-
301- # WHEN: change_status called with CONNECTING
302- pjlink.change_status(status=S_CONNECTING)
303-
304- # THEN: Proper settings should change and signals sent
305- mock_log.debug.assert_has_calls(log_debug_calls)
306- mock_changeStatus.emit.assert_called_once_with(pjlink.ip, S_CONNECTING, STATUS_MSG[S_CONNECTING])
307- assert pjlink.projector_status == S_OK, 'Projector status should not have changed'
308- assert pjlink.status_connect == S_CONNECTING, 'Status connect should be CONNECTING'
309- assert mock_UpdateIcons.emit.called is True, 'Should have called UpdateIcons'
310-
311- @skip('Needs update to new setup')
312- def test_projector_change_status_connection_status_connected(self):
313+ msg=STATUS_MSG[S_OK])),
314+ call('({ip}) error_status: {code}: "{msg}"'.format(ip=pjlink.name,
315+ code=STATUS_CODE[S_OK],
316+ msg=STATUS_MSG[S_OK]))]
317+
318+ # WHEN: change_status called with CONNECTING
319+ pjlink.change_status(status=S_CONNECTING)
320+
321+ # THEN: Proper settings should change and signals sent
322+ mock_log.debug.assert_has_calls(log_debug_calls)
323+ mock_changeStatus.emit.assert_called_once_with(pjlink.ip, S_CONNECTING, STATUS_MSG[S_CONNECTING])
324+ assert pjlink.projector_status == S_OK, 'Projector status should not have changed'
325+ assert pjlink.status_connect == S_CONNECTING, 'Status connect should be CONNECTING'
326+ assert mock_UpdateIcons.emit.called is True, 'Should have called UpdateIcons'
327+
328+ @patch.object(openlp.core.projectors.pjlink.PJLink, 'changeStatus')
329+ @patch.object(openlp.core.projectors.pjlink, 'log')
330+ def test_projector_change_status_connection_status_connected(self, mock_log, mock_changeStatus):
331 """
332 Test change_status with connected status
333 """
334- # GIVEN: Test object and mocks
335- with patch.object(openlp.core.projectors.pjlink, 'log') as mock_log, \
336- patch.object(openlp.core.projectors.pjlink.PJLink, 'changeStatus') as mock_changeStatus:
337-
338- pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
339- pjlink.projector_status = 0
340- pjlink.status_connect = 0
341- log_debug_calls = [
342- call('({ip}) Changing status to {status} "{msg}"'.format(ip=pjlink.name,
343- status=STATUS_CODE[S_CONNECTED],
344- msg=STATUS_MSG[S_CONNECTED])),
345- call('({ip}) status_connect: {code}: "{msg}"'.format(ip=pjlink.name,
346- code=STATUS_CODE[S_CONNECTED],
347+ # GIVEN: Test object
348+ pjlink = self.pjlink
349+ pjlink.projector_status = 0
350+ pjlink.status_connect = 0
351+ log_debug_calls = [
352+ call('({ip}) Changing status to {status} "{msg}"'.format(ip=pjlink.name,
353+ status=STATUS_CODE[S_CONNECTED],
354 msg=STATUS_MSG[S_CONNECTED])),
355- call('({ip}) projector_status: {code}: "{msg}"'.format(ip=pjlink.name,
356- code=STATUS_CODE[S_OK],
357- msg=STATUS_MSG[S_OK])),
358- call('({ip}) error_status: {code}: "{msg}"'.format(ip=pjlink.name,
359+ call('({ip}) status_connect: {code}: "{msg}"'.format(ip=pjlink.name,
360+ code=STATUS_CODE[S_CONNECTED],
361+ msg=STATUS_MSG[S_CONNECTED])),
362+ call('({ip}) projector_status: {code}: "{msg}"'.format(ip=pjlink.name,
363 code=STATUS_CODE[S_OK],
364- msg=STATUS_MSG[S_OK]))]
365-
366- # WHEN: change_status called with CONNECTED
367- pjlink.change_status(status=S_CONNECTED)
368-
369- # THEN: Proper settings should change and signals sent
370- mock_log.debug.assert_has_calls(log_debug_calls)
371- mock_changeStatus.emit.assert_called_once_with(pjlink.ip, S_CONNECTED, 'Connected')
372- assert pjlink.projector_status == S_OK, 'Projector status should not have changed'
373- assert pjlink.status_connect == S_CONNECTED, 'Status connect should be CONNECTED'
374-
375- @skip('Needs update to new setup')
376- def test_projector_change_status_connection_status_with_message(self):
377+ msg=STATUS_MSG[S_OK])),
378+ call('({ip}) error_status: {code}: "{msg}"'.format(ip=pjlink.name,
379+ code=STATUS_CODE[S_OK],
380+ msg=STATUS_MSG[S_OK]))]
381+
382+ # WHEN: change_status called with CONNECTED
383+ pjlink.change_status(status=S_CONNECTED)
384+
385+ # THEN: Proper settings should change and signals sent
386+ mock_log.debug.assert_has_calls(log_debug_calls)
387+ mock_changeStatus.emit.assert_called_once_with(pjlink.ip, S_CONNECTED, 'Connected')
388+ assert pjlink.projector_status == S_OK, 'Projector status should not have changed'
389+ assert pjlink.status_connect == S_CONNECTED, 'Status connect should be CONNECTED'
390+
391+ @patch.object(openlp.core.projectors.pjlink.PJLink, 'changeStatus')
392+ @patch.object(openlp.core.projectors.pjlink, 'log')
393+ def test_projector_change_status_connection_status_with_message(self, mock_log, mock_changeStatus):
394 """
395 Test change_status with connection status
396 """
397- # GIVEN: Test object and mocks
398- with patch.object(openlp.core.projectors.pjlink, 'log') as mock_log, \
399- patch.object(openlp.core.projectors.pjlink.PJLink, 'changeStatus') as mock_changeStatus:
400-
401- pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
402- pjlink.projector_status = 0
403- pjlink.status_connect = 0
404- test_message = 'Different Status Message than default'
405- log_debug_calls = [
406- call('({ip}) Changing status to {status} "{msg}"'.format(ip=pjlink.name,
407- status=STATUS_CODE[S_ON],
408- msg=test_message)),
409- call('({ip}) status_connect: {code}: "{msg}"'.format(ip=pjlink.name,
410- code=STATUS_CODE[S_OK],
411+ # GIVEN: Test object
412+ pjlink = self.pjlink
413+ pjlink.projector_status = 0
414+ pjlink.status_connect = 0
415+ test_message = 'Different Status Message than default'
416+ log_debug_calls = [
417+ call('({ip}) Changing status to {status} "{msg}"'.format(ip=pjlink.name,
418+ status=STATUS_CODE[S_ON],
419 msg=test_message)),
420- call('({ip}) projector_status: {code}: "{msg}"'.format(ip=pjlink.name,
421- code=STATUS_CODE[S_ON],
422- msg=test_message)),
423- call('({ip}) error_status: {code}: "{msg}"'.format(ip=pjlink.name,
424- code=STATUS_CODE[S_OK],
425- msg=test_message))]
426-
427- # WHEN: change_status called with projector ON status
428- pjlink.change_status(status=S_ON, msg=test_message)
429-
430- # THEN: Proper settings should change and signals sent
431- mock_log.debug.assert_has_calls(log_debug_calls)
432- mock_changeStatus.emit.assert_called_once_with(pjlink.ip, S_ON, test_message)
433- assert pjlink.projector_status == S_ON, 'Projector status should be ON'
434- assert pjlink.status_connect == S_OK, 'Status connect should not have changed'
435-
436- @skip('Needs update to new setup')
437- def test_projector_get_av_mute_status(self):
438+ call('({ip}) status_connect: {code}: "{msg}"'.format(ip=pjlink.name,
439+ code=STATUS_CODE[S_OK],
440+ msg=test_message)),
441+ call('({ip}) projector_status: {code}: "{msg}"'.format(ip=pjlink.name,
442+ code=STATUS_CODE[S_ON],
443+ msg=test_message)),
444+ call('({ip}) error_status: {code}: "{msg}"'.format(ip=pjlink.name,
445+ code=STATUS_CODE[S_OK],
446+ msg=test_message))]
447+
448+ # WHEN: change_status called with projector ON status
449+ pjlink.change_status(status=S_ON, msg=test_message)
450+
451+ # THEN: Proper settings should change and signals sent
452+ mock_log.debug.assert_has_calls(log_debug_calls)
453+ mock_changeStatus.emit.assert_called_once_with(pjlink.ip, S_ON, test_message)
454+ assert pjlink.projector_status == S_ON, 'Projector status should be ON'
455+ assert pjlink.status_connect == S_OK, 'Status connect should not have changed'
456+
457+ @patch.object(openlp.core.projectors.pjlink.PJLink, 'send_command')
458+ @patch.object(openlp.core.projectors.pjlink, 'log')
459+ def test_projector_get_av_mute_status(self, mock_log, mock_send_command):
460 """
461 Test sending command to retrieve shutter/audio state
462 """
463- # GIVEN: Test object and mocks
464- with patch.object(openlp.core.projectors.pjlink, 'log') as mock_log, \
465- patch.object(openlp.core.projectors.pjlink.PJLink, 'send_command') as mock_send_command:
466- pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
467- test_data = 'AVMT'
468- log_debug_calls = [call('({ip}) reset_information() connect status is '
469- '{state}'.format(ip=pjlink.name, state=STATUS_CODE[S_NOT_CONNECTED])),
470- call('({ip}) Sending {cmd} command'.format(ip=pjlink.name, cmd=test_data))]
471-
472- # WHEN: get_av_mute_status is called
473- pjlink.get_av_mute_status()
474-
475- # THEN: log data and send_command should have been called
476- mock_log.debug.assert_has_calls(log_debug_calls)
477- mock_send_command.assert_called_once_with(cmd=test_data, priority=False)
478-
479- @skip('Needs update to new setup')
480- def test_projector_get_available_inputs(self):
481+ # GIVEN: Test object
482+ pjlink = self.pjlink
483+ test_data = 'AVMT'
484+ log_debug_calls = [call('({ip}) Sending {cmd} command'.format(ip=pjlink.name, cmd=test_data))]
485+
486+ # WHEN: get_av_mute_status is called
487+ pjlink.get_av_mute_status()
488+
489+ # THEN: log data and send_command should have been called
490+ mock_log.debug.assert_has_calls(log_debug_calls)
491+ mock_send_command.assert_called_once_with(cmd=test_data, priority=False)
492+
493+ @patch.object(openlp.core.projectors.pjlink.PJLink, 'send_command')
494+ @patch.object(openlp.core.projectors.pjlink, 'log')
495+ def test_projector_get_available_inputs(self, mock_log, mock_send_command):
496 """
497 Test sending command to retrieve avaliable inputs
498 """
499- # GIVEN: Test object and mocks
500- with patch.object(openlp.core.projectors.pjlink, 'log') as mock_log, \
501- patch.object(openlp.core.projectors.pjlink.PJLink, 'send_command') as mock_send_command:
502- pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
503- test_data = 'INST'
504- log_debug_calls = [call('({ip}) reset_information() connect status is '
505- '{state}'.format(ip=pjlink.name, state=STATUS_CODE[S_NOT_CONNECTED])),
506- call('({ip}) Sending {cmd} command'.format(ip=pjlink.name, cmd=test_data))]
507-
508- # WHEN: get_available_inputs is called
509- pjlink.get_available_inputs()
510-
511- # THEN: log data and send_command should have been called
512- mock_log.debug.assert_has_calls(log_debug_calls)
513- mock_send_command.assert_called_once_with(cmd=test_data)
514-
515- @skip('Needs update to new setup')
516- def test_projector_get_error_status(self):
517+ # GIVEN: Test object
518+ pjlink = self.pjlink
519+ test_data = 'INST'
520+ log_debug_calls = [call('({ip}) Sending {cmd} command'.format(ip=pjlink.name, cmd=test_data))]
521+
522+ # WHEN: get_available_inputs is called
523+ pjlink.get_available_inputs()
524+
525+ # THEN: log data and send_command should have been called
526+ mock_log.debug.assert_has_calls(log_debug_calls)
527+ mock_send_command.assert_called_once_with(cmd=test_data)
528+
529+ @patch.object(openlp.core.projectors.pjlink.PJLink, 'send_command')
530+ @patch.object(openlp.core.projectors.pjlink, 'log')
531+ def test_projector_get_error_status(self, mock_log, mock_send_command):
532 """
533 Test sending command to retrieve projector error status
534 """
535- # GIVEN: Test object and mocks
536- with patch.object(openlp.core.projectors.pjlink, 'log') as mock_log, \
537- patch.object(openlp.core.projectors.pjlink.PJLink, 'send_command') as mock_send_command:
538- pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
539- test_data = 'ERST'
540- log_debug_calls = [call('({ip}) reset_information() connect status is '
541- '{state}'.format(ip=pjlink.name, state=STATUS_CODE[S_NOT_CONNECTED])),
542- call('({ip}) Sending {cmd} command'.format(ip=pjlink.name, cmd=test_data))]
543-
544- # WHEN: get_error_status is called
545- pjlink.get_error_status()
546-
547- # THEN: log data and send_command should have been called
548- mock_log.debug.assert_has_calls(log_debug_calls)
549- mock_send_command.assert_called_once_with(cmd=test_data)
550-
551- @skip('Needs update to new setup')
552- def test_projector_get_input_source(self):
553+ # GIVEN: Test object
554+ pjlink = self.pjlink
555+ test_data = 'ERST'
556+ log_debug_calls = [call('({ip}) Sending {cmd} command'.format(ip=pjlink.name, cmd=test_data))]
557+
558+ # WHEN: get_error_status is called
559+ pjlink.get_error_status()
560+
561+ # THEN: log data and send_command should have been called
562+ mock_log.debug.assert_has_calls(log_debug_calls)
563+ mock_send_command.assert_called_once_with(cmd=test_data)
564+
565+ @patch.object(openlp.core.projectors.pjlink.PJLink, 'send_command')
566+ @patch.object(openlp.core.projectors.pjlink, 'log')
567+ def test_projector_get_input_source(self, mock_log, mock_send_command):
568 """
569 Test sending command to retrieve current input
570 """
571- # GIVEN: Test object and mocks
572- with patch.object(openlp.core.projectors.pjlink, 'log') as mock_log, \
573- patch.object(openlp.core.projectors.pjlink.PJLink, 'send_command') as mock_send_command:
574- pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
575- test_data = 'INPT'
576- log_debug_calls = [call('({ip}) reset_information() connect status is '
577- '{state}'.format(ip=pjlink.name, state=STATUS_CODE[S_NOT_CONNECTED])),
578- call('({ip}) Sending {cmd} command'.format(ip=pjlink.name, cmd=test_data))]
579-
580- # WHEN: get_input_source is called
581- pjlink.get_input_source()
582-
583- # THEN: log data and send_command should have been called
584- mock_log.debug.assert_has_calls(log_debug_calls)
585- mock_send_command.assert_called_once_with(cmd=test_data)
586-
587- @skip('Needs update to new setup')
588- def test_projector_get_lamp_status(self):
589+ # GIVEN: Test object
590+ pjlink = self.pjlink
591+ test_data = 'INPT'
592+ log_debug_calls = [call('({ip}) Sending {cmd} command'.format(ip=pjlink.name, cmd=test_data))]
593+
594+ # WHEN: get_input_source is called
595+ pjlink.get_input_source()
596+
597+ # THEN: log data and send_command should have been called
598+ mock_log.debug.assert_has_calls(log_debug_calls)
599+ mock_send_command.assert_called_once_with(cmd=test_data)
600+
601+ @patch.object(openlp.core.projectors.pjlink.PJLink, 'send_command')
602+ @patch.object(openlp.core.projectors.pjlink, 'log')
603+ def test_projector_get_lamp_status(self, mock_log, mock_send_command):
604 """
605 Test sending command to retrieve lamp(s) status
606 """
607- # GIVEN: Test object and mocks
608- with patch.object(openlp.core.projectors.pjlink, 'log') as mock_log, \
609- patch.object(openlp.core.projectors.pjlink.PJLink, 'send_command') as mock_send_command:
610- pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
611- test_data = 'LAMP'
612- log_debug_calls = [call('({ip}) reset_information() connect status is '
613- '{state}'.format(ip=pjlink.name, state=STATUS_CODE[S_NOT_CONNECTED])),
614- call('({ip}) Sending {cmd} command'.format(ip=pjlink.name, cmd=test_data))]
615-
616- # WHEN: get_input_source is called
617- pjlink.get_lamp_status()
618-
619- # THEN: log data and send_command should have been called
620- mock_log.debug.assert_has_calls(log_debug_calls)
621- mock_send_command.assert_called_once_with(cmd=test_data)
622-
623- @skip('Needs update to new setup')
624- def test_projector_get_manufacturer(self):
625+ # GIVEN: Test object
626+ pjlink = self.pjlink
627+ test_data = 'LAMP'
628+ log_debug_calls = [call('({ip}) Sending {cmd} command'.format(ip=pjlink.name, cmd=test_data))]
629+
630+ # WHEN: get_input_source is called
631+ pjlink.get_lamp_status()
632+
633+ # THEN: log data and send_command should have been called
634+ mock_log.debug.assert_has_calls(log_debug_calls)
635+ mock_send_command.assert_called_once_with(cmd=test_data)
636+
637+ @patch.object(openlp.core.projectors.pjlink.PJLink, 'send_command')
638+ @patch.object(openlp.core.projectors.pjlink, 'log')
639+ def test_projector_get_manufacturer(self, mock_log, mock_send_command):
640 """
641 Test sending command to retrieve manufacturer name
642 """
643- # GIVEN: Test object and mocks
644- with patch.object(openlp.core.projectors.pjlink, 'log') as mock_log, \
645- patch.object(openlp.core.projectors.pjlink.PJLink, 'send_command') as mock_send_command:
646- pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
647- test_data = 'INF1'
648- log_debug_calls = [call('({ip}) reset_information() connect status is '
649- '{state}'.format(ip=pjlink.name, state=STATUS_CODE[S_NOT_CONNECTED])),
650- call('({ip}) Sending {cmd} command'.format(ip=pjlink.name, cmd=test_data))]
651-
652- # WHEN: get_input_source is called
653- pjlink.get_manufacturer()
654-
655- # THEN: log data and send_command should have been called
656- mock_log.debug.assert_has_calls(log_debug_calls)
657- mock_send_command.assert_called_once_with(cmd=test_data)
658-
659- @skip('Needs update to new setup')
660- def test_projector_get_model(self):
661+ # GIVEN: Test object
662+ pjlink = self.pjlink
663+ test_data = 'INF1'
664+ log_debug_calls = [call('({ip}) Sending {cmd} command'.format(ip=pjlink.name, cmd=test_data))]
665+
666+ # WHEN: get_input_source is called
667+ pjlink.get_manufacturer()
668+
669+ # THEN: log data and send_command should have been called
670+ mock_log.debug.assert_has_calls(log_debug_calls)
671+ mock_send_command.assert_called_once_with(cmd=test_data)
672+
673+ @patch.object(openlp.core.projectors.pjlink.PJLink, 'send_command')
674+ @patch.object(openlp.core.projectors.pjlink, 'log')
675+ def test_projector_get_model(self, mock_log, mock_send_command):
676 """
677 Test sending command to get model information
678 """
679- # GIVEN: Test object and mocks
680- with patch.object(openlp.core.projectors.pjlink, 'log') as mock_log, \
681- patch.object(openlp.core.projectors.pjlink.PJLink, 'send_command') as mock_send_command:
682- pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
683- test_data = 'INF2'
684- log_debug_calls = [call('({ip}) reset_information() connect status is '
685- '{state}'.format(ip=pjlink.name, state=STATUS_CODE[S_NOT_CONNECTED])),
686- call('({ip}) Sending {cmd} command'.format(ip=pjlink.name, cmd=test_data))]
687-
688- # WHEN: get_input_source is called
689- pjlink.get_model()
690-
691- # THEN: log data and send_command should have been called
692- mock_log.debug.assert_has_calls(log_debug_calls)
693- mock_send_command.assert_called_once_with(cmd=test_data)
694-
695- @skip('Needs update to new setup')
696- def test_projector_get_name(self):
697+ # GIVEN: Test object
698+ pjlink = self.pjlink
699+ test_data = 'INF2'
700+ log_debug_calls = [call('({ip}) Sending {cmd} command'.format(ip=pjlink.name, cmd=test_data))]
701+
702+ # WHEN: get_input_source is called
703+ pjlink.get_model()
704+
705+ # THEN: log data and send_command should have been called
706+ mock_log.debug.assert_has_calls(log_debug_calls)
707+ mock_send_command.assert_called_once_with(cmd=test_data)
708+
709+ @patch.object(openlp.core.projectors.pjlink.PJLink, 'send_command')
710+ @patch.object(openlp.core.projectors.pjlink, 'log')
711+ def test_projector_get_name(self, mock_log, mock_send_command):
712 """
713 Test sending command to get user-assigned name
714 """
715- # GIVEN: Test object and mocks
716- with patch.object(openlp.core.projectors.pjlink, 'log') as mock_log, \
717- patch.object(openlp.core.projectors.pjlink.PJLink, 'send_command') as mock_send_command:
718- pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
719- test_data = 'NAME'
720- log_debug_calls = [call('({ip}) reset_information() connect status is '
721- '{state}'.format(ip=pjlink.name, state=STATUS_CODE[S_NOT_CONNECTED])),
722- call('({ip}) Sending {cmd} command'.format(ip=pjlink.name, cmd=test_data))]
723-
724- # WHEN: get_input_source is called
725- pjlink.get_name()
726-
727- # THEN: log data and send_command should have been called
728- mock_log.debug.assert_has_calls(log_debug_calls)
729- mock_send_command.assert_called_once_with(cmd=test_data)
730-
731- @skip('Needs update to new setup')
732- def test_projector_get_other_info(self):
733+ # GIVEN: Test object
734+ pjlink = self.pjlink
735+ test_data = 'NAME'
736+ log_debug_calls = [call('({ip}) Sending {cmd} command'.format(ip=pjlink.name, cmd=test_data))]
737+
738+ # WHEN: get_input_source is called
739+ pjlink.get_name()
740+
741+ # THEN: log data and send_command should have been called
742+ mock_log.debug.assert_has_calls(log_debug_calls)
743+ mock_send_command.assert_called_once_with(cmd=test_data)
744+
745+ @patch.object(openlp.core.projectors.pjlink.PJLink, 'send_command')
746+ @patch.object(openlp.core.projectors.pjlink, 'log')
747+ def test_projector_get_other_info(self, mock_log, mock_send_command):
748 """
749 Test sending command to retrieve other information
750 """
751- # GIVEN: Test object and mocks
752- with patch.object(openlp.core.projectors.pjlink, 'log') as mock_log, \
753- patch.object(openlp.core.projectors.pjlink.PJLink, 'send_command') as mock_send_command:
754- pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
755- test_data = 'INFO'
756- log_debug_calls = [call('({ip}) reset_information() connect status is '
757- '{state}'.format(ip=pjlink.name, state=STATUS_CODE[S_NOT_CONNECTED])),
758- call('({ip}) Sending {cmd} command'.format(ip=pjlink.name, cmd=test_data))]
759-
760- # WHEN: get_input_source is called
761- pjlink.get_other_info()
762-
763- # THEN: log data and send_command should have been called
764- mock_log.debug.assert_has_calls(log_debug_calls)
765- mock_send_command.assert_called_once_with(cmd=test_data)
766-
767- @skip('Needs update to new setup')
768- def test_projector_get_power_status(self):
769+ # GIVEN: Test object
770+ pjlink = self.pjlink
771+ test_data = 'INFO'
772+ log_debug_calls = [call('({ip}) Sending {cmd} command'.format(ip=pjlink.name, cmd=test_data))]
773+
774+ # WHEN: get_input_source is called
775+ pjlink.get_other_info()
776+
777+ # THEN: log data and send_command should have been called
778+ mock_log.debug.assert_has_calls(log_debug_calls)
779+ mock_send_command.assert_called_once_with(cmd=test_data)
780+
781+ @patch.object(openlp.core.projectors.pjlink.PJLink, 'send_command')
782+ @patch.object(openlp.core.projectors.pjlink, 'log')
783+ def test_projector_get_power_status(self, mock_log, mock_send_command):
784 """
785 Test sending command to retrieve current power state
786 """
787- # GIVEN: Test object and mocks
788- with patch.object(openlp.core.projectors.pjlink, 'log') as mock_log, \
789- patch.object(openlp.core.projectors.pjlink.PJLink, 'send_command') as mock_send_command:
790- pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
791- test_data = 'POWR'
792- log_debug_calls = [call('({ip}) reset_information() connect status is '
793- '{state}'.format(ip=pjlink.name, state=STATUS_CODE[S_NOT_CONNECTED])),
794- call('({ip}) Sending {cmd} command'.format(ip=pjlink.name, cmd=test_data))]
795-
796- # WHEN: get_input_source is called
797- pjlink.get_power_status()
798-
799- # THEN: log data and send_command should have been called
800- mock_log.debug.assert_has_calls(log_debug_calls)
801- mock_send_command.assert_called_once_with(cmd=test_data, priority=False)
802-
803- @skip('Needs update to new setup')
804+ # GIVEN: Test object
805+ pjlink = self.pjlink
806+ test_data = 'POWR'
807+ log_debug_calls = [call('({ip}) Sending {cmd} command'.format(ip=pjlink.name, cmd=test_data))]
808+
809+ # WHEN: get_input_source is called
810+ pjlink.get_power_status()
811+
812+ # THEN: log data and send_command should have been called
813+ mock_log.debug.assert_has_calls(log_debug_calls)
814+ mock_send_command.assert_called_once_with(cmd=test_data, priority=False)
815+
816 def test_projector_get_status_invalid(self):
817 """
818 Test to check returned information for error code
819 """
820 # GIVEN: Test object
821- pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
822+ pjlink = self.pjlink
823 test_string = 'NaN test'
824
825 # WHEN: get_status called
826@@ -504,14 +473,13 @@
827 assert code == -1, 'Should have returned -1 as a bad status check'
828 assert message is None, 'Invalid code type should have returned None for message'
829
830- @skip('Needs update to new setup')
831 def test_projector_get_status_valid(self):
832 """
833 Test to check returned information for status codes
834 """
835 # GIVEN: Test object
836 test_message = 'Not Connected'
837- pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
838+ pjlink = self.pjlink
839
840 # WHEN: get_status called
841 code, message = pjlink._get_status(status=S_NOT_CONNECTED)
842@@ -520,13 +488,12 @@
843 assert code == 'S_NOT_CONNECTED', 'Code returned should have been the same code that was sent'
844 assert message == test_message, 'Description of code should have been returned'
845
846- @skip('Needs update to new setup')
847 def test_projector_get_status_unknown(self):
848 """
849 Test to check returned information for unknown code
850 """
851 # GIVEN: Test object
852- pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
853+ pjlink = self.pjlink
854
855 # WHEN: get_status called
856 code, message = pjlink._get_status(status=9999)