|
1 | 1 | import json |
| 2 | +import time |
2 | 3 | from logging import warning |
3 | 4 | from typing import Any, Dict, List |
4 | 5 | import jsonschema |
5 | 6 | import requests |
6 | 7 | import warnings |
| 8 | +from schemathesis.exceptions import CheckFailed |
7 | 9 | from schemathesis.models import APIOperation |
8 | 10 | from schemathesis.specs.openapi.references import ConvertingResolver |
9 | 11 | from schemathesis.specs.openapi.schemas import OpenApi30 |
@@ -81,14 +83,35 @@ def request_with_validation( |
81 | 83 | warnings.warn(f"Delete call for {api} missing wait=true param, adding it") |
82 | 84 | query_params["wait"] = "true" |
83 | 85 |
|
| 86 | + start_time = time.time() |
84 | 87 | response = action( |
85 | 88 | url=get_api_string(QDRANT_HOST, api, path_params), |
86 | 89 | params=query_params, |
87 | 90 | json=body, |
88 | 91 | headers=qdrant_host_headers() |
89 | 92 | ) |
90 | | - |
91 | | - operation.validate_response(response) |
| 93 | + duration = time.time() - start_time |
| 94 | + try: |
| 95 | + operation.validate_response(response) |
| 96 | + except CheckFailed as ex: |
| 97 | + status = response.status_code |
| 98 | + headers_str = "\n".join(f"{k}: {v}" for k, v in response.headers.items()) |
| 99 | + body_text = response.text.strip() |
| 100 | + msg = ( |
| 101 | + f"Failed validation {ex} for response:\n" |
| 102 | + f"Status: {status}\n" |
| 103 | + f"Headers:\n{headers_str}\n" |
| 104 | + f"Body (decoded text):\n{body_text if body_text else '[Empty Body]'}\n" |
| 105 | + f"Duration: {duration:.2f} seconds\n" |
| 106 | + f"Request was:\n" |
| 107 | + f"Method: {method}\n" |
| 108 | + f"URL: {get_api_string(QDRANT_HOST, api, path_params)}\n" |
| 109 | + f"Query params: {query_params}\n" |
| 110 | + f"Headers: {qdrant_host_headers()}\n" |
| 111 | + f"Body: {body}\n" |
| 112 | + ) |
| 113 | + warnings.warn(msg) |
| 114 | + raise |
92 | 115 |
|
93 | 116 | return response |
94 | 117 |
|
|
0 commit comments