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

[GitHub] [trafficcontrol] Kashatlast2 opened a new pull request, #7453: Added divisions test case

Kashatlast2 opened a new pull request, #7453:
URL: https://github.com/apache/trafficcontrol/pull/7453

   <!--
   Thank you for contributing! Please be sure to read our contribution guidelines: https://github.com/apache/trafficcontrol/blob/master/CONTRIBUTING.md
   If this closes or relates to an existing issue, please reference it using one of the following:
   
   Closes: #ISSUE
   Related: #ISSUE
   
   If this PR fixes a security vulnerability, DO NOT submit! Instead, contact
   the Apache Traffic Control Security Team at security@trafficcontrol.apache.org and follow the
   guidelines at https://apache.org/security regarding vulnerability disclosure.
   -->
   
   
   Adding API Contract Test Case for divisions endpoint.
   <!-- **^ Add meaningful description above** --><hr/>
   
   ## Which Traffic Control components are affected by this PR?
   <!-- Please delete all components from this list that are NOT affected by this PR.
   Feel free to add the name of a tool or script that is affected but not on the list.
   -->
   - Traffic Ops Test
   
   
   ## What is the best way to verify this PR?
   
   Step 1 : Install requirements
   pip install -r requirements.txt
   
   Step 2 : To execute divisions API Contract Testcase , navigate to traffic_ops/testing/api_contract/v4
   pytest --to-user Username --to-password Password --to-url URL --config Config Path --request-template Request template --response-template Response template test_divisions.py
   
   Note: Config, Request template and response template paths are optional. 
   
   ## PR submission checklist
   - [x] This PR has tests <!-- If not, please delete this text and explain why this PR does not need tests. -->
   - [x] This PR **DOES NOT FIX A SERIOUS SECURITY VULNERABILITY** (see [the Apache Software Foundation's security guidelines](https://apache.org/security) for details)
   
   <!--
   Licensed to the Apache Software Foundation (ASF) under one
   or more contributor license agreements.  See the NOTICE file
   distributed with this work for additional information
   regarding copyright ownership.  The ASF licenses this file
   to you 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 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


[GitHub] [trafficcontrol] Kashatlast2 commented on a diff in pull request #7453: Added divisions test case

Posted by "Kashatlast2 (via GitHub)" <gi...@apache.org>.
Kashatlast2 commented on code in PR #7453:
URL: https://github.com/apache/trafficcontrol/pull/7453#discussion_r1174042725


##########
traffic_ops/testing/api_contract/v4/test_divisions.py:
##########
@@ -0,0 +1,97 @@
+#
+# 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.
+#
+
+"""API Contract Test Case for divisions endpoint."""
+import json
+import logging
+import os
+import pytest
+import requests
+
+from trafficops.tosession import TOSession
+
+# Create and configure logger
+logger = logging.getLogger()
+
+primitive = bool | int | float | str | None
+
+@pytest.mark.parametrize('request_template_data', ["divisions"], indirect=True)
+def test_division_contract(
+	to_session: TOSession,
+	request_template_data: list[dict[str, object] | list[object] | primitive],
+	response_template_data: list[dict[str, object] | list[object] | primitive],
+	division_post_data: dict[str, object]
+) -> None:
+	"""
+	Test step to validate keys, values and data types from divisions endpoint
+	response.
+	:param to_session: Fixture to get Traffic Ops session.
+	:param get_division_data: Fixture to get division data from a prerequisites file.
+	:param division_prereq: Fixture to get sample division data and actual division response.
+	"""
+	# validate division keys from divisions get response
+	logger.info("Accessing /divisions endpoint through Traffic ops session.")
+
+	division = request_template_data[0]
+	if not isinstance(division, dict):
+		raise TypeError("malformed division in prerequisite data; not an object")
+
+	division_name = division.get("name")
+	if not isinstance(division_name, str):
+		raise TypeError("malformed division in prerequisite data; 'name' not a string")
+
+	division_get_response: tuple[
+		dict[str, object] | list[dict[str, object] | list[object] | primitive] | primitive,
+		requests.Response
+	] = to_session.get_divisions(query_params={"name": division_name})
+	try:
+		division_data = division_get_response[0]
+		if not isinstance(division_data, list):
+			raise TypeError("malformed API response; 'response' property not an array")
+
+		first_division = division_data[0]
+		if not isinstance(first_division, dict):
+			raise TypeError("malformed API response; first division in response is not an object")
+		division_keys = set(first_division.keys())
+
+		logger.info("division Keys from divisions endpoint response %s", division_keys)
+		response_template = response_template_data.get("division").get("properties")
+		# validate division values from prereq data in divisions get response.
+		prereq_values = [
+			division_post_data["name"]]
+		get_values = [first_division["name"]]
+		get_types = {}
+		for key in first_division:
+			get_types[key] = first_division[key].__class__.__name__
+		logger.info("types from division get response %s", get_types)
+		response_template_types= {}
+		for key in response_template:
+			response_template_types[key] = response_template.get(key).get("type")
+		logger.info("types from division response template %s", response_template_types)
+
+		assert division_keys == set(response_template.keys())
+		assert dict(sorted(get_types.items())) == dict(sorted(response_template_types.items()))
+		assert get_values == prereq_values
+	except IndexError:
+		logger.error("Either prerequisite data or API response was malformed")
+		pytest.fail("Either prerequisite data or API response was malformed")
+	finally:
+		# Delete division after test execution to avoid redundancy.
+		try:
+			division_id = division_post_data["id"]
+			to_session.delete_division(division_id=division_id)
+		except IndexError:
+			logger.error("division returned by Traffic Ops is missing an 'id' property")
+			pytest.fail("Response from delete request is empty, Failing test_get_division")

Review Comment:
   Where is the trailing new line here?



##########
traffic_ops/testing/api_contract/v4/conftest.py:
##########
@@ -628,3 +628,46 @@ def profile_post_data(to_session: TOSession, request_template_data: list[JSONDat
 	except IndexError:
 		logger.error("No Profile response data from cdns POST request.")
 		sys.exit(1)
+
+@pytest.fixture()
+def division_post_data(to_session: TOSession, request_template_data: list[JSONData]
+		  ) -> dict[str, object]:
+	"""
+	PyTest Fixture to create POST data for divisions endpoint.
+
+	:param to_session: Fixture to get Traffic Ops session.
+	:param request_template_data: Fixture to get divisions request template data from a prerequisites file.
+	:returns: Sample POST data and the actual API response.
+	"""
+
+	try:
+		division = request_template_data[0]
+	except IndexError as e:
+		raise TypeError(
+			"malformed prerequisite data; no status present in 'status' array property") from e
+
+	if not isinstance(division, dict):
+		raise TypeError(
+			f"malformed prerequisite data; status must be objects, not '{type(division)}'")
+
+	# Return new post data and post response from status POST request
+	randstr = str(randint(0, 1000))
+	try:
+		name = division["name"]
+		if not isinstance(name, str):
+			raise TypeError(f"name must be str, not '{type(name)}'")
+		division["name"] = name[:4] + randstr
+	except KeyError as e:
+		raise TypeError(f"missing Parameter property '{e.args[0]}'") from e
+
+	logger.info("New division data to hit POST method %s", request_template_data)
+	# Hitting sdivision POST methed
+	response: tuple[JSONData, requests.Response] = to_session.create_division(data=division)
+	try:
+		resp_obj = response[0]
+		if not isinstance(resp_obj, dict):
+			raise TypeError("malformed API response; division is not an object")
+		return resp_obj
+	except IndexError:
+		logger.error("No division response data from division POST request.")
+		sys.exit(1)		

Review Comment:
   I'm not sure what I need to do to resolve this one.



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


[GitHub] [trafficcontrol] Kashatlast2 commented on a diff in pull request #7453: Added divisions test case

Posted by "Kashatlast2 (via GitHub)" <gi...@apache.org>.
Kashatlast2 commented on code in PR #7453:
URL: https://github.com/apache/trafficcontrol/pull/7453#discussion_r1189053725


##########
traffic_ops/testing/api_contract/v4/response_template.json:
##########
@@ -176,6 +176,23 @@
     "server_capabilities": {
         "type": "object",
         "properties": {
+            "id": {
+                "type": "int"
+            },

Review Comment:
   I think it was a mistake in resolving the merge conflict.  I'll fix 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


[GitHub] [trafficcontrol] ericholguin commented on a diff in pull request #7453: Added divisions test case

Posted by "ericholguin (via GitHub)" <gi...@apache.org>.
ericholguin commented on code in PR #7453:
URL: https://github.com/apache/trafficcontrol/pull/7453#discussion_r1189050775


##########
traffic_ops/testing/api_contract/v4/response_template.json:
##########
@@ -176,6 +176,23 @@
     "server_capabilities": {
         "type": "object",
         "properties": {
+            "id": {
+                "type": "int"
+            },

Review Comment:
   Not sure why you changed anything here, but it shouldnt have an id property. Tests are failing because of this



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


[GitHub] [trafficcontrol] gokulakrishnansvm commented on a diff in pull request #7453: Added divisions test case

Posted by "gokulakrishnansvm (via GitHub)" <gi...@apache.org>.
gokulakrishnansvm commented on code in PR #7453:
URL: https://github.com/apache/trafficcontrol/pull/7453#discussion_r1172999401


##########
traffic_ops/testing/api_contract/v4/test_divisions.py:
##########
@@ -0,0 +1,97 @@
+#
+# 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.
+#
+
+"""API Contract Test Case for divisions endpoint."""
+import json
+import logging
+import os
+import pytest
+import requests
+
+from trafficops.tosession import TOSession
+
+# Create and configure logger
+logger = logging.getLogger()
+
+primitive = bool | int | float | str | None
+
+@pytest.mark.parametrize('request_template_data', ["divisions"], indirect=True)
+def test_division_contract(
+	to_session: TOSession,
+	request_template_data: list[dict[str, object] | list[object] | primitive],
+	response_template_data: list[dict[str, object] | list[object] | primitive],
+	division_post_data: dict[str, object]
+) -> None:
+	"""
+	Test step to validate keys, values and data types from divisions endpoint
+	response.
+	:param to_session: Fixture to get Traffic Ops session.
+	:param get_division_data: Fixture to get division data from a prerequisites file.
+	:param division_prereq: Fixture to get sample division data and actual division response.
+	"""
+	# validate division keys from divisions get response
+	logger.info("Accessing /divisions endpoint through Traffic ops session.")
+
+	division = request_template_data[0]
+	if not isinstance(division, dict):
+		raise TypeError("malformed division in prerequisite data; not an object")
+
+	division_name = division.get("name")
+	if not isinstance(division_name, str):
+		raise TypeError("malformed division in prerequisite data; 'name' not a string")
+
+	division_get_response: tuple[
+		dict[str, object] | list[dict[str, object] | list[object] | primitive] | primitive,
+		requests.Response
+	] = to_session.get_divisions(query_params={"name": division_name})
+	try:
+		division_data = division_get_response[0]
+		if not isinstance(division_data, list):
+			raise TypeError("malformed API response; 'response' property not an array")
+
+		first_division = division_data[0]
+		if not isinstance(first_division, dict):
+			raise TypeError("malformed API response; first division in response is not an object")
+		division_keys = set(first_division.keys())
+
+		logger.info("division Keys from divisions endpoint response %s", division_keys)
+		response_template = response_template_data.get("division").get("properties")

Review Comment:
   AttributeError on Line 69
   Response template data doesn't have division, Change this to divisions.



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


[GitHub] [trafficcontrol] ericholguin commented on a diff in pull request #7453: Added divisions test case

Posted by "ericholguin (via GitHub)" <gi...@apache.org>.
ericholguin commented on code in PR #7453:
URL: https://github.com/apache/trafficcontrol/pull/7453#discussion_r1187534326


##########
traffic_ops/testing/api_contract/v4/request_template.json:
##########
@@ -55,5 +55,10 @@
 		{
 			"name": "RAM"
 		}
-	]
+	],
+	"divisions":[
+		{
+			"name":"test"
+    }
+  ] 

Review Comment:
   Above 2 lines need tabs



##########
traffic_ops/testing/api_contract/v4/conftest.py:
##########
@@ -681,10 +681,9 @@ def server_capabilities_post_data(to_session: TOSession, request_template_data:
 
 	:param to_session: Fixture to get Traffic Ops session.
 	:param request_template_data: Fixture to get server_capabilities data from a prerequisites file.
-	:returns: Sample POST data and the actual API response.
+  :returns: Sample POST data and the actual API response.

Review Comment:
   Not sure why the tabbing was removed here?



##########
traffic_ops/testing/api_contract/v4/conftest.py:
##########
@@ -716,3 +715,49 @@ def server_capabilities_post_data(to_session: TOSession, request_template_data:
 	except IndexError:
 		logger.error("No server_capabilities response data from server_capabilities POST request.")
 		sys.exit(1)
+
+
+@pytest.fixture()
+def division_post_data(to_session: TOSession, request_template_data: list[JSONData]
+		  ) -> dict[str, object]:
+	"""
+	PyTest Fixture to create POST data for divisions endpoint.
+
+	:param to_session: Fixture to get Traffic Ops session.
+	:param request_template_data: Fixture to get divisions request template data from
+	request_template file.
+  :returns: Sample POST data and the actual API response.

Review Comment:
   Tab



##########
traffic_ops/testing/api_contract/v4/conftest.py:
##########
@@ -681,10 +681,9 @@ def server_capabilities_post_data(to_session: TOSession, request_template_data:
 
 	:param to_session: Fixture to get Traffic Ops session.
 	:param request_template_data: Fixture to get server_capabilities data from a prerequisites file.
-	:returns: Sample POST data and the actual API response.
+  :returns: Sample POST data and the actual API response.
 	"""
-
-	try:
+  try:

Review Comment:
   Same thing here, tabbing



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


[GitHub] [trafficcontrol] gokulakrishnansvm commented on pull request #7453: Added divisions test case

Posted by "gokulakrishnansvm (via GitHub)" <gi...@apache.org>.
gokulakrishnansvm commented on PR #7453:
URL: https://github.com/apache/trafficcontrol/pull/7453#issuecomment-1531554507

   Looks good to me.


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


[GitHub] [trafficcontrol] gokulakrishnansvm commented on a diff in pull request #7453: Added divisions test case

Posted by "gokulakrishnansvm (via GitHub)" <gi...@apache.org>.
gokulakrishnansvm commented on code in PR #7453:
URL: https://github.com/apache/trafficcontrol/pull/7453#discussion_r1172984730


##########
traffic_ops/testing/api_contract/v4/to_data.json:
##########
@@ -1,6 +1,6 @@
 {
     "user": "admin",
-    "password": "twelve12",
+    "password": "twelve",
     "url": "https://localhost/api/4.0",
     "port": 443
 }

Review Comment:
   No newline at EOF
   



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


[GitHub] [trafficcontrol] gokulakrishnansvm commented on a diff in pull request #7453: Added divisions test case

Posted by "gokulakrishnansvm (via GitHub)" <gi...@apache.org>.
gokulakrishnansvm commented on code in PR #7453:
URL: https://github.com/apache/trafficcontrol/pull/7453#discussion_r1172992942


##########
traffic_ops/testing/api_contract/v4/test_divisions.py:
##########
@@ -0,0 +1,97 @@
+#
+# 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.
+#
+
+"""API Contract Test Case for divisions endpoint."""
+import json
+import logging
+import os
+import pytest
+import requests
+

Review Comment:
   Unused json and os imports



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


[GitHub] [trafficcontrol] gokulakrishnansvm commented on a diff in pull request #7453: Added divisions test case

Posted by "gokulakrishnansvm (via GitHub)" <gi...@apache.org>.
gokulakrishnansvm commented on code in PR #7453:
URL: https://github.com/apache/trafficcontrol/pull/7453#discussion_r1172992541


##########
traffic_ops/testing/api_contract/v4/test_divisions.py:
##########
@@ -0,0 +1,97 @@
+#
+# 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.
+#
+
+"""API Contract Test Case for divisions endpoint."""
+import json
+import logging
+import os
+import pytest
+import requests
+
+from trafficops.tosession import TOSession
+
+# Create and configure logger
+logger = logging.getLogger()
+
+primitive = bool | int | float | str | None
+
+@pytest.mark.parametrize('request_template_data', ["divisions"], indirect=True)
+def test_division_contract(
+	to_session: TOSession,
+	request_template_data: list[dict[str, object] | list[object] | primitive],
+	response_template_data: list[dict[str, object] | list[object] | primitive],
+	division_post_data: dict[str, object]
+) -> None:
+	"""
+	Test step to validate keys, values and data types from divisions endpoint
+	response.
+	:param to_session: Fixture to get Traffic Ops session.
+	:param get_division_data: Fixture to get division data from a prerequisites file.
+	:param division_prereq: Fixture to get sample division data and actual division response.
+	"""
+	# validate division keys from divisions get response
+	logger.info("Accessing /divisions endpoint through Traffic ops session.")
+
+	division = request_template_data[0]
+	if not isinstance(division, dict):
+		raise TypeError("malformed division in prerequisite data; not an object")
+
+	division_name = division.get("name")
+	if not isinstance(division_name, str):
+		raise TypeError("malformed division in prerequisite data; 'name' not a string")
+
+	division_get_response: tuple[
+		dict[str, object] | list[dict[str, object] | list[object] | primitive] | primitive,
+		requests.Response
+	] = to_session.get_divisions(query_params={"name": division_name})
+	try:
+		division_data = division_get_response[0]
+		if not isinstance(division_data, list):
+			raise TypeError("malformed API response; 'response' property not an array")
+
+		first_division = division_data[0]
+		if not isinstance(first_division, dict):
+			raise TypeError("malformed API response; first division in response is not an object")
+		division_keys = set(first_division.keys())
+
+		logger.info("division Keys from divisions endpoint response %s", division_keys)
+		response_template = response_template_data.get("division").get("properties")
+		# validate division values from prereq data in divisions get response.
+		prereq_values = [
+			division_post_data["name"]]
+		get_values = [first_division["name"]]
+		get_types = {}
+		for key in first_division:
+			get_types[key] = first_division[key].__class__.__name__
+		logger.info("types from division get response %s", get_types)
+		response_template_types= {}
+		for key in response_template:
+			response_template_types[key] = response_template.get(key).get("type")
+		logger.info("types from division response template %s", response_template_types)
+
+		assert division_keys == set(response_template.keys())
+		assert dict(sorted(get_types.items())) == dict(sorted(response_template_types.items()))
+		assert get_values == prereq_values
+	except IndexError:
+		logger.error("Either prerequisite data or API response was malformed")
+		pytest.fail("Either prerequisite data or API response was malformed")
+	finally:
+		# Delete division after test execution to avoid redundancy.
+		try:
+			division_id = division_post_data["id"]
+			to_session.delete_division(division_id=division_id)
+		except IndexError:
+			logger.error("division returned by Traffic Ops is missing an 'id' property")
+			pytest.fail("Response from delete request is empty, Failing test_get_division")

Review Comment:
   Trailing new lines



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


[GitHub] [trafficcontrol] gokulakrishnansvm commented on a diff in pull request #7453: Added divisions test case

Posted by "gokulakrishnansvm (via GitHub)" <gi...@apache.org>.
gokulakrishnansvm commented on code in PR #7453:
URL: https://github.com/apache/trafficcontrol/pull/7453#discussion_r1172993638


##########
traffic_ops/testing/api_contract/v4/conftest.py:
##########
@@ -628,3 +628,46 @@ def profile_post_data(to_session: TOSession, request_template_data: list[JSONDat
 	except IndexError:
 		logger.error("No Profile response data from cdns POST request.")
 		sys.exit(1)
+
+@pytest.fixture()
+def division_post_data(to_session: TOSession, request_template_data: list[JSONData]
+		  ) -> dict[str, object]:
+	"""
+	PyTest Fixture to create POST data for divisions endpoint.
+
+	:param to_session: Fixture to get Traffic Ops session.
+	:param request_template_data: Fixture to get divisions request template data from a prerequisites file.

Review Comment:
   Line 639 too long



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


[GitHub] [trafficcontrol] mitchell852 commented on pull request #7453: Added divisions test case

Posted by "mitchell852 (via GitHub)" <gi...@apache.org>.
mitchell852 commented on PR #7453:
URL: https://github.com/apache/trafficcontrol/pull/7453#issuecomment-1553343637

   @gokulakrishnansvm - can you make the title more descriptive. maybe something like "Added Api contract tests for divisions"


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


[GitHub] [trafficcontrol] gokulakrishnansvm commented on a diff in pull request #7453: Added divisions test case

Posted by "gokulakrishnansvm (via GitHub)" <gi...@apache.org>.
gokulakrishnansvm commented on code in PR #7453:
URL: https://github.com/apache/trafficcontrol/pull/7453#discussion_r1172984516


##########
traffic_ops/testing/api_contract/v4/response_template.json:
##########
@@ -149,5 +149,19 @@
                 "type": "str"
             }
         }
+    },
+    "divisions": {
+        "type": "object",
+        "properties": {
+            "id": {
+                "type": "int"
+            },
+            "lastUpdated": {
+                "type": "str"
+            },
+            "name": {
+                "type": "str"
+            }
+        }
     }
-}
+}

Review Comment:
   No newline at EOF



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


[GitHub] [trafficcontrol] gokulakrishnansvm commented on a diff in pull request #7453: Added divisions test case

Posted by "gokulakrishnansvm (via GitHub)" <gi...@apache.org>.
gokulakrishnansvm commented on code in PR #7453:
URL: https://github.com/apache/trafficcontrol/pull/7453#discussion_r1182093325


##########
traffic_ops/testing/api_contract/v4/test_divisions.py:
##########
@@ -0,0 +1,94 @@
+#
+# 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.
+#
+
+"""API Contract Test Case for divisions endpoint."""
+import logging
+import pytest
+import requests
+
+from trafficops.tosession import TOSession
+
+# Create and configure logger
+logger = logging.getLogger()
+
+primitive = bool | int | float | str | None
+
+@pytest.mark.parametrize('request_template_data', ["divisions"], indirect=True)
+def test_division_contract(
+	to_session: TOSession,
+	request_template_data: list[dict[str, object] | list[object] | primitive],
+	response_template_data: list[dict[str, object] | list[object] | primitive],
+	division_post_data: dict[str, object]
+) -> None:
+	"""
+	Test step to validate keys, values and data types from divisions endpoint
+	response.
+	:param to_session: Fixture to get Traffic Ops session.
+	:param get_division_data: Fixture to get division data from a prerequisites file.
+	:param division_prereq: Fixture to get sample division data and actual division response.
+	"""
+	# validate division keys from divisions get response
+	logger.info("Accessing divisions endpoint through Traffic ops session.")
+
+	division = request_template_data[0]
+	if not isinstance(division, dict):
+		raise TypeError("malformed division in prerequisite data; not an object")
+
+	division_name = division.get("name")
+	if not isinstance(division_name, str):
+		raise TypeError("malformed division in prerequisite data; 'name' not a string")
+
+	division_get_response: tuple[
+		dict[str, object] | list[dict[str, object] | list[object] | primitive] | primitive,
+		requests.Response
+	] = to_session.get_divisions(query_params={"name": division_name})
+	try:
+		division_data = division_get_response[0]
+		if not isinstance(division_data, list):
+			raise TypeError("malformed API response; 'response' property not an array")
+
+		first_division = division_data[0]
+		if not isinstance(first_division, dict):
+			raise TypeError("malformed API response; first division in response is not an object")
+		division_keys = set(first_division.keys())
+
+		logger.info("division Keys from divisions endpoint response %s", division_keys)
+		response_template = response_template_data.get("divisions").get("properties")
+		# validate division values from prereq data in divisions get response.
+		prereq_values = [
+			division_post_data["name"]]
+		get_values = [first_division["name"]]
+		get_types = {}
+		for key in first_division:
+			get_types[key] = first_division[key].__class__.__name__
+		logger.info("types from division get response %s", get_types)
+		response_template_types= {}
+		for key in response_template:
+			response_template_types[key] = response_template.get(key).get("type")
+		logger.info("types from division response template %s", response_template_types)

Review Comment:
   same as above comment, Use value in accessing response_template types.
   `for key, value in response_template.items():
   	response_template_types[key] = value.get("type")`



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


[GitHub] [trafficcontrol] ericholguin merged pull request #7453: Added divisions test case

Posted by "ericholguin (via GitHub)" <gi...@apache.org>.
ericholguin merged PR #7453:
URL: https://github.com/apache/trafficcontrol/pull/7453


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


[GitHub] [trafficcontrol] Kashatlast2 commented on a diff in pull request #7453: Added divisions test case

Posted by "Kashatlast2 (via GitHub)" <gi...@apache.org>.
Kashatlast2 commented on code in PR #7453:
URL: https://github.com/apache/trafficcontrol/pull/7453#discussion_r1187545765


##########
traffic_ops/testing/api_contract/v4/conftest.py:
##########
@@ -681,10 +681,9 @@ def server_capabilities_post_data(to_session: TOSession, request_template_data:
 
 	:param to_session: Fixture to get Traffic Ops session.
 	:param request_template_data: Fixture to get server_capabilities data from a prerequisites file.
-	:returns: Sample POST data and the actual API response.
+  :returns: Sample POST data and the actual API response.

Review Comment:
   Yeah that's odd because it doesn't look like that on my screen
   ![Screen Shot 2023-05-08 at 10 51 59 AM](https://user-images.githubusercontent.com/100367078/236857072-a05ec69b-edf1-40ff-bdb5-0e6cdae781b8.png)
   



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


[GitHub] [trafficcontrol] gokulakrishnansvm commented on a diff in pull request #7453: Added divisions test case

Posted by "gokulakrishnansvm (via GitHub)" <gi...@apache.org>.
gokulakrishnansvm commented on code in PR #7453:
URL: https://github.com/apache/trafficcontrol/pull/7453#discussion_r1182092174


##########
traffic_ops/testing/api_contract/v4/test_divisions.py:
##########
@@ -0,0 +1,94 @@
+#
+# 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.
+#
+
+"""API Contract Test Case for divisions endpoint."""
+import logging
+import pytest
+import requests
+
+from trafficops.tosession import TOSession
+
+# Create and configure logger
+logger = logging.getLogger()
+
+primitive = bool | int | float | str | None
+
+@pytest.mark.parametrize('request_template_data', ["divisions"], indirect=True)
+def test_division_contract(
+	to_session: TOSession,
+	request_template_data: list[dict[str, object] | list[object] | primitive],
+	response_template_data: list[dict[str, object] | list[object] | primitive],
+	division_post_data: dict[str, object]
+) -> None:
+	"""
+	Test step to validate keys, values and data types from divisions endpoint
+	response.
+	:param to_session: Fixture to get Traffic Ops session.
+	:param get_division_data: Fixture to get division data from a prerequisites file.
+	:param division_prereq: Fixture to get sample division data and actual division response.
+	"""
+	# validate division keys from divisions get response
+	logger.info("Accessing divisions endpoint through Traffic ops session.")
+
+	division = request_template_data[0]
+	if not isinstance(division, dict):
+		raise TypeError("malformed division in prerequisite data; not an object")
+
+	division_name = division.get("name")
+	if not isinstance(division_name, str):
+		raise TypeError("malformed division in prerequisite data; 'name' not a string")
+
+	division_get_response: tuple[
+		dict[str, object] | list[dict[str, object] | list[object] | primitive] | primitive,
+		requests.Response
+	] = to_session.get_divisions(query_params={"name": division_name})
+	try:
+		division_data = division_get_response[0]
+		if not isinstance(division_data, list):
+			raise TypeError("malformed API response; 'response' property not an array")
+
+		first_division = division_data[0]
+		if not isinstance(first_division, dict):
+			raise TypeError("malformed API response; first division in response is not an object")
+		division_keys = set(first_division.keys())
+
+		logger.info("division Keys from divisions endpoint response %s", division_keys)
+		response_template = response_template_data.get("divisions").get("properties")
+		# validate division values from prereq data in divisions get response.
+		prereq_values = [
+			division_post_data["name"]]
+		get_values = [first_division["name"]]
+		get_types = {}
+		for key in first_division:
+			get_types[key] = first_division[key].__class__.__name__

Review Comment:
   Use value in accessing division type.
   ``for key, value in first_division.items():
   			get_types[key] = type(value).__name__``



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


[GitHub] [trafficcontrol] gokulakrishnansvm commented on a diff in pull request #7453: Added divisions test case

Posted by "gokulakrishnansvm (via GitHub)" <gi...@apache.org>.
gokulakrishnansvm commented on code in PR #7453:
URL: https://github.com/apache/trafficcontrol/pull/7453#discussion_r1182092174


##########
traffic_ops/testing/api_contract/v4/test_divisions.py:
##########
@@ -0,0 +1,94 @@
+#
+# 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.
+#
+
+"""API Contract Test Case for divisions endpoint."""
+import logging
+import pytest
+import requests
+
+from trafficops.tosession import TOSession
+
+# Create and configure logger
+logger = logging.getLogger()
+
+primitive = bool | int | float | str | None
+
+@pytest.mark.parametrize('request_template_data', ["divisions"], indirect=True)
+def test_division_contract(
+	to_session: TOSession,
+	request_template_data: list[dict[str, object] | list[object] | primitive],
+	response_template_data: list[dict[str, object] | list[object] | primitive],
+	division_post_data: dict[str, object]
+) -> None:
+	"""
+	Test step to validate keys, values and data types from divisions endpoint
+	response.
+	:param to_session: Fixture to get Traffic Ops session.
+	:param get_division_data: Fixture to get division data from a prerequisites file.
+	:param division_prereq: Fixture to get sample division data and actual division response.
+	"""
+	# validate division keys from divisions get response
+	logger.info("Accessing divisions endpoint through Traffic ops session.")
+
+	division = request_template_data[0]
+	if not isinstance(division, dict):
+		raise TypeError("malformed division in prerequisite data; not an object")
+
+	division_name = division.get("name")
+	if not isinstance(division_name, str):
+		raise TypeError("malformed division in prerequisite data; 'name' not a string")
+
+	division_get_response: tuple[
+		dict[str, object] | list[dict[str, object] | list[object] | primitive] | primitive,
+		requests.Response
+	] = to_session.get_divisions(query_params={"name": division_name})
+	try:
+		division_data = division_get_response[0]
+		if not isinstance(division_data, list):
+			raise TypeError("malformed API response; 'response' property not an array")
+
+		first_division = division_data[0]
+		if not isinstance(first_division, dict):
+			raise TypeError("malformed API response; first division in response is not an object")
+		division_keys = set(first_division.keys())
+
+		logger.info("division Keys from divisions endpoint response %s", division_keys)
+		response_template = response_template_data.get("divisions").get("properties")
+		# validate division values from prereq data in divisions get response.
+		prereq_values = [
+			division_post_data["name"]]
+		get_values = [first_division["name"]]
+		get_types = {}
+		for key in first_division:
+			get_types[key] = first_division[key].__class__.__name__

Review Comment:
   Use value in accessing division type.
   `for key, value in first_division.items():
   			get_types[key] = type(value).__name__`



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


[GitHub] [trafficcontrol] gokulakrishnansvm commented on a diff in pull request #7453: Added divisions test case

Posted by "gokulakrishnansvm (via GitHub)" <gi...@apache.org>.
gokulakrishnansvm commented on code in PR #7453:
URL: https://github.com/apache/trafficcontrol/pull/7453#discussion_r1182092174


##########
traffic_ops/testing/api_contract/v4/test_divisions.py:
##########
@@ -0,0 +1,94 @@
+#
+# 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.
+#
+
+"""API Contract Test Case for divisions endpoint."""
+import logging
+import pytest
+import requests
+
+from trafficops.tosession import TOSession
+
+# Create and configure logger
+logger = logging.getLogger()
+
+primitive = bool | int | float | str | None
+
+@pytest.mark.parametrize('request_template_data', ["divisions"], indirect=True)
+def test_division_contract(
+	to_session: TOSession,
+	request_template_data: list[dict[str, object] | list[object] | primitive],
+	response_template_data: list[dict[str, object] | list[object] | primitive],
+	division_post_data: dict[str, object]
+) -> None:
+	"""
+	Test step to validate keys, values and data types from divisions endpoint
+	response.
+	:param to_session: Fixture to get Traffic Ops session.
+	:param get_division_data: Fixture to get division data from a prerequisites file.
+	:param division_prereq: Fixture to get sample division data and actual division response.
+	"""
+	# validate division keys from divisions get response
+	logger.info("Accessing divisions endpoint through Traffic ops session.")
+
+	division = request_template_data[0]
+	if not isinstance(division, dict):
+		raise TypeError("malformed division in prerequisite data; not an object")
+
+	division_name = division.get("name")
+	if not isinstance(division_name, str):
+		raise TypeError("malformed division in prerequisite data; 'name' not a string")
+
+	division_get_response: tuple[
+		dict[str, object] | list[dict[str, object] | list[object] | primitive] | primitive,
+		requests.Response
+	] = to_session.get_divisions(query_params={"name": division_name})
+	try:
+		division_data = division_get_response[0]
+		if not isinstance(division_data, list):
+			raise TypeError("malformed API response; 'response' property not an array")
+
+		first_division = division_data[0]
+		if not isinstance(first_division, dict):
+			raise TypeError("malformed API response; first division in response is not an object")
+		division_keys = set(first_division.keys())
+
+		logger.info("division Keys from divisions endpoint response %s", division_keys)
+		response_template = response_template_data.get("divisions").get("properties")
+		# validate division values from prereq data in divisions get response.
+		prereq_values = [
+			division_post_data["name"]]
+		get_values = [first_division["name"]]
+		get_types = {}
+		for key in first_division:
+			get_types[key] = first_division[key].__class__.__name__

Review Comment:
   Use value in accessing division type.
   ``for key, value in first_division.items():
   	get_types[key] = type(value).__name__``



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


[GitHub] [trafficcontrol] gokulakrishnansvm commented on a diff in pull request #7453: Added divisions test case

Posted by "gokulakrishnansvm (via GitHub)" <gi...@apache.org>.
gokulakrishnansvm commented on code in PR #7453:
URL: https://github.com/apache/trafficcontrol/pull/7453#discussion_r1172994192


##########
traffic_ops/testing/api_contract/v4/conftest.py:
##########
@@ -628,3 +628,46 @@ def profile_post_data(to_session: TOSession, request_template_data: list[JSONDat
 	except IndexError:
 		logger.error("No Profile response data from cdns POST request.")
 		sys.exit(1)
+
+@pytest.fixture()
+def division_post_data(to_session: TOSession, request_template_data: list[JSONData]
+		  ) -> dict[str, object]:
+	"""
+	PyTest Fixture to create POST data for divisions endpoint.
+
+	:param to_session: Fixture to get Traffic Ops session.
+	:param request_template_data: Fixture to get divisions request template data from a prerequisites file.
+	:returns: Sample POST data and the actual API response.
+	"""
+
+	try:
+		division = request_template_data[0]
+	except IndexError as e:
+		raise TypeError(
+			"malformed prerequisite data; no status present in 'status' array property") from e
+
+	if not isinstance(division, dict):
+		raise TypeError(
+			f"malformed prerequisite data; status must be objects, not '{type(division)}'")
+
+	# Return new post data and post response from status POST request
+	randstr = str(randint(0, 1000))
+	try:
+		name = division["name"]
+		if not isinstance(name, str):
+			raise TypeError(f"name must be str, not '{type(name)}'")
+		division["name"] = name[:4] + randstr
+	except KeyError as e:
+		raise TypeError(f"missing Parameter property '{e.args[0]}'") from e
+
+	logger.info("New division data to hit POST method %s", request_template_data)
+	# Hitting sdivision POST methed
+	response: tuple[JSONData, requests.Response] = to_session.create_division(data=division)
+	try:
+		resp_obj = response[0]
+		if not isinstance(resp_obj, dict):
+			raise TypeError("malformed API response; division is not an object")
+		return resp_obj
+	except IndexError:
+		logger.error("No division response data from division POST request.")
+		sys.exit(1)		

Review Comment:
   Line 673 Trailing whitespace



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


[GitHub] [trafficcontrol] gokulakrishnansvm commented on a diff in pull request #7453: Added divisions test case

Posted by "gokulakrishnansvm (via GitHub)" <gi...@apache.org>.
gokulakrishnansvm commented on code in PR #7453:
URL: https://github.com/apache/trafficcontrol/pull/7453#discussion_r1172993638


##########
traffic_ops/testing/api_contract/v4/conftest.py:
##########
@@ -628,3 +628,46 @@ def profile_post_data(to_session: TOSession, request_template_data: list[JSONDat
 	except IndexError:
 		logger.error("No Profile response data from cdns POST request.")
 		sys.exit(1)
+
+@pytest.fixture()
+def division_post_data(to_session: TOSession, request_template_data: list[JSONData]
+		  ) -> dict[str, object]:
+	"""
+	PyTest Fixture to create POST data for divisions endpoint.
+
+	:param to_session: Fixture to get Traffic Ops session.
+	:param request_template_data: Fixture to get divisions request template data from a prerequisites file.

Review Comment:
   Line too long



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