Merge lp:~alisonken1/openlp/pjlink2-i into lp:openlp
- pjlink2-i
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Raoul Snyman |
Approved revision: | 2760 |
Merged at revision: | 2760 |
Proposed branch: | lp:~alisonken1/openlp/pjlink2-i |
Merge into: | lp:openlp |
Diff against target: |
1078 lines (+690/-117) 3 files modified
openlp/core/lib/projector/pjlink.py (+45/-35) tests/functional/openlp_core_lib/test_projector_pjlink_cmd_routing.py (+1/-1) tests/functional/openlp_core_lib/test_projector_pjlink_commands.py (+644/-81) |
To merge this branch: | bzr merge lp:~alisonken1/openlp/pjlink2-i |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Raoul Snyman | Approve | ||
Tomas Groth | Approve | ||
Tim Bentley | Pending | ||
Review via email: mp+328951@code.launchpad.net |
This proposal supersedes a proposal from 2017-08-12.
Commit message
PJLink2 update I
Description of the change
More minor code cleanups
- Renamed get_shutter_status to get_av_mute_status (checks shutter and audio)
- Renamed shutter/audio mute test
- Update socket read to get 1K bytes in buffer
- Updated get_status for valid input
- Updated process_sver check valid length
- Update change_status to not use NETWORK_SENDING as a connection status check
- Added read check for packet length > allowed max
- Added test for process_inf1
- Added test for process_inf2
- Added test for process_info
- Added test for process_inst
- Added test for process_lamp with invalid data
- Update tests for process_powr
- Added test for process_
- Added tests for process_sver
- Added tests for change_status
- Added test for get_av_mute_status
- Added test for get_available_
- Added test for get_error_status
- Added test for get_input_source
- Added test for get_lamp_status
- Added test for get_manufacturer
- Added test for get_model
- Added test for get_name
- Added test for get_other_info
- Added test for get_power_status
- Added tests for get_status
- Added test for process_inf1
- Added test for get_process_inf2
- Added test for get_process_info
- Added test for reset_information
- Fix deprecated log calls
-------
lp:~alisonken1/openlp/pjlink2-i (revision 2760)
[SUCCESS] https:/
[SUCCESS] https:/
[SUCCESS] https:/
[SUCCESS] https:/
[SUCCESS] https:/
[SUCCESS] https:/
[FAILURE] https:/
Tim Bentley (trb143) wrote : Posted in a previous version of this proposal | # |
Tomas Groth (tomasgroth) wrote : | # |
Looks ok to me.
Raoul Snyman (raoul-snyman) : | # |
Preview Diff
1 | === modified file 'openlp/core/lib/projector/pjlink.py' | |||
2 | --- openlp/core/lib/projector/pjlink.py 2017-08-11 11:04:33 +0000 | |||
3 | +++ openlp/core/lib/projector/pjlink.py 2017-08-12 21:17:39 +0000 | |||
4 | @@ -57,7 +57,7 @@ | |||
5 | 57 | E_AUTHENTICATION, E_CONNECTION_REFUSED, E_GENERAL, E_INVALID_DATA, E_NETWORK, E_NOT_CONNECTED, E_OK, \ | 57 | E_AUTHENTICATION, E_CONNECTION_REFUSED, E_GENERAL, E_INVALID_DATA, E_NETWORK, E_NOT_CONNECTED, E_OK, \ |
6 | 58 | E_PARAMETER, E_PROJECTOR, E_SOCKET_TIMEOUT, E_UNAVAILABLE, E_UNDEFINED, PJLINK_ERRORS, PJLINK_ERST_DATA, \ | 58 | E_PARAMETER, E_PROJECTOR, E_SOCKET_TIMEOUT, E_UNAVAILABLE, E_UNDEFINED, PJLINK_ERRORS, PJLINK_ERST_DATA, \ |
7 | 59 | PJLINK_ERST_STATUS, PJLINK_MAX_PACKET, PJLINK_PORT, PJLINK_POWR_STATUS, PJLINK_VALID_CMD, \ | 59 | PJLINK_ERST_STATUS, PJLINK_MAX_PACKET, PJLINK_PORT, PJLINK_POWR_STATUS, PJLINK_VALID_CMD, \ |
9 | 60 | STATUS_STRING, S_CONNECTED, S_CONNECTING, S_NETWORK_RECEIVED, S_NETWORK_SENDING, \ | 60 | STATUS_STRING, S_CONNECTED, S_CONNECTING, S_INFO, S_NETWORK_RECEIVED, S_NETWORK_SENDING, \ |
10 | 61 | S_NOT_CONNECTED, S_OFF, S_OK, S_ON, S_STATUS | 61 | S_NOT_CONNECTED, S_OFF, S_OK, S_ON, S_STATUS |
11 | 62 | 62 | ||
12 | 63 | # Shortcuts | 63 | # Shortcuts |
13 | @@ -159,7 +159,7 @@ | |||
14 | 159 | # A command returned successfully, no further processing needed | 159 | # A command returned successfully, no further processing needed |
15 | 160 | return | 160 | return |
16 | 161 | elif _cmd not in self.pjlink_functions: | 161 | elif _cmd not in self.pjlink_functions: |
18 | 162 | log.warn("({ip}) Unable to process command='{cmd}' (Future option)".format(ip=self.ip, cmd=cmd)) | 162 | log.warning("({ip}) Unable to process command='{cmd}' (Future option)".format(ip=self.ip, cmd=cmd)) |
19 | 163 | return | 163 | return |
20 | 164 | elif _data in PJLINK_ERRORS: | 164 | elif _data in PJLINK_ERRORS: |
21 | 165 | # Oops - projector error | 165 | # Oops - projector error |
22 | @@ -231,7 +231,7 @@ | |||
23 | 231 | # : Received: '%1CLSS=Class 1' (Optoma) | 231 | # : Received: '%1CLSS=Class 1' (Optoma) |
24 | 232 | # : Received: '%1CLSS=Version1' (BenQ) | 232 | # : Received: '%1CLSS=Version1' (BenQ) |
25 | 233 | if len(data) > 1: | 233 | if len(data) > 1: |
27 | 234 | log.warn("({ip}) Non-standard CLSS reply: '{data}'".format(ip=self.ip, data=data)) | 234 | log.warning("({ip}) Non-standard CLSS reply: '{data}'".format(ip=self.ip, data=data)) |
28 | 235 | # Due to stupid projectors not following standards (Optoma, BenQ comes to mind), | 235 | # Due to stupid projectors not following standards (Optoma, BenQ comes to mind), |
29 | 236 | # AND the different responses that can be received, the semi-permanent way to | 236 | # AND the different responses that can be received, the semi-permanent way to |
30 | 237 | # fix the class reply is to just remove all non-digit characters. | 237 | # fix the class reply is to just remove all non-digit characters. |
31 | @@ -261,15 +261,15 @@ | |||
32 | 261 | """ | 261 | """ |
33 | 262 | if len(data) != PJLINK_ERST_DATA['DATA_LENGTH']: | 262 | if len(data) != PJLINK_ERST_DATA['DATA_LENGTH']: |
34 | 263 | count = PJLINK_ERST_DATA['DATA_LENGTH'] | 263 | count = PJLINK_ERST_DATA['DATA_LENGTH'] |
38 | 264 | log.warn("{ip}) Invalid error status response '{data}': length != {count}".format(ip=self.ip, | 264 | log.warning("{ip}) Invalid error status response '{data}': length != {count}".format(ip=self.ip, |
39 | 265 | data=data, | 265 | data=data, |
40 | 266 | count=count)) | 266 | count=count)) |
41 | 267 | return | 267 | return |
42 | 268 | try: | 268 | try: |
43 | 269 | datacheck = int(data) | 269 | datacheck = int(data) |
44 | 270 | except ValueError: | 270 | except ValueError: |
45 | 271 | # Bad data - ignore | 271 | # Bad data - ignore |
47 | 272 | log.warn("({ip}) Invalid error status response '{data}'".format(ip=self.ip, data=data)) | 272 | log.warning("({ip}) Invalid error status response '{data}'".format(ip=self.ip, data=data)) |
48 | 273 | return | 273 | return |
49 | 274 | if datacheck == 0: | 274 | if datacheck == 0: |
50 | 275 | self.projector_errors = None | 275 | self.projector_errors = None |
51 | @@ -429,9 +429,9 @@ | |||
52 | 429 | if self.model_filter is None: | 429 | if self.model_filter is None: |
53 | 430 | self.model_filter = data | 430 | self.model_filter = data |
54 | 431 | else: | 431 | else: |
58 | 432 | log.warn("({ip}) Filter model already set".format(ip=self.ip)) | 432 | log.warning("({ip}) Filter model already set".format(ip=self.ip)) |
59 | 433 | log.warn("({ip}) Saved model: '{old}'".format(ip=self.ip, old=self.model_filter)) | 433 | log.warning("({ip}) Saved model: '{old}'".format(ip=self.ip, old=self.model_filter)) |
60 | 434 | log.warn("({ip}) New model: '{new}'".format(ip=self.ip, new=data)) | 434 | log.warning("({ip}) New model: '{new}'".format(ip=self.ip, new=data)) |
61 | 435 | 435 | ||
62 | 436 | def process_rlmp(self, data): | 436 | def process_rlmp(self, data): |
63 | 437 | """ | 437 | """ |
64 | @@ -440,9 +440,9 @@ | |||
65 | 440 | if self.model_lamp is None: | 440 | if self.model_lamp is None: |
66 | 441 | self.model_lamp = data | 441 | self.model_lamp = data |
67 | 442 | else: | 442 | else: |
71 | 443 | log.warn("({ip}) Lamp model already set".format(ip=self.ip)) | 443 | log.warning("({ip}) Lamp model already set".format(ip=self.ip)) |
72 | 444 | log.warn("({ip}) Saved lamp: '{old}'".format(ip=self.ip, old=self.model_lamp)) | 444 | log.warning("({ip}) Saved lamp: '{old}'".format(ip=self.ip, old=self.model_lamp)) |
73 | 445 | log.warn("({ip}) New lamp: '{new}'".format(ip=self.ip, new=data)) | 445 | log.warning("({ip}) New lamp: '{new}'".format(ip=self.ip, new=data)) |
74 | 446 | 446 | ||
75 | 447 | def process_snum(self, data): | 447 | def process_snum(self, data): |
76 | 448 | """ | 448 | """ |
77 | @@ -457,27 +457,32 @@ | |||
78 | 457 | else: | 457 | else: |
79 | 458 | # Compare serial numbers and see if we got the same projector | 458 | # Compare serial numbers and see if we got the same projector |
80 | 459 | if self.serial_no != data: | 459 | if self.serial_no != data: |
85 | 460 | log.warn("({ip}) Projector serial number does not match saved serial number".format(ip=self.ip)) | 460 | log.warning("({ip}) Projector serial number does not match saved serial number".format(ip=self.ip)) |
86 | 461 | log.warn("({ip}) Saved: '{old}'".format(ip=self.ip, old=self.serial_no)) | 461 | log.warning("({ip}) Saved: '{old}'".format(ip=self.ip, old=self.serial_no)) |
87 | 462 | log.warn("({ip}) Received: '{new}'".format(ip=self.ip, new=data)) | 462 | log.warning("({ip}) Received: '{new}'".format(ip=self.ip, new=data)) |
88 | 463 | log.warn("({ip}) NOT saving serial number".format(ip=self.ip)) | 463 | log.warning("({ip}) NOT saving serial number".format(ip=self.ip)) |
89 | 464 | self.serial_no_received = data | 464 | self.serial_no_received = data |
90 | 465 | 465 | ||
91 | 466 | def process_sver(self, data): | 466 | def process_sver(self, data): |
92 | 467 | """ | 467 | """ |
93 | 468 | Software version of projector | 468 | Software version of projector |
94 | 469 | """ | 469 | """ |
96 | 470 | if self.sw_version is None: | 470 | if len(data) > 32: |
97 | 471 | # Defined in specs max version is 32 characters | ||
98 | 472 | log.warning("Invalid software version - too long") | ||
99 | 473 | return | ||
100 | 474 | elif self.sw_version is None: | ||
101 | 471 | log.debug("({ip}) Setting projector software version to '{data}'".format(ip=self.ip, data=data)) | 475 | log.debug("({ip}) Setting projector software version to '{data}'".format(ip=self.ip, data=data)) |
102 | 472 | self.sw_version = data | 476 | self.sw_version = data |
103 | 473 | self.db_update = True | 477 | self.db_update = True |
104 | 474 | else: | 478 | else: |
105 | 475 | # Compare software version and see if we got the same projector | 479 | # Compare software version and see if we got the same projector |
106 | 476 | if self.serial_no != data: | 480 | if self.serial_no != data: |
111 | 477 | log.warn("({ip}) Projector software version does not match saved software version".format(ip=self.ip)) | 481 | log.warning("({ip}) Projector software version does not match saved " |
112 | 478 | log.warn("({ip}) Saved: '{old}'".format(ip=self.ip, old=self.sw_version)) | 482 | "software version".format(ip=self.ip)) |
113 | 479 | log.warn("({ip}) Received: '{new}'".format(ip=self.ip, new=data)) | 483 | log.warning("({ip}) Saved: '{old}'".format(ip=self.ip, old=self.sw_version)) |
114 | 480 | log.warn("({ip}) NOT saving serial number".format(ip=self.ip)) | 484 | log.warning("({ip}) Received: '{new}'".format(ip=self.ip, new=data)) |
115 | 485 | log.warning("({ip}) Saving new serial number as sw_version_received".format(ip=self.ip)) | ||
116 | 481 | self.sw_version_received = data | 486 | self.sw_version_received = data |
117 | 482 | 487 | ||
118 | 483 | 488 | ||
119 | @@ -605,7 +610,7 @@ | |||
120 | 605 | Normally called by timer(). | 610 | Normally called by timer(). |
121 | 606 | """ | 611 | """ |
122 | 607 | if self.state() != self.ConnectedState: | 612 | if self.state() != self.ConnectedState: |
124 | 608 | log.warn("({ip}) poll_loop(): Not connected - returning".format(ip=self.ip)) | 613 | log.warning("({ip}) poll_loop(): Not connected - returning".format(ip=self.ip)) |
125 | 609 | return | 614 | return |
126 | 610 | log.debug('({ip}) Updating projector status'.format(ip=self.ip)) | 615 | log.debug('({ip}) Updating projector status'.format(ip=self.ip)) |
127 | 611 | # Reset timer in case we were called from a set command | 616 | # Reset timer in case we were called from a set command |
128 | @@ -649,7 +654,9 @@ | |||
129 | 649 | :param status: Status/Error code | 654 | :param status: Status/Error code |
130 | 650 | :returns: (Status/Error code, String) | 655 | :returns: (Status/Error code, String) |
131 | 651 | """ | 656 | """ |
133 | 652 | if status in ERROR_STRING: | 657 | if not isinstance(status, int): |
134 | 658 | return -1, 'Invalid status code' | ||
135 | 659 | elif status in ERROR_STRING: | ||
136 | 653 | return ERROR_STRING[status], ERROR_MSG[status] | 660 | return ERROR_STRING[status], ERROR_MSG[status] |
137 | 654 | elif status in STATUS_STRING: | 661 | elif status in STATUS_STRING: |
138 | 655 | return STATUS_STRING[status], ERROR_MSG[status] | 662 | return STATUS_STRING[status], ERROR_MSG[status] |
139 | @@ -674,7 +681,7 @@ | |||
140 | 674 | elif status >= S_NOT_CONNECTED and status < S_STATUS: | 681 | elif status >= S_NOT_CONNECTED and status < S_STATUS: |
141 | 675 | self.status_connect = status | 682 | self.status_connect = status |
142 | 676 | self.projector_status = S_NOT_CONNECTED | 683 | self.projector_status = S_NOT_CONNECTED |
144 | 677 | elif status < S_NETWORK_SENDING: | 684 | elif status <= S_INFO: |
145 | 678 | self.status_connect = S_CONNECTED | 685 | self.status_connect = S_CONNECTED |
146 | 679 | self.projector_status = status | 686 | self.projector_status = status |
147 | 680 | (status_code, status_message) = self._get_status(self.status_connect) | 687 | (status_code, status_message) = self._get_status(self.status_connect) |
148 | @@ -803,7 +810,8 @@ | |||
149 | 803 | log.debug('({ip}) get_data(): Not connected - returning'.format(ip=self.ip)) | 810 | log.debug('({ip}) get_data(): Not connected - returning'.format(ip=self.ip)) |
150 | 804 | self.send_busy = False | 811 | self.send_busy = False |
151 | 805 | return | 812 | return |
153 | 806 | read = self.readLine(self.max_size) | 813 | # Although we have a packet length limit, go ahead and use a larger buffer |
154 | 814 | read = self.readLine(1024) | ||
155 | 807 | log.debug("({ip}) get_data(): '{buff}'".format(ip=self.ip, buff=read)) | 815 | log.debug("({ip}) get_data(): '{buff}'".format(ip=self.ip, buff=read)) |
156 | 808 | if read == -1: | 816 | if read == -1: |
157 | 809 | # No data available | 817 | # No data available |
158 | @@ -816,6 +824,8 @@ | |||
159 | 816 | data = data_in.strip() | 824 | data = data_in.strip() |
160 | 817 | if (len(data) < 7) or (not data.startswith(PJLINK_PREFIX)): | 825 | if (len(data) < 7) or (not data.startswith(PJLINK_PREFIX)): |
161 | 818 | return self._trash_buffer(msg='get_data(): Invalid packet - length or prefix') | 826 | return self._trash_buffer(msg='get_data(): Invalid packet - length or prefix') |
162 | 827 | elif len(data) > self.max_size: | ||
163 | 828 | return self._trash_buffer(msg='get_data(): Invalid packet - too long') | ||
164 | 819 | elif '=' not in data: | 829 | elif '=' not in data: |
165 | 820 | return self._trash_buffer(msg='get_data(): Invalid packet does not have equal') | 830 | return self._trash_buffer(msg='get_data(): Invalid packet does not have equal') |
166 | 821 | log.debug('({ip}) get_data(): Checking new data "{data}"'.format(ip=self.ip, data=data)) | 831 | log.debug('({ip}) get_data(): Checking new data "{data}"'.format(ip=self.ip, data=data)) |
167 | @@ -830,8 +840,8 @@ | |||
168 | 830 | log.warning('({ip}) get_data(): Invalid packet - unknown command "{data}"'.format(ip=self.ip, data=cmd)) | 840 | log.warning('({ip}) get_data(): Invalid packet - unknown command "{data}"'.format(ip=self.ip, data=cmd)) |
169 | 831 | return self._trash_buffer(msg='get_data(): Unknown command "{data}"'.format(data=cmd)) | 841 | return self._trash_buffer(msg='get_data(): Unknown command "{data}"'.format(data=cmd)) |
170 | 832 | if int(self.pjlink_class) < int(version): | 842 | if int(self.pjlink_class) < int(version): |
173 | 833 | log.warn('({ip}) get_data(): Projector returned class reply higher ' | 843 | log.warning('({ip}) get_data(): Projector returned class reply higher ' |
174 | 834 | 'than projector stated class'.format(ip=self.ip)) | 844 | 'than projector stated class'.format(ip=self.ip)) |
175 | 835 | return self.process_command(cmd, data) | 845 | return self.process_command(cmd, data) |
176 | 836 | 846 | ||
177 | 837 | @QtCore.pyqtSlot(QtNetwork.QAbstractSocket.SocketError) | 847 | @QtCore.pyqtSlot(QtNetwork.QAbstractSocket.SocketError) |
178 | @@ -993,6 +1003,13 @@ | |||
179 | 993 | self.reset_information() | 1003 | self.reset_information() |
180 | 994 | self.projectorUpdateIcons.emit() | 1004 | self.projectorUpdateIcons.emit() |
181 | 995 | 1005 | ||
182 | 1006 | def get_av_mute_status(self): | ||
183 | 1007 | """ | ||
184 | 1008 | Send command to retrieve shutter status. | ||
185 | 1009 | """ | ||
186 | 1010 | log.debug('({ip}) Sending AVMT command'.format(ip=self.ip)) | ||
187 | 1011 | return self.send_command(cmd='AVMT') | ||
188 | 1012 | |||
189 | 996 | def get_available_inputs(self): | 1013 | def get_available_inputs(self): |
190 | 997 | """ | 1014 | """ |
191 | 998 | Send command to retrieve available source inputs. | 1015 | Send command to retrieve available source inputs. |
192 | @@ -1056,13 +1073,6 @@ | |||
193 | 1056 | log.debug('({ip}) Sending POWR command'.format(ip=self.ip)) | 1073 | log.debug('({ip}) Sending POWR command'.format(ip=self.ip)) |
194 | 1057 | return self.send_command(cmd='POWR') | 1074 | return self.send_command(cmd='POWR') |
195 | 1058 | 1075 | ||
196 | 1059 | def get_shutter_status(self): | ||
197 | 1060 | """ | ||
198 | 1061 | Send command to retrieve shutter status. | ||
199 | 1062 | """ | ||
200 | 1063 | log.debug('({ip}) Sending AVMT command'.format(ip=self.ip)) | ||
201 | 1064 | return self.send_command(cmd='AVMT') | ||
202 | 1065 | |||
203 | 1066 | def set_input_source(self, src=None): | 1076 | def set_input_source(self, src=None): |
204 | 1067 | """ | 1077 | """ |
205 | 1068 | Verify input source available as listed in 'INST' command, | 1078 | Verify input source available as listed in 'INST' command, |
206 | 1069 | 1079 | ||
207 | === modified file 'tests/functional/openlp_core_lib/test_projector_pjlink_cmd_routing.py' | |||
208 | --- tests/functional/openlp_core_lib/test_projector_pjlink_cmd_routing.py 2017-08-11 11:04:33 +0000 | |||
209 | +++ tests/functional/openlp_core_lib/test_projector_pjlink_cmd_routing.py 2017-08-12 21:17:39 +0000 | |||
210 | @@ -179,7 +179,7 @@ | |||
211 | 179 | 179 | ||
212 | 180 | # THEN: Error should be logged and no command called | 180 | # THEN: Error should be logged and no command called |
213 | 181 | self.assertFalse(mock_functions.called, 'Should not have gotten to the end of the method') | 181 | self.assertFalse(mock_functions.called, 'Should not have gotten to the end of the method') |
215 | 182 | mock_log.warn.assert_called_once_with(log_text) | 182 | mock_log.warning.assert_called_once_with(log_text) |
216 | 183 | 183 | ||
217 | 184 | @patch.object(pjlink_test, 'pjlink_functions') | 184 | @patch.object(pjlink_test, 'pjlink_functions') |
218 | 185 | @patch.object(openlp.core.lib.projector.pjlink, 'log') | 185 | @patch.object(openlp.core.lib.projector.pjlink, 'log') |
219 | 186 | 186 | ||
220 | === modified file 'tests/functional/openlp_core_lib/test_projector_pjlink_commands.py' | |||
221 | --- tests/functional/openlp_core_lib/test_projector_pjlink_commands.py 2017-08-11 11:04:33 +0000 | |||
222 | +++ tests/functional/openlp_core_lib/test_projector_pjlink_commands.py 2017-08-12 21:17:39 +0000 | |||
223 | @@ -23,12 +23,14 @@ | |||
224 | 23 | Package to test the openlp.core.lib.projector.pjlink commands package. | 23 | Package to test the openlp.core.lib.projector.pjlink commands package. |
225 | 24 | """ | 24 | """ |
226 | 25 | from unittest import TestCase | 25 | from unittest import TestCase |
228 | 26 | from unittest.mock import patch, MagicMock | 26 | from unittest.mock import patch |
229 | 27 | 27 | ||
230 | 28 | import openlp.core.lib.projector.pjlink | 28 | import openlp.core.lib.projector.pjlink |
231 | 29 | from openlp.core.lib.projector.pjlink import PJLink | 29 | from openlp.core.lib.projector.pjlink import PJLink |
232 | 30 | from openlp.core.lib.projector.constants import ERROR_STRING, PJLINK_ERST_DATA, PJLINK_ERST_STATUS, \ | 30 | from openlp.core.lib.projector.constants import ERROR_STRING, PJLINK_ERST_DATA, PJLINK_ERST_STATUS, \ |
234 | 31 | PJLINK_POWR_STATUS, E_WARN, E_ERROR, S_OFF, S_STANDBY, S_ON | 31 | PJLINK_POWR_STATUS, \ |
235 | 32 | E_ERROR, E_NOT_CONNECTED, E_SOCKET_ADDRESS_NOT_AVAILABLE, E_UNKNOWN_SOCKET_ERROR, E_WARN, \ | ||
236 | 33 | S_CONNECTED, S_OFF, S_ON, S_NOT_CONNECTED, S_CONNECTING, S_STANDBY | ||
237 | 32 | 34 | ||
238 | 33 | from tests.resources.projector.data import TEST_PIN | 35 | from tests.resources.projector.data import TEST_PIN |
239 | 34 | 36 | ||
240 | @@ -45,48 +47,408 @@ | |||
241 | 45 | """ | 47 | """ |
242 | 46 | Tests for the PJLink module | 48 | Tests for the PJLink module |
243 | 47 | """ | 49 | """ |
286 | 48 | def test_projector_reset_information(self): | 50 | @patch.object(pjlink_test, 'changeStatus') |
287 | 49 | """ | 51 | @patch.object(openlp.core.lib.projector.pjlink, 'log') |
288 | 50 | Test reset_information() resets all information and stops timers | 52 | def test_projector_change_status_connection_error(self, mock_log, mock_change_status): |
289 | 51 | """ | 53 | """ |
290 | 52 | # GIVEN: Test object and test data | 54 | Test change_status with connection error |
291 | 53 | pjlink = pjlink_test | 55 | """ |
292 | 54 | pjlink.power = S_ON | 56 | # GIVEN: Test object |
293 | 55 | pjlink.pjlink_name = 'OPENLPTEST' | 57 | pjlink = pjlink_test |
294 | 56 | pjlink.manufacturer = 'PJLINK' | 58 | pjlink.projector_status = 0 |
295 | 57 | pjlink.model = '1' | 59 | pjlink.status_connect = 0 |
296 | 58 | pjlink.shutter = True | 60 | test_code = E_UNKNOWN_SOCKET_ERROR |
297 | 59 | pjlink.mute = True | 61 | mock_change_status.reset_mock() |
298 | 60 | pjlink.lamp = True | 62 | mock_log.reset_mock() |
299 | 61 | pjlink.fan = True | 63 | |
300 | 62 | pjlink.source_available = True | 64 | # WHEN: change_status called with unknown socket error |
301 | 63 | pjlink.other_info = 'ANOTHER TEST' | 65 | pjlink.change_status(status=test_code, msg=None) |
302 | 64 | pjlink.send_queue = True | 66 | |
303 | 65 | pjlink.send_busy = True | 67 | # THEN: Proper settings should change and signals sent |
304 | 66 | pjlink.timer = MagicMock() | 68 | self.assertEqual(pjlink.projector_status, E_NOT_CONNECTED, 'Projector status should be NOT CONNECTED') |
305 | 67 | pjlink.socket_timer = MagicMock() | 69 | self.assertEqual(pjlink.status_connect, E_NOT_CONNECTED, 'Status connect should be NOT CONNECTED') |
306 | 68 | 70 | mock_change_status.emit.assert_called_once_with(pjlink.ip, E_UNKNOWN_SOCKET_ERROR, | |
307 | 69 | # WHEN: reset_information() is called | 71 | 'An unidentified error occurred') |
308 | 70 | with patch.object(pjlink.timer, 'stop') as mock_timer: | 72 | self.assertEqual(mock_log.debug.call_count, 3, 'Debug log should have been called 3 times') |
309 | 71 | with patch.object(pjlink.socket_timer, 'stop') as mock_socket_timer: | 73 | |
310 | 72 | pjlink.reset_information() | 74 | @patch.object(pjlink_test, 'changeStatus') |
311 | 73 | 75 | @patch.object(openlp.core.lib.projector.pjlink, 'log') | |
312 | 74 | # THEN: All information should be reset and timers stopped | 76 | def test_projector_change_status_connection_status_connecting(self, mock_log, mock_change_status): |
313 | 75 | self.assertEqual(pjlink.power, S_OFF, 'Projector power should be OFF') | 77 | """ |
314 | 76 | self.assertIsNone(pjlink.pjlink_name, 'Projector pjlink_name should be None') | 78 | Test change_status with connection status |
315 | 77 | self.assertIsNone(pjlink.manufacturer, 'Projector manufacturer should be None') | 79 | """ |
316 | 78 | self.assertIsNone(pjlink.model, 'Projector model should be None') | 80 | # GIVEN: Test object |
317 | 79 | self.assertIsNone(pjlink.shutter, 'Projector shutter should be None') | 81 | pjlink = pjlink_test |
318 | 80 | self.assertIsNone(pjlink.mute, 'Projector shuttter should be None') | 82 | pjlink.projector_status = 0 |
319 | 81 | self.assertIsNone(pjlink.lamp, 'Projector lamp should be None') | 83 | pjlink.status_connect = 0 |
320 | 82 | self.assertIsNone(pjlink.fan, 'Projector fan should be None') | 84 | test_code = S_CONNECTING |
321 | 83 | self.assertIsNone(pjlink.source_available, 'Projector source_available should be None') | 85 | mock_change_status.reset_mock() |
322 | 84 | self.assertIsNone(pjlink.source, 'Projector source should be None') | 86 | mock_log.reset_mock() |
323 | 85 | self.assertIsNone(pjlink.other_info, 'Projector other_info should be None') | 87 | |
324 | 86 | self.assertEqual(pjlink.send_queue, [], 'Projector send_queue should be an empty list') | 88 | # WHEN: change_status called with unknown socket error |
325 | 87 | self.assertFalse(pjlink.send_busy, 'Projector send_busy should be False') | 89 | pjlink.change_status(status=test_code, msg=None) |
326 | 88 | self.assertTrue(mock_timer.called, 'Projector timer.stop() should have been called') | 90 | |
327 | 89 | self.assertTrue(mock_socket_timer.called, 'Projector socket_timer.stop() should have been called') | 91 | # THEN: Proper settings should change and signals sent |
328 | 92 | self.assertEqual(pjlink.projector_status, S_NOT_CONNECTED, 'Projector status should be NOT CONNECTED') | ||
329 | 93 | self.assertEqual(pjlink.status_connect, S_CONNECTING, 'Status connect should be CONNECTING') | ||
330 | 94 | mock_change_status.emit.assert_called_once_with(pjlink.ip, S_CONNECTING, 'Connecting') | ||
331 | 95 | self.assertEqual(mock_log.debug.call_count, 3, 'Debug log should have been called 3 times') | ||
332 | 96 | |||
333 | 97 | @patch.object(pjlink_test, 'changeStatus') | ||
334 | 98 | @patch.object(openlp.core.lib.projector.pjlink, 'log') | ||
335 | 99 | def test_projector_change_status_connection_status_connected(self, mock_log, mock_change_status): | ||
336 | 100 | """ | ||
337 | 101 | Test change_status with connection status | ||
338 | 102 | """ | ||
339 | 103 | # GIVEN: Test object | ||
340 | 104 | pjlink = pjlink_test | ||
341 | 105 | pjlink.projector_status = 0 | ||
342 | 106 | pjlink.status_connect = 0 | ||
343 | 107 | test_code = S_ON | ||
344 | 108 | mock_change_status.reset_mock() | ||
345 | 109 | mock_log.reset_mock() | ||
346 | 110 | |||
347 | 111 | # WHEN: change_status called with unknown socket error | ||
348 | 112 | pjlink.change_status(status=test_code, msg=None) | ||
349 | 113 | |||
350 | 114 | # THEN: Proper settings should change and signals sent | ||
351 | 115 | self.assertEqual(pjlink.projector_status, S_ON, 'Projector status should be ON') | ||
352 | 116 | self.assertEqual(pjlink.status_connect, S_CONNECTED, 'Status connect should be CONNECTED') | ||
353 | 117 | mock_change_status.emit.assert_called_once_with(pjlink.ip, S_ON, 'Power is on') | ||
354 | 118 | self.assertEqual(mock_log.debug.call_count, 3, 'Debug log should have been called 3 times') | ||
355 | 119 | |||
356 | 120 | @patch.object(pjlink_test, 'changeStatus') | ||
357 | 121 | @patch.object(openlp.core.lib.projector.pjlink, 'log') | ||
358 | 122 | def test_projector_change_status_connection_status_with_message(self, mock_log, mock_change_status): | ||
359 | 123 | """ | ||
360 | 124 | Test change_status with connection status | ||
361 | 125 | """ | ||
362 | 126 | # GIVEN: Test object | ||
363 | 127 | pjlink = pjlink_test | ||
364 | 128 | pjlink.projector_status = 0 | ||
365 | 129 | pjlink.status_connect = 0 | ||
366 | 130 | test_message = 'Different Status Message than default' | ||
367 | 131 | test_code = S_ON | ||
368 | 132 | mock_change_status.reset_mock() | ||
369 | 133 | mock_log.reset_mock() | ||
370 | 134 | |||
371 | 135 | # WHEN: change_status called with unknown socket error | ||
372 | 136 | pjlink.change_status(status=test_code, msg=test_message) | ||
373 | 137 | |||
374 | 138 | # THEN: Proper settings should change and signals sent | ||
375 | 139 | self.assertEqual(pjlink.projector_status, S_ON, 'Projector status should be ON') | ||
376 | 140 | self.assertEqual(pjlink.status_connect, S_CONNECTED, 'Status connect should be CONNECTED') | ||
377 | 141 | mock_change_status.emit.assert_called_once_with(pjlink.ip, S_ON, test_message) | ||
378 | 142 | self.assertEqual(mock_log.debug.call_count, 3, 'Debug log should have been called 3 times') | ||
379 | 143 | |||
380 | 144 | @patch.object(pjlink_test, 'send_command') | ||
381 | 145 | @patch.object(openlp.core.lib.projector.pjlink, 'log') | ||
382 | 146 | def test_projector_get_av_mute_status(self, mock_log, mock_send_command): | ||
383 | 147 | """ | ||
384 | 148 | Test sending command to retrieve shutter/audio state | ||
385 | 149 | """ | ||
386 | 150 | # GIVEN: Test object | ||
387 | 151 | pjlink = pjlink_test | ||
388 | 152 | mock_log.reset_mock() | ||
389 | 153 | mock_send_command.reset_mock() | ||
390 | 154 | test_data = 'AVMT' | ||
391 | 155 | test_log = '(127.0.0.1) Sending AVMT command' | ||
392 | 156 | |||
393 | 157 | # WHEN: get_av_mute_status is called | ||
394 | 158 | pjlink.get_av_mute_status() | ||
395 | 159 | |||
396 | 160 | # THEN: log data and send_command should have been called | ||
397 | 161 | mock_log.debug.assert_called_once_with(test_log) | ||
398 | 162 | mock_send_command.assert_called_once_with(cmd=test_data) | ||
399 | 163 | |||
400 | 164 | @patch.object(pjlink_test, 'send_command') | ||
401 | 165 | @patch.object(openlp.core.lib.projector.pjlink, 'log') | ||
402 | 166 | def test_projector_get_available_inputs(self, mock_log, mock_send_command): | ||
403 | 167 | """ | ||
404 | 168 | Test sending command to retrieve avaliable inputs | ||
405 | 169 | """ | ||
406 | 170 | # GIVEN: Test object | ||
407 | 171 | pjlink = pjlink_test | ||
408 | 172 | mock_log.reset_mock() | ||
409 | 173 | mock_send_command.reset_mock() | ||
410 | 174 | test_data = 'INST' | ||
411 | 175 | test_log = '(127.0.0.1) Sending INST command' | ||
412 | 176 | |||
413 | 177 | # WHEN: get_available_inputs is called | ||
414 | 178 | pjlink.get_available_inputs() | ||
415 | 179 | |||
416 | 180 | # THEN: log data and send_command should have been called | ||
417 | 181 | mock_log.debug.assert_called_once_with(test_log) | ||
418 | 182 | mock_send_command.assert_called_once_with(cmd=test_data) | ||
419 | 183 | |||
420 | 184 | @patch.object(pjlink_test, 'send_command') | ||
421 | 185 | @patch.object(openlp.core.lib.projector.pjlink, 'log') | ||
422 | 186 | def test_projector_get_error_status(self, mock_log, mock_send_command): | ||
423 | 187 | """ | ||
424 | 188 | Test sending command to retrieve projector error status | ||
425 | 189 | """ | ||
426 | 190 | # GIVEN: Test object | ||
427 | 191 | pjlink = pjlink_test | ||
428 | 192 | mock_log.reset_mock() | ||
429 | 193 | mock_send_command.reset_mock() | ||
430 | 194 | test_data = 'ERST' | ||
431 | 195 | test_log = '(127.0.0.1) Sending ERST command' | ||
432 | 196 | |||
433 | 197 | # WHEN: get_error_status is called | ||
434 | 198 | pjlink.get_error_status() | ||
435 | 199 | |||
436 | 200 | # THEN: log data and send_command should have been called | ||
437 | 201 | mock_log.debug.assert_called_once_with(test_log) | ||
438 | 202 | mock_send_command.assert_called_once_with(cmd=test_data) | ||
439 | 203 | |||
440 | 204 | @patch.object(pjlink_test, 'send_command') | ||
441 | 205 | @patch.object(openlp.core.lib.projector.pjlink, 'log') | ||
442 | 206 | def test_projector_get_input_source(self, mock_log, mock_send_command): | ||
443 | 207 | """ | ||
444 | 208 | Test sending command to retrieve current input | ||
445 | 209 | """ | ||
446 | 210 | # GIVEN: Test object | ||
447 | 211 | pjlink = pjlink_test | ||
448 | 212 | mock_log.reset_mock() | ||
449 | 213 | mock_send_command.reset_mock() | ||
450 | 214 | test_data = 'INPT' | ||
451 | 215 | test_log = '(127.0.0.1) Sending INPT command' | ||
452 | 216 | |||
453 | 217 | # WHEN: get_input_source is called | ||
454 | 218 | pjlink.get_input_source() | ||
455 | 219 | |||
456 | 220 | # THEN: log data and send_command should have been called | ||
457 | 221 | mock_log.debug.assert_called_once_with(test_log) | ||
458 | 222 | mock_send_command.assert_called_once_with(cmd=test_data) | ||
459 | 223 | |||
460 | 224 | @patch.object(pjlink_test, 'send_command') | ||
461 | 225 | @patch.object(openlp.core.lib.projector.pjlink, 'log') | ||
462 | 226 | def test_projector_get_lamp_status(self, mock_log, mock_send_command): | ||
463 | 227 | """ | ||
464 | 228 | Test sending command to retrieve lamp(s) status | ||
465 | 229 | """ | ||
466 | 230 | # GIVEN: Test object | ||
467 | 231 | pjlink = pjlink_test | ||
468 | 232 | mock_log.reset_mock() | ||
469 | 233 | mock_send_command.reset_mock() | ||
470 | 234 | test_data = 'LAMP' | ||
471 | 235 | test_log = '(127.0.0.1) Sending LAMP command' | ||
472 | 236 | |||
473 | 237 | # WHEN: get_lamp_status is called | ||
474 | 238 | pjlink.get_lamp_status() | ||
475 | 239 | |||
476 | 240 | # THEN: log data and send_command should have been called | ||
477 | 241 | mock_log.debug.assert_called_once_with(test_log) | ||
478 | 242 | mock_send_command.assert_called_once_with(cmd=test_data) | ||
479 | 243 | |||
480 | 244 | @patch.object(pjlink_test, 'send_command') | ||
481 | 245 | @patch.object(openlp.core.lib.projector.pjlink, 'log') | ||
482 | 246 | def test_projector_get_manufacturer(self, mock_log, mock_send_command): | ||
483 | 247 | """ | ||
484 | 248 | Test sending command to retrieve manufacturer name | ||
485 | 249 | """ | ||
486 | 250 | # GIVEN: Test object | ||
487 | 251 | pjlink = pjlink_test | ||
488 | 252 | mock_log.reset_mock() | ||
489 | 253 | mock_send_command.reset_mock() | ||
490 | 254 | test_data = 'INF1' | ||
491 | 255 | test_log = '(127.0.0.1) Sending INF1 command' | ||
492 | 256 | |||
493 | 257 | # WHEN: get_manufacturer is called | ||
494 | 258 | pjlink.get_manufacturer() | ||
495 | 259 | |||
496 | 260 | # THEN: log data and send_command should have been called | ||
497 | 261 | mock_log.debug.assert_called_once_with(test_log) | ||
498 | 262 | mock_send_command.assert_called_once_with(cmd=test_data) | ||
499 | 263 | |||
500 | 264 | @patch.object(pjlink_test, 'send_command') | ||
501 | 265 | @patch.object(openlp.core.lib.projector.pjlink, 'log') | ||
502 | 266 | def test_projector_get_model(self, mock_log, mock_send_command): | ||
503 | 267 | """ | ||
504 | 268 | Test sending command to get model information | ||
505 | 269 | """ | ||
506 | 270 | # GIVEN: Test object | ||
507 | 271 | pjlink = pjlink_test | ||
508 | 272 | mock_log.reset_mock() | ||
509 | 273 | mock_send_command.reset_mock() | ||
510 | 274 | test_data = 'INF2' | ||
511 | 275 | test_log = '(127.0.0.1) Sending INF2 command' | ||
512 | 276 | |||
513 | 277 | # WHEN: get_model is called | ||
514 | 278 | pjlink.get_model() | ||
515 | 279 | |||
516 | 280 | # THEN: log data and send_command should have been called | ||
517 | 281 | mock_log.debug.assert_called_once_with(test_log) | ||
518 | 282 | mock_send_command.assert_called_once_with(cmd=test_data) | ||
519 | 283 | |||
520 | 284 | @patch.object(pjlink_test, 'send_command') | ||
521 | 285 | @patch.object(openlp.core.lib.projector.pjlink, 'log') | ||
522 | 286 | def test_projector_get_name(self, mock_log, mock_send_command): | ||
523 | 287 | """ | ||
524 | 288 | Test sending command to get user-assigned name | ||
525 | 289 | """ | ||
526 | 290 | # GIVEN: Test object | ||
527 | 291 | pjlink = pjlink_test | ||
528 | 292 | mock_log.reset_mock() | ||
529 | 293 | mock_send_command.reset_mock() | ||
530 | 294 | test_data = 'NAME' | ||
531 | 295 | test_log = '(127.0.0.1) Sending NAME command' | ||
532 | 296 | |||
533 | 297 | # WHEN: get_name is called | ||
534 | 298 | pjlink.get_name() | ||
535 | 299 | |||
536 | 300 | # THEN: log data and send_command should have been called | ||
537 | 301 | mock_log.debug.assert_called_once_with(test_log) | ||
538 | 302 | mock_send_command.assert_called_once_with(cmd=test_data) | ||
539 | 303 | |||
540 | 304 | @patch.object(pjlink_test, 'send_command') | ||
541 | 305 | @patch.object(openlp.core.lib.projector.pjlink, 'log') | ||
542 | 306 | def test_projector_get_other_info(self, mock_log, mock_send_command): | ||
543 | 307 | """ | ||
544 | 308 | Test sending command to retrieve other information | ||
545 | 309 | """ | ||
546 | 310 | # GIVEN: Test object | ||
547 | 311 | pjlink = pjlink_test | ||
548 | 312 | mock_log.reset_mock() | ||
549 | 313 | mock_send_command.reset_mock() | ||
550 | 314 | test_data = 'INFO' | ||
551 | 315 | test_log = '(127.0.0.1) Sending INFO command' | ||
552 | 316 | |||
553 | 317 | # WHEN: get_other_info is called | ||
554 | 318 | pjlink.get_other_info() | ||
555 | 319 | |||
556 | 320 | # THEN: log data and send_command should have been called | ||
557 | 321 | mock_log.debug.assert_called_once_with(test_log) | ||
558 | 322 | mock_send_command.assert_called_once_with(cmd=test_data) | ||
559 | 323 | |||
560 | 324 | @patch.object(pjlink_test, 'send_command') | ||
561 | 325 | @patch.object(openlp.core.lib.projector.pjlink, 'log') | ||
562 | 326 | def test_projector_get_power_status(self, mock_log, mock_send_command): | ||
563 | 327 | """ | ||
564 | 328 | Test sending command to retrieve current power state | ||
565 | 329 | """ | ||
566 | 330 | # GIVEN: Test object | ||
567 | 331 | pjlink = pjlink_test | ||
568 | 332 | mock_log.reset_mock() | ||
569 | 333 | mock_send_command.reset_mock() | ||
570 | 334 | test_data = 'POWR' | ||
571 | 335 | test_log = '(127.0.0.1) Sending POWR command' | ||
572 | 336 | |||
573 | 337 | # WHEN: get_power_status called | ||
574 | 338 | pjlink.get_power_status() | ||
575 | 339 | |||
576 | 340 | # THEN: log data and send_command should have been called | ||
577 | 341 | mock_log.debug.assert_called_once_with(test_log) | ||
578 | 342 | mock_send_command.assert_called_once_with(cmd=test_data) | ||
579 | 343 | |||
580 | 344 | def test_projector_get_status_error(self): | ||
581 | 345 | """ | ||
582 | 346 | Test to check returned information for error code | ||
583 | 347 | """ | ||
584 | 348 | # GIVEN: Test object | ||
585 | 349 | pjlink = pjlink_test | ||
586 | 350 | test_string = 'E_SOCKET_ADDRESS_NOT_AVAILABLE' | ||
587 | 351 | test_message = 'The address specified to socket.bind() does not belong to the host' | ||
588 | 352 | |||
589 | 353 | # WHEN: get_status called | ||
590 | 354 | string, message = pjlink._get_status(status=E_SOCKET_ADDRESS_NOT_AVAILABLE) | ||
591 | 355 | |||
592 | 356 | # THEN: Proper strings should have been returned | ||
593 | 357 | self.assertEqual(string, test_string, 'Code as string should have been returned') | ||
594 | 358 | self.assertEqual(message, test_message, 'Description of code should have been returned') | ||
595 | 359 | |||
596 | 360 | def test_projector_get_status_invalid(self): | ||
597 | 361 | """ | ||
598 | 362 | Test to check returned information for error code | ||
599 | 363 | """ | ||
600 | 364 | # GIVEN: Test object | ||
601 | 365 | pjlink = pjlink_test | ||
602 | 366 | test_string = 'Test string since get_status will only work with int' | ||
603 | 367 | test_message = 'Invalid status code' | ||
604 | 368 | |||
605 | 369 | # WHEN: get_status called | ||
606 | 370 | string, message = pjlink._get_status(status=test_string) | ||
607 | 371 | |||
608 | 372 | # THEN: Proper strings should have been returned | ||
609 | 373 | self.assertEqual(string, -1, 'Should have returned -1 as a bad status check') | ||
610 | 374 | self.assertEqual(message, test_message, 'Error message should have been returned') | ||
611 | 375 | |||
612 | 376 | def test_projector_get_status_status(self): | ||
613 | 377 | """ | ||
614 | 378 | Test to check returned information for status codes | ||
615 | 379 | """ | ||
616 | 380 | # GIVEN: Test object | ||
617 | 381 | pjlink = pjlink_test | ||
618 | 382 | test_string = 'S_NOT_CONNECTED' | ||
619 | 383 | test_message = 'Not connected' | ||
620 | 384 | |||
621 | 385 | # WHEN: get_status called | ||
622 | 386 | string, message = pjlink._get_status(status=S_NOT_CONNECTED) | ||
623 | 387 | |||
624 | 388 | # THEN: Proper strings should have been returned | ||
625 | 389 | self.assertEqual(string, test_string, 'Code as string should have been returned') | ||
626 | 390 | self.assertEqual(message, test_message, 'Description of code should have been returned') | ||
627 | 391 | |||
628 | 392 | def test_projector_get_status_unknown(self): | ||
629 | 393 | """ | ||
630 | 394 | Test to check returned information for unknown code | ||
631 | 395 | """ | ||
632 | 396 | # GIVEN: Test object | ||
633 | 397 | pjlink = pjlink_test | ||
634 | 398 | test_string = 999999 | ||
635 | 399 | test_message = 'Unknown status' | ||
636 | 400 | |||
637 | 401 | # WHEN: get_status called | ||
638 | 402 | string, message = pjlink._get_status(status=test_string) | ||
639 | 403 | |||
640 | 404 | # THEN: Proper strings should have been returned | ||
641 | 405 | self.assertEqual(string, test_string, 'Received code should have been returned') | ||
642 | 406 | self.assertEqual(message, test_message, 'Unknown status string should have been returned') | ||
643 | 407 | |||
644 | 408 | def test_projector_process_inf1(self): | ||
645 | 409 | """ | ||
646 | 410 | Test saving INF1 data (manufacturer) | ||
647 | 411 | """ | ||
648 | 412 | # GIVEN: Test object | ||
649 | 413 | pjlink = pjlink_test | ||
650 | 414 | pjlink.manufacturer = None | ||
651 | 415 | test_data = 'TEst INformation MultiCase' | ||
652 | 416 | |||
653 | 417 | # WHEN: process_inf called with test data | ||
654 | 418 | pjlink.process_inf1(data=test_data) | ||
655 | 419 | |||
656 | 420 | # THEN: Data should be saved | ||
657 | 421 | self.assertEqual(pjlink.manufacturer, test_data, 'Test data should have been saved') | ||
658 | 422 | |||
659 | 423 | def test_projector_process_inf2(self): | ||
660 | 424 | """ | ||
661 | 425 | Test saving INF2 data (model) | ||
662 | 426 | """ | ||
663 | 427 | # GIVEN: Test object | ||
664 | 428 | pjlink = pjlink_test | ||
665 | 429 | pjlink.model = None | ||
666 | 430 | test_data = 'TEst moDEl MultiCase' | ||
667 | 431 | |||
668 | 432 | # WHEN: process_inf called with test data | ||
669 | 433 | pjlink.process_inf2(data=test_data) | ||
670 | 434 | |||
671 | 435 | # THEN: Data should be saved | ||
672 | 436 | self.assertEqual(pjlink.model, test_data, 'Test data should have been saved') | ||
673 | 437 | |||
674 | 438 | def test_projector_process_info(self): | ||
675 | 439 | """ | ||
676 | 440 | Test saving INFO data (other information) | ||
677 | 441 | """ | ||
678 | 442 | # GIVEN: Test object | ||
679 | 443 | pjlink = pjlink_test | ||
680 | 444 | pjlink.other_info = None | ||
681 | 445 | test_data = 'TEst ExtrANEous MultiCase INformatoin that MFGR might Set' | ||
682 | 446 | |||
683 | 447 | # WHEN: process_inf called with test data | ||
684 | 448 | pjlink.process_info(data=test_data) | ||
685 | 449 | |||
686 | 450 | # THEN: Data should be saved | ||
687 | 451 | self.assertEqual(pjlink.other_info, test_data, 'Test data should have been saved') | ||
688 | 90 | 452 | ||
689 | 91 | @patch.object(pjlink_test, 'projectorUpdateIcons') | 453 | @patch.object(pjlink_test, 'projectorUpdateIcons') |
690 | 92 | def test_projector_process_avmt_bad_data(self, mock_UpdateIcons): | 454 | def test_projector_process_avmt_bad_data(self, mock_UpdateIcons): |
691 | @@ -245,12 +607,12 @@ | |||
692 | 245 | 607 | ||
693 | 246 | # WHEN: Process invalid reply | 608 | # WHEN: Process invalid reply |
694 | 247 | pjlink.process_clss('Z') | 609 | pjlink.process_clss('Z') |
696 | 248 | log_warn_text = "(127.0.0.1) NAN clss version reply 'Z' - defaulting to class '1'" | 610 | log_text = "(127.0.0.1) NAN clss version reply 'Z' - defaulting to class '1'" |
697 | 249 | 611 | ||
698 | 250 | # THEN: Projector class should be set with default value | 612 | # THEN: Projector class should be set with default value |
699 | 251 | self.assertEqual(pjlink.pjlink_class, '1', | 613 | self.assertEqual(pjlink.pjlink_class, '1', |
700 | 252 | 'Non-standard class reply should have set class=1') | 614 | 'Non-standard class reply should have set class=1') |
702 | 253 | mock_log.error.assert_called_once_with(log_warn_text) | 615 | mock_log.error.assert_called_once_with(log_text) |
703 | 254 | 616 | ||
704 | 255 | @patch.object(openlp.core.lib.projector.pjlink, 'log') | 617 | @patch.object(openlp.core.lib.projector.pjlink, 'log') |
705 | 256 | def test_projector_process_clss_invalid_no_version(self, mock_log): | 618 | def test_projector_process_clss_invalid_no_version(self, mock_log): |
706 | @@ -262,12 +624,12 @@ | |||
707 | 262 | 624 | ||
708 | 263 | # WHEN: Process invalid reply | 625 | # WHEN: Process invalid reply |
709 | 264 | pjlink.process_clss('Invalid') | 626 | pjlink.process_clss('Invalid') |
711 | 265 | log_warn_text = "(127.0.0.1) No numbers found in class version reply 'Invalid' - defaulting to class '1'" | 627 | log_text = "(127.0.0.1) No numbers found in class version reply 'Invalid' - defaulting to class '1'" |
712 | 266 | 628 | ||
713 | 267 | # THEN: Projector class should be set with default value | 629 | # THEN: Projector class should be set with default value |
714 | 268 | self.assertEqual(pjlink.pjlink_class, '1', | 630 | self.assertEqual(pjlink.pjlink_class, '1', |
715 | 269 | 'Non-standard class reply should have set class=1') | 631 | 'Non-standard class reply should have set class=1') |
717 | 270 | mock_log.error.assert_called_once_with(log_warn_text) | 632 | mock_log.error.assert_called_once_with(log_text) |
718 | 271 | 633 | ||
719 | 272 | def test_projector_process_erst_all_ok(self): | 634 | def test_projector_process_erst_all_ok(self): |
720 | 273 | """ | 635 | """ |
721 | @@ -292,15 +654,15 @@ | |||
722 | 292 | # GIVEN: Test object | 654 | # GIVEN: Test object |
723 | 293 | pjlink = pjlink_test | 655 | pjlink = pjlink_test |
724 | 294 | pjlink.projector_errors = None | 656 | pjlink.projector_errors = None |
726 | 295 | log_warn_text = "127.0.0.1) Invalid error status response '11111111': length != 6" | 657 | log_text = "127.0.0.1) Invalid error status response '11111111': length != 6" |
727 | 296 | 658 | ||
728 | 297 | # WHEN: process_erst called with invalid data (too many values | 659 | # WHEN: process_erst called with invalid data (too many values |
729 | 298 | pjlink.process_erst('11111111') | 660 | pjlink.process_erst('11111111') |
730 | 299 | 661 | ||
731 | 300 | # THEN: pjlink.projector_errors should be empty and warning logged | 662 | # THEN: pjlink.projector_errors should be empty and warning logged |
732 | 301 | self.assertIsNone(pjlink.projector_errors, 'There should be no errors') | 663 | self.assertIsNone(pjlink.projector_errors, 'There should be no errors') |
735 | 302 | self.assertTrue(mock_log.warn.called, 'Warning should have been logged') | 664 | self.assertTrue(mock_log.warning.called, 'Warning should have been logged') |
736 | 303 | mock_log.warn.assert_called_once_with(log_warn_text) | 665 | mock_log.warning.assert_called_once_with(log_text) |
737 | 304 | 666 | ||
738 | 305 | @patch.object(openlp.core.lib.projector.pjlink, 'log') | 667 | @patch.object(openlp.core.lib.projector.pjlink, 'log') |
739 | 306 | def test_projector_process_erst_data_invalid_nan(self, mock_log): | 668 | def test_projector_process_erst_data_invalid_nan(self, mock_log): |
740 | @@ -310,15 +672,15 @@ | |||
741 | 310 | # GIVEN: Test object | 672 | # GIVEN: Test object |
742 | 311 | pjlink = pjlink_test | 673 | pjlink = pjlink_test |
743 | 312 | pjlink.projector_errors = None | 674 | pjlink.projector_errors = None |
745 | 313 | log_warn_text = "(127.0.0.1) Invalid error status response '1111Z1'" | 675 | log_text = "(127.0.0.1) Invalid error status response '1111Z1'" |
746 | 314 | 676 | ||
747 | 315 | # WHEN: process_erst called with invalid data (too many values | 677 | # WHEN: process_erst called with invalid data (too many values |
748 | 316 | pjlink.process_erst('1111Z1') | 678 | pjlink.process_erst('1111Z1') |
749 | 317 | 679 | ||
750 | 318 | # THEN: pjlink.projector_errors should be empty and warning logged | 680 | # THEN: pjlink.projector_errors should be empty and warning logged |
751 | 319 | self.assertIsNone(pjlink.projector_errors, 'There should be no errors') | 681 | self.assertIsNone(pjlink.projector_errors, 'There should be no errors') |
754 | 320 | self.assertTrue(mock_log.warn.called, 'Warning should have been logged') | 682 | self.assertTrue(mock_log.warning.called, 'Warning should have been logged') |
755 | 321 | mock_log.warn.assert_called_once_with(log_warn_text) | 683 | mock_log.warning.assert_called_once_with(log_text) |
756 | 322 | 684 | ||
757 | 323 | def test_projector_process_erst_all_warn(self): | 685 | def test_projector_process_erst_all_warn(self): |
758 | 324 | """ | 686 | """ |
759 | @@ -399,33 +761,67 @@ | |||
760 | 399 | # THEN: Input selected should reflect current input | 761 | # THEN: Input selected should reflect current input |
761 | 400 | self.assertEqual(pjlink.source, '1', 'Input source should be set to "1"') | 762 | self.assertEqual(pjlink.source, '1', 'Input source should be set to "1"') |
762 | 401 | 763 | ||
775 | 402 | @patch.object(pjlink_test, 'projectorReceivedData') | 764 | @patch.object(pjlink_test, 'projectorUpdateIcons') |
776 | 403 | def test_projector_process_lamp_single(self, mock_projectorReceivedData): | 765 | @patch.object(openlp.core.lib.projector.pjlink, 'log') |
777 | 404 | """ | 766 | def test_projector_process_inst(self, mock_log, mock_UpdateIcons): |
778 | 405 | Test status lamp on/off and hours | 767 | """ |
779 | 406 | """ | 768 | Test saving video source available information |
780 | 407 | # GIVEN: Test object | 769 | """ |
781 | 408 | pjlink = pjlink_test | 770 | # GIVEN: Test object |
782 | 409 | 771 | pjlink = pjlink_test | |
783 | 410 | # WHEN: Call process_command with lamp data | 772 | pjlink.source_available = [] |
784 | 411 | pjlink.process_command('LAMP', '22222 1') | 773 | test_data = '21 10 30 31 11 20' |
785 | 412 | 774 | test_saved = ['10', '11', '20', '21', '30', '31'] | |
786 | 413 | # THEN: Lamp should have been set with status=ON and hours=22222 | 775 | log_data = '(127.0.0.1) Setting projector sources_available to ' \ |
787 | 776 | '"[\'10\', \'11\', \'20\', \'21\', \'30\', \'31\']"' | ||
788 | 777 | mock_UpdateIcons.reset_mock() | ||
789 | 778 | mock_log.reset_mock() | ||
790 | 779 | |||
791 | 780 | # WHEN: process_inst called with test data | ||
792 | 781 | pjlink.process_inst(data=test_data) | ||
793 | 782 | |||
794 | 783 | # THEN: Data should have been sorted and saved properly | ||
795 | 784 | self.assertEqual(pjlink.source_available, test_saved, "Sources should have been sorted and saved") | ||
796 | 785 | mock_log.debug.assert_called_once_with(log_data) | ||
797 | 786 | self.assertTrue(mock_UpdateIcons.emit.called, 'Update Icons should have been called') | ||
798 | 787 | |||
799 | 788 | @patch.object(openlp.core.lib.projector.pjlink, 'log') | ||
800 | 789 | def test_projector_process_lamp_invalid(self, mock_log): | ||
801 | 790 | """ | ||
802 | 791 | Test status multiple lamp on/off and hours | ||
803 | 792 | """ | ||
804 | 793 | # GIVEN: Test object | ||
805 | 794 | pjlink = pjlink_test | ||
806 | 795 | pjlink.lamp = [{'Hours': 00000, 'On': True}, | ||
807 | 796 | {'Hours': 11111, 'On': False}] | ||
808 | 797 | log_data = '(127.0.0.1) process_lamp(): Invalid data "11111 1 22222 0 333A3 1"' | ||
809 | 798 | |||
810 | 799 | # WHEN: Call process_command with invalid lamp data | ||
811 | 800 | pjlink.process_lamp('11111 1 22222 0 333A3 1') | ||
812 | 801 | |||
813 | 802 | # THEN: lamps should not have changed | ||
814 | 803 | self.assertEqual(len(pjlink.lamp), 2, | ||
815 | 804 | 'Projector should have kept 2 lamps specified') | ||
816 | 414 | self.assertEqual(pjlink.lamp[0]['On'], True, | 805 | self.assertEqual(pjlink.lamp[0]['On'], True, |
820 | 415 | 'Lamp power status should have been set to TRUE') | 806 | 'Lamp 1 power status should have been set to TRUE') |
821 | 416 | self.assertEqual(pjlink.lamp[0]['Hours'], 22222, | 807 | self.assertEqual(pjlink.lamp[0]['Hours'], 00000, |
822 | 417 | 'Lamp hours should have been set to 22222') | 808 | 'Lamp 1 hours should have been left at 00000') |
823 | 809 | self.assertEqual(pjlink.lamp[1]['On'], False, | ||
824 | 810 | 'Lamp 2 power status should have been set to FALSE') | ||
825 | 811 | self.assertEqual(pjlink.lamp[1]['Hours'], 11111, | ||
826 | 812 | 'Lamp 2 hours should have been left at 11111') | ||
827 | 813 | mock_log.warning.assert_called_once_with(log_data) | ||
828 | 418 | 814 | ||
831 | 419 | @patch.object(pjlink_test, 'projectorReceivedData') | 815 | def test_projector_process_lamp_multiple(self): |
830 | 420 | def test_projector_process_lamp_multiple(self, mock_projectorReceivedData): | ||
832 | 421 | """ | 816 | """ |
833 | 422 | Test status multiple lamp on/off and hours | 817 | Test status multiple lamp on/off and hours |
834 | 423 | """ | 818 | """ |
835 | 424 | # GIVEN: Test object | 819 | # GIVEN: Test object |
836 | 425 | pjlink = pjlink_test | 820 | pjlink = pjlink_test |
837 | 821 | pjlink.lamps = [] | ||
838 | 426 | 822 | ||
839 | 427 | # WHEN: Call process_command with lamp data | 823 | # WHEN: Call process_command with lamp data |
841 | 428 | pjlink.process_command('LAMP', '11111 1 22222 0 33333 1') | 824 | pjlink.process_lamp('11111 1 22222 0 33333 1') |
842 | 429 | 825 | ||
843 | 430 | # THEN: Lamp should have been set with proper lamp status | 826 | # THEN: Lamp should have been set with proper lamp status |
844 | 431 | self.assertEqual(len(pjlink.lamp), 3, | 827 | self.assertEqual(len(pjlink.lamp), 3, |
845 | @@ -443,53 +839,112 @@ | |||
846 | 443 | self.assertEqual(pjlink.lamp[2]['Hours'], 33333, | 839 | self.assertEqual(pjlink.lamp[2]['Hours'], 33333, |
847 | 444 | 'Lamp 3 hours should have been set to 33333') | 840 | 'Lamp 3 hours should have been set to 33333') |
848 | 445 | 841 | ||
850 | 446 | @patch.object(pjlink_test, 'projectorReceivedData') | 842 | def test_projector_process_lamp_single(self): |
851 | 843 | """ | ||
852 | 844 | Test status lamp on/off and hours | ||
853 | 845 | """ | ||
854 | 846 | # GIVEN: Test object | ||
855 | 847 | pjlink = pjlink_test | ||
856 | 848 | pjlink.lamps = [] | ||
857 | 849 | |||
858 | 850 | # WHEN: Call process_command with lamp data | ||
859 | 851 | pjlink.process_lamp('22222 1') | ||
860 | 852 | |||
861 | 853 | # THEN: Lamp should have been set with status=ON and hours=22222 | ||
862 | 854 | self.assertEqual(pjlink.lamp[0]['On'], True, | ||
863 | 855 | 'Lamp power status should have been set to TRUE') | ||
864 | 856 | self.assertEqual(pjlink.lamp[0]['Hours'], 22222, | ||
865 | 857 | 'Lamp hours should have been set to 22222') | ||
866 | 858 | |||
867 | 859 | @patch.object(openlp.core.lib.projector.pjlink, 'log') | ||
868 | 860 | def test_projector_process_name(self, mock_log): | ||
869 | 861 | """ | ||
870 | 862 | Test saving NAME data from projector | ||
871 | 863 | """ | ||
872 | 864 | # GIVEN: Test data | ||
873 | 865 | pjlink = pjlink_test | ||
874 | 866 | test_data = "Some Name the End-User Set IN Projector" | ||
875 | 867 | test_log = '(127.0.0.1) Setting projector PJLink name to "Some Name the End-User Set IN Projector"' | ||
876 | 868 | mock_log.reset_mock() | ||
877 | 869 | |||
878 | 870 | # WHEN: process_name called with test data | ||
879 | 871 | pjlink.process_name(data=test_data) | ||
880 | 872 | |||
881 | 873 | # THEN: name should be set and logged | ||
882 | 874 | self.assertEqual(pjlink.pjlink_name, test_data, 'Name test data should have been saved') | ||
883 | 875 | mock_log.debug.assert_called_once_with(test_log) | ||
884 | 876 | |||
885 | 447 | @patch.object(pjlink_test, 'projectorUpdateIcons') | 877 | @patch.object(pjlink_test, 'projectorUpdateIcons') |
886 | 448 | @patch.object(pjlink_test, 'send_command') | 878 | @patch.object(pjlink_test, 'send_command') |
887 | 449 | @patch.object(pjlink_test, 'change_status') | 879 | @patch.object(pjlink_test, 'change_status') |
888 | 450 | def test_projector_process_powr_on(self, | 880 | def test_projector_process_powr_on(self, |
889 | 451 | mock_change_status, | 881 | mock_change_status, |
890 | 452 | mock_send_command, | 882 | mock_send_command, |
893 | 453 | mock_UpdateIcons, | 883 | mock_UpdateIcons): |
892 | 454 | mock_ReceivedData): | ||
894 | 455 | """ | 884 | """ |
895 | 456 | Test status power to ON | 885 | Test status power to ON |
896 | 457 | """ | 886 | """ |
897 | 458 | # GIVEN: Test object and preset | 887 | # GIVEN: Test object and preset |
898 | 459 | pjlink = pjlink_test | 888 | pjlink = pjlink_test |
899 | 460 | pjlink.power = S_STANDBY | 889 | pjlink.power = S_STANDBY |
900 | 890 | test_data = PJLINK_POWR_STATUS[S_ON] | ||
901 | 461 | 891 | ||
902 | 462 | # WHEN: Call process_command with turn power on command | 892 | # WHEN: Call process_command with turn power on command |
904 | 463 | pjlink.process_command('POWR', PJLINK_POWR_STATUS[S_ON]) | 893 | pjlink.process_command(cmd='POWR', data=test_data) |
905 | 464 | 894 | ||
906 | 465 | # THEN: Power should be set to ON | 895 | # THEN: Power should be set to ON |
907 | 466 | self.assertEqual(pjlink.power, S_ON, 'Power should have been set to ON') | 896 | self.assertEqual(pjlink.power, S_ON, 'Power should have been set to ON') |
908 | 467 | mock_send_command.assert_called_once_with('INST') | 897 | mock_send_command.assert_called_once_with('INST') |
909 | 898 | mock_change_status.assert_called_once_with(PJLINK_POWR_STATUS[test_data]) | ||
910 | 468 | self.assertEqual(mock_UpdateIcons.emit.called, True, 'projectorUpdateIcons should have been called') | 899 | self.assertEqual(mock_UpdateIcons.emit.called, True, 'projectorUpdateIcons should have been called') |
911 | 469 | 900 | ||
913 | 470 | @patch.object(pjlink_test, 'projectorReceivedData') | 901 | @patch.object(pjlink_test, 'projectorUpdateIcons') |
914 | 902 | @patch.object(pjlink_test, 'send_command') | ||
915 | 903 | @patch.object(pjlink_test, 'change_status') | ||
916 | 904 | def test_projector_process_powr_invalid(self, | ||
917 | 905 | mock_change_status, | ||
918 | 906 | mock_send_command, | ||
919 | 907 | mock_UpdateIcons): | ||
920 | 908 | """ | ||
921 | 909 | Test process_powr invalid call | ||
922 | 910 | """ | ||
923 | 911 | # GIVEN: Test object and preset | ||
924 | 912 | pjlink = pjlink_test | ||
925 | 913 | pjlink.power = S_STANDBY | ||
926 | 914 | test_data = '99' | ||
927 | 915 | |||
928 | 916 | # WHEN: Call process_command with turn power on command | ||
929 | 917 | pjlink.process_command(cmd='POWR', data=test_data) | ||
930 | 918 | |||
931 | 919 | # THEN: Power should be set to ON | ||
932 | 920 | self.assertEqual(pjlink.power, S_STANDBY, 'Power should not have changed') | ||
933 | 921 | self.assertFalse(mock_change_status.called, 'Change status should not have been called') | ||
934 | 922 | self.assertFalse(mock_send_command.called, 'send_command("INST") should not have been called') | ||
935 | 923 | self.assertFalse(mock_UpdateIcons.emit.called, 'projectorUpdateIcons should not have been called') | ||
936 | 924 | |||
937 | 471 | @patch.object(pjlink_test, 'projectorUpdateIcons') | 925 | @patch.object(pjlink_test, 'projectorUpdateIcons') |
938 | 472 | @patch.object(pjlink_test, 'send_command') | 926 | @patch.object(pjlink_test, 'send_command') |
939 | 473 | @patch.object(pjlink_test, 'change_status') | 927 | @patch.object(pjlink_test, 'change_status') |
940 | 474 | def test_projector_process_powr_off(self, | 928 | def test_projector_process_powr_off(self, |
941 | 475 | mock_change_status, | 929 | mock_change_status, |
942 | 476 | mock_send_command, | 930 | mock_send_command, |
945 | 477 | mock_UpdateIcons, | 931 | mock_UpdateIcons): |
944 | 478 | mock_ReceivedData): | ||
946 | 479 | """ | 932 | """ |
947 | 480 | Test status power to STANDBY | 933 | Test status power to STANDBY |
948 | 481 | """ | 934 | """ |
949 | 482 | # GIVEN: Test object and preset | 935 | # GIVEN: Test object and preset |
950 | 483 | pjlink = pjlink_test | 936 | pjlink = pjlink_test |
951 | 484 | pjlink.power = S_ON | 937 | pjlink.power = S_ON |
952 | 938 | test_data = PJLINK_POWR_STATUS[S_STANDBY] | ||
953 | 485 | 939 | ||
954 | 486 | # WHEN: Call process_command with turn power on command | 940 | # WHEN: Call process_command with turn power on command |
956 | 487 | pjlink.process_command('POWR', PJLINK_POWR_STATUS[S_STANDBY]) | 941 | pjlink.process_command(cmd='POWR', data=test_data) |
957 | 488 | 942 | ||
958 | 489 | # THEN: Power should be set to STANDBY | 943 | # THEN: Power should be set to STANDBY |
959 | 490 | self.assertEqual(pjlink.power, S_STANDBY, 'Power should have been set to STANDBY') | 944 | self.assertEqual(pjlink.power, S_STANDBY, 'Power should have been set to STANDBY') |
960 | 491 | self.assertEqual(mock_send_command.called, False, 'send_command should not have been called') | ||
961 | 492 | self.assertEqual(mock_UpdateIcons.emit.called, True, 'projectorUpdateIcons should have been called') | 945 | self.assertEqual(mock_UpdateIcons.emit.called, True, 'projectorUpdateIcons should have been called') |
962 | 946 | mock_change_status.assert_called_once_with(PJLINK_POWR_STATUS[test_data]) | ||
963 | 947 | self.assertFalse(mock_send_command.called, "send_command['INST'] should not have been called") | ||
964 | 493 | 948 | ||
965 | 494 | def test_projector_process_rfil_save(self): | 949 | def test_projector_process_rfil_save(self): |
966 | 495 | """ | 950 | """ |
967 | @@ -582,3 +1037,111 @@ | |||
968 | 582 | # THEN: Serial number should be set | 1037 | # THEN: Serial number should be set |
969 | 583 | self.assertNotEquals(pjlink.serial_no, test_number, | 1038 | self.assertNotEquals(pjlink.serial_no, test_number, |
970 | 584 | 'Projector serial number should NOT have been set') | 1039 | 'Projector serial number should NOT have been set') |
971 | 1040 | |||
972 | 1041 | @patch.object(openlp.core.lib.projector.pjlink, 'log') | ||
973 | 1042 | def test_projector_process_sver(self, mock_log): | ||
974 | 1043 | """ | ||
975 | 1044 | Test invalid software version information - too long | ||
976 | 1045 | """ | ||
977 | 1046 | # GIVEN: Test object | ||
978 | 1047 | pjlink = pjlink_test | ||
979 | 1048 | pjlink.sw_version = None | ||
980 | 1049 | pjlink.sw_version_received = None | ||
981 | 1050 | test_data = 'Test 1 Subtest 1' | ||
982 | 1051 | test_log = "(127.0.0.1) Setting projector software version to 'Test 1 Subtest 1'" | ||
983 | 1052 | mock_log.reset_mock() | ||
984 | 1053 | |||
985 | 1054 | # WHEN: process_sver called with invalid data | ||
986 | 1055 | pjlink.process_sver(data=test_data) | ||
987 | 1056 | |||
988 | 1057 | # THEN: Version information should not change | ||
989 | 1058 | self.assertEqual(pjlink.sw_version, test_data, 'Software version should have been updated') | ||
990 | 1059 | self.assertIsNone(pjlink.sw_version_received, 'Received software version should not have changed') | ||
991 | 1060 | mock_log.debug.assert_called_once_with(test_log) | ||
992 | 1061 | |||
993 | 1062 | @patch.object(openlp.core.lib.projector.pjlink, 'log') | ||
994 | 1063 | def test_projector_process_sver_changed(self, mock_log): | ||
995 | 1064 | """ | ||
996 | 1065 | Test invalid software version information - Received different than saved | ||
997 | 1066 | """ | ||
998 | 1067 | # GIVEN: Test object | ||
999 | 1068 | pjlink = pjlink_test | ||
1000 | 1069 | test_data_new = 'Test 1 Subtest 2' | ||
1001 | 1070 | test_data_old = 'Test 1 Subtest 1' | ||
1002 | 1071 | pjlink.sw_version = test_data_old | ||
1003 | 1072 | pjlink.sw_version_received = None | ||
1004 | 1073 | test_log = '(127.0.0.1) Saving new serial number as sw_version_received' | ||
1005 | 1074 | mock_log.reset_mock() | ||
1006 | 1075 | |||
1007 | 1076 | # WHEN: process_sver called with invalid data | ||
1008 | 1077 | pjlink.process_sver(data=test_data_new) | ||
1009 | 1078 | |||
1010 | 1079 | # THEN: Version information should not change | ||
1011 | 1080 | self.assertEqual(pjlink.sw_version, test_data_old, 'Software version should not have been updated') | ||
1012 | 1081 | self.assertEqual(pjlink.sw_version_received, test_data_new, | ||
1013 | 1082 | 'Received software version should have been changed') | ||
1014 | 1083 | self.assertEqual(mock_log.warning.call_count, 4, 'log.warn should have been called 4 times') | ||
1015 | 1084 | # There was 4 calls, but only the last one is checked with this method | ||
1016 | 1085 | mock_log.warning.assert_called_with(test_log) | ||
1017 | 1086 | |||
1018 | 1087 | @patch.object(openlp.core.lib.projector.pjlink, 'log') | ||
1019 | 1088 | def test_projector_process_sver_invalid(self, mock_log): | ||
1020 | 1089 | """ | ||
1021 | 1090 | Test invalid software version information - too long | ||
1022 | 1091 | """ | ||
1023 | 1092 | # GIVEN: Test object | ||
1024 | 1093 | pjlink = pjlink_test | ||
1025 | 1094 | pjlink.sw_version = None | ||
1026 | 1095 | pjlink.sw_version_received = None | ||
1027 | 1096 | test_data = 'This is a test software version line that is too long based on PJLink version 2 specs' | ||
1028 | 1097 | test_log = "Invalid software version - too long" | ||
1029 | 1098 | mock_log.reset_mock() | ||
1030 | 1099 | |||
1031 | 1100 | # WHEN: process_sver called with invalid data | ||
1032 | 1101 | pjlink.process_sver(data=test_data) | ||
1033 | 1102 | |||
1034 | 1103 | # THEN: Version information should not change | ||
1035 | 1104 | self.assertIsNone(pjlink.sw_version, 'Software version should not have changed') | ||
1036 | 1105 | self.assertIsNone(pjlink.sw_version_received, 'Received software version should not have changed') | ||
1037 | 1106 | mock_log.warning.assert_called_once_with(test_log) | ||
1038 | 1107 | |||
1039 | 1108 | def test_projector_reset_information(self): | ||
1040 | 1109 | """ | ||
1041 | 1110 | Test reset_information() resets all information and stops timers | ||
1042 | 1111 | """ | ||
1043 | 1112 | # GIVEN: Test object and test data | ||
1044 | 1113 | pjlink = pjlink_test | ||
1045 | 1114 | pjlink.power = S_ON | ||
1046 | 1115 | pjlink.pjlink_name = 'OPENLPTEST' | ||
1047 | 1116 | pjlink.manufacturer = 'PJLINK' | ||
1048 | 1117 | pjlink.model = '1' | ||
1049 | 1118 | pjlink.shutter = True | ||
1050 | 1119 | pjlink.mute = True | ||
1051 | 1120 | pjlink.lamp = True | ||
1052 | 1121 | pjlink.fan = True | ||
1053 | 1122 | pjlink.source_available = True | ||
1054 | 1123 | pjlink.other_info = 'ANOTHER TEST' | ||
1055 | 1124 | pjlink.send_queue = True | ||
1056 | 1125 | pjlink.send_busy = True | ||
1057 | 1126 | |||
1058 | 1127 | # WHEN: reset_information() is called | ||
1059 | 1128 | with patch.object(pjlink, 'timer') as mock_timer: | ||
1060 | 1129 | with patch.object(pjlink, 'socket_timer') as mock_socket_timer: | ||
1061 | 1130 | pjlink.reset_information() | ||
1062 | 1131 | |||
1063 | 1132 | # THEN: All information should be reset and timers stopped | ||
1064 | 1133 | self.assertEqual(pjlink.power, S_OFF, 'Projector power should be OFF') | ||
1065 | 1134 | self.assertIsNone(pjlink.pjlink_name, 'Projector pjlink_name should be None') | ||
1066 | 1135 | self.assertIsNone(pjlink.manufacturer, 'Projector manufacturer should be None') | ||
1067 | 1136 | self.assertIsNone(pjlink.model, 'Projector model should be None') | ||
1068 | 1137 | self.assertIsNone(pjlink.shutter, 'Projector shutter should be None') | ||
1069 | 1138 | self.assertIsNone(pjlink.mute, 'Projector shuttter should be None') | ||
1070 | 1139 | self.assertIsNone(pjlink.lamp, 'Projector lamp should be None') | ||
1071 | 1140 | self.assertIsNone(pjlink.fan, 'Projector fan should be None') | ||
1072 | 1141 | self.assertIsNone(pjlink.source_available, 'Projector source_available should be None') | ||
1073 | 1142 | self.assertIsNone(pjlink.source, 'Projector source should be None') | ||
1074 | 1143 | self.assertIsNone(pjlink.other_info, 'Projector other_info should be None') | ||
1075 | 1144 | self.assertEqual(pjlink.send_queue, [], 'Projector send_queue should be an empty list') | ||
1076 | 1145 | self.assertFalse(pjlink.send_busy, 'Projector send_busy should be False') | ||
1077 | 1146 | self.assertTrue(mock_timer.stop.called, 'Projector timer.stop() should have been called') | ||
1078 | 1147 | self.assertTrue(mock_socket_timer.stop.called, 'Projector socket_timer.stop() should have been called') |
See inline