Kashatlast2 commented on code in PR #7458:
URL: https://github.com/apache/trafficcontrol/pull/7458#discussion_r1190226570
##########
traffic_ops/testing/api_contract/v4/conftest.py:
##########
@@ -628,3 +628,187 @@ def profile_post_data(to_session: TOSession,
request_template_data: list[JSONDat
except IndexError:
logger.error("No Profile response data from cdns POST request.")
sys.exit(1)
+
[email protected]()
+def division_post_data(to_session: TOSession, request_template_data:
list[JSONData]
+ ) -> dict[str, object]:
+ """
+ PyTest Fixture to create POST data for divisions endpoint.
+
+ :param to_session: Fixture to get Traffic Ops session.
+ :param request_template_data: Fixture to get divisions request template
data from
+ request_template file.
+ :returns: Sample POST data and the actual API response.
+ """
+
+ try:
+ division = request_template_data[0]
+ except IndexError as e:
+ raise TypeError(
+ "malformed prerequisite data; no division present in
'division' array property") from e
+
+ if not isinstance(division, dict):
+ raise TypeError(
+ f"malformed prerequisite data; divisions must be
objects, not '{type(division)}'")
+
+ # Return new post data and post response from division POST request
+ randstr = str(randint(0, 1000))
+ try:
+ name = division["name"]
+ if not isinstance(name, str):
+ raise TypeError(f"name must be str, not '{type(name)}'")
+ division["name"] = name[:4] + randstr
+ except KeyError as e:
+ raise TypeError(f"missing Parameter property '{e.args[0]}'")
from e
+
+ logger.info("New division data to hit POST method %s",
request_template_data)
+ # Hitting division POST methed
+ response: tuple[JSONData, requests.Response] =
to_session.create_division(data=division)
+ try:
+ resp_obj = response[0]
+ if not isinstance(resp_obj, dict):
+ raise TypeError("malformed API response; division is
not an object")
+ return resp_obj
+ except IndexError:
+ logger.error("No division response data from division POST
request.")
+ sys.exit(1)
+
[email protected]()
+def region_post_data(to_session: TOSession, request_template_data:
list[JSONData]
+ ) -> dict[str, object]:
+ """
+ PyTest Fixture to create POST data for regions endpoint.
+
+ :param to_session: Fixture to get Traffic Ops session.
+ :param request_template_data: Fixture to get regions request template
data from
+ request_template file.
+ :returns: Sample POST data and the actual API response.
+ """
+
+ try:
+ region = request_template_data[0]
+ except IndexError as e:
+ raise TypeError(
+ "malformed prerequisite data; no region present in
'regions' array property") from e
+
+ if not isinstance(region, dict):
+ raise TypeError(
+ f"malformed prerequisite data; regions must be objects,
not '{type(region)}'")
+
+ # Return new post data and post response from region POST request
+ randstr = str(randint(0, 1000))
+ try:
+ name = region["name"]
+ if not isinstance(name, str):
+ raise TypeError(f"name must be str, not '{type(name)}'")
+ region["name"] = name[:4] + randstr
+ division = region["division"]
+ if not isinstance(division, str):
+ raise TypeError(f"division must be int, not
'{type(division)}'")
+ region["division"] = division[:4] + randstr
+ divisionname = region["divisionname"]
+ if not isinstance(divisionname, str):
+ raise TypeError(f"divisionname must be str, not
'{type(divisionname)}'")
+ region["divisionname"] = divisionname[:4] + randstr
+ except KeyError as e:
+ raise TypeError(f"missing Parameter property '{e.args[0]}'")
from e
+
+ logger.info("New region data to hit POST method %s",
request_template_data)
+ # Hitting region POST methed
+ response: tuple[JSONData, requests.Response] =
to_session.create_region(data=region)
+ try:
+ resp_obj = response[0]
+ if not isinstance(resp_obj, dict):
+ raise TypeError("malformed API response; region is not
an object")
+ return resp_obj
+ except IndexError:
+ logger.error("No region response data from region POST
request.")
+ sys.exit(1)
+
[email protected]()
+def phys_locations__post_data(to_session: TOSession, request_template_data:
list[JSONData]
+ ) -> dict[str, object]:
+ """
+ PyTest Fixture to create POST data for phys_locations endpoint.
+
+ :param to_session: Fixture to get Traffic Ops session.
+ :param request_template_data: Fixture to get phys_locations request
template data from
+ request_template file.
+ :returns: Sample POST data and the actual API response.
+ """
+
+ try:
+ phys_location = request_template_data[0]
+ except IndexError as e:
+ raise TypeError(
+ "malformed prerequisite data; no phys_location in
'phys_locations' array property") from e
+
+ if not isinstance(phys_location, dict):
+ raise TypeError(
+ f"malformed prerequisite data; phys_locations must be
objects, not '{type(phys_location)}'")
+
+ # Return new post data and post response from phys_locations POST
request
+ randstr = str(randint(0, 1000))
+ try:
+ name = phys_location["name"]
+ if not isinstance(name, str):
+ raise TypeError(f"name must be str, not '{type(name)}'")
+ phys_location["name"] = name[:4] + randstr
+ address = phys_location["address"]
+ if not isinstance(address, str):
+ raise TypeError(f"address must be str, not
'{type(address)}'")
+ phys_location["address"] = address[:4] + randstr
+ city = phys_location["city"]
+ if not isinstance(city, str):
+ raise TypeError(f"city must be str, not '{type(city)}'")
+ phys_location["city"] = city[:4] + randstr
+ zip = phys_location["zip"]
+ if not isinstance(zip, str):
+ raise TypeError(f"zip must be str, not '{type(zip)}'")
+ phys_location["zip"] = zip[:4] + randstr
+ comments = phys_location["comments"]
+ if not isinstance(comments, str):
+ raise TypeError(f"comment must be str, not
'{type(comments)}'")
+ phys_location["comments"] = comments[:4] + randstr
+ email = phys_location["email"]
+ if not isinstance(email, str):
+ raise TypeError(f"email must be str, not
'{type(email)}'")
+ phys_location["email"] = email[:4] + randstr
+ phone = phys_location["phone"]
+ if not isinstance(phone, str):
+ raise TypeError(f"phone must be str, not
'{type(phone)}'")
+ phys_location["phone"] = phone[:4] + randstr
+ poc = phys_location["poc"]
+ if not isinstance(poc, str):
+ raise TypeError(f"poc must be str, not '{type(poc)}'")
+ phys_location["poc"] = poc[:4] + randstr
+ regionid = phys_location["regionid"]
+ if not isinstance(regionid, int):
+ raise TypeError(f"regionid must be int, not
'{type(regionid)}'")
+ phys_location["regionid"] = regionid[:4] + randstr
+ region = phys_location["region"]
+ if not isinstance(region, str):
+ raise TypeError(f"region must be str, not
'{type(region)}'")
+ phys_location["region"] = region[:4] + randstr
+ shortname = phys_location["shortname"]
+ if not isinstance(shortname, str):
+ raise TypeError(f"shortname must be str, not
'{type(shortname)}'")
+ phys_location["shortname"] = shortname[:4] + randstr
+ state = phys_location["state"]
+ if not isinstance(state, str):
+ raise TypeError(f"state must be str, not
'{type(state)}'")
+ phys_location["state"] = state[:4] + randstr
Review Comment:
New data generated from name
--
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]