Merge lp:~alisonken1/openlp/pjlink2-v07 into lp:openlp
- pjlink2-v07
- Merge into trunk
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 |
Related bugs: |
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.
- 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:/
https:/
https:/
https:/
https:/
https:/
https:/
https:/
All builds passed
Raoul Snyman (raoul-snyman) wrote : Posted in a previous version of this proposal | # |
Raoul Snyman (raoul-snyman) wrote : Posted in a previous version of this proposal | # |
Linting passed!
Raoul Snyman (raoul-snyman) wrote : Posted in a previous version of this proposal | # |
macOS tests passed!
Phill (phill-ridout) wrote : Posted in a previous version of this proposal | # |
You have quite a few "assert (chk == E_NO_AUTHENTICA
Also you're "@patch.
Other than that looks good to me!
Raoul Snyman (raoul-snyman) wrote : | # |
Linux tests passed!
Raoul Snyman (raoul-snyman) wrote : | # |
Linting passed!
Raoul Snyman (raoul-snyman) wrote : | # |
macOS tests passed!
Raoul Snyman (raoul-snyman) wrote : | # |
Looks OK to me.
Tim Bentley (trb143) : | # |
Preview Diff
1 | === modified file 'openlp/core/projectors/constants.py' | |||
2 | --- openlp/core/projectors/constants.py 2019-05-04 05:25:07 +0000 | |||
3 | +++ openlp/core/projectors/constants.py 2019-05-15 13:39:42 +0000 | |||
4 | @@ -39,6 +39,7 @@ | |||
5 | 39 | PJLINK_PORT = 4352 | 39 | PJLINK_PORT = 4352 |
6 | 40 | PJLINK_SUFFIX = CR | 40 | PJLINK_SUFFIX = CR |
7 | 41 | PJLINK_TIMEOUT = 30.0 | 41 | PJLINK_TIMEOUT = 30.0 |
8 | 42 | PJLINK_TOKEN_SIZE = 8 # PJLINK 1 <token> : where <token> is 8 characters | ||
9 | 42 | 43 | ||
10 | 43 | # Error and status codes | 44 | # Error and status codes |
11 | 44 | S_OK = E_OK = 0 # E_OK included since I sometimes forget | 45 | S_OK = E_OK = 0 # E_OK included since I sometimes forget |
12 | 45 | 46 | ||
13 | === modified file 'openlp/core/projectors/pjlink.py' | |||
14 | --- openlp/core/projectors/pjlink.py 2019-05-05 04:08:32 +0000 | |||
15 | +++ openlp/core/projectors/pjlink.py 2019-05-15 13:39:42 +0000 | |||
16 | @@ -281,6 +281,7 @@ | |||
17 | 281 | self.pjlink_class = copy(PJLINK_CLASS) | 281 | self.pjlink_class = copy(PJLINK_CLASS) |
18 | 282 | self.pjlink_name = None # NAME | 282 | self.pjlink_name = None # NAME |
19 | 283 | self.power = S_OFF # POWR | 283 | self.power = S_OFF # POWR |
20 | 284 | self.projector_errors = {} # Full ERST errors | ||
21 | 284 | self.serial_no = None # SNUM | 285 | self.serial_no = None # SNUM |
22 | 285 | self.serial_no_received = None | 286 | self.serial_no_received = None |
23 | 286 | self.sw_version = None # SVER | 287 | self.sw_version = None # SVER |
24 | 287 | 288 | ||
25 | === modified file 'openlp/core/projectors/pjlinkcommands.py' | |||
26 | --- openlp/core/projectors/pjlinkcommands.py 2019-05-05 04:08:32 +0000 | |||
27 | +++ openlp/core/projectors/pjlinkcommands.py 2019-05-15 13:39:42 +0000 | |||
28 | @@ -29,13 +29,13 @@ | |||
29 | 29 | 29 | ||
30 | 30 | import logging | 30 | import logging |
31 | 31 | import re | 31 | import re |
32 | 32 | import string | ||
33 | 32 | 33 | ||
34 | 33 | from openlp.core.common.i18n import translate | ||
35 | 34 | from openlp.core.common.settings import Settings | 34 | from openlp.core.common.settings import Settings |
36 | 35 | 35 | ||
37 | 36 | from openlp.core.projectors.constants import E_AUTHENTICATION, PJLINK_DEFAULT_CODES, PJLINK_ERRORS, \ | 36 | from openlp.core.projectors.constants import E_AUTHENTICATION, PJLINK_DEFAULT_CODES, PJLINK_ERRORS, \ |
40 | 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, \ |
41 | 38 | S_STANDBY, STATUS_MSG | 38 | E_NO_AUTHENTICATION, S_AUTHENTICATE, S_CONNECT, S_DATA_OK, S_OFF, S_OK, S_ON, S_STANDBY, STATUS_MSG |
42 | 39 | 39 | ||
43 | 40 | log = logging.getLogger(__name__) | 40 | log = logging.getLogger(__name__) |
44 | 41 | log.debug('Loading pjlinkcommands') | 41 | log.debug('Loading pjlinkcommands') |
45 | @@ -195,8 +195,7 @@ | |||
46 | 195 | # Bad data - ignore | 195 | # Bad data - ignore |
47 | 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)) |
48 | 197 | return | 197 | return |
51 | 198 | datacheck = int(data) | 198 | if int(data) == 0: |
50 | 199 | if datacheck == 0: | ||
52 | 200 | projector.projector_errors = None | 199 | projector.projector_errors = None |
53 | 201 | # No errors | 200 | # No errors |
54 | 202 | return | 201 | return |
55 | @@ -209,23 +208,17 @@ | |||
56 | 209 | data[PJLINK_ERST_DATA['FILTER']], | 208 | data[PJLINK_ERST_DATA['FILTER']], |
57 | 210 | data[PJLINK_ERST_DATA['OTHER']]) | 209 | data[PJLINK_ERST_DATA['OTHER']]) |
58 | 211 | if fan != PJLINK_ERST_STATUS[S_OK]: | 210 | if fan != PJLINK_ERST_STATUS[S_OK]: |
61 | 212 | projector.projector_errors[translate('OpenLP.ProjectorPJLink', 'Fan')] = \ | 211 | projector.projector_errors[PJLINK_ERST_LIST['FAN']] = PJLINK_ERST_STATUS[fan] |
60 | 213 | PJLINK_ERST_STATUS[fan] | ||
62 | 214 | if lamp != PJLINK_ERST_STATUS[S_OK]: | 212 | if lamp != PJLINK_ERST_STATUS[S_OK]: |
65 | 215 | projector.projector_errors[translate('OpenLP.ProjectorPJLink', 'Lamp')] = \ | 213 | projector.projector_errors[PJLINK_ERST_LIST['LAMP']] = PJLINK_ERST_STATUS[lamp] |
64 | 216 | PJLINK_ERST_STATUS[lamp] | ||
66 | 217 | if temp != PJLINK_ERST_STATUS[S_OK]: | 214 | if temp != PJLINK_ERST_STATUS[S_OK]: |
69 | 218 | projector.projector_errors[translate('OpenLP.ProjectorPJLink', 'Temperature')] = \ | 215 | projector.projector_errors[PJLINK_ERST_LIST['TEMP']] = PJLINK_ERST_STATUS[temp] |
68 | 219 | PJLINK_ERST_STATUS[temp] | ||
70 | 220 | if cover != PJLINK_ERST_STATUS[S_OK]: | 216 | if cover != PJLINK_ERST_STATUS[S_OK]: |
73 | 221 | projector.projector_errors[translate('OpenLP.ProjectorPJLink', 'Cover')] = \ | 217 | projector.projector_errors[PJLINK_ERST_LIST['COVER']] = PJLINK_ERST_STATUS[cover] |
72 | 222 | PJLINK_ERST_STATUS[cover] | ||
74 | 223 | if filt != PJLINK_ERST_STATUS[S_OK]: | 218 | if filt != PJLINK_ERST_STATUS[S_OK]: |
77 | 224 | projector.projector_errors[translate('OpenLP.ProjectorPJLink', 'Filter')] = \ | 219 | projector.projector_errors[PJLINK_ERST_LIST['FILTER']] = PJLINK_ERST_STATUS[filt] |
76 | 225 | PJLINK_ERST_STATUS[filt] | ||
78 | 226 | if other != PJLINK_ERST_STATUS[S_OK]: | 220 | if other != PJLINK_ERST_STATUS[S_OK]: |
81 | 227 | projector.projector_errors[translate('OpenLP.ProjectorPJLink', 'Other')] = \ | 221 | projector.projector_errors[PJLINK_ERST_LIST['OTHER']] = PJLINK_ERST_STATUS[other] |
80 | 228 | PJLINK_ERST_STATUS[other] | ||
82 | 229 | return | 222 | return |
83 | 230 | 223 | ||
84 | 231 | 224 | ||
85 | @@ -389,20 +382,29 @@ | |||
86 | 389 | if len(chk) > 1: | 382 | if len(chk) > 1: |
87 | 390 | # Invalid data - there should be nothing after a normal authentication scheme | 383 | # Invalid data - there should be nothing after a normal authentication scheme |
88 | 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)) |
90 | 392 | return E_AUTHENTICATION | 385 | return E_NO_AUTHENTICATION |
91 | 393 | elif projector.pin: | 386 | elif projector.pin: |
92 | 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)) |
94 | 395 | return E_AUTHENTICATION | 388 | return E_NO_AUTHENTICATION |
95 | 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)) |
96 | 397 | return S_CONNECT | 390 | return S_CONNECT |
97 | 398 | elif chk[0] == '1': | 391 | elif chk[0] == '1': |
98 | 399 | if len(chk) < 2: | 392 | if len(chk) < 2: |
99 | 400 | # Not enough information for authenticated connection | 393 | # Not enough information for authenticated connection |
100 | 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)) |
102 | 402 | return E_AUTHENTICATION | 395 | return E_NO_AUTHENTICATION |
103 | 396 | elif len(chk[-1]) != PJLINK_TOKEN_SIZE: | ||
104 | 397 | # Bad token - incorrect size | ||
105 | 398 | log.error('({ip}) Authentication token invalid (size) - aborting'.format(ip=projector.entry.name)) | ||
106 | 399 | return E_NO_AUTHENTICATION | ||
107 | 400 | elif not all(c in string.hexdigits for c in chk[-1]): | ||
108 | 401 | # Bad token - not hexadecimal | ||
109 | 402 | log.error('({ip}) Authentication token invalid (not a hexadecimal number) ' | ||
110 | 403 | '- aborting'.format(ip=projector.entry.name)) | ||
111 | 404 | return E_NO_AUTHENTICATION | ||
112 | 403 | elif not projector.pin: | 405 | elif not projector.pin: |
113 | 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)) |
115 | 405 | return E_AUTHENTICATION | 407 | return E_NO_AUTHENTICATION |
116 | 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)) |
117 | 407 | return S_AUTHENTICATE | 409 | return S_AUTHENTICATE |
118 | 408 | 410 | ||
119 | 409 | 411 | ||
120 | === modified file 'tests/openlp_core/projectors/test_projector_commands_01.py' | |||
121 | --- tests/openlp_core/projectors/test_projector_commands_01.py 2019-05-05 04:08:32 +0000 | |||
122 | +++ tests/openlp_core/projectors/test_projector_commands_01.py 2019-05-15 13:39:42 +0000 | |||
123 | @@ -35,7 +35,7 @@ | |||
124 | 35 | 35 | ||
125 | 36 | class TestPJLinkCommands(TestCase): | 36 | class TestPJLinkCommands(TestCase): |
126 | 37 | """ | 37 | """ |
128 | 38 | Tests PJLink get status commands part 1 | 38 | Tests PJLink commands part 1 |
129 | 39 | """ | 39 | """ |
130 | 40 | def setUp(self): | 40 | def setUp(self): |
131 | 41 | """ | 41 | """ |
132 | @@ -92,7 +92,7 @@ | |||
133 | 92 | # THEN: Shutter should be closed and mute should be True | 92 | # THEN: Shutter should be closed and mute should be True |
134 | 93 | assert self.pjlink.shutter, 'Shutter should changed' | 93 | assert self.pjlink.shutter, 'Shutter should changed' |
135 | 94 | assert self.pjlink.mute, 'Audio should not have changed' | 94 | assert self.pjlink.mute, 'Audio should not have changed' |
137 | 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' |
138 | 96 | mock_log.warning.assert_has_calls(log_warning_text) | 96 | mock_log.warning.assert_has_calls(log_warning_text) |
139 | 97 | mock_log.debug.assert_has_calls(log_debug_text) | 97 | mock_log.debug.assert_has_calls(log_debug_text) |
140 | 98 | 98 | ||
141 | @@ -140,8 +140,8 @@ | |||
142 | 140 | process_command(projector=self.pjlink, cmd='AVMT', data='30') | 140 | process_command(projector=self.pjlink, cmd='AVMT', data='30') |
143 | 141 | 141 | ||
144 | 142 | # THEN: Shutter should be closed and mute should be True | 142 | # THEN: Shutter should be closed and mute should be True |
147 | 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' |
148 | 144 | assert (not self.pjlink.mute), 'Audio should be on' | 144 | assert not self.pjlink.mute, 'Audio should be on' |
149 | 145 | assert mock_UpdateIcons.emit.called, 'Update icons should have been called' | 145 | assert mock_UpdateIcons.emit.called, 'Update icons should have been called' |
150 | 146 | mock_log.warning.assert_has_calls(log_warning_text) | 146 | mock_log.warning.assert_has_calls(log_warning_text) |
151 | 147 | mock_log.debug.assert_has_calls(log_debug_text) | 147 | mock_log.debug.assert_has_calls(log_debug_text) |
152 | @@ -193,7 +193,7 @@ | |||
153 | 193 | assert self.pjlink.shutter, 'Shutter should have been set to closed' | 193 | assert self.pjlink.shutter, 'Shutter should have been set to closed' |
154 | 194 | assert self.pjlink.mute, 'Audio should not have changed' | 194 | assert self.pjlink.mute, 'Audio should not have changed' |
155 | 195 | assert mock_UpdateIcons.emit.called, 'Update icons should have been called' | 195 | assert mock_UpdateIcons.emit.called, 'Update icons should have been called' |
157 | 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' |
158 | 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' |
159 | 198 | mock_log.warning.assert_has_calls(log_warning_text) | 198 | mock_log.warning.assert_has_calls(log_warning_text) |
160 | 199 | mock_log.debug.assert_has_calls(log_debug_text) | 199 | mock_log.debug.assert_has_calls(log_debug_text) |
161 | @@ -214,7 +214,7 @@ | |||
162 | 214 | process_command(projector=self.pjlink, cmd='CLSS', data='1') | 214 | process_command(projector=self.pjlink, cmd='CLSS', data='1') |
163 | 215 | 215 | ||
164 | 216 | # THEN: Projector class should be set with proper value | 216 | # THEN: Projector class should be set with proper value |
166 | 217 | assert ('1' == self.pjlink.pjlink_class), 'Should have set class=1' | 217 | assert '1' == self.pjlink.pjlink_class, 'Should have set class=1' |
167 | 218 | mock_log.error.assert_has_calls(log_error_calls) | 218 | mock_log.error.assert_has_calls(log_error_calls) |
168 | 219 | mock_log.warning.assert_has_calls(log_warning_calls) | 219 | mock_log.warning.assert_has_calls(log_warning_calls) |
169 | 220 | mock_log.debug.assert_has_calls(log_debug_calls) | 220 | mock_log.debug.assert_has_calls(log_debug_calls) |
170 | @@ -235,7 +235,7 @@ | |||
171 | 235 | process_command(projector=self.pjlink, cmd='CLSS', data='2') | 235 | process_command(projector=self.pjlink, cmd='CLSS', data='2') |
172 | 236 | 236 | ||
173 | 237 | # THEN: Projector class should be set with proper value | 237 | # THEN: Projector class should be set with proper value |
175 | 238 | assert ('2' == self.pjlink.pjlink_class), 'Should have set class=2' | 238 | assert '2' == self.pjlink.pjlink_class, 'Should have set class=2' |
176 | 239 | mock_log.error.assert_has_calls(log_error_calls) | 239 | mock_log.error.assert_has_calls(log_error_calls) |
177 | 240 | mock_log.warning.assert_has_calls(log_warning_calls) | 240 | mock_log.warning.assert_has_calls(log_warning_calls) |
178 | 241 | mock_log.debug.assert_has_calls(log_debug_calls) | 241 | mock_log.debug.assert_has_calls(log_debug_calls) |
179 | @@ -256,7 +256,7 @@ | |||
180 | 256 | process_command(projector=self.pjlink, cmd='CLSS', data='Z') | 256 | process_command(projector=self.pjlink, cmd='CLSS', data='Z') |
181 | 257 | 257 | ||
182 | 258 | # THEN: Projector class should be set with default value | 258 | # THEN: Projector class should be set with default value |
184 | 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' |
185 | 260 | mock_log.warning.assert_has_calls(log_warning_calls) | 260 | mock_log.warning.assert_has_calls(log_warning_calls) |
186 | 261 | mock_log.debug.assert_has_calls(log_debug_calls) | 261 | mock_log.debug.assert_has_calls(log_debug_calls) |
187 | 262 | 262 | ||
188 | @@ -276,7 +276,7 @@ | |||
189 | 276 | process_command(projector=self.pjlink, cmd='CLSS', data='Invalid') | 276 | process_command(projector=self.pjlink, cmd='CLSS', data='Invalid') |
190 | 277 | 277 | ||
191 | 278 | # THEN: Projector class should be set with default value | 278 | # THEN: Projector class should be set with default value |
193 | 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' |
194 | 280 | mock_log.warning.assert_has_calls(log_warning_calls) | 280 | mock_log.warning.assert_has_calls(log_warning_calls) |
195 | 281 | mock_log.debug.assert_has_calls(log_debug_calls) | 281 | mock_log.debug.assert_has_calls(log_debug_calls) |
196 | 282 | 282 | ||
197 | @@ -296,7 +296,7 @@ | |||
198 | 296 | process_command(projector=self.pjlink, cmd='CLSS', data='Class 1') | 296 | process_command(projector=self.pjlink, cmd='CLSS', data='Class 1') |
199 | 297 | 297 | ||
200 | 298 | # THEN: Projector class should be set with proper value | 298 | # THEN: Projector class should be set with proper value |
202 | 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' |
203 | 300 | mock_log.error.assert_has_calls(log_error_calls) | 300 | mock_log.error.assert_has_calls(log_error_calls) |
204 | 301 | mock_log.warning.assert_has_calls(log_warning_calls) | 301 | mock_log.warning.assert_has_calls(log_warning_calls) |
205 | 302 | mock_log.debug.assert_has_calls(log_debug_calls) | 302 | mock_log.debug.assert_has_calls(log_debug_calls) |
206 | @@ -316,7 +316,7 @@ | |||
207 | 316 | process_command(projector=self.pjlink, cmd='CLSS', data='Version2') | 316 | process_command(projector=self.pjlink, cmd='CLSS', data='Version2') |
208 | 317 | 317 | ||
209 | 318 | # THEN: Projector class should be set with proper value | 318 | # THEN: Projector class should be set with proper value |
211 | 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' |
212 | 320 | mock_log.warning.assert_has_calls(log_warning_calls) | 320 | mock_log.warning.assert_has_calls(log_warning_calls) |
213 | 321 | mock_log.debug.assert_has_calls(log_debug_calls) | 321 | mock_log.debug.assert_has_calls(log_debug_calls) |
214 | 322 | 322 | ||
215 | @@ -348,7 +348,7 @@ | |||
216 | 348 | process_command(projector=self.pjlink, cmd='ERST', data=chk_data) | 348 | process_command(projector=self.pjlink, cmd='ERST', data=chk_data) |
217 | 349 | 349 | ||
218 | 350 | # THEN: PJLink instance errors should match chk_value | 350 | # THEN: PJLink instance errors should match chk_value |
220 | 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' |
221 | 352 | mock_log.warning.assert_has_calls(log_warning_calls) | 352 | mock_log.warning.assert_has_calls(log_warning_calls) |
222 | 353 | mock_log.debug.assert_has_calls(log_debug_calls) | 353 | mock_log.debug.assert_has_calls(log_debug_calls) |
223 | 354 | 354 | ||
224 | @@ -368,7 +368,7 @@ | |||
225 | 368 | process_command(projector=self.pjlink, cmd='ERST', data=chk_data) | 368 | process_command(projector=self.pjlink, cmd='ERST', data=chk_data) |
226 | 369 | 369 | ||
227 | 370 | # THEN: PJLink instance errors should be None | 370 | # THEN: PJLink instance errors should be None |
229 | 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' |
230 | 372 | mock_log.warning.assert_has_calls(log_warning_calls) | 372 | mock_log.warning.assert_has_calls(log_warning_calls) |
231 | 373 | mock_log.debug.assert_has_calls(log_debug_calls) | 373 | mock_log.debug.assert_has_calls(log_debug_calls) |
232 | 374 | 374 | ||
233 | @@ -400,7 +400,7 @@ | |||
234 | 400 | process_command(projector=self.pjlink, cmd='ERST', data=chk_data) | 400 | process_command(projector=self.pjlink, cmd='ERST', data=chk_data) |
235 | 401 | 401 | ||
236 | 402 | # THEN: PJLink instance errors should match chk_value | 402 | # THEN: PJLink instance errors should match chk_value |
238 | 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' |
239 | 404 | mock_log.warning.assert_has_calls(log_warning_calls) | 404 | mock_log.warning.assert_has_calls(log_warning_calls) |
240 | 405 | mock_log.debug.assert_has_calls(log_debug_calls) | 405 | mock_log.debug.assert_has_calls(log_debug_calls) |
241 | 406 | 406 | ||
242 | @@ -423,7 +423,7 @@ | |||
243 | 423 | process_command(self.pjlink, cmd='ERST', data=chk_data) | 423 | process_command(self.pjlink, cmd='ERST', data=chk_data) |
244 | 424 | 424 | ||
245 | 425 | # THEN: pjlink.projector_errors should be empty and warning logged | 425 | # THEN: pjlink.projector_errors should be empty and warning logged |
247 | 426 | assert (not self.pjlink.projector_errors), 'There should be no errors' | 426 | assert not self.pjlink.projector_errors, 'There should be no errors' |
248 | 427 | mock_log.warning.assert_has_calls(log_warn_calls) | 427 | mock_log.warning.assert_has_calls(log_warn_calls) |
249 | 428 | mock_log.debug.assert_has_calls(log_debug_calls) | 428 | mock_log.debug.assert_has_calls(log_debug_calls) |
250 | 429 | 429 | ||
251 | @@ -445,7 +445,7 @@ | |||
252 | 445 | process_command(self.pjlink, cmd='ERST', data=chk_data) | 445 | process_command(self.pjlink, cmd='ERST', data=chk_data) |
253 | 446 | 446 | ||
254 | 447 | # THEN: pjlink.projector_errors should be empty and warning logged | 447 | # THEN: pjlink.projector_errors should be empty and warning logged |
256 | 448 | assert (not self.pjlink.projector_errors), 'There should be no errors' | 448 | assert not self.pjlink.projector_errors, 'There should be no errors' |
257 | 449 | mock_log.warning.assert_has_calls(log_warn_calls) | 449 | mock_log.warning.assert_has_calls(log_warn_calls) |
258 | 450 | mock_log.debug.assert_has_calls(log_debug_calls) | 450 | mock_log.debug.assert_has_calls(log_debug_calls) |
259 | 451 | 451 | ||
260 | @@ -472,10 +472,10 @@ | |||
261 | 472 | process_command(projector=self.pjlink, cmd='ERST', data=chk_data) | 472 | process_command(projector=self.pjlink, cmd='ERST', data=chk_data) |
262 | 473 | 473 | ||
263 | 474 | # THEN: PJLink instance errors should match only cover warning | 474 | # THEN: PJLink instance errors should match only cover warning |
268 | 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' |
269 | 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' |
270 | 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' |
271 | 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' |
272 | 479 | mock_log.warning.assert_has_calls(log_warn_calls) | 479 | mock_log.warning.assert_has_calls(log_warn_calls) |
273 | 480 | mock_log.debug.assert_has_calls(log_debug_calls) | 480 | mock_log.debug.assert_has_calls(log_debug_calls) |
274 | 481 | 481 | ||
275 | @@ -498,7 +498,7 @@ | |||
276 | 498 | process_command(projector=self.pjlink, cmd='INF1', data=chk_data) | 498 | process_command(projector=self.pjlink, cmd='INF1', data=chk_data) |
277 | 499 | 499 | ||
278 | 500 | # THEN: Data should be saved | 500 | # THEN: Data should be saved |
280 | 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' |
281 | 502 | mock_log.warning.assert_has_calls(log_warn_calls) | 502 | mock_log.warning.assert_has_calls(log_warn_calls) |
282 | 503 | mock_log.debug.assert_has_calls(log_debug_calls) | 503 | mock_log.debug.assert_has_calls(log_debug_calls) |
283 | 504 | 504 | ||
284 | @@ -521,7 +521,7 @@ | |||
285 | 521 | process_command(projector=self.pjlink, cmd='INF2', data=chk_data) | 521 | process_command(projector=self.pjlink, cmd='INF2', data=chk_data) |
286 | 522 | 522 | ||
287 | 523 | # THEN: Data should be saved | 523 | # THEN: Data should be saved |
289 | 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' |
290 | 525 | mock_log.warning.assert_has_calls(log_warn_calls) | 525 | mock_log.warning.assert_has_calls(log_warn_calls) |
291 | 526 | mock_log.debug.assert_has_calls(log_debug_calls) | 526 | mock_log.debug.assert_has_calls(log_debug_calls) |
292 | 527 | 527 | ||
293 | @@ -544,6 +544,6 @@ | |||
294 | 544 | process_command(projector=self.pjlink, cmd='INFO', data=chk_data) | 544 | process_command(projector=self.pjlink, cmd='INFO', data=chk_data) |
295 | 545 | 545 | ||
296 | 546 | # THEN: Data should be saved | 546 | # THEN: Data should be saved |
298 | 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' |
299 | 548 | mock_log.warning.assert_has_calls(log_warn_calls) | 548 | mock_log.warning.assert_has_calls(log_warn_calls) |
300 | 549 | mock_log.debug.assert_has_calls(log_debug_calls) | 549 | mock_log.debug.assert_has_calls(log_debug_calls) |
301 | 550 | 550 | ||
302 | === modified file 'tests/openlp_core/projectors/test_projector_commands_02.py' | |||
303 | --- tests/openlp_core/projectors/test_projector_commands_02.py 2019-05-05 04:08:32 +0000 | |||
304 | +++ tests/openlp_core/projectors/test_projector_commands_02.py 2019-05-15 13:39:42 +0000 | |||
305 | @@ -35,7 +35,7 @@ | |||
306 | 35 | 35 | ||
307 | 36 | class TestPJLinkCommands(TestCase): | 36 | class TestPJLinkCommands(TestCase): |
308 | 37 | """ | 37 | """ |
310 | 38 | Tests PJLink get status commands part 2 | 38 | Tests PJLink commands part 2 |
311 | 39 | """ | 39 | """ |
312 | 40 | def setUp(self): | 40 | def setUp(self): |
313 | 41 | """ | 41 | """ |
314 | @@ -67,7 +67,7 @@ | |||
315 | 67 | process_command(projector=self.pjlink, cmd='INPT', data='21') | 67 | process_command(projector=self.pjlink, cmd='INPT', data='21') |
316 | 68 | 68 | ||
317 | 69 | # THEN: Input selected should reflect current input | 69 | # THEN: Input selected should reflect current input |
319 | 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"' |
320 | 71 | mock_log.warning.assert_has_calls(log_warning_calls) | 71 | mock_log.warning.assert_has_calls(log_warning_calls) |
321 | 72 | mock_log.debug.assert_has_calls(log_debug_calls) | 72 | mock_log.debug.assert_has_calls(log_debug_calls) |
322 | 73 | 73 | ||
323 | @@ -88,7 +88,7 @@ | |||
324 | 88 | process_command(projector=self.pjlink, cmd='INPT', data='91') | 88 | process_command(projector=self.pjlink, cmd='INPT', data='91') |
325 | 89 | 89 | ||
326 | 90 | # THEN: Input selected should reflect current input | 90 | # THEN: Input selected should reflect current input |
328 | 91 | assert (not self.pjlink.source), 'Input source should not have changed' | 91 | assert not self.pjlink.source, 'Input source should not have changed' |
329 | 92 | mock_log.warning.assert_has_calls(log_warning_calls) | 92 | mock_log.warning.assert_has_calls(log_warning_calls) |
330 | 93 | mock_log.debug.assert_has_calls(log_debug_calls) | 93 | mock_log.debug.assert_has_calls(log_debug_calls) |
331 | 94 | 94 | ||
332 | @@ -110,7 +110,7 @@ | |||
333 | 110 | process_command(projector=self.pjlink, cmd='INPT', data='25') | 110 | process_command(projector=self.pjlink, cmd='INPT', data='25') |
334 | 111 | 111 | ||
335 | 112 | # THEN: Input selected should reflect current input | 112 | # THEN: Input selected should reflect current input |
337 | 113 | assert ('11' == self.pjlink.source), 'Input source should not have changed' | 113 | assert '11' == self.pjlink.source, 'Input source should not have changed' |
338 | 114 | mock_log.warning.assert_has_calls(log_warning_calls) | 114 | mock_log.warning.assert_has_calls(log_warning_calls) |
339 | 115 | mock_log.debug.assert_has_calls(log_debug_calls) | 115 | mock_log.debug.assert_has_calls(log_debug_calls) |
340 | 116 | 116 | ||
341 | @@ -138,7 +138,7 @@ | |||
342 | 138 | # THEN: Data should have been sorted and saved properly | 138 | # THEN: Data should have been sorted and saved properly |
343 | 139 | mock_log.warning.assert_has_calls(log_warning_calls) | 139 | mock_log.warning.assert_has_calls(log_warning_calls) |
344 | 140 | mock_log.debug.assert_has_calls(log_debug_calls) | 140 | mock_log.debug.assert_has_calls(log_debug_calls) |
346 | 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" |
347 | 142 | 142 | ||
348 | 143 | @patch.object(openlp.core.projectors.pjlinkcommands, 'log') | 143 | @patch.object(openlp.core.projectors.pjlinkcommands, 'log') |
349 | 144 | def test_projector_lamp_invalid_missing_data(self, mock_log): | 144 | def test_projector_lamp_invalid_missing_data(self, mock_log): |
350 | @@ -158,7 +158,7 @@ | |||
351 | 158 | # THEN: Lamp should have been set with proper lamp status | 158 | # THEN: Lamp should have been set with proper lamp status |
352 | 159 | mock_log.warning.assert_has_calls(log_warning_calls) | 159 | mock_log.warning.assert_has_calls(log_warning_calls) |
353 | 160 | mock_log.debug.assert_has_calls(log_debug_calls) | 160 | mock_log.debug.assert_has_calls(log_debug_calls) |
355 | 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' |
356 | 162 | 162 | ||
357 | 163 | @patch.object(openlp.core.projectors.pjlinkcommands, 'log') | 163 | @patch.object(openlp.core.projectors.pjlinkcommands, 'log') |
358 | 164 | def test_projector_lamp_invalid_nan(self, mock_log): | 164 | def test_projector_lamp_invalid_nan(self, mock_log): |
359 | @@ -180,11 +180,11 @@ | |||
360 | 180 | # THEN: lamps should not have changed | 180 | # THEN: lamps should not have changed |
361 | 181 | mock_log.warning.assert_has_calls(log_warning_calls) | 181 | mock_log.warning.assert_has_calls(log_warning_calls) |
362 | 182 | mock_log.debug.assert_has_calls(log_debug_calls) | 182 | mock_log.debug.assert_has_calls(log_debug_calls) |
364 | 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' |
365 | 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' |
369 | 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' |
370 | 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' |
371 | 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' |
372 | 188 | 188 | ||
373 | 189 | @patch.object(openlp.core.projectors.pjlinkcommands, 'log') | 189 | @patch.object(openlp.core.projectors.pjlinkcommands, 'log') |
374 | 190 | def test_projector_lamp_multiple(self, mock_log): | 190 | def test_projector_lamp_multiple(self, mock_log): |
375 | @@ -204,13 +204,13 @@ | |||
376 | 204 | # THEN: Lamp should have been set with proper lamp status | 204 | # THEN: Lamp should have been set with proper lamp status |
377 | 205 | mock_log.warning.assert_has_calls(log_warning_calls) | 205 | mock_log.warning.assert_has_calls(log_warning_calls) |
378 | 206 | mock_log.debug.assert_has_calls(log_debug_calls) | 206 | mock_log.debug.assert_has_calls(log_debug_calls) |
380 | 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' |
381 | 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' |
385 | 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' |
386 | 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' |
387 | 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' |
388 | 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' |
390 | 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' |
391 | 214 | 214 | ||
392 | 215 | @patch.object(openlp.core.projectors.pjlinkcommands, 'log') | 215 | @patch.object(openlp.core.projectors.pjlinkcommands, 'log') |
393 | 216 | def test_projector_lamp_single(self, mock_log): | 216 | def test_projector_lamp_single(self, mock_log): |
394 | @@ -229,9 +229,9 @@ | |||
395 | 229 | # THEN: Lamp should have been set with proper lamp status | 229 | # THEN: Lamp should have been set with proper lamp status |
396 | 230 | mock_log.warning.assert_has_calls(log_warning_calls) | 230 | mock_log.warning.assert_has_calls(log_warning_calls) |
397 | 231 | mock_log.debug.assert_has_calls(log_debug_calls) | 231 | mock_log.debug.assert_has_calls(log_debug_calls) |
399 | 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' |
400 | 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' |
402 | 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' |
403 | 235 | 235 | ||
404 | 236 | @patch.object(openlp.core.projectors.pjlinkcommands, 'log') | 236 | @patch.object(openlp.core.projectors.pjlinkcommands, 'log') |
405 | 237 | def test_projector_name(self, mock_log): | 237 | def test_projector_name(self, mock_log): |
406 | @@ -253,7 +253,7 @@ | |||
407 | 253 | # THEN: name should be set and logged | 253 | # THEN: name should be set and logged |
408 | 254 | mock_log.warning.assert_has_calls(log_warning_calls) | 254 | mock_log.warning.assert_has_calls(log_warning_calls) |
409 | 255 | mock_log.debug.assert_has_calls(log_debug_calls) | 255 | mock_log.debug.assert_has_calls(log_debug_calls) |
411 | 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' |
412 | 257 | 257 | ||
413 | 258 | @patch.object(openlp.core.projectors.pjlink.PJLink, 'send_command') | 258 | @patch.object(openlp.core.projectors.pjlink.PJLink, 'send_command') |
414 | 259 | @patch.object(openlp.core.projectors.pjlink.PJLink, 'change_status') | 259 | @patch.object(openlp.core.projectors.pjlink.PJLink, 'change_status') |
415 | @@ -276,7 +276,7 @@ | |||
416 | 276 | # THEN: Projector power should not have changed | 276 | # THEN: Projector power should not have changed |
417 | 277 | mock_log.warning.assert_has_calls(log_warning_calls) | 277 | mock_log.warning.assert_has_calls(log_warning_calls) |
418 | 278 | mock_log.debug.assert_has_calls(log_debug_calls) | 278 | mock_log.debug.assert_has_calls(log_debug_calls) |
420 | 279 | assert (S_STANDBY == self.pjlink.power), 'Power should not have changed' | 279 | assert S_STANDBY == self.pjlink.power, 'Power should not have changed' |
421 | 280 | mock_UpdateIcons.emit.assert_not_called() | 280 | mock_UpdateIcons.emit.assert_not_called() |
422 | 281 | mock_change_status.assert_not_called() | 281 | mock_change_status.assert_not_called() |
423 | 282 | mock_send_command.assert_not_called() | 282 | mock_send_command.assert_not_called() |
424 | @@ -302,9 +302,9 @@ | |||
425 | 302 | # THEN: Power should be set to ON | 302 | # THEN: Power should be set to ON |
426 | 303 | mock_log.warning.assert_has_calls(log_warning_calls) | 303 | mock_log.warning.assert_has_calls(log_warning_calls) |
427 | 304 | mock_log.debug.assert_has_calls(log_debug_calls) | 304 | mock_log.debug.assert_has_calls(log_debug_calls) |
429 | 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' |
430 | 306 | assert mock_UpdateIcons.emit.called, 'projectorUpdateIcons should have been called' | 306 | assert mock_UpdateIcons.emit.called, 'projectorUpdateIcons should have been called' |
432 | 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' |
433 | 308 | mock_change_status.assert_called_once_with(S_STANDBY) | 308 | mock_change_status.assert_called_once_with(S_STANDBY) |
434 | 309 | 309 | ||
435 | 310 | @patch.object(openlp.core.projectors.pjlink.PJLink, 'send_command') | 310 | @patch.object(openlp.core.projectors.pjlink.PJLink, 'send_command') |
436 | @@ -328,7 +328,7 @@ | |||
437 | 328 | # THEN: Power should be set to ON | 328 | # THEN: Power should be set to ON |
438 | 329 | mock_log.warning.assert_has_calls(log_warning_calls) | 329 | mock_log.warning.assert_has_calls(log_warning_calls) |
439 | 330 | mock_log.debug.assert_has_calls(log_debug_calls) | 330 | mock_log.debug.assert_has_calls(log_debug_calls) |
441 | 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' |
442 | 332 | assert mock_UpdateIcons.emit.called, 'projectorUpdateIcons should have been called' | 332 | assert mock_UpdateIcons.emit.called, 'projectorUpdateIcons should have been called' |
443 | 333 | mock_send_command.assert_called_once_with('INST') | 333 | mock_send_command.assert_called_once_with('INST') |
444 | 334 | mock_change_status.assert_called_once_with(S_ON) | 334 | mock_change_status.assert_called_once_with(S_ON) |
445 | @@ -352,7 +352,7 @@ | |||
446 | 352 | # THEN: Filter model number should be saved | 352 | # THEN: Filter model number should be saved |
447 | 353 | mock_log.warning.assert_has_calls(log_warning_calls) | 353 | mock_log.warning.assert_has_calls(log_warning_calls) |
448 | 354 | mock_log.debug.assert_has_calls(log_debug_calls) | 354 | mock_log.debug.assert_has_calls(log_debug_calls) |
450 | 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' |
451 | 356 | 356 | ||
452 | 357 | @patch.object(openlp.core.projectors.pjlinkcommands, 'log') | 357 | @patch.object(openlp.core.projectors.pjlinkcommands, 'log') |
453 | 358 | def test_projector_rfil_nosave(self, mock_log): | 358 | def test_projector_rfil_nosave(self, mock_log): |
454 | @@ -374,7 +374,7 @@ | |||
455 | 374 | process_command(projector=self.pjlink, cmd='RFIL', data=new_data) | 374 | process_command(projector=self.pjlink, cmd='RFIL', data=new_data) |
456 | 375 | 375 | ||
457 | 376 | # THEN: Filter model number should be saved | 376 | # THEN: Filter model number should be saved |
459 | 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' |
460 | 378 | mock_log.warning.assert_has_calls(log_warning_calls) | 378 | mock_log.warning.assert_has_calls(log_warning_calls) |
461 | 379 | mock_log.debug.assert_has_calls(log_debug_calls) | 379 | mock_log.debug.assert_has_calls(log_debug_calls) |
462 | 380 | 380 | ||
463 | @@ -397,7 +397,7 @@ | |||
464 | 397 | # THEN: Filter model number should be saved | 397 | # THEN: Filter model number should be saved |
465 | 398 | mock_log.warning.assert_has_calls(log_warning_calls) | 398 | mock_log.warning.assert_has_calls(log_warning_calls) |
466 | 399 | mock_log.debug.assert_has_calls(log_debug_calls) | 399 | mock_log.debug.assert_has_calls(log_debug_calls) |
468 | 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' |
469 | 401 | 401 | ||
470 | 402 | @patch.object(openlp.core.projectors.pjlinkcommands, 'log') | 402 | @patch.object(openlp.core.projectors.pjlinkcommands, 'log') |
471 | 403 | def test_projector_rlmp_nosave(self, mock_log): | 403 | def test_projector_rlmp_nosave(self, mock_log): |
472 | @@ -419,7 +419,7 @@ | |||
473 | 419 | process_command(projector=self.pjlink, cmd='RLMP', data=new_data) | 419 | process_command(projector=self.pjlink, cmd='RLMP', data=new_data) |
474 | 420 | 420 | ||
475 | 421 | # THEN: Filter model number should be saved | 421 | # THEN: Filter model number should be saved |
477 | 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' |
478 | 423 | mock_log.warning.assert_has_calls(log_warning_calls) | 423 | mock_log.warning.assert_has_calls(log_warning_calls) |
479 | 424 | mock_log.debug.assert_has_calls(log_debug_calls) | 424 | mock_log.debug.assert_has_calls(log_debug_calls) |
480 | 425 | 425 | ||
481 | @@ -446,7 +446,7 @@ | |||
482 | 446 | process_command(projector=self.pjlink, cmd='SNUM', data=new_data) | 446 | process_command(projector=self.pjlink, cmd='SNUM', data=new_data) |
483 | 447 | 447 | ||
484 | 448 | # THEN: Serial number should be set | 448 | # THEN: Serial number should be set |
486 | 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' |
487 | 450 | mock_log.warning.assert_has_calls(log_warning_calls) | 450 | mock_log.warning.assert_has_calls(log_warning_calls) |
488 | 451 | mock_log.debug.assert_has_calls(log_debug_calls) | 451 | mock_log.debug.assert_has_calls(log_debug_calls) |
489 | 452 | 452 | ||
490 | @@ -469,7 +469,7 @@ | |||
491 | 469 | process_command(projector=self.pjlink, cmd='SNUM', data=new_data) | 469 | process_command(projector=self.pjlink, cmd='SNUM', data=new_data) |
492 | 470 | 470 | ||
493 | 471 | # THEN: Serial number should be set | 471 | # THEN: Serial number should be set |
495 | 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' |
496 | 473 | mock_log.warning.assert_has_calls(log_warning_calls) | 473 | mock_log.warning.assert_has_calls(log_warning_calls) |
497 | 474 | mock_log.debug.assert_has_calls(log_debug_calls) | 474 | mock_log.debug.assert_has_calls(log_debug_calls) |
498 | 475 | 475 | ||
499 | @@ -497,7 +497,7 @@ | |||
500 | 497 | process_command(self.pjlink, cmd='SVER', data=new_data) | 497 | process_command(self.pjlink, cmd='SVER', data=new_data) |
501 | 498 | 498 | ||
502 | 499 | # THEN: Version information should change | 499 | # THEN: Version information should change |
504 | 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' |
505 | 501 | mock_log.warning.assert_has_calls(log_warning_calls) | 501 | mock_log.warning.assert_has_calls(log_warning_calls) |
506 | 502 | mock_log.debug.assert_has_calls(log_debug_calls) | 502 | mock_log.debug.assert_has_calls(log_debug_calls) |
507 | 503 | 503 | ||
508 | @@ -519,8 +519,8 @@ | |||
509 | 519 | process_command(projector=self.pjlink, cmd='SVER', data=new_data) | 519 | process_command(projector=self.pjlink, cmd='SVER', data=new_data) |
510 | 520 | 520 | ||
511 | 521 | # THEN: Version information should not change | 521 | # THEN: Version information should not change |
514 | 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' |
515 | 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' |
516 | 524 | mock_log.warning.assert_has_calls(log_warning_calls) | 524 | mock_log.warning.assert_has_calls(log_warning_calls) |
517 | 525 | mock_log.debug.assert_has_calls(log_debug_calls) | 525 | mock_log.debug.assert_has_calls(log_debug_calls) |
518 | 526 | 526 | ||
519 | @@ -544,7 +544,7 @@ | |||
520 | 544 | process_command(projector=self.pjlink, cmd='SVER', data=new_data) | 544 | process_command(projector=self.pjlink, cmd='SVER', data=new_data) |
521 | 545 | 545 | ||
522 | 546 | # THEN: Version information should not change | 546 | # THEN: Version information should not change |
525 | 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' |
526 | 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' |
527 | 549 | mock_log.warning.assert_has_calls(log_warning_calls) | 549 | mock_log.warning.assert_has_calls(log_warning_calls) |
528 | 550 | mock_log.debug.assert_has_calls(log_debug_calls) | 550 | mock_log.debug.assert_has_calls(log_debug_calls) |
529 | 551 | 551 | ||
530 | === modified file 'tests/openlp_core/projectors/test_projector_commands_03.py' | |||
531 | --- tests/openlp_core/projectors/test_projector_commands_03.py 2019-05-05 04:08:32 +0000 | |||
532 | +++ tests/openlp_core/projectors/test_projector_commands_03.py 2019-05-15 13:39:42 +0000 | |||
533 | @@ -22,335 +22,232 @@ | |||
534 | 22 | """ | 22 | """ |
535 | 23 | Package to test the openlp.core.projectors.pjlink commands package. | 23 | Package to test the openlp.core.projectors.pjlink commands package. |
536 | 24 | """ | 24 | """ |
538 | 25 | from unittest import TestCase, skip | 25 | from unittest import TestCase |
539 | 26 | from unittest.mock import call, patch | 26 | from unittest.mock import call, patch |
540 | 27 | 27 | ||
541 | 28 | import openlp.core.projectors.pjlink | 28 | import openlp.core.projectors.pjlink |
543 | 29 | from openlp.core.projectors.constants import PJLINK_PORT, S_CONNECTED, S_OFF, S_ON | 29 | from openlp.core.projectors.constants import E_NO_AUTHENTICATION, STATUS_CODE, S_AUTHENTICATE, S_CONNECT |
544 | 30 | from openlp.core.projectors.db import Projector | 30 | from openlp.core.projectors.db import Projector |
547 | 31 | from openlp.core.projectors.pjlink import PJLink, PJLinkUDP | 31 | from openlp.core.projectors.pjlink import PJLink |
548 | 32 | from tests.resources.projector.data import TEST1_DATA, TEST2_DATA, TEST_HASH, TEST_PIN, TEST_SALT | 32 | from openlp.core.projectors.pjlinkcommands import process_command |
549 | 33 | from tests.resources.projector.data import TEST1_DATA, TEST_PIN, TEST_SALT | ||
550 | 33 | 34 | ||
551 | 34 | 35 | ||
552 | 35 | class TestPJLinkCommands(TestCase): | 36 | class TestPJLinkCommands(TestCase): |
553 | 36 | """ | 37 | """ |
555 | 37 | Tests for the PJLinkCommands class part 2 | 38 | Tests PJLink commands part 3 |
556 | 38 | """ | 39 | """ |
633 | 39 | @skip('Needs update to new setup') | 40 | def setUp(self): |
634 | 40 | def test_projector_reset_information(self): | 41 | """ |
635 | 41 | """ | 42 | Initialize test state(s) |
636 | 42 | Test reset_information() resets all information and stops timers | 43 | """ |
637 | 43 | """ | 44 | # Default PJLink instance for tests |
638 | 44 | # GIVEN: Test object | 45 | self.pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True) |
639 | 45 | with patch.object(openlp.core.projectors.pjlink, 'log') as mock_log: | 46 | |
640 | 46 | pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True) | 47 | def tearDown(self): |
641 | 47 | log_debug_calls = [call('({ip}): Calling poll_timer.stop()'.format(ip=pjlink.name)), | 48 | """ |
642 | 48 | call('({ip}): Calling socket_timer.stop()'.format(ip=pjlink.name))] | 49 | Cleanup test state(s) |
643 | 49 | # timer and socket_timer not available until instantiation, so mock here | 50 | """ |
644 | 50 | with patch.object(pjlink, 'socket_timer') as mock_socket_timer, \ | 51 | del(self.pjlink) |
645 | 51 | patch.object(pjlink, 'poll_timer') as mock_timer: | 52 | |
646 | 52 | 53 | @patch.object(openlp.core.projectors.pjlinkcommands, 'log') | |
647 | 53 | pjlink.power = S_ON | 54 | def test_process_pjlink_authenticate(self, mock_log): |
572 | 54 | pjlink.pjlink_name = 'OPENLPTEST' | ||
573 | 55 | pjlink.manufacturer = 'PJLINK' | ||
574 | 56 | pjlink.model = '1' | ||
575 | 57 | pjlink.shutter = True | ||
576 | 58 | pjlink.mute = True | ||
577 | 59 | pjlink.lamp = True | ||
578 | 60 | pjlink.fan = True | ||
579 | 61 | pjlink.source_available = True | ||
580 | 62 | pjlink.other_info = 'ANOTHER TEST' | ||
581 | 63 | pjlink.send_queue = True | ||
582 | 64 | pjlink.send_busy = True | ||
583 | 65 | |||
584 | 66 | # WHEN: reset_information() is called | ||
585 | 67 | pjlink.reset_information() | ||
586 | 68 | |||
587 | 69 | # THEN: All information should be reset and timers stopped | ||
588 | 70 | assert pjlink.power == S_OFF, 'Projector power should be OFF' | ||
589 | 71 | assert pjlink.pjlink_name is None, 'Projector pjlink_name should be None' | ||
590 | 72 | assert pjlink.manufacturer is None, 'Projector manufacturer should be None' | ||
591 | 73 | assert pjlink.model is None, 'Projector model should be None' | ||
592 | 74 | assert pjlink.shutter is None, 'Projector shutter should be None' | ||
593 | 75 | assert pjlink.mute is None, 'Projector shuttter should be None' | ||
594 | 76 | assert pjlink.lamp is None, 'Projector lamp should be None' | ||
595 | 77 | assert pjlink.fan is None, 'Projector fan should be None' | ||
596 | 78 | assert pjlink.source_available is None, 'Projector source_available should be None' | ||
597 | 79 | assert pjlink.source is None, 'Projector source should be None' | ||
598 | 80 | assert pjlink.other_info is None, 'Projector other_info should be None' | ||
599 | 81 | assert pjlink.send_queue == [], 'Projector send_queue should be an empty list' | ||
600 | 82 | assert pjlink.send_busy is False, 'Projector send_busy should be False' | ||
601 | 83 | assert mock_timer.stop.called is True, 'Projector timer.stop() should have been called' | ||
602 | 84 | assert mock_socket_timer.stop.called is True, 'Projector socket_timer.stop() should have been called' | ||
603 | 85 | mock_log.debug.assert_has_calls(log_debug_calls) | ||
604 | 86 | |||
605 | 87 | @skip('Needs update to new setup') | ||
606 | 88 | def test_process_pjlink_normal(self): | ||
607 | 89 | """ | ||
608 | 90 | Test initial connection prompt with no authentication | ||
609 | 91 | """ | ||
610 | 92 | # GIVEN: Initial mocks and data | ||
611 | 93 | mock_log = patch.object(openlp.core.projectors.pjlink, "log").start() | ||
612 | 94 | mock_disconnect_from_host = patch('openlp.core.projectors.pjlink.PJLink.disconnect_from_host').start() | ||
613 | 95 | mock_send_command = patch('openlp.core.projectors.pjlink.PJLink.send_command').start() | ||
614 | 96 | mock_readyRead = patch('openlp.core.projectors.pjlink.PJLink.readyRead').start() | ||
615 | 97 | mock_change_status = patch('openlp.core.projectors.pjlink.PJLink.change_status').start() | ||
616 | 98 | |||
617 | 99 | pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True) | ||
618 | 100 | pjlink.pin = None | ||
619 | 101 | log_check = [call('({ip}) process_pjlink(): Sending "CLSS" initial command'.format(ip=pjlink.name)), ] | ||
620 | 102 | |||
621 | 103 | # WHEN: process_pjlink called with no authentication required | ||
622 | 104 | pjlink.process_pjlink(data="0") | ||
623 | 105 | |||
624 | 106 | # THEN: proper processing should have occured | ||
625 | 107 | mock_log.debug.has_calls(log_check) | ||
626 | 108 | mock_disconnect_from_host.assert_not_called() | ||
627 | 109 | assert 1 == mock_readyRead.connect.call_count, 'Should have only been called once' | ||
628 | 110 | mock_change_status.assert_called_once_with(S_CONNECTED) | ||
629 | 111 | mock_send_command.assert_called_with(cmd='CLSS', priority=True, salt=None) | ||
630 | 112 | |||
631 | 113 | @skip('Needs update to new setup') | ||
632 | 114 | def test_process_pjlink_authenticate(self): | ||
648 | 115 | """ | 55 | """ |
649 | 116 | Test initial connection prompt with authentication | 56 | Test initial connection prompt with authentication |
650 | 117 | """ | 57 | """ |
651 | 118 | # GIVEN: Initial mocks and data | 58 | # GIVEN: Initial mocks and data |
890 | 119 | mock_log = patch.object(openlp.core.projectors.pjlink, "log").start() | 59 | log_error_calls = [] |
891 | 120 | mock_disconnect_from_host = patch('openlp.core.projectors.pjlink.PJLink.disconnect_from_host').start() | 60 | log_warning_calls = [] |
892 | 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, |
893 | 122 | mock_readyRead = patch('openlp.core.projectors.pjlink.PJLink.readyRead').start() | 62 | data=TEST_SALT)), |
894 | 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)), |
895 | 124 | 64 | call('({ip}) Processing PJLINK command'.format(ip=self.pjlink.name)), | |
896 | 125 | pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True) | 65 | call('({ip}) PJLINK: Returning {data}'.format(ip=self.pjlink.name, |
897 | 126 | pjlink.pin = TEST_PIN | 66 | data=STATUS_CODE[S_AUTHENTICATE]))] |
898 | 127 | log_check = [call('({ip}) process_pjlink(): Sending "CLSS" initial command'.format(ip=pjlink.name)), ] | 67 | |
899 | 128 | 68 | self.pjlink.pin = TEST_PIN | |
900 | 129 | # WHEN: process_pjlink called with no authentication required | 69 | |
901 | 130 | pjlink.process_pjlink(data='1 {salt}'.format(salt=TEST_SALT)) | 70 | # WHEN: process_pjlink called with no authentication required |
902 | 131 | 71 | chk = process_command(projector=self.pjlink, cmd='PJLINK', data='1 {salt}'.format(salt=TEST_SALT)) | |
903 | 132 | # THEN: proper processing should have occured | 72 | |
904 | 133 | mock_log.debug.has_calls(log_check) | 73 | # THEN: proper processing should have occured |
905 | 134 | mock_disconnect_from_host.assert_not_called() | 74 | mock_log.error.assert_has_calls(log_error_calls) |
906 | 135 | assert 1 == mock_readyRead.connect.call_count, 'Should have only been called once' | 75 | mock_log.warning.assert_has_calls(log_warning_calls) |
907 | 136 | mock_change_status.assert_called_once_with(S_CONNECTED) | 76 | mock_log.debug.assert_has_calls(log_debug_calls) |
908 | 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]) |
909 | 138 | 78 | ||
910 | 139 | @skip('Needs update to new setup') | 79 | @patch.object(openlp.core.projectors.pjlinkcommands, 'log') |
911 | 140 | def test_process_pjlink_normal_pin_set_error(self): | 80 | def test_process_pjlink_authenticate_pin_not_set_error(self, mock_log): |
912 | 141 | """ | 81 | """ |
913 | 142 | Test process_pjlinnk called with no authentication but pin is set | 82 | Test initial connection prompt with authentication and no pin set |
914 | 143 | """ | 83 | """ |
915 | 144 | # GIVEN: Initial mocks and data | 84 | # GIVEN: Initial mocks and data |
916 | 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))] |
917 | 146 | mock_disconnect_from_host = patch('openlp.core.projectors.pjlink.PJLink.disconnect_from_host').start() | 86 | log_warning_calls = [] |
918 | 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, |
919 | 148 | 88 | data=TEST_SALT)), | |
920 | 149 | pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True) | 89 | call('({ip}) Calling function for PJLINK'.format(ip=self.pjlink.name)), |
921 | 150 | pjlink.pin = TEST_PIN | 90 | call('({ip}) Processing PJLINK command'.format(ip=self.pjlink.name))] |
922 | 151 | log_check = [call('({ip}) Normal connection but PIN set - aborting'.format(ip=pjlink.name)), ] | 91 | |
923 | 152 | 92 | self.pjlink.pin = None | |
924 | 153 | # WHEN: process_pjlink called with invalid authentication scheme | 93 | |
925 | 154 | pjlink.process_pjlink(data='0') | 94 | # WHEN: process_pjlink called with no authentication required |
926 | 155 | 95 | chk = process_command(projector=self.pjlink, cmd='PJLINK', data='1 {salt}'.format(salt=TEST_SALT)) | |
927 | 156 | # THEN: Proper calls should be made | 96 | |
928 | 157 | mock_log.error.assert_has_calls(log_check) | 97 | # THEN: proper processing should have occured |
929 | 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) |
930 | 159 | mock_send_command.assert_not_called() | 99 | mock_log.warning.assert_has_calls(log_warning_calls) |
931 | 160 | 100 | mock_log.debug.assert_has_calls(log_debug_calls) | |
932 | 161 | @skip('Needs update to new setup') | 101 | assert chk == E_NO_AUTHENTICATION, \ |
933 | 162 | def test_process_pjlink_normal_with_salt_error(self): | 102 | 'Should have returned {data}'.format(data=STATUS_CODE[E_NO_AUTHENTICATION]) |
934 | 163 | """ | 103 | |
935 | 164 | Test process_pjlinnk called with no authentication but pin is set | 104 | @patch.object(openlp.core.projectors.pjlinkcommands, 'log') |
936 | 165 | """ | 105 | def test_process_pjlink_authenticate_token_invalid(self, mock_log): |
937 | 166 | # GIVEN: Initial mocks and data | 106 | """ |
938 | 167 | mock_log = patch.object(openlp.core.projectors.pjlink, 'log').start() | 107 | Test initial connection prompt with authentication and bad token |
939 | 168 | mock_disconnect_from_host = patch('openlp.core.projectors.pjlink.PJLink.disconnect_from_host').start() | 108 | """ |
940 | 169 | mock_send_command = patch('openlp.core.projectors.pjlink.PJLink.send_command').start() | 109 | # GIVEN: Initial mocks and data |
941 | 170 | 110 | bad_token = 'abcdefgh' | |
942 | 171 | pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True) | 111 | log_error_calls = [call('({ip}) Authentication token invalid (not a hexadecimal number) - ' |
943 | 172 | pjlink.pin = TEST_PIN | 112 | 'aborting'.format(ip=self.pjlink.name))] |
944 | 173 | log_check = [call('({ip}) Normal connection with extra information - aborting'.format(ip=pjlink.name)), ] | 113 | log_warning_calls = [] |
945 | 174 | 114 | log_debug_calls = [call('({ip}) Processing command "PJLINK" with data ' | |
946 | 175 | # WHEN: process_pjlink called with invalid authentication scheme | 115 | '"1 {data}"'.format(ip=self.pjlink.name, data=bad_token)), |
947 | 176 | pjlink.process_pjlink(data='0 {salt}'.format(salt=TEST_SALT)) | 116 | call('({ip}) Calling function for PJLINK'.format(ip=self.pjlink.name)), |
948 | 177 | 117 | call('({ip}) Processing PJLINK command'.format(ip=self.pjlink.name))] | |
949 | 178 | # THEN: Proper calls should be made | 118 | self.pjlink.pin = TEST_SALT |
950 | 179 | mock_log.error.assert_has_calls(log_check) | 119 | |
951 | 180 | assert 1 == mock_disconnect_from_host.call_count, 'Should have only been called once' | 120 | # WHEN: process_pjlink called with bad token |
952 | 181 | mock_send_command.assert_not_called() | 121 | chk = process_command(projector=self.pjlink, cmd='PJLINK', data='1 {data}'.format(data=bad_token)) |
953 | 182 | 122 | ||
954 | 183 | @skip('Needs update to new setup') | 123 | # THEN: proper processing should have occured |
955 | 184 | def test_process_pjlink_invalid_authentication_scheme_length_error(self): | 124 | mock_log.error.assert_has_calls(log_error_calls) |
956 | 185 | """ | 125 | mock_log.warning.assert_has_calls(log_warning_calls) |
957 | 186 | Test initial connection prompt with authentication scheme longer than 1 character | 126 | mock_log.debug.assert_has_calls(log_debug_calls) |
958 | 187 | """ | 127 | assert chk == E_NO_AUTHENTICATION, \ |
959 | 188 | # GIVEN: Initial mocks and data | 128 | 'Should have returned {data}'.format(data=STATUS_CODE[E_NO_AUTHENTICATION]) |
960 | 189 | mock_log = patch.object(openlp.core.projectors.pjlink, 'log').start() | 129 | |
961 | 190 | mock_disconnect_from_host = patch('openlp.core.projectors.pjlink.PJLink.disconnect_from_host').start() | 130 | @patch.object(openlp.core.projectors.pjlinkcommands, 'log') |
962 | 191 | mock_send_command = patch('openlp.core.projectors.pjlink.PJLink.send_command').start() | 131 | def test_process_pjlink_authenticate_token_length(self, mock_log): |
963 | 192 | 132 | """ | |
964 | 193 | pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True) | 133 | Test initial connection prompt with authentication and bad token |
965 | 194 | log_check = [call('({ip}) Invalid initial authentication scheme - aborting'.format(ip=pjlink.name)), ] | 134 | """ |
966 | 195 | 135 | # GIVEN: Initial mocks and data | |
967 | 196 | # WHEN: process_pjlink called with invalid authentication scheme | 136 | bad_token = '1234abcde' # Length should be 8, this is 9 |
968 | 197 | pjlink.process_pjlink(data='01') | 137 | log_error_calls = [call('({ip}) Authentication token invalid (size) - ' |
969 | 198 | 138 | 'aborting'.format(ip=self.pjlink.name))] | |
970 | 199 | # THEN: socket should be closed and invalid data logged | 139 | log_warning_calls = [] |
971 | 200 | mock_log.error.assert_has_calls(log_check) | 140 | log_debug_calls = [call('({ip}) Processing command "PJLINK" with data ' |
972 | 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)), |
973 | 202 | mock_send_command.assert_not_called() | 142 | call('({ip}) Calling function for PJLINK'.format(ip=self.pjlink.name)), |
974 | 203 | 143 | call('({ip}) Processing PJLINK command'.format(ip=self.pjlink.name))] | |
975 | 204 | @skip('Needs update to new setup') | 144 | self.pjlink.pin = TEST_SALT |
976 | 205 | def test_process_pjlink_invalid_authentication_data_length_error(self): | 145 | |
977 | 206 | """ | 146 | # WHEN: process_pjlink called with bad token |
978 | 207 | Test initial connection prompt with authentication no salt | 147 | chk = process_command(projector=self.pjlink, cmd='PJLINK', data='1 {data}'.format(data=bad_token)) |
979 | 208 | """ | 148 | |
980 | 209 | # GIVEN: Initial mocks and data | 149 | # THEN: proper processing should have occured |
981 | 210 | mock_log = patch.object(openlp.core.projectors.pjlink, 'log').start() | 150 | mock_log.error.assert_has_calls(log_error_calls) |
982 | 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) |
983 | 212 | mock_send_command = patch('openlp.core.projectors.pjlink.PJLink.send_command').start() | 152 | mock_log.debug.assert_has_calls(log_debug_calls) |
984 | 213 | 153 | assert chk == E_NO_AUTHENTICATION, \ | |
985 | 214 | pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True) | 154 | 'Should have returned {data}'.format(data=STATUS_CODE[E_NO_AUTHENTICATION]) |
986 | 215 | log_check = [call('({ip}) Authenticated connection but not enough info - aborting'.format(ip=pjlink.name)), ] | 155 | |
987 | 216 | 156 | @patch.object(openlp.core.projectors.pjlinkcommands, 'log') | |
988 | 217 | # WHEN: process_pjlink called with no salt | 157 | def test_process_pjlink_authenticate_token_missing(self, mock_log): |
989 | 218 | pjlink.process_pjlink(data='1') | 158 | """ |
990 | 219 | 159 | Test initial connection prompt with authentication and missing token | |
991 | 220 | # THEN: socket should be closed and invalid data logged | 160 | """ |
992 | 221 | mock_log.error.assert_has_calls(log_check) | 161 | # GIVEN: Initial mocks and data |
993 | 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 - ' |
994 | 223 | mock_send_command.assert_not_called() | 163 | 'aborting'.format(ip=self.pjlink.name))] |
995 | 224 | 164 | log_warning_calls = [] | |
996 | 225 | @skip('Needs update to new setup') | 165 | log_debug_calls = [call('({ip}) Processing command "PJLINK" with data "1"'.format(ip=self.pjlink.name)), |
997 | 226 | def test_process_pjlink_authenticate_pin_not_set_error(self): | 166 | call('({ip}) Calling function for PJLINK'.format(ip=self.pjlink.name)), |
998 | 227 | """ | 167 | call('({ip}) Processing PJLINK command'.format(ip=self.pjlink.name))] |
999 | 228 | Test process_pjlink authentication but pin not set | 168 | |
1000 | 229 | """ | 169 | self.pjlink.pin = TEST_SALT |
1001 | 230 | # GIVEN: Initial mocks and data | 170 | |
1002 | 231 | mock_log = patch.object(openlp.core.projectors.pjlink, 'log').start() | 171 | # WHEN: process_pjlink called with bad token |
1003 | 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') |
1004 | 233 | mock_send_command = patch('openlp.core.projectors.pjlink.PJLink.send_command').start() | 173 | |
1005 | 234 | 174 | # THEN: proper processing should have occured | |
1006 | 235 | pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True) | 175 | mock_log.error.assert_has_calls(log_error_calls) |
1007 | 236 | pjlink.pin = None | 176 | mock_log.warning.assert_has_calls(log_warning_calls) |
1008 | 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) |
1009 | 238 | 178 | assert chk == E_NO_AUTHENTICATION, \ | |
1010 | 239 | # WHEN: process_pjlink called with no salt | 179 | 'Should have returned {data}'.format(data=STATUS_CODE[E_NO_AUTHENTICATION]) |
1011 | 240 | pjlink.process_pjlink(data='1 {salt}'.format(salt=TEST_SALT)) | 180 | |
1012 | 241 | 181 | @patch.object(openlp.core.projectors.pjlinkcommands, 'log') | |
1013 | 242 | # THEN: socket should be closed and invalid data logged | 182 | def test_process_pjlink_normal(self, mock_log): |
1014 | 243 | mock_log.error.assert_has_calls(log_check) | 183 | """ |
1015 | 244 | assert 1 == mock_disconnect_from_host.call_count, 'Should have only been called once' | 184 | Test processing PJLINK initial prompt |
1016 | 245 | mock_send_command.assert_not_called() | 185 | """ |
1017 | 246 | 186 | # GIVEN: Mocks and data | |
1018 | 247 | @skip('Change to pjlink_udp.get_datagram() call') | 187 | log_error_calls = [] |
1019 | 248 | @patch.object(openlp.core.projectors.pjlink, 'log') | 188 | log_warning_calls = [] |
1020 | 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)), |
1021 | 250 | """ | 190 | call('({ip}) Calling function for PJLINK'.format(ip=self.pjlink.name)), |
1022 | 251 | Test process_ackn method with multiple calls with same data | 191 | call('({ip}) Processing PJLINK command'.format(ip=self.pjlink.name)), |
1023 | 252 | """ | 192 | call('({ip}) PJLINK: Returning {data}'.format(ip=self.pjlink.name, |
1024 | 253 | # TODO: Change this to call pjlink_udp.get_datagram() so ACKN can be processed properly | 193 | data=STATUS_CODE[S_CONNECT]))] |
1025 | 254 | 194 | ||
1026 | 255 | # GIVEN: Test setup | 195 | self.pjlink.pin = None |
1027 | 256 | pjlink = PJLink(projector=self.test_list[0]) | 196 | |
1028 | 257 | check_list = {TEST1_DATA['ip']: {'data': TEST1_DATA['mac_adx'], 'port': PJLINK_PORT}} | 197 | # WHEN: process_pjlink called with no authentication required |
1029 | 258 | log_warn_calls = [call('(___TEST_ONE___) Host {host} already replied - ' | 198 | chk = process_command(projector=self.pjlink, cmd='PJLINK', data="0") |
1030 | 259 | 'ignoring'.format(host=TEST1_DATA['ip']))] | 199 | |
1031 | 260 | log_debug_calls = [call('PJlinkCommands(args=() kwargs={})'), | 200 | # THEN: proper processing should have occured |
1032 | 261 | call('(___TEST_ONE___) reset_information() connect status is S_NOT_CONNECTED'), | 201 | mock_log.error.assert_has_calls(log_error_calls) |
1033 | 262 | call('(___TEST_ONE___) Processing ACKN packet'), | 202 | mock_log.warning.assert_has_calls(log_warning_calls) |
1034 | 263 | call('(___TEST_ONE___) Adding {host} to ACKN list'.format(host=TEST1_DATA['ip'])), | 203 | mock_log.debug.assert_has_calls(log_debug_calls) |
1035 | 264 | call('(___TEST_ONE___) Processing ACKN packet')] | 204 | assert chk == S_CONNECT, 'Should have returned {data}'.format(data=STATUS_CODE[S_CONNECT]) |
1036 | 265 | 205 | ||
1037 | 266 | # WHEN: process_ackn called twice with same data | 206 | @patch.object(openlp.core.projectors.pjlinkcommands, 'log') |
1038 | 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): |
1039 | 268 | pjlink.process_ackn(data=TEST1_DATA['mac_adx'], host=TEST1_DATA['ip'], port=PJLINK_PORT) | 208 | """ |
1040 | 269 | 209 | Test process_pjlinnk called with no authentication but pin is set | |
1041 | 270 | # THEN: pjlink_udp.ack_list should equal test_list | 210 | """ |
1042 | 271 | # NOTE: This assert only returns AssertionError - does not list differences. Maybe add a compare function? | 211 | # GIVEN: Initial mocks and data |
1043 | 272 | if pjlink.ackn_list != check_list: | 212 | log_error_calls = [call('({ip}) Normal connection but PIN set - ' |
1044 | 273 | # Check this way so we can print differences to stdout | 213 | 'aborting'.format(ip=self.pjlink.name))] |
1045 | 274 | print('\nackn_list: ', pjlink.ackn_list) | 214 | log_warning_calls = [] |
1046 | 275 | print('test_list: ', check_list, '\n') | 215 | log_debug_calls = [call('({ip}) Processing command "PJLINK" with data "0"'.format(ip=self.pjlink.name)), |
1047 | 276 | assert pjlink.ackn_list == check_list | 216 | call('({ip}) Calling function for PJLINK'.format(ip=self.pjlink.name)), |
1048 | 277 | mock_log.debug.assert_has_calls(log_debug_calls) | 217 | call('({ip}) Processing PJLINK command'.format(ip=self.pjlink.name))] |
1049 | 278 | mock_log.warning.assert_has_calls(log_warn_calls) | 218 | self.pjlink.pin = TEST_PIN |
1050 | 279 | 219 | ||
1051 | 280 | @skip('Change to pjlink_udp.get_datagram() call') | 220 | # WHEN: process_pjlink called with invalid authentication scheme |
1052 | 281 | @patch.object(openlp.core.projectors.pjlink, 'log') | 221 | chk = process_command(projector=self.pjlink, cmd='PJLINK', data='0') |
1053 | 282 | def test_process_ackn_multiple(self, mock_log): | 222 | |
1054 | 283 | """ | 223 | # THEN: Proper calls should be made |
1055 | 284 | Test process_ackn method with multiple calls | 224 | mock_log.error.assert_has_calls(log_error_calls) |
1056 | 285 | """ | 225 | mock_log.warning.assert_has_calls(log_warning_calls) |
1057 | 286 | # TODO: Change this to call pjlink_udp.get_datagram() so ACKN can be processed properly | 226 | mock_log.debug.assert_has_calls(log_debug_calls) |
1058 | 287 | 227 | assert chk == E_NO_AUTHENTICATION, \ | |
1059 | 288 | # GIVEN: Test setup | 228 | 'Should have returned {data}'.format(data=STATUS_CODE[E_NO_AUTHENTICATION]) |
1060 | 289 | pjlink_udp = PJLinkUDP(projector_list=self.test_list) | 229 | |
1061 | 290 | check_list = {TEST1_DATA['ip']: {'data': TEST1_DATA['mac_adx'], 'port': PJLINK_PORT}, | 230 | @patch.object(openlp.core.projectors.pjlinkcommands, 'log') |
1062 | 291 | TEST2_DATA['ip']: {'data': TEST2_DATA['mac_adx'], 'port': PJLINK_PORT}} | 231 | def test_process_pjlink_normal_with_token(self, mock_log): |
1063 | 292 | log_debug_calls = [call('(UDP) PJLinkUDP() Initialized'), | 232 | """ |
1064 | 293 | call('(UDP) Processing ACKN packet'), | 233 | Test process_pjlinnk called with no authentication but pin is set |
1065 | 294 | call('(UDP) Adding {host} to ACKN list'.format(host=TEST1_DATA['ip'])), | 234 | """ |
1066 | 295 | call('(UDP) Processing ACKN packet'), | 235 | # GIVEN: Initial mocks and data |
1067 | 296 | call('(UDP) Adding {host} to ACKN list'.format(host=TEST2_DATA['ip']))] | 236 | log_error_calls = [call('({ip}) Normal connection with extra information - ' |
1068 | 297 | 237 | 'aborting'.format(ip=self.pjlink.name))] | |
1069 | 298 | # WHEN: process_ackn called twice with different data | 238 | log_warning_calls = [] |
1070 | 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 ' |
1071 | 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)), |
1072 | 301 | 241 | call('({ip}) Calling function for PJLINK'.format(ip=self.pjlink.name)), | |
1073 | 302 | # THEN: pjlink_udp.ack_list should equal test_list | 242 | call('({ip}) Processing PJLINK command'.format(ip=self.pjlink.name))] |
1074 | 303 | # NOTE: This assert only returns AssertionError - does not list differences. Maybe add a compare function? | 243 | self.pjlink.pin = TEST_PIN |
1075 | 304 | if pjlink_udp.ackn_list != check_list: | 244 | |
1076 | 305 | # Check this way so we can print differences to stdout | 245 | # WHEN: process_pjlink called with invalid authentication scheme |
1077 | 306 | print('\nackn_list: ', pjlink_udp.ackn_list) | 246 | chk = process_command(projector=self.pjlink, cmd='PJLINK', data='0 {data}'.format(data=TEST_SALT)) |
1078 | 307 | print('test_list: ', check_list) | 247 | |
1079 | 308 | assert pjlink_udp.ackn_list == check_list | 248 | # THEN: Proper calls should be made |
1080 | 309 | mock_log.debug.assert_has_calls(log_debug_calls) | 249 | mock_log.error.assert_has_calls(log_error_calls) |
1081 | 310 | 250 | mock_log.warning.assert_has_calls(log_warning_calls) | |
1082 | 311 | @skip('Change to pjlink_udp.get_datagram() call') | 251 | mock_log.debug.assert_has_calls(log_debug_calls) |
1083 | 312 | @patch.object(openlp.core.projectors.pjlink, 'log') | 252 | assert chk == E_NO_AUTHENTICATION, \ |
1084 | 313 | def test_process_ackn_single(self, mock_log): | 253 | 'Should have returned {data}'.format(data=STATUS_CODE[E_NO_AUTHENTICATION]) |
847 | 314 | """ | ||
848 | 315 | Test process_ackn method with single call | ||
849 | 316 | """ | ||
850 | 317 | # TODO: Change this to call pjlink_udp.get_datagram() so ACKN can be processed properly | ||
851 | 318 | |||
852 | 319 | # GIVEN: Test setup | ||
853 | 320 | pjlink_udp = PJLinkUDP(projector_list=self.test_list) | ||
854 | 321 | check_list = {TEST1_DATA['ip']: {'data': TEST1_DATA['mac_adx'], 'port': PJLINK_PORT}} | ||
855 | 322 | log_debug_calls = [call('(UDP) PJLinkUDP() Initialized'), | ||
856 | 323 | call('(UDP) Processing ACKN packet'), | ||
857 | 324 | call('(UDP) Adding {host} to ACKN list'.format(host=TEST1_DATA['ip']))] | ||
858 | 325 | |||
859 | 326 | # WHEN: process_ackn called twice with different data | ||
860 | 327 | pjlink_udp.process_ackn(data=TEST1_DATA['mac_adx'], host=TEST1_DATA['ip'], port=PJLINK_PORT) | ||
861 | 328 | |||
862 | 329 | # THEN: pjlink_udp.ack_list should equal test_list | ||
863 | 330 | # NOTE: This assert only returns AssertionError - does not list differences. Maybe add a compare function? | ||
864 | 331 | if pjlink_udp.ackn_list != check_list: | ||
865 | 332 | # Check this way so we can print differences to stdout | ||
866 | 333 | print('\nackn_list: ', pjlink_udp.ackn_list) | ||
867 | 334 | print('test_list: ', check_list) | ||
868 | 335 | assert pjlink_udp.ackn_list == check_list | ||
869 | 336 | mock_log.debug.assert_has_calls(log_debug_calls) | ||
870 | 337 | |||
871 | 338 | @skip('Change to pjlink_udp.get_datagram() call') | ||
872 | 339 | @patch.object(openlp.core.projectors.pjlink, 'log') | ||
873 | 340 | def test_process_srch(self, mock_log): | ||
874 | 341 | """ | ||
875 | 342 | Test process_srch method | ||
876 | 343 | """ | ||
877 | 344 | # TODO: Change this to call pjlink_udp.get_datagram() so ACKN can be processed properly | ||
878 | 345 | |||
879 | 346 | # GIVEN: Test setup | ||
880 | 347 | log_warn_calls = [call('(UDP) SRCH packet received from {ip} - ignoring'.format(ip=TEST1_DATA['ip'])), ] | ||
881 | 348 | log_debug_calls = [call('(UDP) PJLinkUDP() Initialized'), ] | ||
882 | 349 | pjlink_udp = PJLinkUDP(projector_list=self.test_list) | ||
883 | 350 | |||
884 | 351 | # WHEN: process_srch called | ||
885 | 352 | pjlink_udp.process_srch(data=None, host=TEST1_DATA['ip'], port=PJLINK_PORT) | ||
886 | 353 | |||
887 | 354 | # THEN: log entries should be entered | ||
888 | 355 | mock_log.warning.assert_has_calls(log_warn_calls) | ||
889 | 356 | mock_log.debug.assert_has_calls(log_debug_calls) | ||
1085 | 357 | 254 | ||
1086 | === modified file 'tests/openlp_core/projectors/test_projector_pjlink_base_01.py' | |||
1087 | --- tests/openlp_core/projectors/test_projector_pjlink_base_01.py 2019-04-28 19:21:23 +0000 | |||
1088 | +++ tests/openlp_core/projectors/test_projector_pjlink_base_01.py 2019-05-15 13:39:42 +0000 | |||
1089 | @@ -20,7 +20,7 @@ | |||
1090 | 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/>. # |
1091 | 21 | ########################################################################## | 21 | ########################################################################## |
1092 | 22 | """ | 22 | """ |
1094 | 23 | Package to test the openlp.core.projectors.pjlink base package. | 23 | Package to test the openlp.core.projectors.pjlink base package part 1. |
1095 | 24 | """ | 24 | """ |
1096 | 25 | from unittest import TestCase | 25 | from unittest import TestCase |
1097 | 26 | from unittest.mock import MagicMock, call, patch | 26 | from unittest.mock import MagicMock, call, patch |
1098 | 27 | 27 | ||
1099 | === modified file 'tests/openlp_core/projectors/test_projector_pjlink_base_02.py' | |||
1100 | --- tests/openlp_core/projectors/test_projector_pjlink_base_02.py 2019-05-05 04:08:32 +0000 | |||
1101 | +++ tests/openlp_core/projectors/test_projector_pjlink_base_02.py 2019-05-15 13:39:42 +0000 | |||
1102 | @@ -20,7 +20,7 @@ | |||
1103 | 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/>. # |
1104 | 21 | ########################################################################## | 21 | ########################################################################## |
1105 | 22 | """ | 22 | """ |
1107 | 23 | Package to test the openlp.core.projectors.pjlink base package. | 23 | Package to test the openlp.core.projectors.pjlink base package part 2. |
1108 | 24 | """ | 24 | """ |
1109 | 25 | from unittest import TestCase | 25 | from unittest import TestCase |
1110 | 26 | from unittest.mock import call, patch | 26 | from unittest.mock import call, patch |
1111 | @@ -96,10 +96,10 @@ | |||
1112 | 96 | mock_log.warning.assert_has_calls(log_warning_calls) | 96 | mock_log.warning.assert_has_calls(log_warning_calls) |
1113 | 97 | mock_log.debug.assert_has_calls(log_debug_calls) | 97 | mock_log.debug.assert_has_calls(log_debug_calls) |
1114 | 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') |
1117 | 99 | assert (not self.pjlink.send_queue), 'Send queue should be empty' | 99 | assert not self.pjlink.send_queue, 'Send queue should be empty' |
1118 | 100 | assert (not self.pjlink.priority_queue), 'Priority queue should be empty' | 100 | assert not self.pjlink.priority_queue, 'Priority queue should be empty' |
1119 | 101 | assert mock_timer.start.called, 'Timer should have been called' | 101 | assert mock_timer.start.called, 'Timer should have been called' |
1121 | 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' |
1122 | 103 | assert mock_disconnect.called, 'disconnect_from_host() should have been called' | 103 | assert mock_disconnect.called, 'disconnect_from_host() should have been called' |
1123 | 104 | assert self.pjlink.send_busy, 'send_busy should be True' | 104 | assert self.pjlink.send_busy, 'send_busy should be True' |
1124 | 105 | 105 | ||
1125 | @@ -127,10 +127,10 @@ | |||
1126 | 127 | mock_log.error.assert_has_calls(log_error_calls) | 127 | mock_log.error.assert_has_calls(log_error_calls) |
1127 | 128 | mock_log.warning.assert_has_calls(log_warning_calls) | 128 | mock_log.warning.assert_has_calls(log_warning_calls) |
1128 | 129 | mock_log.debug.assert_has_calls(log_debug_calls) | 129 | mock_log.debug.assert_has_calls(log_debug_calls) |
1133 | 130 | assert (not self.pjlink.send_queue), 'Send queue should be empty' | 130 | assert not self.pjlink.send_queue, 'Send queue should be empty' |
1134 | 131 | assert (not self.pjlink.priority_queue), 'Priority queue should be empty' | 131 | assert not self.pjlink.priority_queue, 'Priority queue should be empty' |
1135 | 132 | assert (not mock_timer.called), 'Timer should not have been called' | 132 | assert not mock_timer.called, 'Timer should not have been called' |
1136 | 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' |
1137 | 134 | 134 | ||
1138 | 135 | @patch.object(openlp.core.projectors.pjlink.PJLink, 'write') | 135 | @patch.object(openlp.core.projectors.pjlink.PJLink, 'write') |
1139 | 136 | @patch.object(openlp.core.projectors.pjlink.PJLink, 'disconnect_from_host') | 136 | @patch.object(openlp.core.projectors.pjlink.PJLink, 'disconnect_from_host') |
1140 | @@ -173,11 +173,11 @@ | |||
1141 | 173 | mock_log.error.assert_has_calls(log_error_calls) | 173 | mock_log.error.assert_has_calls(log_error_calls) |
1142 | 174 | mock_log.warning.assert_has_calls(log_warning_calls) | 174 | mock_log.warning.assert_has_calls(log_warning_calls) |
1143 | 175 | mock_log.debug.assert_has_calls(log_debug_calls) | 175 | mock_log.debug.assert_has_calls(log_debug_calls) |
1146 | 176 | assert (not self.pjlink.send_queue), 'Send queue should be empty' | 176 | assert not self.pjlink.send_queue, 'Send queue should be empty' |
1147 | 177 | assert (not self.pjlink.priority_queue), 'Priority queue should be empty' | 177 | assert not self.pjlink.priority_queue, 'Priority queue should be empty' |
1148 | 178 | assert mock_timer.start.called, 'Timer should have been called' | 178 | assert mock_timer.start.called, 'Timer should have been called' |
1151 | 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' |
1152 | 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' |
1153 | 181 | assert self.pjlink.send_busy, 'send_busy flag should be True' | 181 | assert self.pjlink.send_busy, 'send_busy flag should be True' |
1154 | 182 | 182 | ||
1155 | 183 | @patch.object(openlp.core.projectors.pjlink.PJLink, 'disconnect_from_host') | 183 | @patch.object(openlp.core.projectors.pjlink.PJLink, 'disconnect_from_host') |
1156 | @@ -211,12 +211,12 @@ | |||
1157 | 211 | mock_log.error.assert_has_calls(log_error_calls) | 211 | mock_log.error.assert_has_calls(log_error_calls) |
1158 | 212 | mock_log.warning.assert_has_calls(log_warning_calls) | 212 | mock_log.warning.assert_has_calls(log_warning_calls) |
1159 | 213 | mock_log.debug.assert_has_calls(log_debug_calls) | 213 | mock_log.debug.assert_has_calls(log_debug_calls) |
1164 | 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' |
1165 | 215 | assert (not self.pjlink.priority_queue), 'Priority queue should be empty' | 215 | assert not self.pjlink.priority_queue, 'Priority queue should be empty' |
1166 | 216 | assert (not mock_timer.called), 'Timer should not have been called' | 216 | assert not mock_timer.called, 'Timer should not have been called' |
1167 | 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' |
1168 | 218 | assert mock_disconnect.called, 'disconnect_from_host() should have been called' | 218 | assert mock_disconnect.called, 'disconnect_from_host() should have been called' |
1170 | 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' |
1171 | 220 | 220 | ||
1172 | 221 | @patch.object(openlp.core.projectors.pjlink.PJLink, 'write') | 221 | @patch.object(openlp.core.projectors.pjlink.PJLink, 'write') |
1173 | 222 | @patch.object(openlp.core.projectors.pjlink.PJLink, 'disconnect_from_host') | 222 | @patch.object(openlp.core.projectors.pjlink.PJLink, 'disconnect_from_host') |
1174 | @@ -261,11 +261,11 @@ | |||
1175 | 261 | mock_log.error.assert_has_calls(log_error_calls) | 261 | mock_log.error.assert_has_calls(log_error_calls) |
1176 | 262 | mock_log.warning.assert_has_calls(log_warning_calls) | 262 | mock_log.warning.assert_has_calls(log_warning_calls) |
1177 | 263 | mock_log.debug.assert_has_calls(log_debug_calls) | 263 | mock_log.debug.assert_has_calls(log_debug_calls) |
1180 | 264 | assert (not self.pjlink.send_queue), 'Send queue should be empty' | 264 | assert not self.pjlink.send_queue, 'Send queue should be empty' |
1181 | 265 | assert (not self.pjlink.priority_queue), 'Priority queue should be empty' | 265 | assert not self.pjlink.priority_queue, 'Priority queue should be empty' |
1182 | 266 | assert mock_timer.start.called, 'Timer should have been called' | 266 | assert mock_timer.start.called, 'Timer should have been called' |
1185 | 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' |
1186 | 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' |
1187 | 269 | assert self.pjlink.send_busy, 'send_busy flag should be True' | 269 | assert self.pjlink.send_busy, 'send_busy flag should be True' |
1188 | 270 | 270 | ||
1189 | 271 | @patch.object(openlp.core.projectors.pjlink.PJLink, 'write') | 271 | @patch.object(openlp.core.projectors.pjlink.PJLink, 'write') |
1190 | @@ -314,10 +314,10 @@ | |||
1191 | 314 | mock_log.warning.assert_has_calls(log_warning_calls) | 314 | mock_log.warning.assert_has_calls(log_warning_calls) |
1192 | 315 | mock_log.debug.assert_has_calls(log_debug_calls) | 315 | mock_log.debug.assert_has_calls(log_debug_calls) |
1193 | 316 | assert self.pjlink.send_queue, 'Send queue should have one entry' | 316 | assert self.pjlink.send_queue, 'Send queue should have one entry' |
1195 | 317 | assert (not self.pjlink.priority_queue), 'Priority queue should be empty' | 317 | assert not self.pjlink.priority_queue, 'Priority queue should be empty' |
1196 | 318 | assert mock_timer.start.called, 'Timer should have been called' | 318 | assert mock_timer.start.called, 'Timer should have been called' |
1199 | 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' |
1200 | 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' |
1201 | 321 | assert self.pjlink.send_busy, 'send_busy flag should be True' | 321 | assert self.pjlink.send_busy, 'send_busy flag should be True' |
1202 | 322 | 322 | ||
1203 | 323 | @patch.object(openlp.core.projectors.pjlink.PJLink, 'state') | 323 | @patch.object(openlp.core.projectors.pjlink.PJLink, 'state') |
1204 | @@ -358,9 +358,9 @@ | |||
1205 | 358 | mock_log.warning.assert_has_calls(log_warning_calls) | 358 | mock_log.warning.assert_has_calls(log_warning_calls) |
1206 | 359 | mock_log.debug.assert_has_calls(log_debug_calls) | 359 | mock_log.debug.assert_has_calls(log_debug_calls) |
1207 | 360 | assert self.pjlink.send_queue, 'Send queue should have one entry' | 360 | assert self.pjlink.send_queue, 'Send queue should have one entry' |
1211 | 361 | assert (not self.pjlink.priority_queue), 'Priority queue should be empty' | 361 | assert not self.pjlink.priority_queue, 'Priority queue should be empty' |
1212 | 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' |
1213 | 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' |
1214 | 364 | assert self.pjlink.send_busy, 'send_busy flag should be True' | 364 | assert self.pjlink.send_busy, 'send_busy flag should be True' |
1215 | 365 | 365 | ||
1216 | 366 | @patch.object(openlp.core.projectors.pjlink.PJLink, 'state') | 366 | @patch.object(openlp.core.projectors.pjlink.PJLink, 'state') |
1217 | @@ -402,10 +402,10 @@ | |||
1218 | 402 | mock_log.error.assert_has_calls(log_error_calls) | 402 | mock_log.error.assert_has_calls(log_error_calls) |
1219 | 403 | mock_log.warning.assert_has_calls(log_warning_calls) | 403 | mock_log.warning.assert_has_calls(log_warning_calls) |
1220 | 404 | mock_log.debug.assert_has_calls(log_debug_calls) | 404 | mock_log.debug.assert_has_calls(log_debug_calls) |
1222 | 405 | assert (not self.pjlink.send_queue), 'Send queue should be empty' | 405 | assert not self.pjlink.send_queue, 'Send queue should be empty' |
1223 | 406 | assert self.pjlink.priority_queue, 'Priority queue should have one entry' | 406 | assert self.pjlink.priority_queue, 'Priority queue should have one entry' |
1226 | 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' |
1227 | 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' |
1228 | 409 | assert self.pjlink.send_busy, 'send_busy flag should be True' | 409 | assert self.pjlink.send_busy, 'send_busy flag should be True' |
1229 | 410 | 410 | ||
1230 | 411 | # ------------ Test PJLink.send_command ---------- | 411 | # ------------ Test PJLink.send_command ---------- |
1231 | @@ -440,7 +440,7 @@ | |||
1232 | 440 | mock_log.debug.assert_has_calls(log_debug_calls) | 440 | mock_log.debug.assert_has_calls(log_debug_calls) |
1233 | 441 | mock_log.warning.assert_has_calls(log_warning_calls) | 441 | mock_log.warning.assert_has_calls(log_warning_calls) |
1234 | 442 | mock_log.error.assert_has_calls(log_error_calls) | 442 | mock_log.error.assert_has_calls(log_error_calls) |
1236 | 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' |
1237 | 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' |
1238 | 445 | 445 | ||
1239 | 446 | @patch.object(openlp.core.projectors.pjlink.PJLink, 'state') | 446 | @patch.object(openlp.core.projectors.pjlink.PJLink, 'state') |
1240 | @@ -473,8 +473,8 @@ | |||
1241 | 473 | mock_log.warning.assert_has_calls(log_warning_calls) | 473 | mock_log.warning.assert_has_calls(log_warning_calls) |
1242 | 474 | mock_log.error.assert_has_calls(log_error_calls) | 474 | mock_log.error.assert_has_calls(log_error_calls) |
1243 | 475 | mock_priority.append.assert_called_with(test_command) | 475 | mock_priority.append.assert_called_with(test_command) |
1246 | 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' |
1247 | 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' |
1248 | 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' |
1249 | 479 | 479 | ||
1250 | 480 | @patch.object(openlp.core.projectors.pjlink.PJLink, 'state') | 480 | @patch.object(openlp.core.projectors.pjlink.PJLink, 'state') |
1251 | @@ -506,9 +506,9 @@ | |||
1252 | 506 | mock_log.debug.assert_has_calls(log_debug_calls) | 506 | mock_log.debug.assert_has_calls(log_debug_calls) |
1253 | 507 | mock_log.warning.assert_has_calls(log_warning_calls) | 507 | mock_log.warning.assert_has_calls(log_warning_calls) |
1254 | 508 | mock_log.error.assert_has_calls(log_error_calls) | 508 | mock_log.error.assert_has_calls(log_error_calls) |
1258 | 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' |
1259 | 510 | assert (not self.pjlink.priority_queue), 'Priority queue should be empty' | 510 | assert not self.pjlink.priority_queue, 'Priority queue should be empty' |
1260 | 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' |
1261 | 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' |
1262 | 513 | 513 | ||
1263 | 514 | @patch.object(openlp.core.projectors.pjlink.PJLink, 'state') | 514 | @patch.object(openlp.core.projectors.pjlink.PJLink, 'state') |
1264 | @@ -540,9 +540,9 @@ | |||
1265 | 540 | mock_log.debug.assert_has_calls(log_debug_calls) | 540 | mock_log.debug.assert_has_calls(log_debug_calls) |
1266 | 541 | mock_log.warning.assert_has_calls(log_warning_calls) | 541 | mock_log.warning.assert_has_calls(log_warning_calls) |
1267 | 542 | mock_log.error.assert_has_calls(log_error_calls) | 542 | mock_log.error.assert_has_calls(log_error_calls) |
1271 | 543 | assert (not self.pjlink.send_queue), 'Send queue should be empty' | 543 | assert not self.pjlink.send_queue, 'Send queue should be empty' |
1272 | 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' |
1273 | 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' |
1274 | 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' |
1275 | 547 | 547 | ||
1276 | 548 | @patch.object(openlp.core.projectors.pjlink.PJLink, 'state') | 548 | @patch.object(openlp.core.projectors.pjlink.PJLink, 'state') |
1277 | @@ -569,10 +569,10 @@ | |||
1278 | 569 | mock_log.debug.assert_has_calls(log_debug_calls) | 569 | mock_log.debug.assert_has_calls(log_debug_calls) |
1279 | 570 | mock_log.warning.assert_has_calls(log_warning_calls) | 570 | mock_log.warning.assert_has_calls(log_warning_calls) |
1280 | 571 | mock_log.error.assert_has_calls(log_error_calls) | 571 | mock_log.error.assert_has_calls(log_error_calls) |
1285 | 572 | assert (not self.pjlink.send_queue), 'Send queue should be empty' | 572 | assert not self.pjlink.send_queue, 'Send queue should be empty' |
1286 | 573 | assert (not self.pjlink.priority_queue), 'Priority queue should be empty' | 573 | assert not self.pjlink.priority_queue, 'Priority queue should be empty' |
1287 | 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' |
1288 | 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' |
1289 | 576 | 576 | ||
1290 | 577 | @patch.object(openlp.core.projectors.pjlink.PJLink, 'state') | 577 | @patch.object(openlp.core.projectors.pjlink.PJLink, 'state') |
1291 | 578 | @patch.object(openlp.core.projectors.pjlink.PJLink, 'reset_information') | 578 | @patch.object(openlp.core.projectors.pjlink.PJLink, 'reset_information') |
1292 | @@ -602,8 +602,8 @@ | |||
1293 | 602 | mock_log.warning.assert_has_calls(log_warning_calls) | 602 | mock_log.warning.assert_has_calls(log_warning_calls) |
1294 | 603 | mock_log.error.assert_has_calls(log_error_calls) | 603 | mock_log.error.assert_has_calls(log_error_calls) |
1295 | 604 | assert self.pjlink.send_queue, 'Send queue should have one entry' | 604 | assert self.pjlink.send_queue, 'Send queue should have one entry' |
1298 | 605 | assert (not self.pjlink.priority_queue), 'Priority queue should be empty' | 605 | assert not self.pjlink.priority_queue, 'Priority queue should be empty' |
1299 | 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' |
1300 | 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' |
1301 | 608 | 608 | ||
1302 | 609 | @patch.object(openlp.core.projectors.pjlink.PJLink, 'state') | 609 | @patch.object(openlp.core.projectors.pjlink.PJLink, 'state') |
1303 | @@ -633,9 +633,9 @@ | |||
1304 | 633 | mock_log.debug.assert_has_calls(log_debug_calls) | 633 | mock_log.debug.assert_has_calls(log_debug_calls) |
1305 | 634 | mock_log.warning.assert_has_calls(log_warning_calls) | 634 | mock_log.warning.assert_has_calls(log_warning_calls) |
1306 | 635 | mock_log.error.assert_has_calls(log_error_calls) | 635 | mock_log.error.assert_has_calls(log_error_calls) |
1308 | 636 | assert (not self.pjlink.send_queue), 'Send queue should be empty' | 636 | assert not self.pjlink.send_queue, 'Send queue should be empty' |
1309 | 637 | assert self.pjlink.priority_queue, 'Priority queue should have one entry' | 637 | assert self.pjlink.priority_queue, 'Priority queue should have one entry' |
1311 | 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' |
1312 | 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' |
1313 | 640 | 640 | ||
1314 | 641 | @patch.object(openlp.core.projectors.pjlink.PJLink, 'state') | 641 | @patch.object(openlp.core.projectors.pjlink.PJLink, 'state') |
1315 | @@ -661,7 +661,7 @@ | |||
1316 | 661 | mock_log.debug.assert_has_calls(log_debug_calls) | 661 | mock_log.debug.assert_has_calls(log_debug_calls) |
1317 | 662 | mock_log.warning.assert_has_calls(log_warning_calls) | 662 | mock_log.warning.assert_has_calls(log_warning_calls) |
1318 | 663 | mock_log.error.assert_has_calls(log_error_calls) | 663 | mock_log.error.assert_has_calls(log_error_calls) |
1321 | 664 | assert (not self.pjlink.send_queue), 'Send queue should be empty' | 664 | assert not self.pjlink.send_queue, 'Send queue should be empty' |
1322 | 665 | assert (not self.pjlink.priority_queue), 'Priority queue should be empty' | 665 | assert not self.pjlink.priority_queue, 'Priority queue should be empty' |
1323 | 666 | assert mock_reset.called, 'reset_information() should have been called' | 666 | assert mock_reset.called, 'reset_information() should have been called' |
1325 | 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' |
1326 | 668 | 668 | ||
1327 | === added file 'tests/openlp_core/projectors/test_projector_pjlink_base_03.py' | |||
1328 | --- tests/openlp_core/projectors/test_projector_pjlink_base_03.py 1970-01-01 00:00:00 +0000 | |||
1329 | +++ tests/openlp_core/projectors/test_projector_pjlink_base_03.py 2019-05-15 13:39:42 +0000 | |||
1330 | @@ -0,0 +1,130 @@ | |||
1331 | 1 | # -*- coding: utf-8 -*- | ||
1332 | 2 | # vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 | ||
1333 | 3 | |||
1334 | 4 | ########################################################################## | ||
1335 | 5 | # OpenLP - Open Source Lyrics Projection # | ||
1336 | 6 | # ---------------------------------------------------------------------- # | ||
1337 | 7 | # Copyright (c) 2008-2019 OpenLP Developers # | ||
1338 | 8 | # ---------------------------------------------------------------------- # | ||
1339 | 9 | # This program is free software: you can redistribute it and/or modify # | ||
1340 | 10 | # it under the terms of the GNU General Public License as published by # | ||
1341 | 11 | # the Free Software Foundation, either version 3 of the License, or # | ||
1342 | 12 | # (at your option) any later version. # | ||
1343 | 13 | # # | ||
1344 | 14 | # This program is distributed in the hope that it will be useful, # | ||
1345 | 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # | ||
1346 | 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # | ||
1347 | 17 | # GNU General Public License for more details. # | ||
1348 | 18 | # # | ||
1349 | 19 | # You should have received a copy of the GNU General Public License # | ||
1350 | 20 | # along with this program. If not, see <https://www.gnu.org/licenses/>. # | ||
1351 | 21 | ########################################################################## | ||
1352 | 22 | """ | ||
1353 | 23 | Package to test the openlp.core.projectors.pjlink base package part 3. | ||
1354 | 24 | """ | ||
1355 | 25 | from unittest import TestCase | ||
1356 | 26 | from unittest.mock import call, patch | ||
1357 | 27 | |||
1358 | 28 | import openlp.core.projectors.pjlink | ||
1359 | 29 | from openlp.core.projectors.constants import PJLINK_CLASS, STATUS_CODE, \ | ||
1360 | 30 | S_NOT_CONNECTED, S_OFF, S_ON, QSOCKET_STATE | ||
1361 | 31 | from openlp.core.projectors.db import Projector | ||
1362 | 32 | from openlp.core.projectors.pjlink import PJLink | ||
1363 | 33 | from tests.resources.projector.data import TEST1_DATA | ||
1364 | 34 | |||
1365 | 35 | |||
1366 | 36 | class TestPJLinkBase(TestCase): | ||
1367 | 37 | """ | ||
1368 | 38 | Tests for the PJLink module | ||
1369 | 39 | """ | ||
1370 | 40 | def setUp(self): | ||
1371 | 41 | """ | ||
1372 | 42 | Initialize test state(s) | ||
1373 | 43 | """ | ||
1374 | 44 | # Default PJLink instance for tests | ||
1375 | 45 | self.pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True) | ||
1376 | 46 | |||
1377 | 47 | def tearDown(self): | ||
1378 | 48 | """ | ||
1379 | 49 | Cleanup test state(s) | ||
1380 | 50 | """ | ||
1381 | 51 | del(self.pjlink) | ||
1382 | 52 | |||
1383 | 53 | @patch.object(openlp.core.projectors.pjlink, 'log') | ||
1384 | 54 | def test_projector_reset_information(self, mock_log): | ||
1385 | 55 | """ | ||
1386 | 56 | Test reset_information() resets all information and stops timers | ||
1387 | 57 | """ | ||
1388 | 58 | # GIVEN: Test object | ||
1389 | 59 | log_debug_calls = [call('({ip}) reset_information() connect status is ' | ||
1390 | 60 | 'S_NOT_CONNECTED'.format(ip=self.pjlink.name)), | ||
1391 | 61 | call('({ip}): Calling poll_timer.stop()'.format(ip=self.pjlink.name)), | ||
1392 | 62 | call('({ip}): Calling socket_timer.stop()'.format(ip=self.pjlink.name)), | ||
1393 | 63 | call('({ip}): Calling status_timer.stop()'.format(ip=self.pjlink.name))] | ||
1394 | 64 | |||
1395 | 65 | # Attributes not available until instantiation, so mock here | ||
1396 | 66 | with patch.object(self.pjlink, 'socket_timer') as mock_socket_timer, \ | ||
1397 | 67 | patch.object(self.pjlink, 'status_timer') as mock_status_timer, \ | ||
1398 | 68 | patch.object(self.pjlink, 'poll_timer') as mock_poll_timer, \ | ||
1399 | 69 | patch.object(self.pjlink, 'state') as mock_state: | ||
1400 | 70 | mock_state.return_value = QSOCKET_STATE[S_NOT_CONNECTED] | ||
1401 | 71 | # Set attributes to something other than None or {} or [] | ||
1402 | 72 | self.pjlink.fan = True | ||
1403 | 73 | self.pjlink.filter_time = True | ||
1404 | 74 | self.pjlink.lamp = True | ||
1405 | 75 | self.pjlink.mac_adx_received = 'Some random MAC' | ||
1406 | 76 | self.pjlink.manufacturer = 'PJLINK' | ||
1407 | 77 | self.pjlink.model = '1' | ||
1408 | 78 | self.pjlink.model_filter = 'Filter' | ||
1409 | 79 | self.pjlink.model_lamp = 'Lamp' | ||
1410 | 80 | self.pjlink.mute = True | ||
1411 | 81 | self.pjlink.other_info = 'Another Test' | ||
1412 | 82 | self.pjlink.pjlink_class = 2 | ||
1413 | 83 | self.pjlink.pjlink_name = 'OPENLPTEST' | ||
1414 | 84 | self.pjlink.power = S_ON | ||
1415 | 85 | self.pjlink.projector_errors = {'test1': True, 'test2': False} | ||
1416 | 86 | self.pjlink.serial_no = 'Some Number' | ||
1417 | 87 | self.pjlink.serial_no_received = 'Some Other Number' | ||
1418 | 88 | self.pjlink.sw_version = 'Some Version' | ||
1419 | 89 | self.pjlink.sw_version_received = 'Some Other Version' | ||
1420 | 90 | self.pjlink.shutter = True | ||
1421 | 91 | self.pjlink.source_available = True | ||
1422 | 92 | self.pjlink.source = True | ||
1423 | 93 | self.pjlink.status_timer_checks = {'test1': object(), 'test2': object()} | ||
1424 | 94 | self.pjlink.send_busy = False | ||
1425 | 95 | self.pjlink.send_queue = ['test1', 'test2'] | ||
1426 | 96 | self.pjlink.priority_queue = ['test1', 'test2'] | ||
1427 | 97 | |||
1428 | 98 | # WHEN: reset_information() is called | ||
1429 | 99 | self.pjlink.reset_information() | ||
1430 | 100 | |||
1431 | 101 | # THEN: All information should be reset and timers stopped | ||
1432 | 102 | mock_log.debug.assert_has_calls(log_debug_calls) | ||
1433 | 103 | assert self.pjlink.fan is None, 'fan should be None' | ||
1434 | 104 | assert self.pjlink.filter_time is None, 'filter_time should be None' | ||
1435 | 105 | assert self.pjlink.lamp is None, 'lamp should be None' | ||
1436 | 106 | assert self.pjlink.mac_adx_received is None, 'mac_adx_received should be None' | ||
1437 | 107 | assert self.pjlink.manufacturer is None, 'manufacturer should be None' | ||
1438 | 108 | assert self.pjlink.model is None, 'model should be None' | ||
1439 | 109 | assert self.pjlink.model_filter is None, 'model_filter should be None' | ||
1440 | 110 | assert self.pjlink.model_lamp is None, 'model_lamp should be None' | ||
1441 | 111 | assert not self.pjlink.mute, 'mute should be False' | ||
1442 | 112 | assert self.pjlink.other_info is None, 'other should be None' | ||
1443 | 113 | assert self.pjlink.pjlink_class == PJLINK_CLASS, 'pjlink_class should be {cls}'.format(cls=PJLINK_CLASS) | ||
1444 | 114 | assert self.pjlink.pjlink_name is None, 'pjlink_name should be None' | ||
1445 | 115 | assert self.pjlink.power == S_OFF, 'power should be {data}'.format(data=STATUS_CODE[S_OFF]) | ||
1446 | 116 | assert self.pjlink.projector_errors == {}, 'projector_errors should be an empty dict' | ||
1447 | 117 | assert self.pjlink.serial_no is None, 'serial_no should be None' | ||
1448 | 118 | assert self.pjlink.serial_no_received is None, 'serial_no_received should be None' | ||
1449 | 119 | assert self.pjlink.sw_version is None, 'sw_version should be None' | ||
1450 | 120 | assert self.pjlink.sw_version_received is None, 'sw_version_received should be None' | ||
1451 | 121 | assert not self.pjlink.shutter, 'shutter should be False' | ||
1452 | 122 | assert self.pjlink.source_available is None, 'source_available should be None' | ||
1453 | 123 | assert self.pjlink.source is None, 'source should be None' | ||
1454 | 124 | assert self.pjlink.status_timer_checks == {}, 'status_timer_checks should be an empty dict' | ||
1455 | 125 | assert not self.pjlink.send_busy, 'send_busy should be False' | ||
1456 | 126 | assert self.pjlink.send_queue == [], 'send_queue should be an empty list' | ||
1457 | 127 | assert self.pjlink.priority_queue == [], 'priority_queue should be an empty list' | ||
1458 | 128 | assert mock_socket_timer.stop.called, 'socket_timer.stop() should have been called' | ||
1459 | 129 | assert mock_status_timer.stop.called, 'status_timer.stop() should have been called' | ||
1460 | 130 | assert mock_poll_timer.stop.called, 'poll_timer.stop() should have been called' |
Linux tests passed!