From d629ad239729f3b4b4131c012c3808d8b1491889 Mon Sep 17 00:00:00 2001 From: DenisGNoonan Date: Wed, 4 Oct 2023 12:34:55 +0100 Subject: [PATCH] NONRTRIC-933: NONRTRIC - A1Sim - sendstatus needs to return HTTP code 204 Issue-ID: NONRTRIC-933 Change-Id: I13d876740a3b867c795c6993af7395983ab1b470 Signed-off-by: DenisGNoonan --- near-rt-ric-simulator/src/STD_2.0.0/a1.py | 4 +- near-rt-ric-simulator/src/STD_2.0.0/main.py | 3 +- near-rt-ric-simulator/test/STD_2.0.0/basic_test.sh | 2 +- near-rt-ric-simulator/tests/test_osc_2_1_0.py | 16 ----- near-rt-ric-simulator/tests/test_std_2_0_0.py | 72 +++++++++++++++------- 5 files changed, 53 insertions(+), 44 deletions(-) diff --git a/near-rt-ric-simulator/src/STD_2.0.0/a1.py b/near-rt-ric-simulator/src/STD_2.0.0/a1.py index e70a8ed..f773118 100755 --- a/near-rt-ric-simulator/src/STD_2.0.0/a1.py +++ b/near-rt-ric-simulator/src/STD_2.0.0/a1.py @@ -152,8 +152,8 @@ def put_policy(policyTypeId, policyId): policy_fingerprint[fp]=policy_id - noti=request.args.get('notificationDestination') - callbacks[policy_id]=noti + noti = request.args.get('notificationDestination') + callbacks[policy_id] = noti policy_instances[policy_type_id][policy_id]=data diff --git a/near-rt-ric-simulator/src/STD_2.0.0/main.py b/near-rt-ric-simulator/src/STD_2.0.0/main.py index 9733a0f..d2ac7cb 100644 --- a/near-rt-ric-simulator/src/STD_2.0.0/main.py +++ b/near-rt-ric-simulator/src/STD_2.0.0/main.py @@ -199,8 +199,7 @@ def sendstatus(): if (resp.status_code<199 & resp.status_code > 299): return Response('Post status failed with code: '+resp.status_code, status=500, mimetype=TEXT_PLAIN) - data = resp.json() - return Response(data, 200, mimetype=APPL_JSON) + return Response(None, 204, mimetype=APPL_JSON) #Receive status (only for testing callbacks) #/statustest diff --git a/near-rt-ric-simulator/test/STD_2.0.0/basic_test.sh b/near-rt-ric-simulator/test/STD_2.0.0/basic_test.sh index fd49caa..cabb757 100755 --- a/near-rt-ric-simulator/test/STD_2.0.0/basic_test.sh +++ b/near-rt-ric-simulator/test/STD_2.0.0/basic_test.sh @@ -373,7 +373,7 @@ do_curl GET /A1-P/v2/policytypes/STD_1/policies/pi2/status 200 echo "=== Send status for pi2===" RESULT="json:{\"enforceStatus\": \"NOTOK\", \"enforceReason\": \"notok_reason\"}" -do_curl POST '/sendstatus?policyid=pi2' 200 +do_curl POST '/sendstatus?policyid=pi2' 204 echo "=== Get counter: datadelivery ===" RESULT="0" diff --git a/near-rt-ric-simulator/tests/test_osc_2_1_0.py b/near-rt-ric-simulator/tests/test_osc_2_1_0.py index 169f360..b1d947b 100644 --- a/near-rt-ric-simulator/tests/test_osc_2_1_0.py +++ b/near-rt-ric-simulator/tests/test_osc_2_1_0.py @@ -581,22 +581,6 @@ def test_apis(client): assert response.status_code == 200 assert response.data == b"2" - -def test_notificationDestination(client): - testdata=get_testdata_dir() - # Header for json payload - header = { - "Content-Type" : "application/json" - } - - # === API: Update policy instance pi2 of type: 2 ===" - with open(testdata+'pi2.json') as json_file: - policytype_2 = json.load(json_file) - response = client.put(SERVER_URL+"a1-p/policytypes/2/policies/pi2?notificationDestination=http://localhost:8085/statustest", headers=header, data=json.dumps(policytype_2)) - assert response.status_code == 202 - result = response.data - assert result == b"" - def test_notificationDestination(client): test_data = get_testdata_dir() + 'pi2.json' # Header for json payload diff --git a/near-rt-ric-simulator/tests/test_std_2_0_0.py b/near-rt-ric-simulator/tests/test_std_2_0_0.py index 2a01d83..84d05dd 100644 --- a/near-rt-ric-simulator/tests/test_std_2_0_0.py +++ b/near-rt-ric-simulator/tests/test_std_2_0_0.py @@ -15,21 +15,23 @@ # ============LICENSE_END================================================= # -# This test case test the STD_2.0.0 version of the simulator +# This test case tests the STD_2.0.0 version of the simulator. import json import time +import multiprocessing +from unittest_setup import SERVER_URL, HOST_IP, PORT_NUMBER, setup_env, get_testdata_dir, client +from unittest_setup import run_flask_app -#Version of simulator -INTERFACE_VERSION="STD_2.0.0" +# Setup env and import paths -from unittest_setup import SERVER_URL, HOST_IP, PORT_NUMBER, setup_env, get_testdata_dir, client +# Version of simulator +INTERFACE_VERSION="STD_2.0.0" -#Setup env and import paths setup_env(INTERFACE_VERSION) - from compare_json import compare + def test_apis(client): testdata=get_testdata_dir() @@ -390,22 +392,6 @@ def test_apis(client): res=compare(data_response, result) assert res == True - - # #Found no way to test these functions - # #'sendstatus' will send a http request that will fail - # #since no server will receive the call - # #These function is instead tested when running the bash script in the 'test' dir - # # # Send status for pi2 - # # response=client.post(SERVER_URL+'sendstatus?policyid=pi2') - # # assert response.status_code == 200 - # # result=json.loads(response.data) - # # res=compare(data_get_status, result) - # # assert res == True - - # # # Send status, shall fail - # # response=client.post(SERVER_URL+'sendstatus') - # # assert response.status_code == 400 - # Get counter: data_delivery response=client.get(SERVER_URL+'counter/datadelivery') assert response.status_code == 200 @@ -438,4 +424,44 @@ def test_apis(client): # Get counter: types response=client.get(SERVER_URL+'counter/num_types') assert response.status_code == 200 - assert response.data == b"1" \ No newline at end of file + assert response.data == b"1" + +def test_notificationDestination(client): + test_data = get_testdata_dir() + 'pi2.json' + # Header for json payload + header = { "Content-Type" : "application/json" } + + # === API: Update policy instance pi2 of type: 2 ===" + with open(test_data) as json_file: + payload = json.load(json_file) + response = client.put(SERVER_URL+"A1-P/v2/policytypes/STD_1/policies/pi2?notificationDestination=http://localhost:8085/statustest", headers=header, data=json.dumps(payload)) + assert response.status_code == 200 + result = json.loads(response.data) + assert compare(payload, result) == True + +def test_sendstatus(client): + # Create a new thread to run the Flask app in parallel on a different port so that we can call the callback. + proc = multiprocessing.Process(target=run_flask_app, args=()) + proc.start() + + test_data = get_testdata_dir() + 'pi2.json' + header = { "Content-Type" : "application/json" } + + # === Send status for pi2=== + with open(test_data) as json_file: + payload = json.load(json_file) + response = client.post(SERVER_URL+'sendstatus?policyid=pi2', headers=header, data=json.dumps(payload)) + + assert response.status_code == 204 + result = response.data + assert result == b"" + + # Send status, negative test with missing parameter + response = client.post(SERVER_URL+'sendstatus', headers=header, data="") + assert response.status_code == 400 + + # Send status pi9, negative test for policy id not found + response = client.post(SERVER_URL+'sendstatus?policyid=pi9', headers=header, data="") + assert response.status_code == 404 + + proc.terminate() -- 2.16.6