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
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
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')
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')
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
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