aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAleksandr Taranov <aleksandr.taranov@telekom.com>2023-05-24 09:11:07 +0300
committerAleksandr Taranov <aleksandr.taranov@telekom.com>2023-05-24 09:11:07 +0300
commite712b6a1378a0a237dffbf053837c5926526293d (patch)
treef9f48eab25be71a111eebe02ebe435bf690c5d61
parent36c7b5ec92c34257b8ad135f1ef91f4717b7fcf9 (diff)
Fix SDNC GR-API endpoint
Issue-ID: TEST-395 Signed-off-by: Aleksandr Taranov <aleksandr.taranov@telekom.com> Change-Id: I0f9321f5dd8803f95b329fcd1fe525ede3c62d68
-rw-r--r--src/onapsdk/sdnc/services.py27
-rw-r--r--tests/test_sdnc_service.py59
2 files changed, 86 insertions, 0 deletions
diff --git a/src/onapsdk/sdnc/services.py b/src/onapsdk/sdnc/services.py
index 50c9186..d4d8ed6 100644
--- a/src/onapsdk/sdnc/services.py
+++ b/src/onapsdk/sdnc/services.py
@@ -77,6 +77,33 @@ class Service(SdncElement):
service_status=service_status
)
+ @classmethod
+ def get(cls, service_instance_id) -> "Service":
+ """Get service by service-instance-id via GENERIC-RESOURCES-API.
+
+ Return:
+ Service
+ """
+ service_iterable = cls.send_message_json(
+ "GET",
+ "Get SDNC services",
+ f"{cls.base_url}/rests/data/"
+ f"GENERIC-RESOURCE-API:services/service={service_instance_id}"
+ )
+ service = service_iterable["GENERIC-RESOURCE-API:service"][0]
+ try:
+ service_data = service["service-data"]
+ except KeyError:
+ service_data = {}
+ try:
+ service_status = service["service-status"]
+ except KeyError:
+ service_status = {}
+ return Service(service_instance_id=service_instance_id,
+ service_data=service_data,
+ service_status=service_status
+ )
+
def create(self) -> None:
"""Create service using GENERIC-RESOURCES-API."""
service_data = self.service_data if self.service_data is not None else ""
diff --git a/tests/test_sdnc_service.py b/tests/test_sdnc_service.py
index bc69797..7e2fc38 100644
--- a/tests/test_sdnc_service.py
+++ b/tests/test_sdnc_service.py
@@ -69,6 +69,39 @@ SDNC_SERVICES_INFORMATION_GET = {
]
}
+SDNC_SERVICES_INFORMATION_GET_STATUS_MISSING = {
+ "GENERIC-RESOURCE-API:service": [
+ {
+ "service-instance-id": "sdnc-int-test-fffffffffff",
+ "service-data": {
+ "service-level-oper-status": {
+ "last-rpc-action": "assign",
+ "last-action": "CreateServiceInstance",
+ "order-status": "Created"
+ }
+ }
+ }
+ ]
+}
+
+SDNC_SERVICES_INFORMATION_GET_DATA_MISSING = {
+ "GENERIC-RESOURCE-API:service": [
+ {
+ "service-instance-id": "sdnc-int-test-fffffffffff",
+ "service-status": {
+ "response-code": "string",
+ "response-message": "string",
+ "final-indicator": "string",
+ "request-status": "string",
+ "action": "string",
+ "rpc-name": "string",
+ "rpc-action": "string",
+ "response-timestamp": "string"
+ }
+ }
+ ]
+}
+
SDNC_SERVICES_INFORMATION_GET_ALL_SERVICE_DATA_MISSING = {
"services": {
"service": [
@@ -121,6 +154,14 @@ def test_sdnc_service_gr_api_get_all(mock_send_message_json):
assert service.service_instance_id == SDNC_SERVICE_ID
+@mock.patch.object(Service, "send_message_json")
+def test_sdnc_service_gr_api_get(mock_send_message_json):
+ mock_send_message_json.return_value = SDNC_SERVICES_INFORMATION_GET
+ sdnc_service = Service.get(SDNC_SERVICE_ID)
+ assert isinstance(sdnc_service, Service)
+ assert sdnc_service.service_instance_id == SDNC_SERVICE_ID
+
+
@mock.patch.object(Service, "send_message")
def test_sdnc_service_gr_api_create(mock_send_message):
service = Service(SDNC_SERVICES_INFORMATION["services"]["service"][0]["service-instance-id"],
@@ -186,3 +227,21 @@ def test_sdnc_service_gr_api_get_all_key_error_status(mock_send_message_json):
service = sdnc_all_services_list[0]
assert isinstance(service, Service)
assert service.service_status == {}
+
+
+@mock.patch.object(Service, "send_message_json")
+def test_sdnc_service_gr_api_get_key_error_data(mock_send_message_json):
+ mock_send_message_json.return_value = SDNC_SERVICES_INFORMATION_GET_DATA_MISSING
+ sdnc_service = Service.get(SDNC_SERVICE_ID)
+ assert isinstance(sdnc_service, Service)
+ assert sdnc_service.service_instance_id == SDNC_SERVICE_ID
+ assert sdnc_service.service_data == {}
+
+
+@mock.patch.object(Service, "send_message_json")
+def test_sdnc_service_gr_api_get_key_error_status(mock_send_message_json):
+ mock_send_message_json.return_value = SDNC_SERVICES_INFORMATION_GET_STATUS_MISSING
+ sdnc_service = Service.get(SDNC_SERVICE_ID)
+ assert isinstance(sdnc_service, Service)
+ assert sdnc_service.service_instance_id == SDNC_SERVICE_ID
+ assert sdnc_service.service_status == {} \ No newline at end of file