Makes a POST request with JSON body to the given endpoint and checks the response. endpoint str: The endpoint to make the request to. json_data: The JSON-serializable data to send with the request (dict, list, etc.). expected_status_code int: The expected status code of the respons
(
endpoint: str,
json_data=None,
expected_status_code: int = 200,
headers: dict = {},
should_check_response: bool = True,
)
| 62 | |
| 63 | |
| 64 | def json_post( |
| 65 | endpoint: str, |
| 66 | json_data=None, |
| 67 | expected_status_code: int = 200, |
| 68 | headers: dict = {}, |
| 69 | should_check_response: bool = True, |
| 70 | ) -> requests.Response: |
| 71 | """ |
| 72 | Makes a POST request with JSON body to the given endpoint and checks the response. |
| 73 | |
| 74 | endpoint str: The endpoint to make the request to. |
| 75 | json_data: The JSON-serializable data to send with the request (dict, list, etc.). |
| 76 | expected_status_code int: The expected status code of the response. |
| 77 | headers dict: The headers to send with the request. |
| 78 | should_check_response bool: A boolean to indicate if the status code and headers should be checked. |
| 79 | """ |
| 80 | |
| 81 | endpoint = endpoint.strip("/") |
| 82 | response = requests.post(f"{BASE_URL}/{endpoint}", json=json_data, headers=headers) |
| 83 | if should_check_response: |
| 84 | check_response(response, expected_status_code) |
| 85 | return response |
| 86 | |
| 87 | |
| 88 | def json_put( |