[#322] Added classmethod decorator in Http client

Signed-off-by: Dmitriy Zayakin <d.zayakin@yadro.com>
This commit is contained in:
Dmitriy Zayakin 2024-11-18 16:57:14 +03:00 committed by Dmitriy Zayakin
parent a1953684b8
commit 8eaa511e5c

View file

@ -50,7 +50,8 @@ class HttpClient:
return response return response
def _attach_response(self, response: httpx.Response): @classmethod
def _attach_response(cls, response: httpx.Response):
request = response.request request = response.request
try: try:
@ -83,12 +84,13 @@ class HttpClient:
f"Response Headers: {response_headers}\n\n" f"Response Headers: {response_headers}\n\n"
f"Response Body: {response.text}\n\n" f"Response Body: {response.text}\n\n"
) )
curl_request = self._create_curl_request(request.url, request.method, request.headers, request_body) curl_request = cls._create_curl_request(request.url, request.method, request.headers, request_body)
reporter.attach(report, "Requests Info") reporter.attach(report, "Requests Info")
reporter.attach(curl_request, "CURL") reporter.attach(curl_request, "CURL")
def _create_curl_request(self, url: str, method: str, headers: httpx.Headers, data: str) -> str: @classmethod
def _create_curl_request(cls, url: str, method: str, headers: httpx.Headers, data: str) -> str:
headers = " ".join(f'-H "{name.title()}: {value}"' for name, value in headers.items()) headers = " ".join(f'-H "{name.title()}: {value}"' for name, value in headers.items())
data = f" -d '{data}'" if data else "" data = f" -d '{data}'" if data else ""
# Option -k means no verify SSL # Option -k means no verify SSL