You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@trafficcontrol.apache.org by "gokulakrishnansvm (via GitHub)" <gi...@apache.org> on 2023/06/20 17:06:12 UTC

[GitHub] [trafficcontrol] gokulakrishnansvm commented on a diff in pull request #7583: Added Api contract test case for users and topologies endpoints.

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


##########
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")
+
+
+@pytest.fixture(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:
   Yes, It should be user_id, I've changed it.



-- 
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-unsubscribe@trafficcontrol.apache.org

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