gokulakrishnansvm commented on code in PR #7424:
URL: https://github.com/apache/trafficcontrol/pull/7424#discussion_r1159897942


##########
traffic_ops/testing/api_contract/v4/conftest.py:
##########
@@ -293,18 +300,81 @@ def to_login(to_args: ArgsType) -> TOSession:
        return to_session
 
 
+@pytest.fixture(name="request_template_data", scope="session")
+def request_prerequiste_data(pytestconfig: pytest.Config, request: 
pytest.FixtureRequest
+                         ) -> list[dict[str, object] | list[object] | 
primitive]:
+       """
+       PyTest Fixture to store POST request template data for api endpoint.
+       :param pytestconfig: Session-scoped fixture that returns the session's 
pytest.Config object.
+       :param request: Fixture to access information about the requesting test 
function and its fixtures
+
+       :returns: Prerequisite request data for api endpoint.
+       """
+       request_template_path = pytestconfig.getoption("--request-template")
+       if not isinstance(request_template_path, str):
+               # unlike the configuration file, this must be present
+               raise ValueError("prereqisites path not configured")
+
+       # Response keys for api endpoint
+       data: dict[
+               str,
+               list[dict[str, object] | list[object] | primitive] |\
+                       dict[object, object] |\
+                       primitive
+               ] |\
+       primitive = None
+       with open(request_template_path, encoding="utf-8", mode="r") as 
prereq_file:
+               data = json.load(prereq_file)
+       if not isinstance(data, dict):
+               raise TypeError(f"request template data must be an object, not 
'{type(data)}'")
+       request_template = data[request.param]
+       if not isinstance(request_template, list):
+               raise TypeError(f"Request template data must be a list, not 
'{type(request_template)}'")
+
+       return request_template
+
+@pytest.fixture()
+def response_template_data(pytestconfig: pytest.Config,
+                         ) -> dict[str, object]:
+       """
+       PyTest Fixture to store response template data for api endpoint.
+       :param pytestconfig: Session-scoped fixture that returns the session's 
pytest.Config object.
+       :returns: Prerequisite response data for api endpoint.
+       """
+       prereq_path = pytestconfig.getoption("--response-template")
+       if not isinstance(prereq_path, str):
+               # unlike the configuration file, this must be present
+               raise ValueError("prereqisites path not configured")
+
+       # Response keys for api endpoint
+       response_template: dict[
+               str,
+               list[dict[str, object] | list[object] | primitive] |\
+                       dict[object, object] |\
+                       primitive
+               ] |\
+       primitive = None
+       with open(prereq_path, encoding="utf-8", mode="r") as prereq_file:
+               response_template = json.load(prereq_file)
+       if not isinstance(response_template, dict):
+               raise TypeError(f"Response template data must be an object, not 
'{type(response_template)}'")
+
+       return response_template

Review Comment:
   yes, My mistake, Updated the response_template return type in function's 
declaration.



-- 
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: issues-unsubscr...@trafficcontrol.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to