gokulakrishnansvm commented on code in PR #7583:
URL: https://github.com/apache/trafficcontrol/pull/7583#discussion_r1235612367
##########
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")
+ # Create a cursor object to interact with the database
+ cursor = db_connection.cursor()
+ cursor.execute("DELETE FROM tm_user WHERE id = %s;", (coordinate_id,))
Review Comment:
Yes we need that trailing comma, In the context of the execute method,
trailing comma is required when passing a single parameter as a tuple, allows
it to be passed as the second argument to the execute method.
--
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]