ericholguin commented on code in PR #7529:
URL: https://github.com/apache/trafficcontrol/pull/7529#discussion_r1210663749


##########
traffic_ops/testing/api_contract/v4/conftest.py:
##########
@@ -845,6 +850,102 @@ def server_post_data(to_session: TOSession, 
request_template_data: list[JSONData
        resp_obj = check_template_data(response, "server")
        return resp_obj
 
+
[email protected](name="delivery_services_post_data")
+def delivery_services_data_post(to_session: TOSession, request_template_data: 
list[JSONData]
+                     ) -> dict[str, object]:
+       """
+       PyTest Fixture to create POST data for server endpoint.
+       :param to_session: Fixture to get Traffic Ops session.
+       :param request_template_data: Fixture to get profile data from a 
prerequisites file.
+       :returns: Sample POST data and the actual API response.
+       """
+       delivery_services = check_template_data(
+               request_template_data["delivery_services"], "delivery_services")
+
+       randstr = str(randint(0, 1000))
+       try:
+               xml_id = delivery_services["xmlId"]
+               if not isinstance(xml_id, str):
+                       raise TypeError(f"xmlId must be str, not 
'{type(xml_id)}'")
+               delivery_services["xmlId"] = xml_id[:4] + randstr
+       except KeyError as e:
+               raise TypeError(f"missing delivery_services property 
'{e.args[0]}'") from e
+
+       # Check if cdn already exists, otherwise create it
+       cdn_data = check_template_data(request_template_data["cdns"], "cdns")
+       cdn_object = create_or_get_existing(to_session, "cdns", "cdn", cdn_data)
+       delivery_services["cdnId"] = cdn_object["id"]
+
+       # Check if profile with cdn already exists, otherwise create it
+       profile_data = check_template_data(request_template_data["profiles"], 
"profiles")
+       profile_data["cdn"] = cdn_object["id"]
+       profile_object = create_or_get_existing(to_session, "profiles", 
"profile", profile_data,
+                                        {"cdn": cdn_object["id"]})
+       delivery_services["profileId"] = profile_object["id"]
+
+       # Check if status already exists, otherwise create it
+       tenant_data = check_template_data(request_template_data["tenants"], 
"tenants")
+       tenant_object = create_or_get_existing(to_session, "tenants", "tenant",
+                                       tenant_data, {"name": "root"})
+       delivery_services["tenantId"] = tenant_object["id"]
+
+       # Check if status already exists, otherwise create it

Review Comment:
   comment is incorrect



-- 
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]

Reply via email to