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

Proposed by Ken Roberts
Status: Merged
Merged at revision: 2871
Proposed branch: lp:~alisonken1/openlp/pjlink2-v07
Merge into: lp:openlp
Prerequisite: lp:~alisonken1/openlp/pjlink2-v06
Diff against target: 1460 lines (+478/-447)
9 files modified
openlp/core/projectors/constants.py (+1/-0)
openlp/core/projectors/pjlink.py (+1/-0)
openlp/core/projectors/pjlinkcommands.py (+23/-21)
tests/openlp_core/projectors/test_projector_commands_01.py (+23/-23)
tests/openlp_core/projectors/test_projector_commands_02.py (+33/-33)
tests/openlp_core/projectors/test_projector_commands_03.py (+216/-319)
tests/openlp_core/projectors/test_projector_pjlink_base_01.py (+1/-1)
tests/openlp_core/projectors/test_projector_pjlink_base_02.py (+50/-50)
tests/openlp_core/projectors/test_projector_pjlink_base_03.py (+130/-0)
To merge this branch: bzr merge lp:~alisonken1/openlp/pjlink2-v07
Reviewer Review Type Date Requested Status
Tim Bentley Approve
Raoul Snyman Approve
Phill Pending
Review via email: mp+367473@code.launchpad.net

This proposal supersedes a proposal from 2019-05-11.

Commit message

PJLink 2 Update v07

Description of the change

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

- Move reset_information() test from commands_03 module to pjlink_base_03 module
- Add missing attribute pjlink.projector_errors {} for ERST data
- Remove extraneous translates from process_erst()
- Added import string to pjlinkcommands to validate authentication token
- Fix return codes for PJLINK command
- Update/add tests for PJLINK command
- Remove tests for commands not handled yet
- Remove extraneous parens in asserts

--------------------------------------------------------------------------------
lp:~alisonken1/openlp/pjlink2-v07 (revision 2871)
https://ci.openlp.io/job/Branch-01-Pull/2737/ [SUCCESS]
https://ci.openlp.io/job/Branch-02a-Linux-Tests/2631/ [SUCCESS]
https://ci.openlp.io/job/Branch-02b-macOS-Tests/406/ [SUCCESS]
https://ci.openlp.io/job/Branch-03a-Build-Source/228/ [SUCCESS]
https://ci.openlp.io/job/Branch-03b-Build-macOS/212/ [SUCCESS]
https://ci.openlp.io/job/Branch-04a-Code-Lint/1690/ [SUCCESS]
https://ci.openlp.io/job/Branch-04b-Test-Coverage/1503/ [SUCCESS]
https://ci.openlp.io/job/Branch-05-AppVeyor-Tests/381/ [SUCCESS]

All builds passed

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

Linux tests passed!

Revision history for this message
Raoul Snyman (raoul-snyman) wrote : Posted in a previous version of this proposal

Linting passed!

Revision history for this message
Raoul Snyman (raoul-snyman) wrote : Posted in a previous version of this proposal

macOS tests passed!

Revision history for this message
Phill (phill-ridout) wrote : Posted in a previous version of this proposal

You have quite a few "assert (chk == E_NO_AUTHENTICATION), '....'" the brackets are not needed.

Also you're "@patch.object(openlp.core.projectors.pjlinkcommands, 'log')" a lot, have you considered putting it in the setUp method?

Other than that looks good to me!

review: Needs Fixing
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
Raoul Snyman (raoul-snyman) wrote :

