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