38
38
Tests for the PJLink module
40
@patch.object(openlp.core.projectors.pjlink.PJLink, 'state')
41
@patch.object(openlp.core.projectors.pjlink.PJLink, 'reset_information')
42
@patch.object(openlp.core.projectors.pjlink.PJLink, '_send_command')
43
@patch.object(openlp.core.projectors.pjlink, 'log')
44
def test_send_command_no_data(self, mock_log, mock_send_command, mock_reset, mock_state):
46
Test _send_command with no data to send
49
log_warning_calls = [call('({ip}) send_command(): Not connected - returning'.format(ip=TEST1_DATA['name']))]
51
log_debug_calls = [call('PJlink(projector="< Projector(id="None", ip="111.111.111.111", port="1111", '
52
'mac_adx="11:11:11:11:11:11", pin="1111", name="___TEST_ONE___", '
53
'location="location one", notes="notes one", pjlink_name="None", '
54
'pjlink_class="None", manufacturer="None", model="None", '
55
'serial_no="Serial Number 1", other="None", sources="None", source_list="[]", '
56
'model_filter="Filter type 1", model_lamp="Lamp type 1", '
57
'sw_version="Version 1") >", args="()" kwargs="{\'no_poll\': True}")'),
58
call('PJlinkCommands(args=() kwargs={})')]
42
Initialize test state(s)
44
# Default PJLink instance for tests
45
self.pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
53
# ------------ Test PJLink._underscore_send_command ----------
54
@patch.object(openlp.core.projectors.pjlink.PJLink, 'change_status')
55
@patch.object(openlp.core.projectors.pjlink.PJLink, 'write')
56
@patch.object(openlp.core.projectors.pjlink.PJLink, 'disconnect_from_host')
57
@patch.object(openlp.core.projectors.pjlink.PJLink, 'state')
58
@patch.object(openlp.core.projectors.pjlink.PJLink, 'reset_information')
59
@patch.object(openlp.core.projectors.pjlink, 'log')
60
def test_local_send_command_network_error(self, mock_log, mock_reset, mock_state, mock_disconnect, mock_write,
63
Test _underscore_send_command when possible network error occured
66
test_command = '{prefix}{clss}CLSS ?{suff}'.format(prefix=PJLINK_PREFIX,
67
clss=self.pjlink.pjlink_class,
70
log_warning_calls = [call('({ip}) _send_command(): -1 received - '
71
'disconnecting from host'.format(ip=self.pjlink.name))]
72
log_debug_calls = [call('({ip}) _send_command(data="None")'.format(ip=self.pjlink.name)),
73
call('({ip}) _send_command(): priority_queue: []'.format(ip=self.pjlink.name)),
74
call("({ip}) _send_command(): send_queue: ['{data}\\r']".format(ip=self.pjlink.name,
75
data=test_command.strip())),
76
call('({ip}) _send_command(): Connection status: S_CONNECTED'.format(ip=self.pjlink.name)),
77
call('({ip}) _send_command(): Getting normal queued packet'.format(ip=self.pjlink.name)),
78
call('({ip}) _send_command(): Sending "{data}"'.format(ip=self.pjlink.name,
79
data=test_command.strip()))
82
mock_state.return_value = QSOCKET_STATE[S_CONNECTED]
83
mock_write.return_value = -1
84
self.pjlink.send_queue = [test_command]
85
self.pjlink.priority_queue = []
87
# WHEN: _send_command called with no data and queue's emtpy
88
# Patch some attributes here since they are not available until after instantiation
89
with patch.object(self.pjlink, 'socket_timer') as mock_timer, \
90
patch.object(self.pjlink, 'waitForBytesWritten') as mock_waitBytes:
91
mock_waitBytes.return_value = True
92
self.pjlink._send_command()
95
mock_log.error.assert_has_calls(log_error_calls)
96
mock_log.warning.assert_has_calls(log_warning_calls)
97
mock_log.debug.assert_has_calls(log_debug_calls)
98
mock_change_status.called_with(E_NETWORK, 'Error while sending data to projector')
99
assert (not self.pjlink.send_queue), 'Send queue should be empty'
100
assert (not self.pjlink.priority_queue), 'Priority queue should be empty'
101
assert mock_timer.start.called, 'Timer should have been called'
102
assert (not mock_reset.called), 'reset_information() should not should have been called'
103
assert mock_disconnect.called, 'disconnect_from_host() should have been called'
104
assert self.pjlink.send_busy, 'send_busy should be True'
106
@patch.object(openlp.core.projectors.pjlink.PJLink, 'state')
107
@patch.object(openlp.core.projectors.pjlink.PJLink, 'reset_information')
108
@patch.object(openlp.core.projectors.pjlink, 'log')
109
def test_local_send_command_no_data(self, mock_log, mock_reset, mock_state):
111
Test _underscore_send_command with no data to send
115
log_warning_calls = [call('({ip}) _send_command(): Nothing to send - returning'.format(ip=self.pjlink.name))]
117
mock_state.return_value = S_CONNECTED
118
self.pjlink.send_queue = []
119
self.pjlink.priority_queue = []
121
# WHEN: _send_command called with no data and queue's emtpy
122
# Patch some attributes here since they are not available until after instantiation
123
with patch.object(self.pjlink, 'socket_timer') as mock_timer:
124
self.pjlink._send_command()
127
mock_log.error.assert_has_calls(log_error_calls)
128
mock_log.warning.assert_has_calls(log_warning_calls)
129
mock_log.debug.assert_has_calls(log_debug_calls)
130
assert (not self.pjlink.send_queue), 'Send queue should be empty'
131
assert (not self.pjlink.priority_queue), 'Priority queue should be empty'
132
assert (not mock_timer.called), 'Timer should not have been called'
133
assert (not mock_reset.called), 'reset_information() should not have been called'
135
@patch.object(openlp.core.projectors.pjlink.PJLink, 'state')
136
@patch.object(openlp.core.projectors.pjlink.PJLink, 'reset_information')
137
@patch.object(openlp.core.projectors.pjlink, 'log')
138
def test_local_send_command_no_data_queue_check(self, mock_log, mock_reset, mock_state):
140
Test _underscore_send_command last queue length check
144
log_warning_calls = [call('({ip}) _send_command(): No data to send'.format(ip=self.pjlink.name))]
146
mock_state.return_value = QSOCKET_STATE[S_CONNECTED]
147
self.pjlink.priority_queue = []
149
# WHEN: _send_command called with no data and queue's emtpy
150
# Patch some attributes here since they are not available until after instantiation
151
with patch.object(self.pjlink, 'socket_timer') as mock_timer, \
152
patch.object(self.pjlink, 'send_queue') as mock_queue:
153
# Unlikely case of send_queue not really empty, but len(send_queue) returns 0
154
mock_queue.return_value = ['test']
155
mock_queue.__len__.return_value = 0
156
self.pjlink._send_command(data=None)
159
mock_log.error.assert_has_calls(log_error_calls)
160
mock_log.warning.assert_has_calls(log_warning_calls)
161
mock_log.debug.assert_has_calls(log_debug_calls)
162
assert (not self.pjlink.priority_queue), 'Priority queue should be empty'
163
assert (not mock_timer.called), 'Timer should not have been called'
164
assert (not mock_reset.called), 'reset_information() should not have been called'
166
@patch.object(openlp.core.projectors.pjlink.PJLink, 'write')
167
@patch.object(openlp.core.projectors.pjlink.PJLink, 'disconnect_from_host')
168
@patch.object(openlp.core.projectors.pjlink.PJLink, 'state')
169
@patch.object(openlp.core.projectors.pjlink.PJLink, 'reset_information')
170
@patch.object(openlp.core.projectors.pjlink, 'log')
171
def test_local_send_command_normal_send(self, mock_log, mock_reset, mock_state, mock_disconnect, mock_write):
173
Test _underscore_send_command using normal queue
176
test_command = '{prefix}{clss}CLSS ?{suff}'.format(prefix=PJLINK_PREFIX,
177
clss=self.pjlink.pjlink_class,
180
log_warning_calls = []
181
log_debug_calls = [call('({ip}) _send_command(data="None")'.format(ip=self.pjlink.name)),
182
call('({ip}) _send_command(): priority_queue: []'.format(ip=self.pjlink.name)),
183
call("({ip}) _send_command(): send_queue: ['{data}\\r']".format(ip=self.pjlink.name,
184
data=test_command.strip())),
185
call('({ip}) _send_command(): Connection status: S_CONNECTED'.format(ip=self.pjlink.name)),
186
call('({ip}) _send_command(): Getting normal queued packet'.format(ip=self.pjlink.name)),
187
call('({ip}) _send_command(): Sending "{data}"'.format(ip=self.pjlink.name,
188
data=test_command.strip()))
191
mock_state.return_value = QSOCKET_STATE[S_CONNECTED]
192
mock_write.return_value = len(test_command)
193
self.pjlink.send_queue = [test_command]
194
self.pjlink.priority_queue = []
196
# WHEN: _send_command called with no data and queue's emtpy
197
# Patch some attributes here since they are not available until after instantiation
198
with patch.object(self.pjlink, 'socket_timer') as mock_timer, \
199
patch.object(self.pjlink, 'waitForBytesWritten') as mock_waitBytes:
200
mock_waitBytes.return_value = True
201
self.pjlink._send_command()
204
mock_log.error.assert_has_calls(log_error_calls)
205
mock_log.warning.assert_has_calls(log_warning_calls)
206
mock_log.debug.assert_has_calls(log_debug_calls)
207
assert (not self.pjlink.send_queue), 'Send queue should be empty'
208
assert (not self.pjlink.priority_queue), 'Priority queue should be empty'
209
assert mock_timer.start.called, 'Timer should have been called'
210
assert (not mock_reset.called), 'reset_information() should not have been called'
211
assert (not mock_disconnect.called), 'disconnect_from_host() should not have been called'
212
assert self.pjlink.send_busy, 'send_busy flag should be True'
214
@patch.object(openlp.core.projectors.pjlink.PJLink, 'disconnect_from_host')
215
@patch.object(openlp.core.projectors.pjlink.PJLink, 'state')
216
@patch.object(openlp.core.projectors.pjlink.PJLink, 'reset_information')
217
@patch.object(openlp.core.projectors.pjlink, 'log')
218
def test_local_send_command_not_connected(self, mock_log, mock_reset, mock_state, mock_disconnect):
220
Test _underscore_send_command when not connected
223
test_command = '{prefix}{clss}CLSS ?{suff}'.format(prefix=PJLINK_PREFIX,
224
clss=self.pjlink.pjlink_class,
227
log_warning_calls = [call('({ip}) _send_command() Not connected - abort'.format(ip=self.pjlink.name))]
228
log_debug_calls = [call('({ip}) _send_command(data="None")'.format(ip=self.pjlink.name)),
229
call('({ip}) _send_command(): priority_queue: []'.format(ip=self.pjlink.name)),
230
call("({ip}) _send_command(): send_queue: ['%1CLSS ?\\r']".format(ip=self.pjlink.name)),
231
call('({ip}) _send_command(): Connection status: S_OK'.format(ip=self.pjlink.name))]
59
232
mock_state.return_value = S_NOT_CONNECTED
60
pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
61
pjlink.send_queue = []
62
pjlink.priority_queue = []
64
# WHEN: _send_command called with no data and queue's empty
65
pjlink.send_command(cmd='DONTCARE')
68
mock_log.debug.assert_has_calls(log_debug_calls)
69
mock_log.warning.assert_has_calls(log_warning_calls)
70
assert mock_reset.called is True
71
assert mock_reset.called is True
73
@patch.object(openlp.core.projectors.pjlink, 'log')
74
def test_local_send_command_no_data(self, mock_log):
76
Test _send_command with no data to send
79
log_debug_calls = [call('PJlink(projector="< Projector(id="None", ip="111.111.111.111", port="1111", '
80
'mac_adx="11:11:11:11:11:11", pin="1111", name="___TEST_ONE___", '
81
'location="location one", notes="notes one", pjlink_name="None", '
82
'pjlink_class="None", manufacturer="None", model="None", '
83
'serial_no="Serial Number 1", other="None", sources="None", source_list="[]", '
84
'model_filter="Filter type 1", model_lamp="Lamp type 1", '
85
'sw_version="Version 1") >", args="()" kwargs="{\'no_poll\': True}")'),
86
call('PJlinkCommands(args=() kwargs={})'),
87
call('(___TEST_ONE___) reset_information() connect status is S_NOT_CONNECTED'),
88
call('(___TEST_ONE___) _send_command(): Nothing to send - returning')]
90
pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True)
91
pjlink.send_queue = []
92
pjlink.priority_queue = []
233
self.pjlink.send_queue = [test_command]
234
self.pjlink.priority_queue = []
94
236
# WHEN: _send_command called with no data and queue's emtpy
95
237
# Patch here since pjlink does not have socket_timer until after instantiation
96
with patch.object(pjlink, 'socket_timer') as mock_timer:
97
pjlink._send_command(data=None, utf8=False)
100
mock_log.debug.assert_has_calls(log_debug_calls)
101
assert mock_timer.called is False
238
with patch.object(self.pjlink, 'socket_timer') as mock_timer:
239
self.pjlink._send_command()
242
mock_log.error.assert_has_calls(log_error_calls)
243
mock_log.warning.assert_has_calls(log_warning_calls)
244
mock_log.debug.assert_has_calls(log_debug_calls)
245
assert (self.pjlink.send_queue == [test_command]), 'Send queue should have one entry'
246
assert (not self.pjlink.priority_queue), 'Priority queue should be empty'
247
assert (not mock_timer.called), 'Timer should not have been called'
248
assert (not mock_reset.called), 'reset_information() should not have been called'
249
assert mock_disconnect.called, 'disconnect_from_host() should have been called'
250
assert (not self.pjlink.send_busy), 'send_busy flag should be False'
252
@patch.object(openlp.core.projectors.pjlink.PJLink, 'write')
253
@patch.object(openlp.core.projectors.pjlink.PJLink, 'disconnect_from_host')
254
@patch.object(openlp.core.projectors.pjlink.PJLink, 'state')
255
@patch.object(openlp.core.projectors.pjlink.PJLink, 'reset_information')
256
@patch.object(openlp.core.projectors.pjlink, 'log')
257
def test_local_send_command_priority_send(self, mock_log, mock_reset, mock_state, mock_disconnect, mock_write):
259
Test _underscore_send_command with priority queue
262
test_command = '{prefix}{clss}CLSS ?{suff}'.format(prefix=PJLINK_PREFIX,
263
clss=self.pjlink.pjlink_class,
266
log_warning_calls = []
267
log_debug_calls = [call('({ip}) _send_command(data="{data}")'.format(ip=self.pjlink.name,
268
data=test_command.strip())),
269
call('({ip}) _send_command(): priority_queue: []'.format(ip=self.pjlink.name)),
270
call('({ip}) _send_command(): send_queue: []'.format(ip=self.pjlink.name)),
271
call('({ip}) _send_command(): Connection status: S_CONNECTED'.format(ip=self.pjlink.name)),
272
call('({ip}) _send_command(): Priority packet - '
273
'adding to priority queue'.format(ip=self.pjlink.name)),
274
call('({ip}) _send_command(): Getting priority queued packet'.format(ip=self.pjlink.name)),
275
call('({ip}) _send_command(): Sending "{data}"'.format(ip=self.pjlink.name,
276
data=test_command.strip()))
279
mock_state.return_value = QSOCKET_STATE[S_CONNECTED]
280
mock_write.return_value = len(test_command)
281
self.pjlink.send_queue = []
282
self.pjlink.priority_queue = []
284
# WHEN: _send_command called with no data and queue's emtpy
285
# Patch some attributes here since they are not available until after instantiation
286
with patch.object(self.pjlink, 'socket_timer') as mock_timer, \
287
patch.object(self.pjlink, 'waitForBytesWritten') as mock_waitBytes:
288
mock_waitBytes.return_value = True
289
self.pjlink._send_command(data=test_command)
292
mock_log.error.assert_has_calls(log_error_calls)
293
mock_log.warning.assert_has_calls(log_warning_calls)
294
mock_log.debug.assert_has_calls(log_debug_calls)
295
assert (not self.pjlink.send_queue), 'Send queue should be empty'
296
assert (not self.pjlink.priority_queue), 'Priority queue should be empty'
297
assert mock_timer.start.called, 'Timer should have been called'
298
assert (not mock_reset.called), 'reset_information() should not have been called'
299
assert (not mock_disconnect.called), 'disconnect_from_host() should not have been called'
300
assert self.pjlink.send_busy, 'send_busy flag should be True'
302
@patch.object(openlp.core.projectors.pjlink.PJLink, 'write')
303
@patch.object(openlp.core.projectors.pjlink.PJLink, 'disconnect_from_host')
304
@patch.object(openlp.core.projectors.pjlink.PJLink, 'state')
305
@patch.object(openlp.core.projectors.pjlink.PJLink, 'reset_information')
306
@patch.object(openlp.core.projectors.pjlink, 'log')
307
def test_local_send_command_priority_send_with_normal_queue(self, mock_log, mock_reset, mock_state,
308
mock_disconnect, mock_write):
310
Test _underscore_send_command with priority queue when normal queue active
313
test_command = '{prefix}{clss}CLSS ?{suff}'.format(prefix=PJLINK_PREFIX,
314
clss=self.pjlink.pjlink_class,
317
log_warning_calls = []
318
log_debug_calls = [call('({ip}) _send_command(data="{data}")'.format(ip=self.pjlink.name,
319
data=test_command.strip())),
320
call('({ip}) _send_command(): priority_queue: []'.format(ip=self.pjlink.name)),
321
call("({ip}) _send_command(): send_queue: ['{data}\\r']".format(ip=self.pjlink.name,
322
data=test_command.strip())),
323
call('({ip}) _send_command(): Connection status: S_CONNECTED'.format(ip=self.pjlink.name)),
324
call('({ip}) _send_command(): Priority packet - '
325
'adding to priority queue'.format(ip=self.pjlink.name)),
326
call('({ip}) _send_command(): Getting priority queued packet'.format(ip=self.pjlink.name)),
327
call('({ip}) _send_command(): Sending "{data}"'.format(ip=self.pjlink.name,
328
data=test_command.strip()))
331
mock_state.return_value = QSOCKET_STATE[S_CONNECTED]
332
mock_write.return_value = len(test_command)
333
self.pjlink.send_queue = [test_command]
334
self.pjlink.priority_queue = []
336
# WHEN: _send_command called with no data and queue's emtpy
337
# Patch some attributes here since they are not available until after instantiation
338
with patch.object(self.pjlink, 'socket_timer') as mock_timer, \
339
patch.object(self.pjlink, 'waitForBytesWritten') as mock_waitBytes:
340
mock_waitBytes.return_value = True
341
self.pjlink._send_command(data=test_command)
344
mock_log.error.assert_has_calls(log_error_calls)
345
mock_log.warning.assert_has_calls(log_warning_calls)
346
mock_log.debug.assert_has_calls(log_debug_calls)
347
assert self.pjlink.send_queue, 'Send queue should have one entry'
348
assert (not self.pjlink.priority_queue), 'Priority queue should be empty'
349
assert mock_timer.start.called, 'Timer should have been called'
350
assert (not mock_reset.called), 'reset_information() should not have been called'
351
assert (not mock_disconnect.called), 'disconnect_from_host() should not have been called'
352
assert self.pjlink.send_busy, 'send_busy flag should be True'
354
@patch.object(openlp.core.projectors.pjlink.PJLink, 'state')
355
@patch.object(openlp.core.projectors.pjlink.PJLink, 'reset_information')
356
@patch.object(openlp.core.projectors.pjlink, 'log')
357
def test_local_send_command_send_busy_normal_queue(self, mock_log, mock_reset, mock_state):
359
Test _underscore_send_command send_busy flag with normal queue
362
test_command = '{prefix}{clss}CLSS ?{suff}'.format(prefix=PJLINK_PREFIX,
363
clss=self.pjlink.pjlink_class,
366
log_warning_calls = []
367
log_debug_calls = [call('({ip}) _send_command(data="None")'.format(ip=self.pjlink.name)),
368
call('({ip}) _send_command(): priority_queue: []'.format(ip=self.pjlink.name)),
369
call("({ip}) _send_command(): send_queue: ['{data}\\r']".format(ip=self.pjlink.name,
370
data=test_command.strip())),
371
call('({ip}) _send_command(): Connection status: S_CONNECTED'.format(ip=self.pjlink.name)),
372
call('({ip}) _send_command(): Still busy, returning'.format(ip=self.pjlink.name)),
373
call('({ip}) _send_command(): Priority queue = []'.format(ip=self.pjlink.name)),
374
call("({ip}) _send_command(): Normal queue = "
375
"['{data}\\r']".format(ip=self.pjlink.name, data=test_command.strip()))]
377
mock_state.return_value = QSOCKET_STATE[S_CONNECTED]
378
self.pjlink.send_busy = True
379
self.pjlink.send_queue = [test_command]
380
self.pjlink.priority_queue = []
382
# WHEN: _send_command called with no data and queue's emtpy
383
# Patch some attributes here since they are not available until after instantiation
384
with patch.object(self.pjlink, 'socket_timer') as mock_timer:
385
self.pjlink._send_command()
388
mock_log.error.assert_has_calls(log_error_calls)
389
mock_log.warning.assert_has_calls(log_warning_calls)
390
mock_log.debug.assert_has_calls(log_debug_calls)
391
assert self.pjlink.send_queue, 'Send queue should have one entry'
392
assert (not self.pjlink.priority_queue), 'Priority queue should be empty'
393
assert (not mock_timer.start.called), 'Timer should not have been called'
394
assert (not mock_reset.called), 'reset_information() should not have been called'
395
assert self.pjlink.send_busy, 'send_busy flag should be True'
397
@patch.object(openlp.core.projectors.pjlink.PJLink, 'state')
398
@patch.object(openlp.core.projectors.pjlink.PJLink, 'reset_information')
399
@patch.object(openlp.core.projectors.pjlink, 'log')
400
def test_local_send_command_send_busy_priority_queue(self, mock_log, mock_reset, mock_state):
402
Test _underscore_send_command send_busy flag with priority queue
405
test_command = '{prefix}{clss}CLSS ?{suff}'.format(prefix=PJLINK_PREFIX,
406
clss=self.pjlink.pjlink_class,
409
log_warning_calls = []
410
log_debug_calls = [call('({ip}) _send_command(data="None")'.format(ip=self.pjlink.name)),
411
call("({ip}) _send_command(): priority_queue: "
412
"['{data}\\r']".format(ip=self.pjlink.name,
413
data=test_command.strip())),
414
call('({ip}) _send_command(): send_queue: []'.format(ip=self.pjlink.name)),
415
call('({ip}) _send_command(): Connection status: S_CONNECTED'.format(ip=self.pjlink.name)),
416
call('({ip}) _send_command(): Still busy, returning'.format(ip=self.pjlink.name)),
417
call("({ip}) _send_command(): Priority queue = "
418
"['{data}\\r']".format(ip=self.pjlink.name, data=test_command.strip())),
419
call('({ip}) _send_command(): Normal queue = []'.format(ip=self.pjlink.name))
422
mock_state.return_value = QSOCKET_STATE[S_CONNECTED]
423
self.pjlink.send_busy = True
424
self.pjlink.send_queue = []
425
self.pjlink.priority_queue = [test_command]
427
# WHEN: _send_command called with no data and queue's emtpy
428
# Patch some attributes here since they are not available until after instantiation
429
with patch.object(self.pjlink, 'socket_timer') as mock_timer:
430
self.pjlink._send_command()
433
mock_log.error.assert_has_calls(log_error_calls)
434
mock_log.warning.assert_has_calls(log_warning_calls)
435
mock_log.debug.assert_has_calls(log_debug_calls)
436
assert (not self.pjlink.send_queue), 'Send queue should be empty'
437
assert self.pjlink.priority_queue, 'Priority queue should have one entry'
438
assert (not mock_timer.start.called), 'Timer should not have been called'
439
assert (not mock_reset.called), 'reset_information() should not have been called'
440
assert self.pjlink.send_busy, 'send_busy flag should be True'
442
# ------------ Test PJLink.send_command ----------
443
@patch.object(openlp.core.projectors.pjlink.PJLink, 'state')
444
@patch.object(openlp.core.projectors.pjlink.PJLink, 'reset_information')
445
@patch.object(openlp.core.projectors.pjlink.PJLink, '_send_command')
446
@patch.object(openlp.core.projectors.pjlink, 'log')
447
def test_send_command_add_normal_command(self, mock_log, mock_send_command, mock_reset, mock_state):
449
Test send_command adding normal queue item
452
test_command = '{prefix}{clss}CLSS ?{suff}'.format(prefix=PJLINK_PREFIX,
453
clss=self.pjlink.pjlink_class,
456
log_warning_calls = []
457
log_debug_calls = [call('({ip}) send_command(): Building cmd="CLSS" opts="?"'.format(ip=self.pjlink.name)),
458
call('({ip}) send_command(): Adding to normal queue'.format(ip=self.pjlink.name))]
459
mock_state.return_value = S_CONNECTED
461
# Patch here since pjlink does not have priority or send queue's until instantiated
462
with patch.object(self.pjlink, 'send_queue') as mock_send, \
463
patch.object(self.pjlink, 'priority_queue') as mock_priority:
465
# WHEN: send_command called with valid normal command
466
self.pjlink.send_command(cmd='CLSS')
469
mock_send.append.called_with(test_command)
470
mock_priority.append.called is False
471
mock_log.debug.assert_has_calls(log_debug_calls)
472
mock_log.warning.assert_has_calls(log_warning_calls)
473
mock_log.error.assert_has_calls(log_error_calls)
474
assert (not mock_reset.called), 'reset_information() should not have been called'
475
assert mock_send_command.called, '_underscore_send_command() should have been called'
477
@patch.object(openlp.core.projectors.pjlink.PJLink, 'state')
478
@patch.object(openlp.core.projectors.pjlink.PJLink, 'reset_information')
479
@patch.object(openlp.core.projectors.pjlink.PJLink, '_send_command')
480
@patch.object(openlp.core.projectors.pjlink, 'log')
481
def test_send_command_add_priority_command(self, mock_log, mock_send_command, mock_reset, mock_state):
483
Test _send_command adding priority queue item
486
test_command = '{prefix}{clss}CLSS ?{suff}'.format(prefix=PJLINK_PREFIX,
487
clss=self.pjlink.pjlink_class,
490
log_warning_calls = []
491
log_debug_calls = [call('({ip}) send_command(): Building cmd="CLSS" opts="?"'.format(ip=self.pjlink.name)),
492
call('({ip}) send_command(): Adding to priority queue'.format(ip=self.pjlink.name))]
493
mock_state.return_value = S_CONNECTED
495
# Patch here since pjlink does not have priority or send queue's until instantiated
496
with patch.object(self.pjlink, 'send_queue') as mock_send, \
497
patch.object(self.pjlink, 'priority_queue') as mock_priority:
499
# WHEN: send_command called with valid priority command
500
self.pjlink.send_command(cmd='CLSS', priority=True)
503
mock_log.debug.assert_has_calls(log_debug_calls)
504
mock_log.warning.assert_has_calls(log_warning_calls)
505
mock_log.error.assert_has_calls(log_error_calls)
506
mock_priority.append.assert_called_with(test_command)
507
assert (not mock_send.append.called), 'send_queue should not have changed'
508
assert (not mock_reset.called), 'reset_information() should not have been called'
509
assert mock_send_command.called, '_underscore_send_command() should have been called'
511
@patch.object(openlp.core.projectors.pjlink.PJLink, 'state')
512
@patch.object(openlp.core.projectors.pjlink.PJLink, 'reset_information')
513
@patch.object(openlp.core.projectors.pjlink.PJLink, '_send_command')
514
@patch.object(openlp.core.projectors.pjlink, 'log')
515
def test_send_command_duplicate_normal_command(self, mock_log, mock_send_command, mock_reset, mock_state):
517
Test send_command with duplicate item for normal queue
520
test_command = '{prefix}{clss}CLSS ?{suff}'.format(prefix=PJLINK_PREFIX,
521
clss=self.pjlink.pjlink_class,
524
log_warning_calls = [call('({ip}) send_command(): Already in normal queue - '
525
'skipping'.format(ip=self.pjlink.name))]
526
log_debug_calls = [call('({ip}) send_command(): Building cmd="CLSS" opts="?"'.format(ip=self.pjlink.name))]
527
mock_state.return_value = S_CONNECTED
528
self.pjlink.send_queue = [test_command]
529
self.pjlink.priority_queue = []
531
# WHEN: send_command called with same command in normal queue
532
self.pjlink.send_command(cmd='CLSS')
535
mock_log.debug.assert_has_calls(log_debug_calls)
536
mock_log.warning.assert_has_calls(log_warning_calls)
537
mock_log.error.assert_has_calls(log_error_calls)
538
assert (self.pjlink.send_queue == [test_command]), 'Send queue should have one entry'
539
assert (not self.pjlink.priority_queue), 'Priority queue should be empty'
540
assert (not mock_reset.called), 'reset_information() should not have been called'
541
assert mock_send_command.called, '_underscore_send_command() should have been called'
543
@patch.object(openlp.core.projectors.pjlink.PJLink, 'state')
544
@patch.object(openlp.core.projectors.pjlink.PJLink, 'reset_information')
545
@patch.object(openlp.core.projectors.pjlink.PJLink, '_send_command')
546
@patch.object(openlp.core.projectors.pjlink, 'log')
547
def test_send_command_duplicate_priority_command(self, mock_log, mock_send_command, mock_reset, mock_state):
549
Test send_command with duplicate item for priority queue
552
test_command = '{prefix}{clss}CLSS ?{suff}'.format(prefix=PJLINK_PREFIX,
553
clss=self.pjlink.pjlink_class,
556
log_warning_calls = [call('({ip}) send_command(): Already in priority queue - '
557
'skipping'.format(ip=self.pjlink.name))]
558
log_debug_calls = [call('({ip}) send_command(): Building cmd="CLSS" opts="?"'.format(ip=self.pjlink.name))]
559
mock_state.return_value = S_CONNECTED
560
self.pjlink.send_queue = []
561
self.pjlink.priority_queue = [test_command]
563
# WHEN: send_command called with same command in priority queue
564
self.pjlink.send_command(cmd='CLSS', priority=True)
567
mock_log.debug.assert_has_calls(log_debug_calls)
568
mock_log.warning.assert_has_calls(log_warning_calls)
569
mock_log.error.assert_has_calls(log_error_calls)
570
assert (not self.pjlink.send_queue), 'Send queue should be empty'
571
assert (self.pjlink.priority_queue == [test_command]), 'Priority queue should have one entry'
572
assert (not mock_reset.called), 'reset_information() should not have been called'
573
assert mock_send_command.called, '_underscore_send_command() should have been called'
575
@patch.object(openlp.core.projectors.pjlink.PJLink, 'state')
576
@patch.object(openlp.core.projectors.pjlink.PJLink, 'reset_information')
577
@patch.object(openlp.core.projectors.pjlink.PJLink, '_send_command')
578
@patch.object(openlp.core.projectors.pjlink, 'log')
579
def test_send_command_invalid_command_empty_queues(self, mock_log, mock_send_command, mock_reset, mock_state):
581
Test send_command with invalid command
584
log_error_calls = [call('({ip}) send_command(): Invalid command requested - '
585
'ignoring.'.format(ip=self.pjlink.name))]
586
log_warning_calls = []
588
mock_state.return_value = S_CONNECTED
589
self.pjlink.send_queue = []
590
self.pjlink.priority_queue = []
592
# WHEN: send_command with invalid command
593
self.pjlink.send_command(cmd='DONTCARE')
596
mock_log.debug.assert_has_calls(log_debug_calls)
597
mock_log.warning.assert_has_calls(log_warning_calls)
598
mock_log.error.assert_has_calls(log_error_calls)
599
assert (not self.pjlink.send_queue), 'Send queue should be empty'
600
assert (not self.pjlink.priority_queue), 'Priority queue should be empty'
601
assert (not mock_reset.called), 'reset_information() should not have been called'
602
assert (not mock_send_command.called), '_underscore_send_command() should not have been called'
604
@patch.object(openlp.core.projectors.pjlink.PJLink, 'state')
605
@patch.object(openlp.core.projectors.pjlink.PJLink, 'reset_information')
606
@patch.object(openlp.core.projectors.pjlink.PJLink, '_send_command')
607
@patch.object(openlp.core.projectors.pjlink, 'log')
608
def test_send_command_invalid_command_normal_queue(self, mock_log, mock_send_command, mock_reset, mock_state):
610
Test _send_command with invalid command for normal queue
613
test_command = '{prefix}{clss}CLSS ?{suff}'.format(prefix=PJLINK_PREFIX,
614
clss=self.pjlink.pjlink_class,
616
log_error_calls = [call('({ip}) send_command(): Invalid command requested - '
617
'ignoring.'.format(ip=self.pjlink.name))]
618
log_warning_calls = []
620
mock_state.return_value = S_CONNECTED
621
self.pjlink.send_queue = [test_command]
622
self.pjlink.priority_queue = []
624
# WHEN: send_command with invalid command
625
self.pjlink.send_command(cmd='DONTCARE')
628
mock_log.debug.assert_has_calls(log_debug_calls)
629
mock_log.warning.assert_has_calls(log_warning_calls)
630
mock_log.error.assert_has_calls(log_error_calls)
631
assert self.pjlink.send_queue, 'Send queue should have one entry'
632
assert (not self.pjlink.priority_queue), 'Priority queue should be empty'
633
assert (not mock_reset.called), 'reset_information() should not have been called'
634
assert mock_send_command.called, '_underscore_send_command() should have been called'
636
@patch.object(openlp.core.projectors.pjlink.PJLink, 'state')
637
@patch.object(openlp.core.projectors.pjlink.PJLink, 'reset_information')
638
@patch.object(openlp.core.projectors.pjlink.PJLink, '_send_command')
639
@patch.object(openlp.core.projectors.pjlink, 'log')
640
def test_send_command_invalid_command_priority_queue(self, mock_log, mock_send_command, mock_reset, mock_state):
642
Test _send_command with invalid command for priority queue
645
test_command = '{prefix}{clss}CLSS ?{suff}'.format(prefix=PJLINK_PREFIX,
646
clss=self.pjlink.pjlink_class,
648
log_error_calls = [call('({ip}) send_command(): Invalid command requested - '
649
'ignoring.'.format(ip=self.pjlink.name))]
650
log_warning_calls = []
652
mock_state.return_value = S_CONNECTED
653
self.pjlink.send_queue = []
654
self.pjlink.priority_queue = [test_command]
656
# WHEN: send_command with invalid command
657
self.pjlink.send_command(cmd='DONTCARE', priority=True)
660
mock_log.debug.assert_has_calls(log_debug_calls)
661
mock_log.warning.assert_has_calls(log_warning_calls)
662
mock_log.error.assert_has_calls(log_error_calls)
663
assert (not self.pjlink.send_queue), 'Send queue should be empty'
664
assert self.pjlink.priority_queue, 'Priority queue should have one entry'
665
assert (not mock_reset.called), 'reset_information() should not have been called'
666
assert mock_send_command.called, '_underscore_send_command() should have been called'
668
@patch.object(openlp.core.projectors.pjlink.PJLink, 'state')
669
@patch.object(openlp.core.projectors.pjlink.PJLink, 'reset_information')
670
@patch.object(openlp.core.projectors.pjlink.PJLink, '_send_command')
671
@patch.object(openlp.core.projectors.pjlink, 'log')
672
def test_send_command_not_connected(self, mock_log, mock_send_command, mock_reset, mock_state):
674
Test send_command when not connected
678
log_warning_calls = [call('({ip}) send_command(): Not connected - returning'.format(ip=self.pjlink.name))]
680
mock_state.return_value = S_NOT_CONNECTED
681
self.pjlink.send_queue = []
682
self.pjlink.priority_queue = []
684
# WHEN: send_command called when not connected
685
self.pjlink.send_command(cmd=None)
688
mock_log.debug.assert_has_calls(log_debug_calls)
689
mock_log.warning.assert_has_calls(log_warning_calls)
690
mock_log.error.assert_has_calls(log_error_calls)
691
assert (not self.pjlink.send_queue), 'Send queue should be empty'
692
assert (not self.pjlink.priority_queue), 'Priority queue should be empty'
693
assert mock_reset.called, 'reset_information() should have been called'
694
assert (not mock_send_command.called), '_underscore_send_command() should not have been called'