Esempio n. 1
0
    def run(self):
        """ """

        self.is_executing = True
        endpoint = '/command-async' if self.is_async else '/command-sync'

        try:
            self.add_response(comm.send_request(
                endpoint=endpoint,
                remote_connection=self.remote_connection,
                data=dict(
                    command=self.command,
                    args=self.args
                )
            ))
        except Exception as error:
            self.exception = error
            self.add_response(Response().fail(
                code='COMM_EXECUTION_ERROR',
                error=error,
                message='Communication execution error'
            ).response)

        while not self.is_finished:
            time.sleep(1)
            self.add_response(self.check_status())

        self.is_executing = False
Esempio n. 2
0
    def test_send_request_invalid(self, request_get: MagicMock):
        """ should fail to send request """

        request_get.side_effect = ValueError('Fake Error')

        response = comm.send_request('/fake', method='get')
        self.assert_has_error_code(response, 'CONNECTION_ERROR')
Esempio n. 3
0
    def check_status(self) -> Response:
        """ """

        run_uid = self.responses[-1].data.get('run_uid', '')
        endpoint = '/abort' if self.abort else '/run-status/{}'.format(run_uid)

        return comm.send_request(endpoint=endpoint,
                                 remote_connection=self.remote_connection,
                                 method='GET')
Esempio n. 4
0
    def test_send_request_valid(self, request: MagicMock,
                                parse_http_response: MagicMock):
        """Should successfully send request"""
        request.return_value = HttpResponse()
        parse_http_response.return_value = environ.Response('test')

        response = comm.send_request(endpoint='/fake',
                                     method='post',
                                     data=dict(a=1, b=2))
        self.assertEqual(response.identifier, 'test')
Esempio n. 5
0
    def check_status(self) -> Response:
        """ """

        run_uid = self.responses[-1].data.get('run_uid', '')
        endpoint = '/abort' if self.abort else '/run-status/{}'.format(run_uid)

        return comm.send_request(
            endpoint=endpoint,
            remote_connection=self.remote_connection,
            method='GET'
        )
Esempio n. 6
0
    def run(self):
        """ """

        self.is_executing = True
        endpoint = '/command-async' if self.is_async else '/command-sync'

        try:
            self.add_response(
                comm.send_request(endpoint=endpoint,
                                  remote_connection=self.remote_connection,
                                  data=dict(command=self.command,
                                            args=self.args)))
        except Exception as error:
            self.exception = error
            self.add_response(Response().fail(
                code='COMM_EXECUTION_ERROR',
                error=error,
                message='Communication execution error').response)

        while not self.is_finished:
            time.sleep(1)
            self.add_response(self.check_status())

        self.is_executing = False
Esempio n. 7
0
 def test_send_request_invalid(self, request: MagicMock):
     """Should fail to send request"""
     request.side_effect = requests.ConnectionError('Fake Error')
     response = comm.send_request('/fake', method='GET')
     self.assert_has_error_code(response, 'COMMUNICATION_ERROR')