TerekhovaKate commented on code in PR #7523:
URL: https://github.com/apache/trafficcontrol/pull/7523#discussion_r1195567600
##########
traffic_ops/testing/api_contract/v4/conftest.py:
##########
@@ -363,6 +366,94 @@ def response_template_data(pytestconfig: pytest.Config
return response_template
+def api_response_data(api_response: tuple[primitive | dict[str, object] |
list[primitive |
+ dict[str, object] | list[object]],
requests.Response],
+ request_type: str=None) -> dict[str,
object]:
+ """
+ Checks API get/post response.
+ :param api_response: Raw api response.
+ :returns: Verified response data
+ """
+ if request_type == "get":
+ try:
+ api_response = api_response[0]
+ if not isinstance(api_response, list):
+ raise TypeError("malformed API response;
'response' property not an array")
+ except KeyError as e:
+ raise TypeError(f"missing API property '{e.args[0]}'")
from e
+ if api_response:
Review Comment:
Validate api_data before returning: Currently, the code assumes that if
api_response is not empty, the first element of api_response is the desired
data. However, it doesn’t verify if it’s a valid data object. Consider adding
validation for api_data before returning it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]