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


##########
traffic_ops/testing/api_contract/v4/conftest.py:
##########
@@ -0,0 +1,94 @@
+import pytest
+from trafficops.tosession import TOSession
+from urllib.parse import urlparse
+import sys 
+import json
+from random import randint
+import logging
+
+
+""" 
+Passing in Traffic Ops Arguments [Username, Password, Url and Hostname] from 
Command Line
+"""
+def pytest_addoption(parser):
+    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'
+    )
+    parser.addoption(
+        '--hostname', action='store',  help='Traffic Ops hostname'
+    )
+
+
+""" 
+PyTest fixture to store Traffic ops Arguments passed from command line
+"""
+@pytest.fixture
+def to_data(pytestconfig):
+    args = {}
+    args['user'] = pytestconfig.getoption('--to_user')
+    args['password'] = pytestconfig.getoption('--to_password')
+    args['url'] = pytestconfig.getoption('--to_url')
+    args['hostname'] = pytestconfig.getoption('--hostname')
+    return args
+
+
+"""
+PyTest Fixture to create a Traffic Ops session from Traffic Ops Arguments
+passed as command line arguments in to_data fixture in conftest
+"""
+@pytest.fixture()
+def to_login(to_data):
+
+    # Create a Traffic Ops V4 session and login
+    print("Parsed TO args {}".format(to_data))
+    if to_data["user"] == None:
+        f = open('to_data.json')
+        data = json.load(f)
+        to_data = data["test"]
+    to_url = urlparse(to_data["url"])
+    to_host = to_url.hostname
+
+    
TO=TOSession(host_ip=to_host,host_port=443,api_version='4.0',ssl=True,verify_cert=False)
+    print("established connection")
+
+    # Login To TO_API
+    TO.login(to_data["user"], to_data["password"])
+
+    if not TO.logged_in:
+        print("Failure Logging into Traffic Ops")
+        sys.exit(-1)
+    else:
+        print("Successfully logged into Traffic Ops")

Review Comment:
   Replaced print with logging



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