gokulakrishnansvm commented on code in PR #7453: URL: https://github.com/apache/trafficcontrol/pull/7453#discussion_r1172999401
########## traffic_ops/testing/api_contract/v4/test_divisions.py: ########## @@ -0,0 +1,97 @@ +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +"""API Contract Test Case for divisions endpoint.""" +import json +import logging +import os +import pytest +import requests + +from trafficops.tosession import TOSession + +# Create and configure logger +logger = logging.getLogger() + +primitive = bool | int | float | str | None + [email protected]('request_template_data', ["divisions"], indirect=True) +def test_division_contract( + to_session: TOSession, + request_template_data: list[dict[str, object] | list[object] | primitive], + response_template_data: list[dict[str, object] | list[object] | primitive], + division_post_data: dict[str, object] +) -> None: + """ + Test step to validate keys, values and data types from divisions endpoint + response. + :param to_session: Fixture to get Traffic Ops session. + :param get_division_data: Fixture to get division data from a prerequisites file. + :param division_prereq: Fixture to get sample division data and actual division response. + """ + # validate division keys from divisions get response + logger.info("Accessing /divisions endpoint through Traffic ops session.") + + division = request_template_data[0] + if not isinstance(division, dict): + raise TypeError("malformed division in prerequisite data; not an object") + + division_name = division.get("name") + if not isinstance(division_name, str): + raise TypeError("malformed division in prerequisite data; 'name' not a string") + + division_get_response: tuple[ + dict[str, object] | list[dict[str, object] | list[object] | primitive] | primitive, + requests.Response + ] = to_session.get_divisions(query_params={"name": division_name}) + try: + division_data = division_get_response[0] + if not isinstance(division_data, list): + raise TypeError("malformed API response; 'response' property not an array") + + first_division = division_data[0] + if not isinstance(first_division, dict): + raise TypeError("malformed API response; first division in response is not an object") + division_keys = set(first_division.keys()) + + logger.info("division Keys from divisions endpoint response %s", division_keys) + response_template = response_template_data.get("division").get("properties") Review Comment: AttributeError on Line 69 Response template data doesn't have division, Change this to divisions. -- 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]
