Add step to httpClient for log write #373
1 changed files with 10 additions and 3 deletions
|
@ -15,14 +15,14 @@ LOGGING_CONFIG = {
|
||||||
"handlers": {"default": {"class": "logging.StreamHandler", "formatter": "http", "stream": "ext://sys.stderr"}},
|
"handlers": {"default": {"class": "logging.StreamHandler", "formatter": "http", "stream": "ext://sys.stderr"}},
|
||||||
"formatters": {
|
"formatters": {
|
||||||
"http": {
|
"http": {
|
||||||
"format": "%(levelname)s [%(asctime)s] %(name)s - %(message)s",
|
"format": "%(asctime)s [%(levelname)s] %(name)s - %(message)s",
|
||||||
"datefmt": "%Y-%m-%d %H:%M:%S",
|
"datefmt": "%Y-%m-%d %H:%M:%S",
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"loggers": {
|
"loggers": {
|
||||||
"httpx": {
|
"httpx": {
|
||||||
"handlers": ["default"],
|
"handlers": ["default"],
|
||||||
"level": "DEBUG",
|
"level": "ERROR",
|
||||||
},
|
},
|
||||||
"httpcore": {
|
"httpcore": {
|
||||||
"handlers": ["default"],
|
"handlers": ["default"],
|
||||||
|
@ -43,7 +43,7 @@ class HttpClient:
|
||||||
response = client.request(method, url, **kwargs)
|
response = client.request(method, url, **kwargs)
|
||||||
|
|
||||||
self._attach_response(response, **kwargs)
|
self._attach_response(response, **kwargs)
|
||||||
logger.info(f"Response: {response.status_code} => {response.text}")
|
# logger.info(f"Response: {response.status_code} => {response.text}")
|
||||||
|
|
||||||
if expected_status_code:
|
if expected_status_code:
|
||||||
assert (
|
assert (
|
||||||
|
@ -131,6 +131,7 @@ class HttpClient:
|
||||||
|
|
||||||
reporter.attach(report, "Requests Info")
|
reporter.attach(report, "Requests Info")
|
||||||
reporter.attach(curl_request, "CURL")
|
reporter.attach(curl_request, "CURL")
|
||||||
|
cls._write_log(curl_request, response_body, response.status_code)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _create_curl_request(cls, url: str, method: str, headers: httpx.Headers, data: str, files: dict) -> str:
|
def _create_curl_request(cls, url: str, method: str, headers: httpx.Headers, data: str, files: dict) -> str:
|
||||||
|
@ -143,3 +144,9 @@ class HttpClient:
|
||||||
|
|
||||||
# Option -k means no verify SSL
|
# Option -k means no verify SSL
|
||||||
return f"curl {url} -X {method} {headers}{data} -k"
|
return f"curl {url} -X {method} {headers}{data} -k"
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _write_log(cls, curl: str, res_body: str, res_code: int) -> None:
|
||||||
|
if res_body:
|
||||||
|
curl += f"\nResponse: {res_code}\n{res_body}"
|
||||||
|
logger.info(f"{curl}")
|
||||||
|
|
Loading…
Add table
Reference in a new issue