Looks OK to me.

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'openlp/core/projectors/constants.py'
--- openlp/core/projectors/constants.py 2019-05-04 05:25:07 +0000
+++ openlp/core/projectors/constants.py 2019-05-15 13:39:42 +0000
@@ -39,6 +39,7 @@
39PJLINK_PORT = 435239PJLINK_PORT = 4352
40PJLINK_SUFFIX = CR40PJLINK_SUFFIX = CR
41PJLINK_TIMEOUT = 30.041PJLINK_TIMEOUT = 30.0
42PJLINK_TOKEN_SIZE = 8 # PJLINK 1 <token> : where <token> is 8 characters
4243
43# Error and status codes44# Error and status codes
44S_OK = E_OK = 0 # E_OK included since I sometimes forget45S_OK = E_OK = 0 # E_OK included since I sometimes forget
4546
=== modified file 'openlp/core/projectors/pjlink.py'
--- openlp/core/projectors/pjlink.py 2019-05-05 04:08:32 +0000
+++ openlp/core/projectors/pjlink.py 2019-05-15 13:39:42 +0000
@@ -281,6 +281,7 @@
281 self.pjlink_class = copy(PJLINK_CLASS)281 self.pjlink_class = copy(PJLINK_CLASS)
282 self.pjlink_name = None # NAME282 self.pjlink_name = None # NAME
283 self.power = S_OFF # POWR283 self.power = S_OFF # POWR
284 self.projector_errors = {} # Full ERST errors
284 self.serial_no = None # SNUM285 self.serial_no = None # SNUM
285 self.serial_no_received = None286 self.serial_no_received = None
286 self.sw_version = None # SVER287 self.sw_version = None # SVER
287288
=== modified file 'openlp/core/projectors/pjlinkcommands.py'
--- openlp/core/projectors/pjlinkcommands.py 2019-05-05 04:08:32 +0000
+++ openlp/core/projectors/pjlinkcommands.py 2019-05-15 13:39:42 +0000
@@ -29,13 +29,13 @@
2929
30import logging30import logging
31import re31import re
32import string
3233
33from openlp.core.common.i18n import translate
34from openlp.core.common.settings import Settings34from openlp.core.common.settings import Settings
3535
36from openlp.core.projectors.constants import E_AUTHENTICATION, PJLINK_DEFAULT_CODES, PJLINK_ERRORS, \36from openlp.core.projectors.constants import E_AUTHENTICATION, PJLINK_DEFAULT_CODES, PJLINK_ERRORS, \
37 PJLINK_ERST_DATA, PJLINK_ERST_STATUS, PJLINK_POWR_STATUS, S_AUTHENTICATE, S_CONNECT, S_DATA_OK, S_OFF, S_OK, S_ON, \37 PJLINK_ERST_DATA, PJLINK_ERST_LIST, PJLINK_ERST_STATUS, PJLINK_POWR_STATUS, PJLINK_TOKEN_SIZE, \
38 S_STANDBY, STATUS_MSG38 E_NO_AUTHENTICATION, S_AUTHENTICATE, S_CONNECT, S_DATA_OK, S_OFF, S_OK, S_ON, S_STANDBY, STATUS_MSG
3939
40log = logging.getLogger(__name__)40log = logging.getLogger(__name__)
41log.debug('Loading pjlinkcommands')41log.debug('Loading pjlinkcommands')
@@ -195,8 +195,7 @@
195 # Bad data - ignore195 # Bad data - ignore
196 log.warning('({ip}) Invalid error status response "{data}"'.format(ip=projector.entry.name, data=data))196 log.warning('({ip}) Invalid error status response "{data}"'.format(ip=projector.entry.name, data=data))
197 return197 return
198 datacheck = int(data)198 if int(data) == 0:
199 if datacheck == 0:
200 projector.projector_errors = None199 projector.projector_errors = None
201 # No errors200 # No errors
202 return201 return
@@ -209,23 +208,17 @@
209 data[PJLINK_ERST_DATA['FILTER']],208 data[PJLINK_ERST_DATA['FILTER']],
210 data[PJLINK_ERST_DATA['OTHER']])209 data[PJLINK_ERST_DATA['OTHER']])
211 if fan != PJLINK_ERST_STATUS[S_OK]:210 if fan != PJLINK_ERST_STATUS[S_OK]:
212 projector.projector_errors[translate('OpenLP.ProjectorPJLink', 'Fan')] = \211 projector.projector_errors[PJLINK_ERST_LIST['FAN']] = PJLINK_ERST_STATUS[fan]
213 PJLINK_ERST_STATUS[fan]
214 if lamp != PJLINK_ERST_STATUS[S_OK]:212 if lamp != PJLINK_ERST_STATUS[S_OK]:
215 projector.projector_errors[translate('OpenLP.ProjectorPJLink', 'Lamp')] = \213 projector.projector_errors[PJLINK_ERST_LIST['LAMP']] = PJLINK_ERST_STATUS[lamp]
216 PJLINK_ERST_STATUS[lamp]
217 if temp != PJLINK_ERST_STATUS[S_OK]:214 if temp != PJLINK_ERST_STATUS[S_OK]:
218 projector.projector_errors[translate('OpenLP.ProjectorPJLink', 'Temperature')] = \215 projector.projector_errors[PJLINK_ERST_LIST['TEMP']] = PJLINK_ERST_STATUS[temp]
219 PJLINK_ERST_STATUS[temp]
220 if cover != PJLINK_ERST_STATUS[S_OK]:216 if cover != PJLINK_ERST_STATUS[S_OK]:
221 projector.projector_errors[translate('OpenLP.ProjectorPJLink', 'Cover')] = \217 projector.projector_errors[PJLINK_ERST_LIST['COVER']] = PJLINK_ERST_STATUS[cover]
222 PJLINK_ERST_STATUS[cover]
223 if filt != PJLINK_ERST_STATUS[S_OK]:218 if filt != PJLINK_ERST_STATUS[S_OK]:
224 projector.projector_errors[translate('OpenLP.ProjectorPJLink', 'Filter')] = \219 projector.projector_errors[PJLINK_ERST_LIST['FILTER']] = PJLINK_ERST_STATUS[filt]
225 PJLINK_ERST_STATUS[filt]
226 if other != PJLINK_ERST_STATUS[S_OK]:220 if other != PJLINK_ERST_STATUS[S_OK]:
227 projector.projector_errors[translate('OpenLP.ProjectorPJLink', 'Other')] = \221 projector.projector_errors[PJLINK_ERST_LIST['OTHER']] = PJLINK_ERST_STATUS[other]
228 PJLINK_ERST_STATUS[other]
229 return222 return
230223
231224
@@ -389,20 +382,29 @@
389 if len(chk) > 1:382 if len(chk) > 1:
390 # Invalid data - there should be nothing after a normal authentication scheme383 # Invalid data - there should be nothing after a normal authentication scheme
391 log.error('({ip}) Normal connection with extra information - aborting'.format(ip=projector.entry.name))384 log.error('({ip}) Normal connection with extra information - aborting'.format(ip=projector.entry.name))
392 return E_AUTHENTICATION385 return E_NO_AUTHENTICATION
393 elif projector.pin:386 elif projector.pin:
394 log.error('({ip}) Normal connection but PIN set - aborting'.format(ip=projector.entry.name))387 log.error('({ip}) Normal connection but PIN set - aborting'.format(ip=projector.entry.name))
395 return E_AUTHENTICATION388 return E_NO_AUTHENTICATION
396 log.debug('({ip}) PJLINK: Returning S_CONNECT'.format(ip=projector.entry.name))389 log.debug('({ip}) PJLINK: Returning S_CONNECT'.format(ip=projector.entry.name))
397 return S_CONNECT390 return S_CONNECT
398 elif chk[0] == '1':391 elif chk[0] == '1':
399 if len(chk) < 2:392 if len(chk) < 2:
400 # Not enough information for authenticated connection393 # Not enough information for authenticated connection
401 log.error('({ip}) Authenticated connection but not enough info - aborting'.format(ip=projector.entry.name))394 log.error('({ip}) Authenticated connection but not enough info - aborting'.format(ip=projector.entry.name))
402 return E_AUTHENTICATION395 return E_NO_AUTHENTICATION
396 elif len(chk[-1]) != PJLINK_TOKEN_SIZE:
397 # Bad token - incorrect size
398 log.error('({ip}) Authentication token invalid (size) - aborting'.format(ip=projector.entry.name))
399 return E_NO_AUTHENTICATION
400 elif not all(c in string.hexdigits for c in chk[-1]):
401 # Bad token - not hexadecimal
402 log.error('({ip}) Authentication token invalid (not a hexadecimal number) '
403 '- aborting'.format(ip=projector.entry.name))
404 return E_NO_AUTHENTICATION
403 elif not projector.pin:405 elif not projector.pin:
404 log.error('({ip}) Authenticate connection but no PIN - aborting'.format(ip=projector.entry.name))406 log.error('({ip}) Authenticate connection but no PIN - aborting'.format(ip=projector.entry.name))
405 return E_AUTHENTICATION407 return E_NO_AUTHENTICATION
406 log.debug('({ip}) PJLINK: Returning S_AUTHENTICATE'.format(ip=projector.entry.name))408 log.debug('({ip}) PJLINK: Returning S_AUTHENTICATE'.format(ip=projector.entry.name))
407 return S_AUTHENTICATE409 return S_AUTHENTICATE
408410
409411
=== modified file 'tests/openlp_core/projectors/test_projector_commands_01.py'
--- tests/openlp_core/projectors/test_projector_commands_01.py 2019-05-05 04:08:32 +0000
+++ tests/openlp_core/projectors/test_projector_commands_01.py 2019-05-15 13:39:42 +0000
@@ -35,7 +35,7 @@
3535
36class TestPJLinkCommands(TestCase):36class TestPJLinkCommands(TestCase):
37 """37 """
38 Tests PJLink get status commands part 138 Tests PJLink commands part 1
39 """39 """
40 def setUp(self):40 def setUp(self):
41 """41 """
@@ -92,7 +92,7 @@
92 # THEN: Shutter should be closed and mute should be True92 # THEN: Shutter should be closed and mute should be True
93 assert self.pjlink.shutter, 'Shutter should changed'93 assert self.pjlink.shutter, 'Shutter should changed'
94 assert self.pjlink.mute, 'Audio should not have changed'94 assert self.pjlink.mute, 'Audio should not have changed'
95 assert (not mock_UpdateIcons.emit.called), 'Update icons should NOT have been called'95 assert not mock_UpdateIcons.emit.called, 'Update icons should NOT have been called'
96 mock_log.warning.assert_has_calls(log_warning_text)96 mock_log.warning.assert_has_calls(log_warning_text)
97 mock_log.debug.assert_has_calls(log_debug_text)97 mock_log.debug.assert_has_calls(log_debug_text)
9898
@@ -140,8 +140,8 @@
140 process_command(projector=self.pjlink, cmd='AVMT', data='30')140 process_command(projector=self.pjlink, cmd='AVMT', data='30')
141141
142 # THEN: Shutter should be closed and mute should be True142 # THEN: Shutter should be closed and mute should be True
143 assert (not self.pjlink.shutter), 'Shutter should have been set to off'143 assert not self.pjlink.shutter, 'Shutter should have been set to off'
144 assert (not self.pjlink.mute), 'Audio should be on'144 assert not self.pjlink.mute, 'Audio should be on'
145 assert mock_UpdateIcons.emit.called, 'Update icons should have been called'145 assert mock_UpdateIcons.emit.called, 'Update icons should have been called'
146 mock_log.warning.assert_has_calls(log_warning_text)146 mock_log.warning.assert_has_calls(log_warning_text)
147 mock_log.debug.assert_has_calls(log_debug_text)147 mock_log.debug.assert_has_calls(log_debug_text)
@@ -193,7 +193,7 @@
193 assert self.pjlink.shutter, 'Shutter should have been set to closed'193 assert self.pjlink.shutter, 'Shutter should have been set to closed'
194 assert self.pjlink.mute, 'Audio should not have changed'194 assert self.pjlink.mute, 'Audio should not have changed'
195 assert mock_UpdateIcons.emit.called, 'Update icons should have been called'195 assert mock_UpdateIcons.emit.called, 'Update icons should have been called'
196 assert ('AVMT' not in self.pjlink.status_timer_checks), 'Status timer list should not have AVMT callback'196 assert 'AVMT' not in self.pjlink.status_timer_checks, 'Status timer list should not have AVMT callback'
197 assert mock_status_timer.stop.called, 'Projector status_timer.stop() should have been called'197 assert mock_status_timer.stop.called, 'Projector status_timer.stop() should have been called'
198 mock_log.warning.assert_has_calls(log_warning_text)198 mock_log.warning.assert_has_calls(log_warning_text)
199 mock_log.debug.assert_has_calls(log_debug_text)199 mock_log.debug.assert_has_calls(log_debug_text)
@@ -214,7 +214,7 @@
214 process_command(projector=self.pjlink, cmd='CLSS', data='1')214 process_command(projector=self.pjlink, cmd='CLSS', data='1')
215215
216 # THEN: Projector class should be set with proper value216 # THEN: Projector class should be set with proper value
217 assert ('1' == self.pjlink.pjlink_class), 'Should have set class=1'217 assert '1' == self.pjlink.pjlink_class, 'Should have set class=1'
218 mock_log.error.assert_has_calls(log_error_calls)218 mock_log.error.assert_has_calls(log_error_calls)
219 mock_log.warning.assert_has_calls(log_warning_calls)219 mock_log.warning.assert_has_calls(log_warning_calls)
220 mock_log.debug.assert_has_calls(log_debug_calls)220 mock_log.debug.assert_has_calls(log_debug_calls)
@@ -235,7 +235,7 @@
235 process_command(projector=self.pjlink, cmd='CLSS', data='2')235 process_command(projector=self.pjlink, cmd='CLSS', data='2')
236236
237 # THEN: Projector class should be set with proper value237 # THEN: Projector class should be set with proper value
238 assert ('2' == self.pjlink.pjlink_class), 'Should have set class=2'238 assert '2' == self.pjlink.pjlink_class, 'Should have set class=2'
239 mock_log.error.assert_has_calls(log_error_calls)239 mock_log.error.assert_has_calls(log_error_calls)
240 mock_log.warning.assert_has_calls(log_warning_calls)240 mock_log.warning.assert_has_calls(log_warning_calls)
241 mock_log.debug.assert_has_calls(log_debug_calls)241 mock_log.debug.assert_has_calls(log_debug_calls)
@@ -256,7 +256,7 @@
256 process_command(projector=self.pjlink, cmd='CLSS', data='Z')256 process_command(projector=self.pjlink, cmd='CLSS', data='Z')
257257
258 # THEN: Projector class should be set with default value258 # THEN: Projector class should be set with default value
259 assert (self.pjlink.pjlink_class == '1'), 'Invalid NaN class reply should have set class=1'259 assert self.pjlink.pjlink_class == '1', 'Invalid NaN class reply should have set class=1'
260 mock_log.warning.assert_has_calls(log_warning_calls)260 mock_log.warning.assert_has_calls(log_warning_calls)
261 mock_log.debug.assert_has_calls(log_debug_calls)261 mock_log.debug.assert_has_calls(log_debug_calls)
262262
@@ -276,7 +276,7 @@
276 process_command(projector=self.pjlink, cmd='CLSS', data='Invalid')276 process_command(projector=self.pjlink, cmd='CLSS', data='Invalid')
277277
278 # THEN: Projector class should be set with default value278 # THEN: Projector class should be set with default value
279 assert (self.pjlink.pjlink_class == '1'), 'Invalid class reply should have set class=1'279 assert self.pjlink.pjlink_class == '1', 'Invalid class reply should have set class=1'
280 mock_log.warning.assert_has_calls(log_warning_calls)280 mock_log.warning.assert_has_calls(log_warning_calls)
281 mock_log.debug.assert_has_calls(log_debug_calls)281 mock_log.debug.assert_has_calls(log_debug_calls)
282282
@@ -296,7 +296,7 @@
296 process_command(projector=self.pjlink, cmd='CLSS', data='Class 1')296 process_command(projector=self.pjlink, cmd='CLSS', data='Class 1')
297297
298 # THEN: Projector class should be set with proper value298 # THEN: Projector class should be set with proper value
299 assert ('1' == self.pjlink.pjlink_class), 'Non-standard class reply should have set class=1'299 assert '1' == self.pjlink.pjlink_class, 'Non-standard class reply should have set class=1'
300 mock_log.error.assert_has_calls(log_error_calls)300 mock_log.error.assert_has_calls(log_error_calls)
301 mock_log.warning.assert_has_calls(log_warning_calls)301 mock_log.warning.assert_has_calls(log_warning_calls)
302 mock_log.debug.assert_has_calls(log_debug_calls)302 mock_log.debug.assert_has_calls(log_debug_calls)
@@ -316,7 +316,7 @@
316 process_command(projector=self.pjlink, cmd='CLSS', data='Version2')316 process_command(projector=self.pjlink, cmd='CLSS', data='Version2')
317317
318 # THEN: Projector class should be set with proper value318 # THEN: Projector class should be set with proper value
319 assert ('2' == self.pjlink.pjlink_class), 'Non-standard class reply should have set class=1'319 assert '2' == self.pjlink.pjlink_class, 'Non-standard class reply should have set class=1'
320 mock_log.warning.assert_has_calls(log_warning_calls)320 mock_log.warning.assert_has_calls(log_warning_calls)
321 mock_log.debug.assert_has_calls(log_debug_calls)321 mock_log.debug.assert_has_calls(log_debug_calls)
322322
@@ -348,7 +348,7 @@
348 process_command(projector=self.pjlink, cmd='ERST', data=chk_data)348 process_command(projector=self.pjlink, cmd='ERST', data=chk_data)
349349
350 # THEN: PJLink instance errors should match chk_value350 # THEN: PJLink instance errors should match chk_value
351 assert (self.pjlink.projector_errors == chk_test), 'Projector errors should be all E_ERROR'351 assert self.pjlink.projector_errors == chk_test, 'Projector errors should be all E_ERROR'
352 mock_log.warning.assert_has_calls(log_warning_calls)352 mock_log.warning.assert_has_calls(log_warning_calls)
353 mock_log.debug.assert_has_calls(log_debug_calls)353 mock_log.debug.assert_has_calls(log_debug_calls)
354354
@@ -368,7 +368,7 @@
368 process_command(projector=self.pjlink, cmd='ERST', data=chk_data)368 process_command(projector=self.pjlink, cmd='ERST', data=chk_data)
369369
370 # THEN: PJLink instance errors should be None370 # THEN: PJLink instance errors should be None
371 assert (self.pjlink.projector_errors is None), 'projector_errors should have been set to None'371 assert self.pjlink.projector_errors is None, 'projector_errors should have been set to None'
372 mock_log.warning.assert_has_calls(log_warning_calls)372 mock_log.warning.assert_has_calls(log_warning_calls)
373 mock_log.debug.assert_has_calls(log_debug_calls)373 mock_log.debug.assert_has_calls(log_debug_calls)
374374
@@ -400,7 +400,7 @@
400 process_command(projector=self.pjlink, cmd='ERST', data=chk_data)400 process_command(projector=self.pjlink, cmd='ERST', data=chk_data)
401401
402 # THEN: PJLink instance errors should match chk_value402 # THEN: PJLink instance errors should match chk_value
403 assert (self.pjlink.projector_errors == chk_test), 'Projector errors should be all E_WARN'403 assert self.pjlink.projector_errors == chk_test, 'Projector errors should be all E_WARN'
404 mock_log.warning.assert_has_calls(log_warning_calls)404 mock_log.warning.assert_has_calls(log_warning_calls)
405 mock_log.debug.assert_has_calls(log_debug_calls)405 mock_log.debug.assert_has_calls(log_debug_calls)
406406
@@ -423,7 +423,7 @@
423 process_command(self.pjlink, cmd='ERST', data=chk_data)423 process_command(self.pjlink, cmd='ERST', data=chk_data)
424424
425 # THEN: pjlink.projector_errors should be empty and warning logged425 # THEN: pjlink.projector_errors should be empty and warning logged
426 assert (not self.pjlink.projector_errors), 'There should be no errors'426 assert not self.pjlink.projector_errors, 'There should be no errors'
427 mock_log.warning.assert_has_calls(log_warn_calls)427 mock_log.warning.assert_has_calls(log_warn_calls)
428 mock_log.debug.assert_has_calls(log_debug_calls)428 mock_log.debug.assert_has_calls(log_debug_calls)
429429
@@ -445,7 +445,7 @@
445 process_command(self.pjlink, cmd='ERST', data=chk_data)445 process_command(self.pjlink, cmd='ERST', data=chk_data)
446446
447 # THEN: pjlink.projector_errors should be empty and warning logged447 # THEN: pjlink.projector_errors should be empty and warning logged
448 assert (not self.pjlink.projector_errors), 'There should be no errors'448 assert not self.pjlink.projector_errors, 'There should be no errors'
449 mock_log.warning.assert_has_calls(log_warn_calls)449 mock_log.warning.assert_has_calls(log_warn_calls)
450 mock_log.debug.assert_has_calls(log_debug_calls)450 mock_log.debug.assert_has_calls(log_debug_calls)
451451
@@ -472,10 +472,10 @@
472 process_command(projector=self.pjlink, cmd='ERST', data=chk_data)472 process_command(projector=self.pjlink, cmd='ERST', data=chk_data)
473473
474 # THEN: PJLink instance errors should match only cover warning474 # THEN: PJLink instance errors should match only cover warning
475 assert (1 == len(self.pjlink.projector_errors)), 'There should only be 1 error listed in projector_errors'475 assert 1 == len(self.pjlink.projector_errors), 'There should only be 1 error listed in projector_errors'
476 assert ('Cover' in self.pjlink.projector_errors), '"Cover" should be the only error listed'476 assert 'Cover' in self.pjlink.projector_errors, '"Cover" should be the only error listed'
477 assert (self.pjlink.projector_errors['Cover'] == E_WARN), '"Cover" should have E_WARN listed as error'477 assert self.pjlink.projector_errors['Cover'] == E_WARN, '"Cover" should have E_WARN listed as error'
478 assert (chk_test == self.pjlink.projector_errors), 'projector_errors should match test errors'478 assert chk_test == self.pjlink.projector_errors, 'projector_errors should match test errors'
479 mock_log.warning.assert_has_calls(log_warn_calls)479 mock_log.warning.assert_has_calls(log_warn_calls)
480 mock_log.debug.assert_has_calls(log_debug_calls)480 mock_log.debug.assert_has_calls(log_debug_calls)
481481
@@ -498,7 +498,7 @@
498 process_command(projector=self.pjlink, cmd='INF1', data=chk_data)498 process_command(projector=self.pjlink, cmd='INF1', data=chk_data)
499499
500 # THEN: Data should be saved500 # THEN: Data should be saved
501 assert (self.pjlink.manufacturer == chk_data), 'Test data should have been saved'501 assert self.pjlink.manufacturer == chk_data, 'Test data should have been saved'
502 mock_log.warning.assert_has_calls(log_warn_calls)502 mock_log.warning.assert_has_calls(log_warn_calls)
503 mock_log.debug.assert_has_calls(log_debug_calls)503 mock_log.debug.assert_has_calls(log_debug_calls)
504504
@@ -521,7 +521,7 @@
521 process_command(projector=self.pjlink, cmd='INF2', data=chk_data)521 process_command(projector=self.pjlink, cmd='INF2', data=chk_data)
522522
523 # THEN: Data should be saved523 # THEN: Data should be saved
524 assert (self.pjlink.model == chk_data), 'Test data should have been saved'524 assert self.pjlink.model == chk_data, 'Test data should have been saved'
525 mock_log.warning.assert_has_calls(log_warn_calls)525 mock_log.warning.assert_has_calls(log_warn_calls)
526 mock_log.debug.assert_has_calls(log_debug_calls)526 mock_log.debug.assert_has_calls(log_debug_calls)
527527
@@ -544,6 +544,6 @@
544 process_command(projector=self.pjlink, cmd='INFO', data=chk_data)544 process_command(projector=self.pjlink, cmd='INFO', data=chk_data)
545545
546 # THEN: Data should be saved546 # THEN: Data should be saved
547 assert (self.pjlink.other_info == chk_data), 'Test data should have been saved'547 assert self.pjlink.other_info == chk_data, 'Test data should have been saved'
548 mock_log.warning.assert_has_calls(log_warn_calls)548 mock_log.warning.assert_has_calls(log_warn_calls)
549 mock_log.debug.assert_has_calls(log_debug_calls)549 mock_log.debug.assert_has_calls(log_debug_calls)
550550
=== modified file 'tests/openlp_core/projectors/test_projector_commands_02.py'
--- tests/openlp_core/projectors/test_projector_commands_02.py 2019-05-05 04:08:32 +0000
+++ tests/openlp_core/projectors/test_projector_commands_02.py 2019-05-15 13:39:42 +0000
@@ -35,7 +35,7 @@
3535
36class TestPJLinkCommands(TestCase):36class TestPJLinkCommands(TestCase):
37 """37 """
38 Tests PJLink get status commands part 238 Tests PJLink commands part 2
39 """39 """
40 def setUp(self):40 def setUp(self):
41 """41 """
@@ -67,7 +67,7 @@
67 process_command(projector=self.pjlink, cmd='INPT', data='21')67 process_command(projector=self.pjlink, cmd='INPT', data='21')
6868
69 # THEN: Input selected should reflect current input69 # THEN: Input selected should reflect current input
70 assert ('21' == self.pjlink.source), 'Input source should be set to "21"'70 assert '21' == self.pjlink.source, 'Input source should be set to "21"'
71 mock_log.warning.assert_has_calls(log_warning_calls)71 mock_log.warning.assert_has_calls(log_warning_calls)
72 mock_log.debug.assert_has_calls(log_debug_calls)72 mock_log.debug.assert_has_calls(log_debug_calls)
7373
@@ -88,7 +88,7 @@
88 process_command(projector=self.pjlink, cmd='INPT', data='91')88 process_command(projector=self.pjlink, cmd='INPT', data='91')
8989
90 # THEN: Input selected should reflect current input90 # THEN: Input selected should reflect current input
91 assert (not self.pjlink.source), 'Input source should not have changed'91 assert not self.pjlink.source, 'Input source should not have changed'
92 mock_log.warning.assert_has_calls(log_warning_calls)92 mock_log.warning.assert_has_calls(log_warning_calls)
93 mock_log.debug.assert_has_calls(log_debug_calls)93 mock_log.debug.assert_has_calls(log_debug_calls)
9494
@@ -110,7 +110,7 @@
110 process_command(projector=self.pjlink, cmd='INPT', data='25')110 process_command(projector=self.pjlink, cmd='INPT', data='25')
111111
112 # THEN: Input selected should reflect current input112 # THEN: Input selected should reflect current input
113 assert ('11' == self.pjlink.source), 'Input source should not have changed'113 assert '11' == self.pjlink.source, 'Input source should not have changed'
114 mock_log.warning.assert_has_calls(log_warning_calls)114 mock_log.warning.assert_has_calls(log_warning_calls)
115 mock_log.debug.assert_has_calls(log_debug_calls)115 mock_log.debug.assert_has_calls(log_debug_calls)
116116
@@ -138,7 +138,7 @@
138 # THEN: Data should have been sorted and saved properly138 # THEN: Data should have been sorted and saved properly
139 mock_log.warning.assert_has_calls(log_warning_calls)139 mock_log.warning.assert_has_calls(log_warning_calls)
140 mock_log.debug.assert_has_calls(log_debug_calls)140 mock_log.debug.assert_has_calls(log_debug_calls)
141 assert (self.pjlink.source_available == chk_test), "Sources should have been sorted and saved"141 assert self.pjlink.source_available == chk_test, "Sources should have been sorted and saved"
142142
143 @patch.object(openlp.core.projectors.pjlinkcommands, 'log')143 @patch.object(openlp.core.projectors.pjlinkcommands, 'log')
144 def test_projector_lamp_invalid_missing_data(self, mock_log):144 def test_projector_lamp_invalid_missing_data(self, mock_log):
@@ -158,7 +158,7 @@
158 # THEN: Lamp should have been set with proper lamp status158 # THEN: Lamp should have been set with proper lamp status
159 mock_log.warning.assert_has_calls(log_warning_calls)159 mock_log.warning.assert_has_calls(log_warning_calls)
160 mock_log.debug.assert_has_calls(log_debug_calls)160 mock_log.debug.assert_has_calls(log_debug_calls)
161 assert (not self.pjlink.lamp), 'Projector lamp info should not have changed'161 assert not self.pjlink.lamp, 'Projector lamp info should not have changed'
162162
163 @patch.object(openlp.core.projectors.pjlinkcommands, 'log')163 @patch.object(openlp.core.projectors.pjlinkcommands, 'log')
164 def test_projector_lamp_invalid_nan(self, mock_log):164 def test_projector_lamp_invalid_nan(self, mock_log):
@@ -180,11 +180,11 @@
180 # THEN: lamps should not have changed180 # THEN: lamps should not have changed
181 mock_log.warning.assert_has_calls(log_warning_calls)181 mock_log.warning.assert_has_calls(log_warning_calls)
182 mock_log.debug.assert_has_calls(log_debug_calls)182 mock_log.debug.assert_has_calls(log_debug_calls)
183 assert (2 == len(self.pjlink.lamp)), 'Projector lamp list should not have changed'183 assert 2 == len(self.pjlink.lamp), 'Projector lamp list should not have changed'
184 assert self.pjlink.lamp[0]['On'], 'Lamp 1 power status should not have changed'184 assert self.pjlink.lamp[0]['On'], 'Lamp 1 power status should not have changed'
185 assert (0 == self.pjlink.lamp[0]['Hours']), 'Lamp 1 hours should not have changed'185 assert 0 == self.pjlink.lamp[0]['Hours'], 'Lamp 1 hours should not have changed'
186 assert (not self.pjlink.lamp[1]['On']), 'Lamp 2 power status should not have changed'186 assert not self.pjlink.lamp[1]['On'], 'Lamp 2 power status should not have changed'
187 assert (11111 == self.pjlink.lamp[1]['Hours']), 'Lamp 2 hours should not have changed'187 assert 11111 == self.pjlink.lamp[1]['Hours'], 'Lamp 2 hours should not have changed'
188188
189 @patch.object(openlp.core.projectors.pjlinkcommands, 'log')189 @patch.object(openlp.core.projectors.pjlinkcommands, 'log')
190 def test_projector_lamp_multiple(self, mock_log):190 def test_projector_lamp_multiple(self, mock_log):
@@ -204,13 +204,13 @@
204 # THEN: Lamp should have been set with proper lamp status204 # THEN: Lamp should have been set with proper lamp status
205 mock_log.warning.assert_has_calls(log_warning_calls)205 mock_log.warning.assert_has_calls(log_warning_calls)
206 mock_log.debug.assert_has_calls(log_debug_calls)206 mock_log.debug.assert_has_calls(log_debug_calls)
207 assert (3 == len(self.pjlink.lamp)), 'Projector should have 3 lamps specified'207 assert 3 == len(self.pjlink.lamp), 'Projector should have 3 lamps specified'
208 assert self.pjlink.lamp[0]['On'], 'Lamp 1 power status should have been set to TRUE'208 assert self.pjlink.lamp[0]['On'], 'Lamp 1 power status should have been set to TRUE'
209 assert (11111 == self.pjlink.lamp[0]['Hours']), 'Lamp 1 hours should have been set to 11111'209 assert 11111 == self.pjlink.lamp[0]['Hours'], 'Lamp 1 hours should have been set to 11111'
210 assert (not self.pjlink.lamp[1]['On']), 'Lamp 2 power status should have been set to FALSE'210 assert not self.pjlink.lamp[1]['On'], 'Lamp 2 power status should have been set to FALSE'
211 assert (22222 == self.pjlink.lamp[1]['Hours']), 'Lamp 2 hours should have been set to 22222'211 assert 22222 == self.pjlink.lamp[1]['Hours'], 'Lamp 2 hours should have been set to 22222'
212 assert self.pjlink.lamp[2]['On'], 'Lamp 3 power status should have been set to TRUE'212 assert self.pjlink.lamp[2]['On'], 'Lamp 3 power status should have been set to TRUE'
213 assert (33333 == self.pjlink.lamp[2]['Hours']), 'Lamp 3 hours should have been set to 33333'213 assert 33333 == self.pjlink.lamp[2]['Hours'], 'Lamp 3 hours should have been set to 33333'
214214
215 @patch.object(openlp.core.projectors.pjlinkcommands, 'log')215 @patch.object(openlp.core.projectors.pjlinkcommands, 'log')
216 def test_projector_lamp_single(self, mock_log):216 def test_projector_lamp_single(self, mock_log):
@@ -229,9 +229,9 @@
229 # THEN: Lamp should have been set with proper lamp status229 # THEN: Lamp should have been set with proper lamp status
230 mock_log.warning.assert_has_calls(log_warning_calls)230 mock_log.warning.assert_has_calls(log_warning_calls)
231 mock_log.debug.assert_has_calls(log_debug_calls)231 mock_log.debug.assert_has_calls(log_debug_calls)
232 assert (1 == len(self.pjlink.lamp)), 'Projector should have 1 lamp specified'232 assert 1 == len(self.pjlink.lamp), 'Projector should have 1 lamp specified'
233 assert self.pjlink.lamp[0]['On'], 'Lamp 1 power status should have been set to TRUE'233 assert self.pjlink.lamp[0]['On'], 'Lamp 1 power status should have been set to TRUE'
234 assert (11111 == self.pjlink.lamp[0]['Hours']), 'Lamp 1 hours should have been set to 11111'234 assert 11111 == self.pjlink.lamp[0]['Hours'], 'Lamp 1 hours should have been set to 11111'
235235
236 @patch.object(openlp.core.projectors.pjlinkcommands, 'log')236 @patch.object(openlp.core.projectors.pjlinkcommands, 'log')
237 def test_projector_name(self, mock_log):237 def test_projector_name(self, mock_log):
@@ -253,7 +253,7 @@
253 # THEN: name should be set and logged253 # THEN: name should be set and logged
254 mock_log.warning.assert_has_calls(log_warning_calls)254 mock_log.warning.assert_has_calls(log_warning_calls)
255 mock_log.debug.assert_has_calls(log_debug_calls)255 mock_log.debug.assert_has_calls(log_debug_calls)
256 assert (self.pjlink.pjlink_name == chk_data), 'Name test data should have been saved'256 assert self.pjlink.pjlink_name == chk_data, 'Name test data should have been saved'
257257
258 @patch.object(openlp.core.projectors.pjlink.PJLink, 'send_command')258 @patch.object(openlp.core.projectors.pjlink.PJLink, 'send_command')
259 @patch.object(openlp.core.projectors.pjlink.PJLink, 'change_status')259 @patch.object(openlp.core.projectors.pjlink.PJLink, 'change_status')
@@ -276,7 +276,7 @@
276 # THEN: Projector power should not have changed276 # THEN: Projector power should not have changed
277 mock_log.warning.assert_has_calls(log_warning_calls)277 mock_log.warning.assert_has_calls(log_warning_calls)
278 mock_log.debug.assert_has_calls(log_debug_calls)278 mock_log.debug.assert_has_calls(log_debug_calls)
279 assert (S_STANDBY == self.pjlink.power), 'Power should not have changed'279 assert S_STANDBY == self.pjlink.power, 'Power should not have changed'
280 mock_UpdateIcons.emit.assert_not_called()280 mock_UpdateIcons.emit.assert_not_called()
281 mock_change_status.assert_not_called()281 mock_change_status.assert_not_called()
282 mock_send_command.assert_not_called()282 mock_send_command.assert_not_called()
@@ -302,9 +302,9 @@
302 # THEN: Power should be set to ON302 # THEN: Power should be set to ON
303 mock_log.warning.assert_has_calls(log_warning_calls)303 mock_log.warning.assert_has_calls(log_warning_calls)
304 mock_log.debug.assert_has_calls(log_debug_calls)304 mock_log.debug.assert_has_calls(log_debug_calls)
305 assert (S_STANDBY == self.pjlink.power), 'Power should have been set to OFF'305 assert S_STANDBY == self.pjlink.power, 'Power should have been set to OFF'
306 assert mock_UpdateIcons.emit.called, 'projectorUpdateIcons should have been called'306 assert mock_UpdateIcons.emit.called, 'projectorUpdateIcons should have been called'
307 assert (not mock_send_command.called), 'send_command should not have been called'307 assert not mock_send_command.called, 'send_command should not have been called'
308 mock_change_status.assert_called_once_with(S_STANDBY)308 mock_change_status.assert_called_once_with(S_STANDBY)
309309
310 @patch.object(openlp.core.projectors.pjlink.PJLink, 'send_command')310 @patch.object(openlp.core.projectors.pjlink.PJLink, 'send_command')
@@ -328,7 +328,7 @@
328 # THEN: Power should be set to ON328 # THEN: Power should be set to ON
329 mock_log.warning.assert_has_calls(log_warning_calls)329 mock_log.warning.assert_has_calls(log_warning_calls)
330 mock_log.debug.assert_has_calls(log_debug_calls)330 mock_log.debug.assert_has_calls(log_debug_calls)
331 assert (S_ON == self.pjlink.power), 'Power should have been set to ON'331 assert S_ON == self.pjlink.power, 'Power should have been set to ON'
332 assert mock_UpdateIcons.emit.called, 'projectorUpdateIcons should have been called'332 assert mock_UpdateIcons.emit.called, 'projectorUpdateIcons should have been called'
333 mock_send_command.assert_called_once_with('INST')333 mock_send_command.assert_called_once_with('INST')
334 mock_change_status.assert_called_once_with(S_ON)334 mock_change_status.assert_called_once_with(S_ON)
@@ -352,7 +352,7 @@
352 # THEN: Filter model number should be saved352 # THEN: Filter model number should be saved
353 mock_log.warning.assert_has_calls(log_warning_calls)353 mock_log.warning.assert_has_calls(log_warning_calls)
354 mock_log.debug.assert_has_calls(log_debug_calls)354 mock_log.debug.assert_has_calls(log_debug_calls)
355 assert (self.pjlink.model_filter == new_data), 'Filter model should have been saved'355 assert self.pjlink.model_filter == new_data, 'Filter model should have been saved'
356356
357 @patch.object(openlp.core.projectors.pjlinkcommands, 'log')357 @patch.object(openlp.core.projectors.pjlinkcommands, 'log')
358 def test_projector_rfil_nosave(self, mock_log):358 def test_projector_rfil_nosave(self, mock_log):
@@ -374,7 +374,7 @@
374 process_command(projector=self.pjlink, cmd='RFIL', data=new_data)374 process_command(projector=self.pjlink, cmd='RFIL', data=new_data)
375375
376 # THEN: Filter model number should be saved376 # THEN: Filter model number should be saved
377 assert (self.pjlink.model_filter != new_data), 'Filter model should NOT have been saved'377 assert self.pjlink.model_filter != new_data, 'Filter model should NOT have been saved'
378 mock_log.warning.assert_has_calls(log_warning_calls)378 mock_log.warning.assert_has_calls(log_warning_calls)
379 mock_log.debug.assert_has_calls(log_debug_calls)379 mock_log.debug.assert_has_calls(log_debug_calls)
380380
@@ -397,7 +397,7 @@
397 # THEN: Filter model number should be saved397 # THEN: Filter model number should be saved
398 mock_log.warning.assert_has_calls(log_warning_calls)398 mock_log.warning.assert_has_calls(log_warning_calls)
399 mock_log.debug.assert_has_calls(log_debug_calls)399 mock_log.debug.assert_has_calls(log_debug_calls)
400 assert (self.pjlink.model_lamp == new_data), 'Lamp model should have been saved'400 assert self.pjlink.model_lamp == new_data, 'Lamp model should have been saved'
401401
402 @patch.object(openlp.core.projectors.pjlinkcommands, 'log')402 @patch.object(openlp.core.projectors.pjlinkcommands, 'log')
403 def test_projector_rlmp_nosave(self, mock_log):403 def test_projector_rlmp_nosave(self, mock_log):
@@ -419,7 +419,7 @@
419 process_command(projector=self.pjlink, cmd='RLMP', data=new_data)419 process_command(projector=self.pjlink, cmd='RLMP', data=new_data)
420420
421 # THEN: Filter model number should be saved421 # THEN: Filter model number should be saved
422 assert (self.pjlink.model_lamp != new_data), 'Lamp model should NOT have been saved'422 assert self.pjlink.model_lamp != new_data, 'Lamp model should NOT have been saved'
423 mock_log.warning.assert_has_calls(log_warning_calls)423 mock_log.warning.assert_has_calls(log_warning_calls)
424 mock_log.debug.assert_has_calls(log_debug_calls)424 mock_log.debug.assert_has_calls(log_debug_calls)
425425
@@ -446,7 +446,7 @@
446 process_command(projector=self.pjlink, cmd='SNUM', data=new_data)446 process_command(projector=self.pjlink, cmd='SNUM', data=new_data)
447447
448 # THEN: Serial number should be set448 # THEN: Serial number should be set
449 assert (self.pjlink.serial_no != new_data), 'Projector serial number should NOT have been set'449 assert self.pjlink.serial_no != new_data, 'Projector serial number should NOT have been set'
450 mock_log.warning.assert_has_calls(log_warning_calls)450 mock_log.warning.assert_has_calls(log_warning_calls)
451 mock_log.debug.assert_has_calls(log_debug_calls)451 mock_log.debug.assert_has_calls(log_debug_calls)
452452
@@ -469,7 +469,7 @@
469 process_command(projector=self.pjlink, cmd='SNUM', data=new_data)469 process_command(projector=self.pjlink, cmd='SNUM', data=new_data)
470470
471 # THEN: Serial number should be set471 # THEN: Serial number should be set
472 assert (self.pjlink.serial_no == new_data), 'Projector serial number should have been set'472 assert self.pjlink.serial_no == new_data, 'Projector serial number should have been set'
473 mock_log.warning.assert_has_calls(log_warning_calls)473 mock_log.warning.assert_has_calls(log_warning_calls)
474 mock_log.debug.assert_has_calls(log_debug_calls)474 mock_log.debug.assert_has_calls(log_debug_calls)
475475
@@ -497,7 +497,7 @@
497 process_command(self.pjlink, cmd='SVER', data=new_data)497 process_command(self.pjlink, cmd='SVER', data=new_data)
498498
499 # THEN: Version information should change499 # THEN: Version information should change
500 assert (self.pjlink.sw_version == new_data), 'Software version should have changed'500 assert self.pjlink.sw_version == new_data, 'Software version should have changed'
501 mock_log.warning.assert_has_calls(log_warning_calls)501 mock_log.warning.assert_has_calls(log_warning_calls)
502 mock_log.debug.assert_has_calls(log_debug_calls)502 mock_log.debug.assert_has_calls(log_debug_calls)
503503
@@ -519,8 +519,8 @@
519 process_command(projector=self.pjlink, cmd='SVER', data=new_data)519 process_command(projector=self.pjlink, cmd='SVER', data=new_data)
520520
521 # THEN: Version information should not change521 # THEN: Version information should not change
522 assert (not self.pjlink.sw_version), 'Software version should not have changed'522 assert not self.pjlink.sw_version, 'Software version should not have changed'
523 assert (not self.pjlink.sw_version_received), 'Received software version should not have changed'523 assert not self.pjlink.sw_version_received, 'Received software version should not have changed'
524 mock_log.warning.assert_has_calls(log_warning_calls)524 mock_log.warning.assert_has_calls(log_warning_calls)
525 mock_log.debug.assert_has_calls(log_debug_calls)525 mock_log.debug.assert_has_calls(log_debug_calls)
526526
@@ -544,7 +544,7 @@
544 process_command(projector=self.pjlink, cmd='SVER', data=new_data)544 process_command(projector=self.pjlink, cmd='SVER', data=new_data)
545545
546 # THEN: Version information should not change546 # THEN: Version information should not change
547 assert (self.pjlink.sw_version == new_data), 'Software version should have been updated'547 assert self.pjlink.sw_version == new_data, 'Software version should have been updated'
548 assert (not self.pjlink.sw_version_received), 'Received version field should not have changed'548 assert not self.pjlink.sw_version_received, 'Received version field should not have changed'
549 mock_log.warning.assert_has_calls(log_warning_calls)549 mock_log.warning.assert_has_calls(log_warning_calls)
550 mock_log.debug.assert_has_calls(log_debug_calls)550 mock_log.debug.assert_has_calls(log_debug_calls)
551551
=== modified file 'tests/openlp_core/projectors/test_projector_commands_03.py'
--- tests/openlp_core/projectors/test_projector_commands_03.py 2019-05-05 04:08:32 +0000
+++ tests/openlp_core/projectors/test_projector_commands_03.py 2019-05-15 13:39:42 +0000
@@ -22,335 +22,232 @@
22"""22"""
23Package to test the openlp.core.projectors.pjlink commands package.23Package to test the openlp.core.projectors.pjlink commands package.
24"""24"""
25from unittest import TestCase, skip25from unittest import TestCase
26from unittest.mock import call, patch26from unittest.mock import call, patch
2727
28import openlp.core.projectors.pjlink28import openlp.core.projectors.pjlink
29from openlp.core.projectors.constants import PJLINK_PORT, S_CONNECTED, S_OFF, S_ON29from openlp.core.projectors.constants import E_NO_AUTHENTICATION, STATUS_CODE, S_AUTHENTICATE, S_CONNECT
30from openlp.core.projectors.db import Projector30from openlp.core.projectors.db import Projector
31from openlp.core.projectors.pjlink import PJLink, PJLinkUDP31from openlp.core.projectors.pjlink import PJLink
32from tests.resources.projector.data import TEST1_DATA, TEST2_DATA, TEST_HASH, TEST_PIN, TEST_SALT32from openlp.core.projectors.pjlinkcommands import process_command
33from tests.resources.projector.data import TEST1_DATA, TEST_PIN, TEST_SALT
3334
3435
35class TestPJLinkCommands(TestCase):36class TestPJLinkCommands(TestCase):
36 """37 """
37 Tests for the PJLinkCommands class part 238 Tests PJLink commands part 3
38 """39 """
39 @skip('Needs update to new setup')40 def setUp(self):
40 def test_projector_reset_information(self):41 """
41 """42 Initialize test state(s)
42 Test reset_information() resets all information and stops timers43 """
43 """44 # Default PJLink instance for tests
44 # GIVEN: Test object45 self.pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
45 with patch.object(openlp.core.projectors.pjlink, 'log') as mock_log:46
46 pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)47 def tearDown(self):
47 log_debug_calls = [call('({ip}): Calling poll_timer.stop()'.format(ip=pjlink.name)),48 """
48 call('({ip}): Calling socket_timer.stop()'.format(ip=pjlink.name))]49 Cleanup test state(s)
49 # timer and socket_timer not available until instantiation, so mock here50 """
50 with patch.object(pjlink, 'socket_timer') as mock_socket_timer, \51 del(self.pjlink)
51 patch.object(pjlink, 'poll_timer') as mock_timer:52
5253 @patch.object(openlp.core.projectors.pjlinkcommands, 'log')
53 pjlink.power = S_ON54 def test_process_pjlink_authenticate(self, mock_log):
54 pjlink.pjlink_name = 'OPENLPTEST'
55 pjlink.manufacturer = 'PJLINK'
56 pjlink.model = '1'
57 pjlink.shutter = True
58 pjlink.mute = True
59 pjlink.lamp = True
60 pjlink.fan = True
61 pjlink.source_available = True
62 pjlink.other_info = 'ANOTHER TEST'
63 pjlink.send_queue = True
64 pjlink.send_busy = True
65
66 # WHEN: reset_information() is called
67 pjlink.reset_information()
68
69 # THEN: All information should be reset and timers stopped
70 assert pjlink.power == S_OFF, 'Projector power should be OFF'
71 assert pjlink.pjlink_name is None, 'Projector pjlink_name should be None'
72 assert pjlink.manufacturer is None, 'Projector manufacturer should be None'
73 assert pjlink.model is None, 'Projector model should be None'
74 assert pjlink.shutter is None, 'Projector shutter should be None'
75 assert pjlink.mute is None, 'Projector shuttter should be None'
76 assert pjlink.lamp is None, 'Projector lamp should be None'
77 assert pjlink.fan is None, 'Projector fan should be None'
78 assert pjlink.source_available is None, 'Projector source_available should be None'
79 assert pjlink.source is None, 'Projector source should be None'
80 assert pjlink.other_info is None, 'Projector other_info should be None'
81 assert pjlink.send_queue == [], 'Projector send_queue should be an empty list'
82 assert pjlink.send_busy is False, 'Projector send_busy should be False'
83 assert mock_timer.stop.called is True, 'Projector timer.stop() should have been called'
84 assert mock_socket_timer.stop.called is True, 'Projector socket_timer.stop() should have been called'
85 mock_log.debug.assert_has_calls(log_debug_calls)
86
87 @skip('Needs update to new setup')
88 def test_process_pjlink_normal(self):
89 """
90 Test initial connection prompt with no authentication
91 """
92 # GIVEN: Initial mocks and data
93 mock_log = patch.object(openlp.core.projectors.pjlink, "log").start()
94 mock_disconnect_from_host = patch('openlp.core.projectors.pjlink.PJLink.disconnect_from_host').start()
95 mock_send_command = patch('openlp.core.projectors.pjlink.PJLink.send_command').start()
96 mock_readyRead = patch('openlp.core.projectors.pjlink.PJLink.readyRead').start()
97 mock_change_status = patch('openlp.core.projectors.pjlink.PJLink.change_status').start()
98
99 pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
100 pjlink.pin = None
101 log_check = [call('({ip}) process_pjlink(): Sending "CLSS" initial command'.format(ip=pjlink.name)), ]
102
103 # WHEN: process_pjlink called with no authentication required
104 pjlink.process_pjlink(data="0")
105
106 # THEN: proper processing should have occured
107 mock_log.debug.has_calls(log_check)
108 mock_disconnect_from_host.assert_not_called()
109 assert 1 == mock_readyRead.connect.call_count, 'Should have only been called once'
110 mock_change_status.assert_called_once_with(S_CONNECTED)
111 mock_send_command.assert_called_with(cmd='CLSS', priority=True, salt=None)
112
113 @skip('Needs update to new setup')
114 def test_process_pjlink_authenticate(self):
115 """55 """
116 Test initial connection prompt with authentication56 Test initial connection prompt with authentication
117 """57 """
118 # GIVEN: Initial mocks and data58 # GIVEN: Initial mocks and data
119 mock_log = patch.object(openlp.core.projectors.pjlink, "log").start()59 log_error_calls = []
120 mock_disconnect_from_host = patch('openlp.core.projectors.pjlink.PJLink.disconnect_from_host').start()60 log_warning_calls = []
121 mock_send_command = patch('openlp.core.projectors.pjlink.PJLink.send_command').start()61 log_debug_calls = [call('({ip}) Processing command "PJLINK" with data "1 {data}"'.format(ip=self.pjlink.name,
122 mock_readyRead = patch('openlp.core.projectors.pjlink.PJLink.readyRead').start()62 data=TEST_SALT)),
123 mock_change_status = patch('openlp.core.projectors.pjlink.PJLink.change_status').start()63 call('({ip}) Calling function for PJLINK'.format(ip=self.pjlink.name)),
12464 call('({ip}) Processing PJLINK command'.format(ip=self.pjlink.name)),
125 pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)65 call('({ip}) PJLINK: Returning {data}'.format(ip=self.pjlink.name,
126 pjlink.pin = TEST_PIN66 data=STATUS_CODE[S_AUTHENTICATE]))]
127 log_check = [call('({ip}) process_pjlink(): Sending "CLSS" initial command'.format(ip=pjlink.name)), ]67
12868 self.pjlink.pin = TEST_PIN
129 # WHEN: process_pjlink called with no authentication required69
130 pjlink.process_pjlink(data='1 {salt}'.format(salt=TEST_SALT))70 # WHEN: process_pjlink called with no authentication required
13171 chk = process_command(projector=self.pjlink, cmd='PJLINK', data='1 {salt}'.format(salt=TEST_SALT))
132 # THEN: proper processing should have occured72
133 mock_log.debug.has_calls(log_check)73 # THEN: proper processing should have occured
134 mock_disconnect_from_host.assert_not_called()74 mock_log.error.assert_has_calls(log_error_calls)
135 assert 1 == mock_readyRead.connect.call_count, 'Should have only been called once'75 mock_log.warning.assert_has_calls(log_warning_calls)
136 mock_change_status.assert_called_once_with(S_CONNECTED)76 mock_log.debug.assert_has_calls(log_debug_calls)
137 mock_send_command.assert_called_with(cmd='CLSS', priority=True, salt=TEST_HASH)77 assert chk == S_AUTHENTICATE, 'Should have returned {data}'.format(data=STATUS_CODE[S_AUTHENTICATE])
13878
139 @skip('Needs update to new setup')79 @patch.object(openlp.core.projectors.pjlinkcommands, 'log')
140 def test_process_pjlink_normal_pin_set_error(self):80 def test_process_pjlink_authenticate_pin_not_set_error(self, mock_log):
141 """81 """
142 Test process_pjlinnk called with no authentication but pin is set82 Test initial connection prompt with authentication and no pin set
143 """83 """
144 # GIVEN: Initial mocks and data84 # GIVEN: Initial mocks and data
145 mock_log = patch.object(openlp.core.projectors.pjlink, 'log').start()85 log_error_calls = [call('({ip}) Authenticate connection but no PIN - aborting'.format(ip=self.pjlink.name))]
146 mock_disconnect_from_host = patch('openlp.core.projectors.pjlink.PJLink.disconnect_from_host').start()86 log_warning_calls = []
147 mock_send_command = patch('openlp.core.projectors.pjlink.PJLink.send_command').start()87 log_debug_calls = [call('({ip}) Processing command "PJLINK" with data "1 {data}"'.format(ip=self.pjlink.name,
14888 data=TEST_SALT)),
149 pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)89 call('({ip}) Calling function for PJLINK'.format(ip=self.pjlink.name)),
150 pjlink.pin = TEST_PIN90 call('({ip}) Processing PJLINK command'.format(ip=self.pjlink.name))]
151 log_check = [call('({ip}) Normal connection but PIN set - aborting'.format(ip=pjlink.name)), ]91
15292 self.pjlink.pin = None
153 # WHEN: process_pjlink called with invalid authentication scheme93
154 pjlink.process_pjlink(data='0')94 # WHEN: process_pjlink called with no authentication required
15595 chk = process_command(projector=self.pjlink, cmd='PJLINK', data='1 {salt}'.format(salt=TEST_SALT))
156 # THEN: Proper calls should be made96
157 mock_log.error.assert_has_calls(log_check)97 # THEN: proper processing should have occured
158 assert 1 == mock_disconnect_from_host.call_count, 'Should have only been called once'98 mock_log.error.assert_has_calls(log_error_calls)
159 mock_send_command.assert_not_called()99 mock_log.warning.assert_has_calls(log_warning_calls)
160100 mock_log.debug.assert_has_calls(log_debug_calls)
161 @skip('Needs update to new setup')101 assert chk == E_NO_AUTHENTICATION, \
162 def test_process_pjlink_normal_with_salt_error(self):102 'Should have returned {data}'.format(data=STATUS_CODE[E_NO_AUTHENTICATION])
163 """103
164 Test process_pjlinnk called with no authentication but pin is set104 @patch.object(openlp.core.projectors.pjlinkcommands, 'log')
165 """105 def test_process_pjlink_authenticate_token_invalid(self, mock_log):
166 # GIVEN: Initial mocks and data106 """
167 mock_log = patch.object(openlp.core.projectors.pjlink, 'log').start()107 Test initial connection prompt with authentication and bad token
168 mock_disconnect_from_host = patch('openlp.core.projectors.pjlink.PJLink.disconnect_from_host').start()108 """
169 mock_send_command = patch('openlp.core.projectors.pjlink.PJLink.send_command').start()109 # GIVEN: Initial mocks and data
170110 bad_token = 'abcdefgh'
171 pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)111 log_error_calls = [call('({ip}) Authentication token invalid (not a hexadecimal number) - '
172 pjlink.pin = TEST_PIN112 'aborting'.format(ip=self.pjlink.name))]
173 log_check = [call('({ip}) Normal connection with extra information - aborting'.format(ip=pjlink.name)), ]113 log_warning_calls = []
174114 log_debug_calls = [call('({ip}) Processing command "PJLINK" with data '
175 # WHEN: process_pjlink called with invalid authentication scheme115 '"1 {data}"'.format(ip=self.pjlink.name, data=bad_token)),
176 pjlink.process_pjlink(data='0 {salt}'.format(salt=TEST_SALT))116 call('({ip}) Calling function for PJLINK'.format(ip=self.pjlink.name)),
177117 call('({ip}) Processing PJLINK command'.format(ip=self.pjlink.name))]
178 # THEN: Proper calls should be made118 self.pjlink.pin = TEST_SALT
179 mock_log.error.assert_has_calls(log_check)119
180 assert 1 == mock_disconnect_from_host.call_count, 'Should have only been called once'120 # WHEN: process_pjlink called with bad token
181 mock_send_command.assert_not_called()121 chk = process_command(projector=self.pjlink, cmd='PJLINK', data='1 {data}'.format(data=bad_token))
182122
183 @skip('Needs update to new setup')123 # THEN: proper processing should have occured
184 def test_process_pjlink_invalid_authentication_scheme_length_error(self):124 mock_log.error.assert_has_calls(log_error_calls)
185 """125 mock_log.warning.assert_has_calls(log_warning_calls)
186 Test initial connection prompt with authentication scheme longer than 1 character126 mock_log.debug.assert_has_calls(log_debug_calls)
187 """127 assert chk == E_NO_AUTHENTICATION, \
188 # GIVEN: Initial mocks and data128 'Should have returned {data}'.format(data=STATUS_CODE[E_NO_AUTHENTICATION])
189 mock_log = patch.object(openlp.core.projectors.pjlink, 'log').start()129
190 mock_disconnect_from_host = patch('openlp.core.projectors.pjlink.PJLink.disconnect_from_host').start()130 @patch.object(openlp.core.projectors.pjlinkcommands, 'log')
191 mock_send_command = patch('openlp.core.projectors.pjlink.PJLink.send_command').start()131 def test_process_pjlink_authenticate_token_length(self, mock_log):
192132 """
193 pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)133 Test initial connection prompt with authentication and bad token
194 log_check = [call('({ip}) Invalid initial authentication scheme - aborting'.format(ip=pjlink.name)), ]134 """
195135 # GIVEN: Initial mocks and data
196 # WHEN: process_pjlink called with invalid authentication scheme136 bad_token = '1234abcde' # Length should be 8, this is 9
197 pjlink.process_pjlink(data='01')137 log_error_calls = [call('({ip}) Authentication token invalid (size) - '
198138 'aborting'.format(ip=self.pjlink.name))]
199 # THEN: socket should be closed and invalid data logged139 log_warning_calls = []
200 mock_log.error.assert_has_calls(log_check)140 log_debug_calls = [call('({ip}) Processing command "PJLINK" with data '
201 assert 1 == mock_disconnect_from_host.call_count, 'Should have only been called once'141 '"1 {data}"'.format(ip=self.pjlink.name, data=bad_token)),
202 mock_send_command.assert_not_called()142 call('({ip}) Calling function for PJLINK'.format(ip=self.pjlink.name)),
203143 call('({ip}) Processing PJLINK command'.format(ip=self.pjlink.name))]
204 @skip('Needs update to new setup')144 self.pjlink.pin = TEST_SALT
205 def test_process_pjlink_invalid_authentication_data_length_error(self):145
206 """146 # WHEN: process_pjlink called with bad token
207 Test initial connection prompt with authentication no salt147 chk = process_command(projector=self.pjlink, cmd='PJLINK', data='1 {data}'.format(data=bad_token))
208 """148
209 # GIVEN: Initial mocks and data149 # THEN: proper processing should have occured
210 mock_log = patch.object(openlp.core.projectors.pjlink, 'log').start()150 mock_log.error.assert_has_calls(log_error_calls)
211 mock_disconnect_from_host = patch('openlp.core.projectors.pjlink.PJLink.disconnect_from_host').start()151 mock_log.warning.assert_has_calls(log_warning_calls)
212 mock_send_command = patch('openlp.core.projectors.pjlink.PJLink.send_command').start()152 mock_log.debug.assert_has_calls(log_debug_calls)
213153 assert chk == E_NO_AUTHENTICATION, \
214 pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)154 'Should have returned {data}'.format(data=STATUS_CODE[E_NO_AUTHENTICATION])
215 log_check = [call('({ip}) Authenticated connection but not enough info - aborting'.format(ip=pjlink.name)), ]155
216156 @patch.object(openlp.core.projectors.pjlinkcommands, 'log')
217 # WHEN: process_pjlink called with no salt157 def test_process_pjlink_authenticate_token_missing(self, mock_log):
218 pjlink.process_pjlink(data='1')158 """
219159 Test initial connection prompt with authentication and missing token
220 # THEN: socket should be closed and invalid data logged160 """
221 mock_log.error.assert_has_calls(log_check)161 # GIVEN: Initial mocks and data
222 assert 1 == mock_disconnect_from_host.call_count, 'Should have only been called once'162 log_error_calls = [call('({ip}) Authenticated connection but not enough info - '
223 mock_send_command.assert_not_called()163 'aborting'.format(ip=self.pjlink.name))]
224164 log_warning_calls = []
225 @skip('Needs update to new setup')165 log_debug_calls = [call('({ip}) Processing command "PJLINK" with data "1"'.format(ip=self.pjlink.name)),
226 def test_process_pjlink_authenticate_pin_not_set_error(self):166 call('({ip}) Calling function for PJLINK'.format(ip=self.pjlink.name)),
227 """167 call('({ip}) Processing PJLINK command'.format(ip=self.pjlink.name))]
228 Test process_pjlink authentication but pin not set168
229 """169 self.pjlink.pin = TEST_SALT
230 # GIVEN: Initial mocks and data170
231 mock_log = patch.object(openlp.core.projectors.pjlink, 'log').start()171 # WHEN: process_pjlink called with bad token
232 mock_disconnect_from_host = patch('openlp.core.projectors.pjlink.PJLink.disconnect_from_host').start()172 chk = process_command(projector=self.pjlink, cmd='PJLINK', data='1')
233 mock_send_command = patch('openlp.core.projectors.pjlink.PJLink.send_command').start()173
234174 # THEN: proper processing should have occured
235 pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)175 mock_log.error.assert_has_calls(log_error_calls)
236 pjlink.pin = None176 mock_log.warning.assert_has_calls(log_warning_calls)
237 log_check = [call('({ip}) Authenticate connection but no PIN - aborting'.format(ip=pjlink.name)), ]177 mock_log.debug.assert_has_calls(log_debug_calls)
238178 assert chk == E_NO_AUTHENTICATION, \
239 # WHEN: process_pjlink called with no salt179 'Should have returned {data}'.format(data=STATUS_CODE[E_NO_AUTHENTICATION])
240 pjlink.process_pjlink(data='1 {salt}'.format(salt=TEST_SALT))180
241181 @patch.object(openlp.core.projectors.pjlinkcommands, 'log')
242 # THEN: socket should be closed and invalid data logged182 def test_process_pjlink_normal(self, mock_log):
243 mock_log.error.assert_has_calls(log_check)183 """
244 assert 1 == mock_disconnect_from_host.call_count, 'Should have only been called once'184 Test processing PJLINK initial prompt
245 mock_send_command.assert_not_called()185 """
246186 # GIVEN: Mocks and data
247 @skip('Change to pjlink_udp.get_datagram() call')187 log_error_calls = []
248 @patch.object(openlp.core.projectors.pjlink, 'log')188 log_warning_calls = []
249 def test_process_ackn_duplicate(self, mock_log):189 log_debug_calls = [call('({ip}) Processing command "PJLINK" with data "0"'.format(ip=self.pjlink.name)),
250 """190 call('({ip}) Calling function for PJLINK'.format(ip=self.pjlink.name)),
251 Test process_ackn method with multiple calls with same data191 call('({ip}) Processing PJLINK command'.format(ip=self.pjlink.name)),
252 """192 call('({ip}) PJLINK: Returning {data}'.format(ip=self.pjlink.name,
253 # TODO: Change this to call pjlink_udp.get_datagram() so ACKN can be processed properly193 data=STATUS_CODE[S_CONNECT]))]
254194
255 # GIVEN: Test setup195 self.pjlink.pin = None
256 pjlink = PJLink(projector=self.test_list[0])196
257 check_list = {TEST1_DATA['ip']: {'data': TEST1_DATA['mac_adx'], 'port': PJLINK_PORT}}197 # WHEN: process_pjlink called with no authentication required
258 log_warn_calls = [call('(___TEST_ONE___) Host {host} already replied - '198 chk = process_command(projector=self.pjlink, cmd='PJLINK', data="0")
259 'ignoring'.format(host=TEST1_DATA['ip']))]199
260 log_debug_calls = [call('PJlinkCommands(args=() kwargs={})'),200 # THEN: proper processing should have occured
261 call('(___TEST_ONE___) reset_information() connect status is S_NOT_CONNECTED'),201 mock_log.error.assert_has_calls(log_error_calls)
262 call('(___TEST_ONE___) Processing ACKN packet'),202 mock_log.warning.assert_has_calls(log_warning_calls)
263 call('(___TEST_ONE___) Adding {host} to ACKN list'.format(host=TEST1_DATA['ip'])),203 mock_log.debug.assert_has_calls(log_debug_calls)
264 call('(___TEST_ONE___) Processing ACKN packet')]204 assert chk == S_CONNECT, 'Should have returned {data}'.format(data=STATUS_CODE[S_CONNECT])
265205
266 # WHEN: process_ackn called twice with same data206 @patch.object(openlp.core.projectors.pjlinkcommands, 'log')
267 pjlink.process_ackn(data=TEST1_DATA['mac_adx'], host=TEST1_DATA['ip'], port=PJLINK_PORT)207 def test_process_pjlink_normal_pin_set_error(self, mock_log):
268 pjlink.process_ackn(data=TEST1_DATA['mac_adx'], host=TEST1_DATA['ip'], port=PJLINK_PORT)208 """
269209 Test process_pjlinnk called with no authentication but pin is set
270 # THEN: pjlink_udp.ack_list should equal test_list210 """
271 # NOTE: This assert only returns AssertionError - does not list differences. Maybe add a compare function?211 # GIVEN: Initial mocks and data
272 if pjlink.ackn_list != check_list:212 log_error_calls = [call('({ip}) Normal connection but PIN set - '
273 # Check this way so we can print differences to stdout213 'aborting'.format(ip=self.pjlink.name))]
274 print('\nackn_list: ', pjlink.ackn_list)214 log_warning_calls = []
275 print('test_list: ', check_list, '\n')215 log_debug_calls = [call('({ip}) Processing command "PJLINK" with data "0"'.format(ip=self.pjlink.name)),
276 assert pjlink.ackn_list == check_list216 call('({ip}) Calling function for PJLINK'.format(ip=self.pjlink.name)),
277 mock_log.debug.assert_has_calls(log_debug_calls)217 call('({ip}) Processing PJLINK command'.format(ip=self.pjlink.name))]
278 mock_log.warning.assert_has_calls(log_warn_calls)218 self.pjlink.pin = TEST_PIN
279219
280 @skip('Change to pjlink_udp.get_datagram() call')220 # WHEN: process_pjlink called with invalid authentication scheme
281 @patch.object(openlp.core.projectors.pjlink, 'log')221 chk = process_command(projector=self.pjlink, cmd='PJLINK', data='0')
282 def test_process_ackn_multiple(self, mock_log):222
283 """223 # THEN: Proper calls should be made
284 Test process_ackn method with multiple calls224 mock_log.error.assert_has_calls(log_error_calls)
285 """225 mock_log.warning.assert_has_calls(log_warning_calls)
286 # TODO: Change this to call pjlink_udp.get_datagram() so ACKN can be processed properly226 mock_log.debug.assert_has_calls(log_debug_calls)
287227 assert chk == E_NO_AUTHENTICATION, \
288 # GIVEN: Test setup228 'Should have returned {data}'.format(data=STATUS_CODE[E_NO_AUTHENTICATION])
289 pjlink_udp = PJLinkUDP(projector_list=self.test_list)229
290 check_list = {TEST1_DATA['ip']: {'data': TEST1_DATA['mac_adx'], 'port': PJLINK_PORT},230 @patch.object(openlp.core.projectors.pjlinkcommands, 'log')
291 TEST2_DATA['ip']: {'data': TEST2_DATA['mac_adx'], 'port': PJLINK_PORT}}231 def test_process_pjlink_normal_with_token(self, mock_log):
292 log_debug_calls = [call('(UDP) PJLinkUDP() Initialized'),232 """
293 call('(UDP) Processing ACKN packet'),233 Test process_pjlinnk called with no authentication but pin is set
294 call('(UDP) Adding {host} to ACKN list'.format(host=TEST1_DATA['ip'])),234 """
295 call('(UDP) Processing ACKN packet'),235 # GIVEN: Initial mocks and data
296 call('(UDP) Adding {host} to ACKN list'.format(host=TEST2_DATA['ip']))]236 log_error_calls = [call('({ip}) Normal connection with extra information - '
297237 'aborting'.format(ip=self.pjlink.name))]
298 # WHEN: process_ackn called twice with different data238 log_warning_calls = []
299 pjlink_udp.process_ackn(data=TEST1_DATA['mac_adx'], host=TEST1_DATA['ip'], port=PJLINK_PORT)239 log_debug_calls = [call('({ip}) Processing command "PJLINK" with data '
300 pjlink_udp.process_ackn(data=TEST2_DATA['mac_adx'], host=TEST2_DATA['ip'], port=PJLINK_PORT)240 '"0 {data}"'.format(ip=self.pjlink.name, data=TEST_SALT)),
301241 call('({ip}) Calling function for PJLINK'.format(ip=self.pjlink.name)),
302 # THEN: pjlink_udp.ack_list should equal test_list242 call('({ip}) Processing PJLINK command'.format(ip=self.pjlink.name))]
303 # NOTE: This assert only returns AssertionError - does not list differences. Maybe add a compare function?243 self.pjlink.pin = TEST_PIN
304 if pjlink_udp.ackn_list != check_list:244
305 # Check this way so we can print differences to stdout245 # WHEN: process_pjlink called with invalid authentication scheme
306 print('\nackn_list: ', pjlink_udp.ackn_list)246 chk = process_command(projector=self.pjlink, cmd='PJLINK', data='0 {data}'.format(data=TEST_SALT))
307 print('test_list: ', check_list)247
308 assert pjlink_udp.ackn_list == check_list248 # THEN: Proper calls should be made
309 mock_log.debug.assert_has_calls(log_debug_calls)249 mock_log.error.assert_has_calls(log_error_calls)
310250 mock_log.warning.assert_has_calls(log_warning_calls)
311 @skip('Change to pjlink_udp.get_datagram() call')251 mock_log.debug.assert_has_calls(log_debug_calls)
312 @patch.object(openlp.core.projectors.pjlink, 'log')252 assert chk == E_NO_AUTHENTICATION, \
313 def test_process_ackn_single(self, mock_log):253 'Should have returned {data}'.format(data=STATUS_CODE[E_NO_AUTHENTICATION])
314 """
315 Test process_ackn method with single call
316 """
317 # TODO: Change this to call pjlink_udp.get_datagram() so ACKN can be processed properly
318
319 # GIVEN: Test setup
320 pjlink_udp = PJLinkUDP(projector_list=self.test_list)
321 check_list = {TEST1_DATA['ip']: {'data': TEST1_DATA['mac_adx'], 'port': PJLINK_PORT}}
322 log_debug_calls = [call('(UDP) PJLinkUDP() Initialized'),
323 call('(UDP) Processing ACKN packet'),
324 call('(UDP) Adding {host} to ACKN list'.format(host=TEST1_DATA['ip']))]
325
326 # WHEN: process_ackn called twice with different data
327 pjlink_udp.process_ackn(data=TEST1_DATA['mac_adx'], host=TEST1_DATA['ip'], port=PJLINK_PORT)
328
329 # THEN: pjlink_udp.ack_list should equal test_list
330 # NOTE: This assert only returns AssertionError - does not list differences. Maybe add a compare function?
331 if pjlink_udp.ackn_list != check_list:
332 # Check this way so we can print differences to stdout
333 print('\nackn_list: ', pjlink_udp.ackn_list)
334 print('test_list: ', check_list)
335 assert pjlink_udp.ackn_list == check_list
336 mock_log.debug.assert_has_calls(log_debug_calls)
337
338 @skip('Change to pjlink_udp.get_datagram() call')
339 @patch.object(openlp.core.projectors.pjlink, 'log')
340 def test_process_srch(self, mock_log):
341 """
342 Test process_srch method
343 """
344 # TODO: Change this to call pjlink_udp.get_datagram() so ACKN can be processed properly
345
346 # GIVEN: Test setup
347 log_warn_calls = [call('(UDP) SRCH packet received from {ip} - ignoring'.format(ip=TEST1_DATA['ip'])), ]
348 log_debug_calls = [call('(UDP) PJLinkUDP() Initialized'), ]
349 pjlink_udp = PJLinkUDP(projector_list=self.test_list)
350
351 # WHEN: process_srch called
352 pjlink_udp.process_srch(data=None, host=TEST1_DATA['ip'], port=PJLINK_PORT)
353
354 # THEN: log entries should be entered
355 mock_log.warning.assert_has_calls(log_warn_calls)
356 mock_log.debug.assert_has_calls(log_debug_calls)
357254
=== modified file 'tests/openlp_core/projectors/test_projector_pjlink_base_01.py'
--- tests/openlp_core/projectors/test_projector_pjlink_base_01.py 2019-04-28 19:21:23 +0000
+++ tests/openlp_core/projectors/test_projector_pjlink_base_01.py 2019-05-15 13:39:42 +0000
@@ -20,7 +20,7 @@
20# along with this program. If not, see <https://www.gnu.org/licenses/>. #20# along with this program. If not, see <https://www.gnu.org/licenses/>. #
21##########################################################################21##########################################################################
22"""22"""
23Package to test the openlp.core.projectors.pjlink base package.23Package to test the openlp.core.projectors.pjlink base package part 1.
24"""24"""
25from unittest import TestCase25from unittest import TestCase
26from unittest.mock import MagicMock, call, patch26from unittest.mock import MagicMock, call, patch
2727
=== modified file 'tests/openlp_core/projectors/test_projector_pjlink_base_02.py'
--- tests/openlp_core/projectors/test_projector_pjlink_base_02.py 2019-05-05 04:08:32 +0000
+++ tests/openlp_core/projectors/test_projector_pjlink_base_02.py 2019-05-15 13:39:42 +0000
@@ -20,7 +20,7 @@
20# along with this program. If not, see <https://www.gnu.org/licenses/>. #20# along with this program. If not, see <https://www.gnu.org/licenses/>. #
21##########################################################################21##########################################################################
22"""22"""
23Package to test the openlp.core.projectors.pjlink base package.23Package to test the openlp.core.projectors.pjlink base package part 2.
24"""24"""
25from unittest import TestCase25from unittest import TestCase
26from unittest.mock import call, patch26from unittest.mock import call, patch
@@ -96,10 +96,10 @@
96 mock_log.warning.assert_has_calls(log_warning_calls)96 mock_log.warning.assert_has_calls(log_warning_calls)
97 mock_log.debug.assert_has_calls(log_debug_calls)97 mock_log.debug.assert_has_calls(log_debug_calls)
98 mock_change_status.called_with(E_NETWORK, 'Error while sending data to projector')98 mock_change_status.called_with(E_NETWORK, 'Error while sending data to projector')
99 assert (not self.pjlink.send_queue), 'Send queue should be empty'99 assert not self.pjlink.send_queue, 'Send queue should be empty'
100 assert (not self.pjlink.priority_queue), 'Priority queue should be empty'100 assert not self.pjlink.priority_queue, 'Priority queue should be empty'
101 assert mock_timer.start.called, 'Timer should have been called'101 assert mock_timer.start.called, 'Timer should have been called'
102 assert (not mock_reset.called), 'reset_information() should not should have been called'102 assert not mock_reset.called, 'reset_information() should not should have been called'
103 assert mock_disconnect.called, 'disconnect_from_host() should have been called'103 assert mock_disconnect.called, 'disconnect_from_host() should have been called'
104 assert self.pjlink.send_busy, 'send_busy should be True'104 assert self.pjlink.send_busy, 'send_busy should be True'
105105
@@ -127,10 +127,10 @@
127 mock_log.error.assert_has_calls(log_error_calls)127 mock_log.error.assert_has_calls(log_error_calls)
128 mock_log.warning.assert_has_calls(log_warning_calls)128 mock_log.warning.assert_has_calls(log_warning_calls)
129 mock_log.debug.assert_has_calls(log_debug_calls)129 mock_log.debug.assert_has_calls(log_debug_calls)
130 assert (not self.pjlink.send_queue), 'Send queue should be empty'130 assert not self.pjlink.send_queue, 'Send queue should be empty'
131 assert (not self.pjlink.priority_queue), 'Priority queue should be empty'131 assert not self.pjlink.priority_queue, 'Priority queue should be empty'
132 assert (not mock_timer.called), 'Timer should not have been called'132 assert not mock_timer.called, 'Timer should not have been called'
133 assert (not mock_reset.called), 'reset_information() should not have been called'133 assert not mock_reset.called, 'reset_information() should not have been called'
134134
135 @patch.object(openlp.core.projectors.pjlink.PJLink, 'write')135 @patch.object(openlp.core.projectors.pjlink.PJLink, 'write')
136 @patch.object(openlp.core.projectors.pjlink.PJLink, 'disconnect_from_host')136 @patch.object(openlp.core.projectors.pjlink.PJLink, 'disconnect_from_host')
@@ -173,11 +173,11 @@
173 mock_log.error.assert_has_calls(log_error_calls)173 mock_log.error.assert_has_calls(log_error_calls)
174 mock_log.warning.assert_has_calls(log_warning_calls)174 mock_log.warning.assert_has_calls(log_warning_calls)
175 mock_log.debug.assert_has_calls(log_debug_calls)175 mock_log.debug.assert_has_calls(log_debug_calls)
176 assert (not self.pjlink.send_queue), 'Send queue should be empty'176 assert not self.pjlink.send_queue, 'Send queue should be empty'
177 assert (not self.pjlink.priority_queue), 'Priority queue should be empty'177 assert not self.pjlink.priority_queue, 'Priority queue should be empty'
178 assert mock_timer.start.called, 'Timer should have been called'178 assert mock_timer.start.called, 'Timer should have been called'
179 assert (not mock_reset.called), 'reset_information() should not have been called'179 assert not mock_reset.called, 'reset_information() should not have been called'
180 assert (not mock_disconnect.called), 'disconnect_from_host() should not have been called'180 assert not mock_disconnect.called, 'disconnect_from_host() should not have been called'
181 assert self.pjlink.send_busy, 'send_busy flag should be True'181 assert self.pjlink.send_busy, 'send_busy flag should be True'
182182
183 @patch.object(openlp.core.projectors.pjlink.PJLink, 'disconnect_from_host')183 @patch.object(openlp.core.projectors.pjlink.PJLink, 'disconnect_from_host')
@@ -211,12 +211,12 @@
211 mock_log.error.assert_has_calls(log_error_calls)211 mock_log.error.assert_has_calls(log_error_calls)
212 mock_log.warning.assert_has_calls(log_warning_calls)212 mock_log.warning.assert_has_calls(log_warning_calls)
213 mock_log.debug.assert_has_calls(log_debug_calls)213 mock_log.debug.assert_has_calls(log_debug_calls)
214 assert (self.pjlink.send_queue == [test_command]), 'Send queue should have one entry'214 assert self.pjlink.send_queue == [test_command], 'Send queue should have one entry'
215 assert (not self.pjlink.priority_queue), 'Priority queue should be empty'215 assert not self.pjlink.priority_queue, 'Priority queue should be empty'
216 assert (not mock_timer.called), 'Timer should not have been called'216 assert not mock_timer.called, 'Timer should not have been called'
217 assert (not mock_reset.called), 'reset_information() should not have been called'217 assert not mock_reset.called, 'reset_information() should not have been called'
218 assert mock_disconnect.called, 'disconnect_from_host() should have been called'218 assert mock_disconnect.called, 'disconnect_from_host() should have been called'
219 assert (not self.pjlink.send_busy), 'send_busy flag should be False'219 assert not self.pjlink.send_busy, 'send_busy flag should be False'
220220
221 @patch.object(openlp.core.projectors.pjlink.PJLink, 'write')221 @patch.object(openlp.core.projectors.pjlink.PJLink, 'write')
222 @patch.object(openlp.core.projectors.pjlink.PJLink, 'disconnect_from_host')222 @patch.object(openlp.core.projectors.pjlink.PJLink, 'disconnect_from_host')
@@ -261,11 +261,11 @@
261 mock_log.error.assert_has_calls(log_error_calls)261 mock_log.error.assert_has_calls(log_error_calls)
262 mock_log.warning.assert_has_calls(log_warning_calls)262 mock_log.warning.assert_has_calls(log_warning_calls)
263 mock_log.debug.assert_has_calls(log_debug_calls)263 mock_log.debug.assert_has_calls(log_debug_calls)
264 assert (not self.pjlink.send_queue), 'Send queue should be empty'264 assert not self.pjlink.send_queue, 'Send queue should be empty'
265 assert (not self.pjlink.priority_queue), 'Priority queue should be empty'265 assert not self.pjlink.priority_queue, 'Priority queue should be empty'
266 assert mock_timer.start.called, 'Timer should have been called'266 assert mock_timer.start.called, 'Timer should have been called'
267 assert (not mock_reset.called), 'reset_information() should not have been called'267 assert not mock_reset.called, 'reset_information() should not have been called'
268 assert (not mock_disconnect.called), 'disconnect_from_host() should not have been called'268 assert not mock_disconnect.called, 'disconnect_from_host() should not have been called'
269 assert self.pjlink.send_busy, 'send_busy flag should be True'269 assert self.pjlink.send_busy, 'send_busy flag should be True'
270270
271 @patch.object(openlp.core.projectors.pjlink.PJLink, 'write')271 @patch.object(openlp.core.projectors.pjlink.PJLink, 'write')
@@ -314,10 +314,10 @@
314 mock_log.warning.assert_has_calls(log_warning_calls)314 mock_log.warning.assert_has_calls(log_warning_calls)
315 mock_log.debug.assert_has_calls(log_debug_calls)315 mock_log.debug.assert_has_calls(log_debug_calls)
316 assert self.pjlink.send_queue, 'Send queue should have one entry'316 assert self.pjlink.send_queue, 'Send queue should have one entry'
317 assert (not self.pjlink.priority_queue), 'Priority queue should be empty'317 assert not self.pjlink.priority_queue, 'Priority queue should be empty'
318 assert mock_timer.start.called, 'Timer should have been called'318 assert mock_timer.start.called, 'Timer should have been called'
319 assert (not mock_reset.called), 'reset_information() should not have been called'319 assert not mock_reset.called, 'reset_information() should not have been called'
320 assert (not mock_disconnect.called), 'disconnect_from_host() should not have been called'320 assert not mock_disconnect.called, 'disconnect_from_host() should not have been called'
321 assert self.pjlink.send_busy, 'send_busy flag should be True'321 assert self.pjlink.send_busy, 'send_busy flag should be True'
322322
323 @patch.object(openlp.core.projectors.pjlink.PJLink, 'state')323 @patch.object(openlp.core.projectors.pjlink.PJLink, 'state')
@@ -358,9 +358,9 @@
358 mock_log.warning.assert_has_calls(log_warning_calls)358 mock_log.warning.assert_has_calls(log_warning_calls)
359 mock_log.debug.assert_has_calls(log_debug_calls)359 mock_log.debug.assert_has_calls(log_debug_calls)
360 assert self.pjlink.send_queue, 'Send queue should have one entry'360 assert self.pjlink.send_queue, 'Send queue should have one entry'
361 assert (not self.pjlink.priority_queue), 'Priority queue should be empty'361 assert not self.pjlink.priority_queue, 'Priority queue should be empty'
362 assert (not mock_timer.start.called), 'Timer should not have been called'362 assert not mock_timer.start.called, 'Timer should not have been called'
363 assert (not mock_reset.called), 'reset_information() should not have been called'363 assert not mock_reset.called, 'reset_information() should not have been called'
364 assert self.pjlink.send_busy, 'send_busy flag should be True'364 assert self.pjlink.send_busy, 'send_busy flag should be True'
365365
366 @patch.object(openlp.core.projectors.pjlink.PJLink, 'state')366 @patch.object(openlp.core.projectors.pjlink.PJLink, 'state')
@@ -402,10 +402,10 @@
402 mock_log.error.assert_has_calls(log_error_calls)402 mock_log.error.assert_has_calls(log_error_calls)
403 mock_log.warning.assert_has_calls(log_warning_calls)403 mock_log.warning.assert_has_calls(log_warning_calls)
404 mock_log.debug.assert_has_calls(log_debug_calls)404 mock_log.debug.assert_has_calls(log_debug_calls)
405 assert (not self.pjlink.send_queue), 'Send queue should be empty'405 assert not self.pjlink.send_queue, 'Send queue should be empty'
406 assert self.pjlink.priority_queue, 'Priority queue should have one entry'406 assert self.pjlink.priority_queue, 'Priority queue should have one entry'
407 assert (not mock_timer.start.called), 'Timer should not have been called'407 assert not mock_timer.start.called, 'Timer should not have been called'
408 assert (not mock_reset.called), 'reset_information() should not have been called'408 assert not mock_reset.called, 'reset_information() should not have been called'
409 assert self.pjlink.send_busy, 'send_busy flag should be True'409 assert self.pjlink.send_busy, 'send_busy flag should be True'
410410
411 # ------------ Test PJLink.send_command ----------411 # ------------ Test PJLink.send_command ----------
@@ -440,7 +440,7 @@
440 mock_log.debug.assert_has_calls(log_debug_calls)440 mock_log.debug.assert_has_calls(log_debug_calls)
441 mock_log.warning.assert_has_calls(log_warning_calls)441 mock_log.warning.assert_has_calls(log_warning_calls)
442 mock_log.error.assert_has_calls(log_error_calls)442 mock_log.error.assert_has_calls(log_error_calls)
443 assert (not mock_reset.called), 'reset_information() should not have been called'443 assert not mock_reset.called, 'reset_information() should not have been called'
444 assert mock_send_command.called, '_underscore_send_command() should have been called'444 assert mock_send_command.called, '_underscore_send_command() should have been called'
445445
446 @patch.object(openlp.core.projectors.pjlink.PJLink, 'state')446 @patch.object(openlp.core.projectors.pjlink.PJLink, 'state')
@@ -473,8 +473,8 @@
473 mock_log.warning.assert_has_calls(log_warning_calls)473 mock_log.warning.assert_has_calls(log_warning_calls)
474 mock_log.error.assert_has_calls(log_error_calls)474 mock_log.error.assert_has_calls(log_error_calls)
475 mock_priority.append.assert_called_with(test_command)475 mock_priority.append.assert_called_with(test_command)
476 assert (not mock_send.append.called), 'send_queue should not have changed'476 assert not mock_send.append.called, 'send_queue should not have changed'
477 assert (not mock_reset.called), 'reset_information() should not have been called'477 assert not mock_reset.called, 'reset_information() should not have been called'
478 assert mock_send_command.called, '_underscore_send_command() should have been called'478 assert mock_send_command.called, '_underscore_send_command() should have been called'
479479
480 @patch.object(openlp.core.projectors.pjlink.PJLink, 'state')480 @patch.object(openlp.core.projectors.pjlink.PJLink, 'state')
@@ -506,9 +506,9 @@
506 mock_log.debug.assert_has_calls(log_debug_calls)506 mock_log.debug.assert_has_calls(log_debug_calls)
507 mock_log.warning.assert_has_calls(log_warning_calls)507 mock_log.warning.assert_has_calls(log_warning_calls)
508 mock_log.error.assert_has_calls(log_error_calls)508 mock_log.error.assert_has_calls(log_error_calls)
509 assert (self.pjlink.send_queue == [test_command]), 'Send queue should have one entry'509 assert self.pjlink.send_queue == [test_command], 'Send queue should have one entry'
510 assert (not self.pjlink.priority_queue), 'Priority queue should be empty'510 assert not self.pjlink.priority_queue, 'Priority queue should be empty'
511 assert (not mock_reset.called), 'reset_information() should not have been called'511 assert not mock_reset.called, 'reset_information() should not have been called'
512 assert mock_send_command.called, '_underscore_send_command() should have been called'512 assert mock_send_command.called, '_underscore_send_command() should have been called'
513513
514 @patch.object(openlp.core.projectors.pjlink.PJLink, 'state')514 @patch.object(openlp.core.projectors.pjlink.PJLink, 'state')
@@ -540,9 +540,9 @@
540 mock_log.debug.assert_has_calls(log_debug_calls)540 mock_log.debug.assert_has_calls(log_debug_calls)
541 mock_log.warning.assert_has_calls(log_warning_calls)541 mock_log.warning.assert_has_calls(log_warning_calls)
542 mock_log.error.assert_has_calls(log_error_calls)542 mock_log.error.assert_has_calls(log_error_calls)
543 assert (not self.pjlink.send_queue), 'Send queue should be empty'543 assert not self.pjlink.send_queue, 'Send queue should be empty'
544 assert (self.pjlink.priority_queue == [test_command]), 'Priority queue should have one entry'544 assert self.pjlink.priority_queue == [test_command], 'Priority queue should have one entry'
545 assert (not mock_reset.called), 'reset_information() should not have been called'545 assert not mock_reset.called, 'reset_information() should not have been called'
546 assert mock_send_command.called, '_underscore_send_command() should have been called'546 assert mock_send_command.called, '_underscore_send_command() should have been called'
547547
548 @patch.object(openlp.core.projectors.pjlink.PJLink, 'state')548 @patch.object(openlp.core.projectors.pjlink.PJLink, 'state')
@@ -569,10 +569,10 @@
569 mock_log.debug.assert_has_calls(log_debug_calls)569 mock_log.debug.assert_has_calls(log_debug_calls)
570 mock_log.warning.assert_has_calls(log_warning_calls)570 mock_log.warning.assert_has_calls(log_warning_calls)
571 mock_log.error.assert_has_calls(log_error_calls)571 mock_log.error.assert_has_calls(log_error_calls)
572 assert (not self.pjlink.send_queue), 'Send queue should be empty'572 assert not self.pjlink.send_queue, 'Send queue should be empty'
573 assert (not self.pjlink.priority_queue), 'Priority queue should be empty'573 assert not self.pjlink.priority_queue, 'Priority queue should be empty'
574 assert (not mock_reset.called), 'reset_information() should not have been called'574 assert not mock_reset.called, 'reset_information() should not have been called'
575 assert (not mock_send_command.called), '_underscore_send_command() should not have been called'575 assert not mock_send_command.called, '_underscore_send_command() should not have been called'
576576
577 @patch.object(openlp.core.projectors.pjlink.PJLink, 'state')577 @patch.object(openlp.core.projectors.pjlink.PJLink, 'state')
578 @patch.object(openlp.core.projectors.pjlink.PJLink, 'reset_information')578 @patch.object(openlp.core.projectors.pjlink.PJLink, 'reset_information')
@@ -602,8 +602,8 @@
602 mock_log.warning.assert_has_calls(log_warning_calls)602 mock_log.warning.assert_has_calls(log_warning_calls)
603 mock_log.error.assert_has_calls(log_error_calls)603 mock_log.error.assert_has_calls(log_error_calls)
604 assert self.pjlink.send_queue, 'Send queue should have one entry'604 assert self.pjlink.send_queue, 'Send queue should have one entry'
605 assert (not self.pjlink.priority_queue), 'Priority queue should be empty'605 assert not self.pjlink.priority_queue, 'Priority queue should be empty'
606 assert (not mock_reset.called), 'reset_information() should not have been called'606 assert not mock_reset.called, 'reset_information() should not have been called'
607 assert mock_send_command.called, '_underscore_send_command() should have been called'607 assert mock_send_command.called, '_underscore_send_command() should have been called'
608608
609 @patch.object(openlp.core.projectors.pjlink.PJLink, 'state')609 @patch.object(openlp.core.projectors.pjlink.PJLink, 'state')
@@ -633,9 +633,9 @@
633 mock_log.debug.assert_has_calls(log_debug_calls)633 mock_log.debug.assert_has_calls(log_debug_calls)
634 mock_log.warning.assert_has_calls(log_warning_calls)634 mock_log.warning.assert_has_calls(log_warning_calls)
635 mock_log.error.assert_has_calls(log_error_calls)635 mock_log.error.assert_has_calls(log_error_calls)
636 assert (not self.pjlink.send_queue), 'Send queue should be empty'636 assert not self.pjlink.send_queue, 'Send queue should be empty'
637 assert self.pjlink.priority_queue, 'Priority queue should have one entry'637 assert self.pjlink.priority_queue, 'Priority queue should have one entry'
638 assert (not mock_reset.called), 'reset_information() should not have been called'638 assert not mock_reset.called, 'reset_information() should not have been called'
639 assert mock_send_command.called, '_underscore_send_command() should have been called'639 assert mock_send_command.called, '_underscore_send_command() should have been called'
640640
641 @patch.object(openlp.core.projectors.pjlink.PJLink, 'state')641 @patch.object(openlp.core.projectors.pjlink.PJLink, 'state')
@@ -661,7 +661,7 @@
661 mock_log.debug.assert_has_calls(log_debug_calls)661 mock_log.debug.assert_has_calls(log_debug_calls)
662 mock_log.warning.assert_has_calls(log_warning_calls)662 mock_log.warning.assert_has_calls(log_warning_calls)
663 mock_log.error.assert_has_calls(log_error_calls)663 mock_log.error.assert_has_calls(log_error_calls)
664 assert (not self.pjlink.send_queue), 'Send queue should be empty'664 assert not self.pjlink.send_queue, 'Send queue should be empty'
665 assert (not self.pjlink.priority_queue), 'Priority queue should be empty'665 assert not self.pjlink.priority_queue, 'Priority queue should be empty'
666 assert mock_reset.called, 'reset_information() should have been called'666 assert mock_reset.called, 'reset_information() should have been called'
667 assert (not mock_send_command.called), '_underscore_send_command() should not have been called'667 assert not mock_send_command.called, '_underscore_send_command() should not have been called'
668668
=== added file 'tests/openlp_core/projectors/test_projector_pjlink_base_03.py'
--- tests/openlp_core/projectors/test_projector_pjlink_base_03.py 1970-01-01 00:00:00 +0000
+++ tests/openlp_core/projectors/test_projector_pjlink_base_03.py 2019-05-15 13:39:42 +0000
@@ -0,0 +1,130 @@
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-2019 OpenLP Developers #
8# ---------------------------------------------------------------------- #
9# This program is free software: you can redistribute it and/or modify #
10# it under the terms of the GNU General Public License as published by #
11# the Free Software Foundation, either version 3 of the License, or #
12# (at your option) any later version. #
13# #
14# This program is distributed in the hope that it will be useful, #
15# but WITHOUT ANY WARRANTY; without even the implied warranty of #
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
17# GNU General Public License for more details. #
18# #
19# You should have received a copy of the GNU General Public License #
20# along with this program. If not, see <https://www.gnu.org/licenses/>. #
21##########################################################################
22"""
23Package to test the openlp.core.projectors.pjlink base package part 3.
24"""
25from unittest import TestCase
26from unittest.mock import call, patch
27
28import openlp.core.projectors.pjlink
29from openlp.core.projectors.constants import PJLINK_CLASS, STATUS_CODE, \
30 S_NOT_CONNECTED, S_OFF, S_ON, QSOCKET_STATE
31from openlp.core.projectors.db import Projector
32from openlp.core.projectors.pjlink import PJLink
33from tests.resources.projector.data import TEST1_DATA
34
35
36class TestPJLinkBase(TestCase):
37 """
38 Tests for the PJLink module
39 """
40 def setUp(self):
41 """
42 Initialize test state(s)
43 """
44 # Default PJLink instance for tests
45 self.pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
46
47 def tearDown(self):
48 """
49 Cleanup test state(s)
50 """
51 del(self.pjlink)
52
53 @patch.object(openlp.core.projectors.pjlink, 'log')
54 def test_projector_reset_information(self, mock_log):
55 """
56 Test reset_information() resets all information and stops timers
57 """
58 # GIVEN: Test object
59 log_debug_calls = [call('({ip}) reset_information() connect status is '
60 'S_NOT_CONNECTED'.format(ip=self.pjlink.name)),
61 call('({ip}): Calling poll_timer.stop()'.format(ip=self.pjlink.name)),
62 call('({ip}): Calling socket_timer.stop()'.format(ip=self.pjlink.name)),
63 call('({ip}): Calling status_timer.stop()'.format(ip=self.pjlink.name))]
64
65 # Attributes not available until instantiation, so mock here
66 with patch.object(self.pjlink, 'socket_timer') as mock_socket_timer, \
67 patch.object(self.pjlink, 'status_timer') as mock_status_timer, \
68 patch.object(self.pjlink, 'poll_timer') as mock_poll_timer, \
69 patch.object(self.pjlink, 'state') as mock_state:
70 mock_state.return_value = QSOCKET_STATE[S_NOT_CONNECTED]
71 # Set attributes to something other than None or {} or []
72 self.pjlink.fan = True
73 self.pjlink.filter_time = True
74 self.pjlink.lamp = True
75 self.pjlink.mac_adx_received = 'Some random MAC'
76 self.pjlink.manufacturer = 'PJLINK'
77 self.pjlink.model = '1'
78 self.pjlink.model_filter = 'Filter'
79 self.pjlink.model_lamp = 'Lamp'
80 self.pjlink.mute = True
81 self.pjlink.other_info = 'Another Test'
82 self.pjlink.pjlink_class = 2
83 self.pjlink.pjlink_name = 'OPENLPTEST'
84 self.pjlink.power = S_ON
85 self.pjlink.projector_errors = {'test1': True, 'test2': False}
86 self.pjlink.serial_no = 'Some Number'
87 self.pjlink.serial_no_received = 'Some Other Number'
88 self.pjlink.sw_version = 'Some Version'
89 self.pjlink.sw_version_received = 'Some Other Version'
90 self.pjlink.shutter = True
91 self.pjlink.source_available = True
92 self.pjlink.source = True
93 self.pjlink.status_timer_checks = {'test1': object(), 'test2': object()}
94 self.pjlink.send_busy = False
95 self.pjlink.send_queue = ['test1', 'test2']
96 self.pjlink.priority_queue = ['test1', 'test2']
97
98 # WHEN: reset_information() is called
99 self.pjlink.reset_information()
100
101 # THEN: All information should be reset and timers stopped
102 mock_log.debug.assert_has_calls(log_debug_calls)
103 assert self.pjlink.fan is None, 'fan should be None'
104 assert self.pjlink.filter_time is None, 'filter_time should be None'
105 assert self.pjlink.lamp is None, 'lamp should be None'
106 assert self.pjlink.mac_adx_received is None, 'mac_adx_received should be None'
107 assert self.pjlink.manufacturer is None, 'manufacturer should be None'
108 assert self.pjlink.model is None, 'model should be None'
109 assert self.pjlink.model_filter is None, 'model_filter should be None'
110 assert self.pjlink.model_lamp is None, 'model_lamp should be None'
111 assert not self.pjlink.mute, 'mute should be False'
112 assert self.pjlink.other_info is None, 'other should be None'
113 assert self.pjlink.pjlink_class == PJLINK_CLASS, 'pjlink_class should be {cls}'.format(cls=PJLINK_CLASS)
114 assert self.pjlink.pjlink_name is None, 'pjlink_name should be None'
115 assert self.pjlink.power == S_OFF, 'power should be {data}'.format(data=STATUS_CODE[S_OFF])
116 assert self.pjlink.projector_errors == {}, 'projector_errors should be an empty dict'
117 assert self.pjlink.serial_no is None, 'serial_no should be None'
118 assert self.pjlink.serial_no_received is None, 'serial_no_received should be None'
119 assert self.pjlink.sw_version is None, 'sw_version should be None'
120 assert self.pjlink.sw_version_received is None, 'sw_version_received should be None'
121 assert not self.pjlink.shutter, 'shutter should be False'
122 assert self.pjlink.source_available is None, 'source_available should be None'
123 assert self.pjlink.source is None, 'source should be None'
124 assert self.pjlink.status_timer_checks == {}, 'status_timer_checks should be an empty dict'
125 assert not self.pjlink.send_busy, 'send_busy should be False'
126 assert self.pjlink.send_queue == [], 'send_queue should be an empty list'
127 assert self.pjlink.priority_queue == [], 'priority_queue should be an empty list'
128 assert mock_socket_timer.stop.called, 'socket_timer.stop() should have been called'
129 assert mock_status_timer.stop.called, 'status_timer.stop() should have been called'
130 assert mock_poll_timer.stop.called, 'poll_timer.stop() should have been called'