コード例 #1
0
def client_echo_valid(endpoint):
    """
    This will validate if the user's endpoint is valid and returning the echo
    data sent to it
    """
    try:
        request_handler = RequestHandler(verify_ssl=False,
                                         request_timeout=REQUEST_TIMEOUT)
        validation_key = common.generate_key()

        try:
            returned_json, status_code = request_handler.get(
                endpoint, params={'echo': validation_key})
        # pylint: disable=W0703
        except:
            return False

        if status_code != client.OK:
            return False
        if returned_json['echo'] != validation_key:
            return False
    # pylint: disable=W0703
    except Exception:
        return False

    return True
コード例 #2
0
def client_echo_valid(endpoint):
    """
    This will validate if the user's endpoint is valid and returning the echo
    data sent to it
    """
    try:
        request_handler = RequestHandler(
            verify_ssl=False, request_timeout=REQUEST_TIMEOUT)
        validation_key = common.generate_key()

        try:
            returned_json, status_code = request_handler.get(
                endpoint, params={'echo': validation_key})
        # pylint: disable=W0703
        except:
            return False

        if status_code != client.OK:
            return False
        if returned_json['echo'] != validation_key:
            return False
    # pylint: disable=W0703
    except Exception:
        return False

    return True
コード例 #3
0
    def test_get(self):

        with requests_mock.Mocker() as mocker:
            mocker.register_uri('GET',
                                'http://localhost?test=123',
                                json={'test': 'value'},
                                status_code=200)

            request_handler = RequestHandler()
            data, status = request_handler.get('http://localhost',
                                               params={'test': 123},
                                               api_key='12345',
                                               username='******')
            self.assertEqual(status, client.OK)
            self.assertEqual({'test': 'value'}, data)
            self.assertEqual(request_handler.headers['username'], 'johndoe')
            self.assertEqual(request_handler.headers['api-key'], '12345')
            self.assertEqual(request_handler.headers['Content-Type'],
                             'application/json')
            self.assertEqual(request_handler.headers['Accept'],
                             'application/json')
コード例 #4
0
    def test_get(self):

        with requests_mock.Mocker() as mocker:
            mocker.register_uri('GET', 'http://localhost?test=123',
                                json={'test': 'value'},
                                status_code=200)

            request_handler = RequestHandler()
            data, status = request_handler.get(
                'http://localhost',
                params={'test': 123},
                api_key='12345',
                username='******'
            )
            self.assertEqual(status, client.OK)
            self.assertEqual({'test': 'value'}, data)
            self.assertEqual(request_handler.headers['username'], 'johndoe')
            self.assertEqual(request_handler.headers['api-key'], '12345')
            self.assertEqual(
                request_handler.headers['Content-Type'], 'application/json')
            self.assertEqual(
                request_handler.headers['Accept'], 'application/json')
コード例 #5
0
def client_reset_key(endpoint, key_type, key_value):
    """
    This will send an api_key or secret_key to the configured endpoint
    (assists with resets of an api_key or secret_key)
    """
    try:
        request_handler = RequestHandler(verify_ssl=False,
                                         request_timeout=REQUEST_TIMEOUT)

        try:
            returned_json, status_code = request_handler.get(
                endpoint, params={key_type: key_value})
        # pylint: disable=W0703
        except:
            return False

        if status_code != client.OK:
            return False
    # pylint: disable=W0703
    except Exception:
        return False

    return True
コード例 #6
0
def client_reset_key(endpoint, key_type, key_value):
    """
    This will send an api_key or secret_key to the configured endpoint
    (assists with resets of an api_key or secret_key)
    """
    try:
        request_handler = RequestHandler(
            verify_ssl=False, request_timeout=REQUEST_TIMEOUT)

        try:
            returned_json, status_code = request_handler.get(
                endpoint, params={key_type: key_value})
        # pylint: disable=W0703
        except:
            return False

        if status_code != client.OK:
            return False
    # pylint: disable=W0703
    except Exception:
        return False

    return True