def call_endpoint(self, method: str, endpoint: str, *args: List[Any], **kwargs: Dict[Any, Any]) -> Response:
"""Call api endpoint method.
:param method: REST API methods name (string) - 'POST', 'GET', 'PUT', 'PATCH', 'DELETE'
:param endpoint: endpoint which will be called with method.
:param args: additional arguments
:param kwargs: additional key-worded arguments
:return:
"""
logging.info('Calling method %s for endpoint %s', method, endpoint)
if method.upper() not in REST_API_METHODS:
logging.error('Method %s does not match REST API METHODS: %s', method, ','.join(REST_API_METHODS))
raise TypeError('Method {0} does not match REST API METHODS: {1}'.format(str(method),
','.join(REST_API_METHODS)))
req_method = getattr(requests, method.lower())
resp = req_method(urljoin(self.host_name, endpoint), *args, **kwargs)
return resp
评论列表
文章目录