This is an automated email from the ASF dual-hosted git repository.
ericholguin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git
The following commit(s) were added to refs/heads/master by this push:
new 5352de9036 Added api contract test case for system/info endpoint
(#7772)
5352de9036 is described below
commit 5352de9036c732942f4d39ac2895c5a4c836d3d9
Author: Gokula Krishnan <[email protected]>
AuthorDate: Tue Sep 5 20:26:48 2023 +0530
Added api contract test case for system/info endpoint (#7772)
* Added api contract test case for system/info endpoint
* modified response template
---
.../api_contract/v4/data/response_template.json | 44 +++++++++++++--
.../testing/api_contract/v4/test_system_info.py | 62 ++++++++++++++++++++++
2 files changed, 103 insertions(+), 3 deletions(-)
diff --git a/traffic_ops/testing/api_contract/v4/data/response_template.json
b/traffic_ops/testing/api_contract/v4/data/response_template.json
index 73d93492bc..50e78230fa 100644
--- a/traffic_ops/testing/api_contract/v4/data/response_template.json
+++ b/traffic_ops/testing/api_contract/v4/data/response_template.json
@@ -1929,8 +1929,8 @@
},
"type": {
"type": "string"
- }
- }
+ }
+ }
},
"delivery_service_capacity": {
"type": "object",
@@ -2100,7 +2100,7 @@
}
}
},
- "server_server_capabilities":{
+ "server_server_capabilities": {
"type": "object",
"required": [
"lastUpdated",
@@ -2122,5 +2122,43 @@
"type": "string"
}
}
+ },
+ "system_info": {
+ "type": "object",
+ "required": [
+ "parameters"
+ ],
+ "properties": {
+ "parameters": {
+ "type": "object",
+ "required": [
+ "tm.instance_name",
+ "tm.toolname"
+ ],
+ "properties": {
+ "default_geo_miss_latitude": {
+ "type": "string"
+ },
+ "default_geo_miss_longitude": {
+ "type": "string"
+ },
+ "tm.infourl": {
+ "type": "string"
+ },
+ "tm.instance_name": {
+ "type": "string"
+ },
+ "tm.toolname": {
+ "type": "string"
+ },
+ "tm.url": {
+ "type": "string"
+ },
+ "use_reval_pending": {
+ "type": "string"
+ }
+ }
+ }
+ }
}
}
diff --git a/traffic_ops/testing/api_contract/v4/test_system_info.py
b/traffic_ops/testing/api_contract/v4/test_system_info.py
new file mode 100644
index 0000000000..5c55704f6f
--- /dev/null
+++ b/traffic_ops/testing/api_contract/v4/test_system_info.py
@@ -0,0 +1,62 @@
+#
+# 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 system_info endpoint."""
+import logging
+from typing import Union
+
+import pytest
+import requests
+from jsonschema import validate
+
+from trafficops.tosession import TOSession
+
+# Create and configure logger
+logger = logging.getLogger()
+
+Primitive = Union[bool, int, float, str, None]
+
+
+def test_system_info_contract(to_session: TOSession,
+ response_template_data: dict[str, Union[Primitive, list[Union[Primitive,
+ dict[str, object],
list[object]]], dict[object, object]]]) -> None:
+ """
+ Test step to validate keys, values and data types from system_info
endpoint
+ response.
+ :param to_session: Fixture to get Traffic Ops session.
+ :param response_template_data: Fixture to get response template data
from a prerequisites file.
+ """
+ # validate system_info keys from system_infos get response
+ logger.info("Accessing /system_infos endpoint through Traffic ops
session.")
+
+ system_info_get_response: tuple[
+ Union[dict[str, object], list[Union[dict[str, object],
list[object], Primitive]], Primitive],
+ requests.Response
+ ] = to_session.get_system_info()
+ try:
+ first_system_info = system_info_get_response[0]
+ if not isinstance(first_system_info, dict):
+ raise TypeError("malformed API response; first
system_info in response is not an dict")
+ logger.info("system_info Api get response %s",
first_system_info)
+
+ system_info_response_template =
response_template_data.get("system_info")
+ if not isinstance(system_info_response_template, dict):
+ raise TypeError(
+ f"system_info response template data must be a
dict, not '{type(system_info_response_template)}'")
+
+ # validate keys, data types and values from system_infos get
json response.
+ assert validate(instance=first_system_info,
schema=system_info_response_template) is None
+ except IndexError:
+ logger.error("Either prerequisite data or API response was
malformed")
+ pytest.fail("API contract test failed for system_info endpoint:
API response was malformed")