forked from openlp/openlp
"Convert strings to python3 in plugins part 4
- Convert strings in plugins/songusage - Convert missed string in projector/pjlink1 - Updated projectorpjlink1 test -------------------------------- lp:~alisonken1/openlp/strings-plugins4 (revision 2670) [SUCCESS] https://ci.openlp.io/job/Branch-01-Pull/1578/ [SUCCESS] https://ci.openlp.io/job/Branch-02-Functional-Tests/1489/ [SUCCESS] https://ci.openlp.io/job/Branch-03-Interface-Tests/1427/ [SUCCESS] https://ci.openlp.io/job/Branch-04a-Windows_F..." bzr-revno: 2671
This commit is contained in:
commit
41dcf85cbe
@ -58,7 +58,7 @@ SocketSTate = QAbstractSocket.SocketState
|
|||||||
|
|
||||||
PJLINK_PREFIX = '%'
|
PJLINK_PREFIX = '%'
|
||||||
PJLINK_CLASS = '1'
|
PJLINK_CLASS = '1'
|
||||||
PJLINK_HEADER = '%s%s' % (PJLINK_PREFIX, PJLINK_CLASS)
|
PJLINK_HEADER = '{prefix}{linkclass}'.format(prefix=PJLINK_PREFIX, linkclass=PJLINK_CLASS)
|
||||||
PJLINK_SUFFIX = CR
|
PJLINK_SUFFIX = CR
|
||||||
|
|
||||||
|
|
||||||
@ -160,8 +160,10 @@ class PJLink1(QTcpSocket):
|
|||||||
self.source = None
|
self.source = None
|
||||||
self.other_info = None
|
self.other_info = None
|
||||||
if hasattr(self, 'timer'):
|
if hasattr(self, 'timer'):
|
||||||
|
log.debug('({ip}): Calling timer.stop()'.format(ip=self.ip))
|
||||||
self.timer.stop()
|
self.timer.stop()
|
||||||
if hasattr(self, 'socket_timer'):
|
if hasattr(self, 'socket_timer'):
|
||||||
|
log.debug('({ip}): Calling socket_timer.stop()'.format(ip=self.ip))
|
||||||
self.socket_timer.stop()
|
self.socket_timer.stop()
|
||||||
self.send_queue = []
|
self.send_queue = []
|
||||||
self.send_busy = False
|
self.send_busy = False
|
||||||
|
@ -81,9 +81,10 @@ class SongUsageDetailForm(QtWidgets.QDialog, Ui_SongUsageDetailDialog, RegistryP
|
|||||||
)
|
)
|
||||||
return
|
return
|
||||||
check_directory_exists(path)
|
check_directory_exists(path)
|
||||||
file_name = translate('SongUsagePlugin.SongUsageDetailForm', 'usage_detail_%s_%s.txt') % \
|
file_name = translate('SongUsagePlugin.SongUsageDetailForm',
|
||||||
(self.from_date_calendar.selectedDate().toString('ddMMyyyy'),
|
'usage_detail_{old}_{new}.txt'
|
||||||
self.to_date_calendar.selectedDate().toString('ddMMyyyy'))
|
).format(old=self.from_date_calendar.selectedDate().toString('ddMMyyyy'),
|
||||||
|
new=self.to_date_calendar.selectedDate().toString('ddMMyyyy'))
|
||||||
Settings().setValue(self.plugin.settings_section + '/from date', self.from_date_calendar.selectedDate())
|
Settings().setValue(self.plugin.settings_section + '/from date', self.from_date_calendar.selectedDate())
|
||||||
Settings().setValue(self.plugin.settings_section + '/to date', self.to_date_calendar.selectedDate())
|
Settings().setValue(self.plugin.settings_section + '/to date', self.to_date_calendar.selectedDate())
|
||||||
usage = self.plugin.manager.get_all_objects(
|
usage = self.plugin.manager.get_all_objects(
|
||||||
@ -95,21 +96,23 @@ class SongUsageDetailForm(QtWidgets.QDialog, Ui_SongUsageDetailDialog, RegistryP
|
|||||||
try:
|
try:
|
||||||
file_handle = open(report_file_name, 'wb')
|
file_handle = open(report_file_name, 'wb')
|
||||||
for instance in usage:
|
for instance in usage:
|
||||||
record = '\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",' \
|
record = ('\"{date}\",\"{time}\",\"{title}\",\"{copyright}\",\"{ccli}\",\"{authors}\",'
|
||||||
'\"%s\",\"%s\"\n' % \
|
'\"{name}\",\"{source}\"\n').format(date=instance.usagedate, time=instance.usagetime,
|
||||||
(instance.usagedate, instance.usagetime, instance.title, instance.copyright,
|
title=instance.title, copyright=instance.copyright,
|
||||||
instance.ccl_number, instance.authors, instance.plugin_name, instance.source)
|
ccli=instance.ccl_number, authors=instance.authors,
|
||||||
|
name=instance.plugin_name, source=instance.source)
|
||||||
file_handle.write(record.encode('utf-8'))
|
file_handle.write(record.encode('utf-8'))
|
||||||
self.main_window.information_message(
|
self.main_window.information_message(
|
||||||
translate('SongUsagePlugin.SongUsageDetailForm', 'Report Creation'),
|
translate('SongUsagePlugin.SongUsageDetailForm', 'Report Creation'),
|
||||||
translate('SongUsagePlugin.SongUsageDetailForm',
|
translate('SongUsagePlugin.SongUsageDetailForm',
|
||||||
'Report \n%s \nhas been successfully created. ') % report_file_name
|
'Report \n{name} \nhas been successfully created. ').format(name=report_file_name)
|
||||||
)
|
)
|
||||||
except OSError as ose:
|
except OSError as ose:
|
||||||
log.exception('Failed to write out song usage records')
|
log.exception('Failed to write out song usage records')
|
||||||
critical_error_message_box(translate('SongUsagePlugin.SongUsageDetailForm', 'Report Creation Failed'),
|
critical_error_message_box(translate('SongUsagePlugin.SongUsageDetailForm', 'Report Creation Failed'),
|
||||||
translate('SongUsagePlugin.SongUsageDetailForm',
|
translate('SongUsagePlugin.SongUsageDetailForm',
|
||||||
'An error occurred while creating the report: %s') % ose.strerror)
|
'An error occurred while creating the report: {error}'
|
||||||
|
).format(error=ose.strerror))
|
||||||
finally:
|
finally:
|
||||||
if file_handle:
|
if file_handle:
|
||||||
file_handle.close()
|
file_handle.close()
|
||||||
|
@ -35,6 +35,20 @@ from tests.resources.projector.data import TEST_PIN, TEST_SALT, TEST_CONNECT_AUT
|
|||||||
pjlink_test = PJLink1(name='test', ip='127.0.0.1', pin=TEST_PIN, no_poll=True)
|
pjlink_test = PJLink1(name='test', ip='127.0.0.1', pin=TEST_PIN, no_poll=True)
|
||||||
|
|
||||||
|
|
||||||
|
class DummyTimer(object):
|
||||||
|
'''
|
||||||
|
Dummy class to fake timers
|
||||||
|
'''
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def start(self, *args, **kwargs):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def stop(self, *args, **kwargs):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class TestPJLink(TestCase):
|
class TestPJLink(TestCase):
|
||||||
"""
|
"""
|
||||||
Tests for the PJLink module
|
Tests for the PJLink module
|
||||||
@ -43,13 +57,10 @@ class TestPJLink(TestCase):
|
|||||||
@patch.object(pjlink_test, 'send_command')
|
@patch.object(pjlink_test, 'send_command')
|
||||||
@patch.object(pjlink_test, 'waitForReadyRead')
|
@patch.object(pjlink_test, 'waitForReadyRead')
|
||||||
@patch('openlp.core.common.qmd5_hash')
|
@patch('openlp.core.common.qmd5_hash')
|
||||||
def authenticated_connection_call_test(self,
|
def authenticated_connection_call_test(self, mock_qmd5_hash, mock_waitForReadyRead, mock_send_command,
|
||||||
mock_qmd5_hash,
|
|
||||||
mock_waitForReadyRead,
|
|
||||||
mock_send_command,
|
|
||||||
mock_readyRead):
|
mock_readyRead):
|
||||||
"""
|
"""
|
||||||
Fix for projector connect with PJLink authentication exception. Ticket 92187.
|
Ticket 92187: Fix for projector connect with PJLink authentication exception.
|
||||||
"""
|
"""
|
||||||
# GIVEN: Test object
|
# GIVEN: Test object
|
||||||
pjlink = pjlink_test
|
pjlink = pjlink_test
|
||||||
@ -63,9 +74,23 @@ class TestPJLink(TestCase):
|
|||||||
self.assertTrue(mock_qmd5_hash.called_with(TEST_PIN,
|
self.assertTrue(mock_qmd5_hash.called_with(TEST_PIN,
|
||||||
"Connection request should have been called with TEST_PIN"))
|
"Connection request should have been called with TEST_PIN"))
|
||||||
|
|
||||||
|
def projector_class_test(self):
|
||||||
|
"""
|
||||||
|
Test class version from projector
|
||||||
|
"""
|
||||||
|
# GIVEN: Test object
|
||||||
|
pjlink = pjlink_test
|
||||||
|
|
||||||
|
# WHEN: Process class response
|
||||||
|
pjlink.process_clss('1')
|
||||||
|
|
||||||
|
# THEN: Projector class should be set to 1
|
||||||
|
self.assertEquals(pjlink.pjlink_class, '1',
|
||||||
|
'Projector should have returned class=1')
|
||||||
|
|
||||||
def non_standard_class_reply_test(self):
|
def non_standard_class_reply_test(self):
|
||||||
"""
|
"""
|
||||||
bugfix 1550891 - CLSS request returns non-standard 'Class N' reply
|
Bugfix 1550891: CLSS request returns non-standard 'Class N' reply
|
||||||
"""
|
"""
|
||||||
# GIVEN: Test object
|
# GIVEN: Test object
|
||||||
pjlink = pjlink_test
|
pjlink = pjlink_test
|
||||||
@ -264,3 +289,46 @@ class TestPJLink(TestCase):
|
|||||||
|
|
||||||
# THEN: Input selected should reflect current input
|
# THEN: Input selected should reflect current input
|
||||||
self.assertEquals(pjlink.source, '1', 'Input source should be set to "1"')
|
self.assertEquals(pjlink.source, '1', 'Input source should be set to "1"')
|
||||||
|
|
||||||
|
def projector_reset_information_test(self):
|
||||||
|
"""
|
||||||
|
Test reset_information() resets all information and stops timers
|
||||||
|
"""
|
||||||
|
# GIVEN: Test object and test data
|
||||||
|
pjlink = pjlink_test
|
||||||
|
pjlink.power = S_ON
|
||||||
|
pjlink.pjlink_name = 'OPENLPTEST'
|
||||||
|
pjlink.manufacturer = 'PJLINK'
|
||||||
|
pjlink.model = '1'
|
||||||
|
pjlink.shutter = True
|
||||||
|
pjlink.mute = True
|
||||||
|
pjlink.lamp = True
|
||||||
|
pjlink.fan = True
|
||||||
|
pjlink.source_available = True
|
||||||
|
pjlink.other_info = 'ANOTHER TEST'
|
||||||
|
pjlink.send_queue = True
|
||||||
|
pjlink.send_busy = True
|
||||||
|
pjlink.timer = DummyTimer()
|
||||||
|
pjlink.socket_timer = DummyTimer()
|
||||||
|
|
||||||
|
# WHEN: reset_information() is called
|
||||||
|
with patch.object(pjlink.timer, 'stop') as mock_timer:
|
||||||
|
with patch.object(pjlink.socket_timer, 'stop') as mock_socket_timer:
|
||||||
|
pjlink.reset_information()
|
||||||
|
|
||||||
|
# THEN: All information should be reset and timers stopped
|
||||||
|
self.assertEquals(pjlink.power, S_OFF, 'Projector power should be OFF')
|
||||||
|
self.assertIsNone(pjlink.pjlink_name, 'Projector pjlink_name should be None')
|
||||||
|
self.assertIsNone(pjlink.manufacturer, 'Projector manufacturer should be None')
|
||||||
|
self.assertIsNone(pjlink.model, 'Projector model should be None')
|
||||||
|
self.assertIsNone(pjlink.shutter, 'Projector shutter should be None')
|
||||||
|
self.assertIsNone(pjlink.mute, 'Projector shuttter should be None')
|
||||||
|
self.assertIsNone(pjlink.lamp, 'Projector lamp should be None')
|
||||||
|
self.assertIsNone(pjlink.fan, 'Projector fan should be None')
|
||||||
|
self.assertIsNone(pjlink.source_available, 'Projector source_available should be None')
|
||||||
|
self.assertIsNone(pjlink.source, 'Projector source should be None')
|
||||||
|
self.assertIsNone(pjlink.other_info, 'Projector other_info should be None')
|
||||||
|
self.assertEquals(pjlink.send_queue, [], 'Projector send_queue should be an empty list')
|
||||||
|
self.assertFalse(pjlink.send_busy, 'Projector send_busy should be False')
|
||||||
|
self.assertTrue(mock_timer.called, 'Projector timer.stop() should have been called')
|
||||||
|
self.assertTrue(mock_socket_timer.called, 'Projector socket_timer.stop() should have been called')
|
||||||
|
Loading…
Reference in New Issue
Block a user