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


##########
traffic_ops/testing/api_contract/v4/conftest.py:
##########
@@ -0,0 +1,122 @@
+#
+# 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.
+#
+
+"""This module is used to create a Traffic Ops session 
+and to store prerequisite data for endpoints."""
+import json
+import logging
+import sys
+from random import randint
+from urllib.parse import urlparse
+import pytest
+from trafficops.tosession import TOSession
+from trafficops.restapi import OperationError
+
+
+# Create and configure logger
+logger = logging.getLogger()
+
+
+def pytest_addoption(parser: object) -> None:
+    """Passing in Traffic Ops arguments [Username, Password, Url and Hostname] 
from command line.
+    :param parser: Parser to parse command line arguments
+    """
+    parser.addoption(
+        "--to-user", action="store", help="User name for Traffic Ops Session."
+    )
+    parser.addoption(
+        "--to-password", action="store", help="Password for Traffic Ops 
Session."
+    )
+    parser.addoption(
+        "--to-url", action="store", help="Traffic Ops URL."
+    )
+
+
[email protected](name="to_args")
+def to_data(pytestconfig: pytest.Config) -> dict:
+    """PyTest fixture to store Traffic ops arguments passed from command line.
+    :param pytestconfig: Session-scoped fixture that returns the session's 
pytest.Config object
+    :returns args: Return Traffic Ops arguments
+    """
+    args = {}
+    with open("to_data.json", encoding="utf-8", mode="r") as session_file:
+        data = json.load(session_file)
+    session_data = data["test"]
+    args["api_version"] = urlparse(
+        session_data.get("url")).path.strip("/").split("/")[1]
+    args["port"] = session_data.get("port")
+
+    to_user = pytestconfig.getoption("--to-user")
+    to_password = pytestconfig.getoption("--to-password")
+    to_url = pytestconfig.getoption("--to-url")
+
+    if not all([to_user, to_password, to_url]):
+        logger.info(
+            "Traffic Ops session data were not passed from Command line Args.")
+        args["user"] = session_data.get("user")
+        args["password"] = session_data.get("password")
+        args["url"] = session_data.get("url")
+    else:
+        args["user"] = to_user
+        args["password"] = to_password
+        args["url"] = to_url
+        logger.info("Parsed Traffic ops session data from args %s", args)
+    return args
+
+
[email protected](name="to_session")
+def to_login(to_args: dict) -> TOSession:

Review Comment:
   Changed it to ArgsType.



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