ericholguin commented on code in PR #7583:
URL: https://github.com/apache/trafficcontrol/pull/7583#discussion_r1235446254
##########
traffic_ops/testing/api_contract/v4/conftest.py:
##########
@@ -311,6 +312,23 @@ def to_login(to_args: ArgsType) -> TOSession:
return to_session
[email protected](scope="session", name="db_connection")
+def open_db_connection():
+ """
+ Creates new traffic ops db connection.
+ :returns: New Traffic ops database connection
+ """
+ conn = psycopg2.connect(
+ user="traffic_ops",
+ password="twelve",
+ host="127.0.0.1",
+ port=5432,
+ database="traffic_ops",
+ sslmode="disable"
Review Comment:
this DB setup will only work for a local install or an install with that
specific username and password, this should be set in our config file instead
##########
traffic_ops/testing/api_contract/v4/conftest.py:
##########
@@ -1153,3 +1230,83 @@ def coordinate_data_post(to_session: TOSession,
request_template_data: list[JSON
if msg is None:
logger.error("coordinate returned by Traffic Ops is missing an
'id' property")
pytest.fail("Response from delete request is empty, Failing
test_case")
+
+
[email protected](name="user_post_data")
+def user_data_post(to_session: TOSession, request_template_data:
list[JSONData],
+ tenant_post_data:dict[str, object], db_connection:
psycopg2.connect) -> dict[str, object]:
+ """
+ PyTest Fixture to create POST data for users endpoint.
+ :param to_session: Fixture to get Traffic Ops session.
+ :param request_template_data: Fixture to get users request template
from a prerequisites file.
+ :returns: Sample POST data and the actual API response.
+ """
+
+ user = check_template_data(request_template_data["users"], "users")
+
+ # Return new post data and post response from users POST request
+ randstr = str(randint(0, 1000))
+ try:
+ username = user["username"]
+ if not isinstance(username, str):
+ raise TypeError(f"username must be str, not
'{type(username)}'")
+ unique_name = username[:4] + randstr
+ user["username"] = generate_unique_data(to_session=to_session,
base_name=unique_name,
+ object_type="users",
query_key="username")
+ except KeyError as e:
+ raise TypeError(f"missing user property '{e.args[0]}'") from e
+ user["tenantId"] = tenant_post_data["id"]
+
+ logger.info("New user data to hit POST method %s", user)
+ # Hitting users POST methed
+ response: tuple[JSONData, requests.Response] =
to_session.create_user(data=user)
+ resp_obj = check_template_data(response, "user")
+ yield resp_obj
+ coordinate_id = resp_obj.get("id")
Review Comment:
should this be user_id
--
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]