def test_queue_login_invalid(self, mock_connect): """ Test: An exception is raised When: We are unable to log in via the client """ con_exp = ConnectionException('Queue') mock_connect.side_effect = con_exp self.assertRaises(RuntimeError, ms.login_queue)
def test_database_login_invalid(self, mock_connect): """ Test: None is returned When: We are unable to log in via the database client """ con_exp = ConnectionException('MySQL') mock_connect.side_effect = con_exp self.assertIsNone(ms.login_database())
def test_icat_login_invalid(self, mock_connect, _): """ Test: None is returned When: We are unable to log in via the icat client """ con_exp = ConnectionException('icat') mock_connect.side_effect = con_exp self.assertIsNone(ms.login_icat())
def _test_connection(self): """ Test that the connection has been successful """ try: self.client.refresh() except icat.exception.ICATSessionError as exp: raise ConnectionException("ICAT") from exp return True
def _test_connection(self): """ Ensure that the connection has been established or raise exception if not :return: True if connection is establish """ try: self.data_model.Instrument.objects.first() self.variable_model.Variable.objects.first() # pylint:disable=broad-except except Exception as exp: raise ConnectionException("MySQL") from exp return True
def _test_connection(self): """ Test whether there is a connection to the SFTP server :return: True if there is a connection. :raises ConnectionException: If there is no existing connection or it is not valid. """ try: self._connection.pwd except AttributeError as exp: raise ConnectionException("SFTP") from exp return True
def __init__(self, credentials=None): if not credentials: credentials = CYCLE_SETTINGS super(CycleIngestionClient, self).__init__(credentials) self._uows_client = None self._scheduler_client = None self._session_id = None self._errors = { "invalid_uows_client": TypeError("The UOWS Client does not exist" "or has not been initialised properly"), "invalid_scheduler_client": TypeError("The Scheduler Client does not exist" "or has not been initialised properly"), "invalid_session_id": ConnectionException("Cycle Ingestion") }
def _test_connection(self): """ Ensure that the connection has been established :return: True if connection is establish """ try: # pylint: disable=no-member self._connection.execute('SELECT 1').fetchall() # pylint:disable=broad-except except Exception as exp: # The original exception appears to be wrapped in a different exception # as such it is not being consistently caught so we should check # the exception name instead if type(exp).__name__ == 'OperationalError': raise ConnectionException("MySQL") from exp raise return True
def _create_connection(self, listener=None): """ Create the connection to the queuing service and store as self._connection :param listener: A ConnectionListener object to assign to the stomp connection, optionally """ if self._connection is None or not self._connection.is_connected(): try: host_port = [(self.credentials.host, int(self.credentials.port))] connection = stomp.Connection(host_and_ports=host_port, use_ssl=False) if listener: connection.set_listener('Autoreduction', listener) self._logger.info("Starting connection to %s", host_port) connection.connect(username=self.credentials.username, passcode=self.credentials.password, wait=True) except ConnectFailedException as exp: raise ConnectionException("ActiveMQ") from exp # Sleep required to avoid using the service too quickly after establishing connection # time.sleep(0.5) self._connection = connection
def _test_connection(self): if not self._connection.is_connected(): raise ConnectionException("ActiveMQ") return True