diff --git a/openlp/core/lib/projector/constants.py b/openlp/core/lib/projector/constants.py index ff2d2a69f..6b691d79d 100644 --- a/openlp/core/lib/projector/constants.py +++ b/openlp/core/lib/projector/constants.py @@ -153,72 +153,66 @@ PJLINK_ERRORS = {'ERRA': E_AUTHENTICATION, # Authentication error 'ERR2': E_PARAMETER, # Invalid parameter error 'ERR3': E_UNAVAILABLE, # Projector busy 'ERR4': E_PROJECTOR, # Projector or display failure - E_AUTHENTICATION: translate('OpenLP.ProjectorConstants', 'ERRA'), - E_UNDEFINED: translate('OpenLP.ProjectorConstants', 'ERR1'), - E_PARAMETER: translate('OpenLP.ProjectorConstants', 'ERR2'), - E_UNAVAILABLE: translate('OpenLP.ProjectorConstants', 'ERR3'), - E_PROJECTOR: translate('OpenLP.ProjectorConstants', 'ERR4')} + E_AUTHENTICATION: 'ERRA', + E_UNDEFINED: 'ERR1', + E_PARAMETER: 'ERR2', + E_UNAVAILABLE: 'ERR3', + E_PROJECTOR: 'ERR4'} # Map error/status codes to string -ERROR_STRING = {0: translate('OpenLP.ProjectorConstants', 'S_OK'), - E_GENERAL: translate('OpenLP.ProjectorConstants', 'E_GENERAL'), - E_NOT_CONNECTED: translate('OpenLP.ProjectorConstants', 'E_NOT_CONNECTED'), - E_FAN: translate('OpenLP.ProjectorConstants', 'E_FAN'), - E_LAMP: translate('OpenLP.ProjectorConstants', 'E_LAMP'), - E_TEMP: translate('OpenLP.ProjectorConstants', 'E_TEMP'), - E_COVER: translate('OpenLP.ProjectorConstants', 'E_COVER'), - E_FILTER: translate('OpenLP.ProjectorConstants', 'E_FILTER'), - E_AUTHENTICATION: translate('OpenLP.ProjectorConstants', 'E_AUTHENTICATION'), - E_NO_AUTHENTICATION: translate('OpenLP.ProjectorConstants', 'E_NO_AUTHENTICATION'), - E_UNDEFINED: translate('OpenLP.ProjectorConstants', 'E_UNDEFINED'), - E_PARAMETER: translate('OpenLP.ProjectorConstants', 'E_PARAMETER'), - E_UNAVAILABLE: translate('OpenLP.ProjectorConstants', 'E_UNAVAILABLE'), - E_PROJECTOR: translate('OpenLP.ProjectorConstants', 'E_PROJECTOR'), - E_INVALID_DATA: translate('OpenLP.ProjectorConstants', 'E_INVALID_DATA'), - E_WARN: translate('OpenLP.ProjectorConstants', 'E_WARN'), - E_ERROR: translate('OpenLP.ProjectorConstants', 'E_ERROR'), - E_CLASS: translate('OpenLP.ProjectorConstants', 'E_CLASS'), - E_PREFIX: translate('OpenLP.ProjectorConstants', 'E_PREFIX'), # Last projector error - E_CONNECTION_REFUSED: translate('OpenLP.ProjectorConstants', - 'E_CONNECTION_REFUSED'), # First QtSocket error - E_REMOTE_HOST_CLOSED_CONNECTION: translate('OpenLP.ProjectorConstants', - 'E_REMOTE_HOST_CLOSED_CONNECTION'), - E_HOST_NOT_FOUND: translate('OpenLP.ProjectorConstants', 'E_HOST_NOT_FOUND'), - E_SOCKET_ACCESS: translate('OpenLP.ProjectorConstants', 'E_SOCKET_ACCESS'), - E_SOCKET_RESOURCE: translate('OpenLP.ProjectorConstants', 'E_SOCKET_RESOURCE'), - E_SOCKET_TIMEOUT: translate('OpenLP.ProjectorConstants', 'E_SOCKET_TIMEOUT'), - E_DATAGRAM_TOO_LARGE: translate('OpenLP.ProjectorConstants', 'E_DATAGRAM_TOO_LARGE'), - E_NETWORK: translate('OpenLP.ProjectorConstants', 'E_NETWORK'), - E_ADDRESS_IN_USE: translate('OpenLP.ProjectorConstants', 'E_ADDRESS_IN_USE'), - E_SOCKET_ADDRESS_NOT_AVAILABLE: translate('OpenLP.ProjectorConstants', - 'E_SOCKET_ADDRESS_NOT_AVAILABLE'), - E_UNSUPPORTED_SOCKET_OPERATION: translate('OpenLP.ProjectorConstants', - 'E_UNSUPPORTED_SOCKET_OPERATION'), - E_PROXY_AUTHENTICATION_REQUIRED: translate('OpenLP.ProjectorConstants', - 'E_PROXY_AUTHENTICATION_REQUIRED'), - E_SLS_HANDSHAKE_FAILED: translate('OpenLP.ProjectorConstants', 'E_SLS_HANDSHAKE_FAILED'), - E_UNFINISHED_SOCKET_OPERATION: translate('OpenLP.ProjectorConstants', - 'E_UNFINISHED_SOCKET_OPERATION'), - E_PROXY_CONNECTION_REFUSED: translate('OpenLP.ProjectorConstants', 'E_PROXY_CONNECTION_REFUSED'), - E_PROXY_CONNECTION_CLOSED: translate('OpenLP.ProjectorConstants', 'E_PROXY_CONNECTION_CLOSED'), - E_PROXY_CONNECTION_TIMEOUT: translate('OpenLP.ProjectorConstants', 'E_PROXY_CONNECTION_TIMEOUT'), - E_PROXY_NOT_FOUND: translate('OpenLP.ProjectorConstants', 'E_PROXY_NOT_FOUND'), - E_PROXY_PROTOCOL: translate('OpenLP.ProjectorConstants', 'E_PROXY_PROTOCOL'), - E_UNKNOWN_SOCKET_ERROR: translate('OpenLP.ProjectorConstants', 'E_UNKNOWN_SOCKET_ERROR')} +ERROR_STRING = {0: 'S_OK', + E_GENERAL: 'E_GENERAL', + E_NOT_CONNECTED: 'E_NOT_CONNECTED', + E_FAN: 'E_FAN', + E_LAMP: 'E_LAMP', + E_TEMP: 'E_TEMP', + E_COVER: 'E_COVER', + E_FILTER: 'E_FILTER', + E_AUTHENTICATION: 'E_AUTHENTICATION', + E_NO_AUTHENTICATION: 'E_NO_AUTHENTICATION', + E_UNDEFINED: 'E_UNDEFINED', + E_PARAMETER: 'E_PARAMETER', + E_UNAVAILABLE: 'E_UNAVAILABLE', + E_PROJECTOR: 'E_PROJECTOR', + E_INVALID_DATA: 'E_INVALID_DATA', + E_WARN: 'E_WARN', + E_ERROR: 'E_ERROR', + E_CLASS: 'E_CLASS', + E_PREFIX: 'E_PREFIX', # Last projector error + E_CONNECTION_REFUSED: 'E_CONNECTION_REFUSED', # First QtSocket error + E_REMOTE_HOST_CLOSED_CONNECTION: 'E_REMOTE_HOST_CLOSED_CONNECTION', + E_HOST_NOT_FOUND: 'E_HOST_NOT_FOUND', + E_SOCKET_ACCESS: 'E_SOCKET_ACCESS', + E_SOCKET_RESOURCE: 'E_SOCKET_RESOURCE', + E_SOCKET_TIMEOUT: 'E_SOCKET_TIMEOUT', + E_DATAGRAM_TOO_LARGE: 'E_DATAGRAM_TOO_LARGE', + E_NETWORK: 'E_NETWORK', + E_ADDRESS_IN_USE: 'E_ADDRESS_IN_USE', + E_SOCKET_ADDRESS_NOT_AVAILABLE: 'E_SOCKET_ADDRESS_NOT_AVAILABLE', + E_UNSUPPORTED_SOCKET_OPERATION: 'E_UNSUPPORTED_SOCKET_OPERATION', + E_PROXY_AUTHENTICATION_REQUIRED: 'E_PROXY_AUTHENTICATION_REQUIRED', + E_SLS_HANDSHAKE_FAILED: 'E_SLS_HANDSHAKE_FAILED', + E_UNFINISHED_SOCKET_OPERATION: 'E_UNFINISHED_SOCKET_OPERATION', + E_PROXY_CONNECTION_REFUSED: 'E_PROXY_CONNECTION_REFUSED', + E_PROXY_CONNECTION_CLOSED: 'E_PROXY_CONNECTION_CLOSED', + E_PROXY_CONNECTION_TIMEOUT: 'E_PROXY_CONNECTION_TIMEOUT', + E_PROXY_NOT_FOUND: 'E_PROXY_NOT_FOUND', + E_PROXY_PROTOCOL: 'E_PROXY_PROTOCOL', + E_UNKNOWN_SOCKET_ERROR: 'E_UNKNOWN_SOCKET_ERROR'} -STATUS_STRING = {S_NOT_CONNECTED: translate('OpenLP.ProjectorConstants', 'S_NOT_CONNECTED'), - S_CONNECTING: translate('OpenLP.ProjectorConstants', 'S_CONNECTING'), - S_CONNECTED: translate('OpenLP.ProjectorConstants', 'S_CONNECTED'), - S_STATUS: translate('OpenLP.ProjectorConstants', 'S_STATUS'), - S_OFF: translate('OpenLP.ProjectorConstants', 'S_OFF'), - S_INITIALIZE: translate('OpenLP.ProjectorConstants', 'S_INITIALIZE'), - S_STANDBY: translate('OpenLP.ProjectorConstants', 'S_STANDBY'), - S_WARMUP: translate('OpenLP.ProjectorConstants', 'S_WARMUP'), - S_ON: translate('OpenLP.ProjectorConstants', 'S_ON'), - S_COOLDOWN: translate('OpenLP.ProjectorConstants', 'S_COOLDOWN'), - S_INFO: translate('OpenLP.ProjectorConstants', 'S_INFO'), - S_NETWORK_SENDING: translate('OpenLP.ProjectorConstants', 'S_NETWORK_SENDING'), - S_NETWORK_RECEIVED: translate('OpenLP.ProjectorConstants', 'S_NETWORK_RECEIVED')} +STATUS_STRING = {S_NOT_CONNECTED: 'S_NOT_CONNECTED', + S_CONNECTING: 'S_CONNECTING', + S_CONNECTED: 'S_CONNECTED', + S_STATUS: 'S_STATUS', + S_OFF: 'S_OFF', + S_INITIALIZE: 'S_INITIALIZE', + S_STANDBY: 'S_STANDBY', + S_WARMUP: 'S_WARMUP', + S_ON: 'S_ON', + S_COOLDOWN: 'S_COOLDOWN', + S_INFO: 'S_INFO', + S_NETWORK_SENDING: 'S_NETWORK_SENDING', + S_NETWORK_RECEIVED: 'S_NETWORK_RECEIVED'} # Map error/status codes to message strings ERROR_MSG = {E_OK: translate('OpenLP.ProjectorConstants', 'OK'), # E_OK | S_OK diff --git a/tests/functional/openlp_core_lib/test_projectordb.py b/tests/functional/openlp_core_lib/test_projectordb.py index 3fc49d596..c6afb6735 100644 --- a/tests/functional/openlp_core_lib/test_projectordb.py +++ b/tests/functional/openlp_core_lib/test_projectordb.py @@ -29,7 +29,7 @@ PREREQUISITE: add_record() and get_all() functions validated. from unittest import TestCase from tests.functional import MagicMock, patch -from openlp.core.lib.projector.db import Projector, ProjectorDB +from openlp.core.lib.projector.db import Projector, ProjectorDB, ProjectorSource from tests.resources.projector.data import TEST1_DATA, TEST2_DATA, TEST3_DATA @@ -49,6 +49,17 @@ def compare_data(one, two): one.notes == two.notes +def compare_source(one, two): + """ + Verify two ProjectorSource instances contain the same data + """ + return one is not None and \ + two is not None and \ + one.projector_id == two.projector_id and \ + one.code == two.code and \ + one.text == two.text + + def add_records(self, test): """ Add record if not in database @@ -151,3 +162,22 @@ class TestProjectorDB(TestCase): # THEN: Record ID should remain the same, but data should be changed self.assertEqual(record_id, record.id, 'Edited record should have the same ID') self.assertTrue(compare_data(TEST3_DATA, record), 'Edited record should have new data') + + def source_add_test(self): + """ + Test saved source text matches projector + """ + # GIVEN: Record entries in database + item = self.projector.get_projector_by_ip(TEST1_DATA.ip) + if item is None: + self.projector.add_projector(TEST1_DATA) + item = self.projector.get_projector_by_id(TEST1_DATA.id) + item_id = item.id + source = ProjectorSource(projector_id=item_id, code='11', text='First RGB source') + self.projector.add_source(source) + + # WHEN: Retrieve the projector item + item = self.projector.get_projector_by_id(item_id) + + # THEN: Projector should have the same source entry + self.assertTrue(compare_source(item.source_list[0], source))