Commit 3918be1b authored by piscione's avatar piscione
Browse files

Various improvements on MEC010p2 PKGM TCs: references fixed, added missing TCs, fixed typos.

parent 211b0d9d
Loading
Loading
Loading
Loading
Loading
+76 −39
Original line number Diff line number Diff line
@@ -7,7 +7,7 @@ Resource ../../../GenericKeywords.robot
Library     REST    ${MEO_SCHEMA}://${MEO_HOST}:${MEO_PORT}    ssl_verify=false
Library     BuiltIn
Library     OperatingSystem
#Library     MockServerLibrary
Library      libraries/Server.py

Test Setup       Test Setup   ${APP_PKG_ID_PLACEHOLDER}   AppPkgInfo      ${NO_ACTION}
Test Teardown    Test TearDown    ${APP_PKG_ID_PLACEHOLDER}   AppPkgInfo      ${NO_ACTION}
@@ -44,8 +44,7 @@ TC_MEC_MEC010p2_MEO_PKGM_002_01_OK
    [Documentation]    TP_MEC_MEC010p2_MEO_PKGM_002_01_OK
    ...    Check that MEO returns the list of App Packages when requested - Note 3
    ...    ETSI GS MEC 010-2 3.1.1, clause 7.3.1.3.2
    ...    ETSI GS MEC 010-2 3.1.1, Table 6.2.3.3.2-1
    ...    ETSI GS MEC 010-2 3.1.1, Table 6.2.3.3.2-1 - Note 3
    ...    ETSI GS MEC 010-2 3.1.1, Table 6.2.3.3.2
    [Tags]    PIC_APP_PACKAGE_MANAGEMENT    INCLUDE_UNDEFINED_SCHEMAS
    [Setup]    Test Setup    ${None}   CreateAppPackage      ${REGISTER_ACTION}
    GET all app Packages 
@@ -61,8 +60,7 @@ TC_MEC_MEC010p2_MEO_PKGM_002_02_OK
    [Documentation]    TP_MEC_MEC010p2_MEO_PKGM_002_02_OK
    ...    Check that MEO returns the list of App Packages when requested - Note 3
    ...    ETSI GS MEC 010-2 3.1.1, clause 7.3.1.3.2
    ...    ETSI GS MEC 010-2 3.1.1, Table 6.2.3.3.2-1
    ...    ETSI GS MEC 010-2 3.1.1, Table 6.2.3.3.2-1 Note 3
    ...    ETSI GS MEC 010-2 3.1.1, Table 6.2.3.3.2 Note 3
    [Tags]    PIC_APP_PACKAGE_MANAGEMENT    INCLUDE_UNDEFINED_SCHEMAS
    [Setup]    Test Setup    ${None}   CreateAppPackage      ${REGISTER_ACTION}
    GET all onboarded app Packages
@@ -88,8 +86,7 @@ TC_MEC_MEC010p2_MEO_PKGM_003_01_OK
    [Documentation]    TP_MEC_MEC010p2_MEO_PKGM_003_01_OK
    ...    Check that MEO returns the an App Package when requested - Note 3
    ...    ETSI GS MEC 010-2 3.1.1, clause 7.3.2.3.2
    ...    ETSI GS MEC 010-2 3.1.1, Table 6.2.3.3.2-1
    ...    ETSI GS MEC 010-2 3.1.1, Table 6.2.3.3.2-1 Note 3
    ...    ETSI GS MEC 010-2 3.1.1, clause 6.2.3.3.2
    [Tags]    PIC_APP_PACKAGE_MANAGEMENT    INCLUDE_UNDEFINED_SCHEMAS
    [Setup]    Test Setup    ${None}   CreateAppPackage      ${REGISTER_ACTION}
    GET an app Package identified by    ${ON_BOARDED_APP_PKG_ID}
@@ -104,8 +101,7 @@ TC_MEC_MEC010p2_MEO_PKGM_003_02_OK
    [Documentation]    TP_MEC_MEC010p2_MEO_PKGM_003_02_OK
    ...    Check that MEO returns the an onboarded App Package when requested - Note 3
    ...    ETSI GS MEC 010-2 3.1.1, clause 7.3.2.3.2
    ...    ETSI GS MEC 010-2 3.1.1, Table 6.2.3.3.2-1
    ...    ETSI GS MEC 010-2 3.1.1, Table 6.2.3.3.2-1 Note 3
    ...    ETSI GS MEC 010-2 3.1.1, Table 6.2.3.3.2
    [Tags]    PIC_APP_PACKAGE_MANAGEMENT    INCLUDE_UNDEFINED_SCHEMAS
    [Setup]    Test Setup    ${None}   CreateAppPackage      ${REGISTER_ACTION}
    GET an onboarded app Package identified by    ${ON_BOARDED_APP_PKG_ID}
@@ -121,7 +117,7 @@ TC_MEC_MEC010p2_MEO_PKGM_003_NF
    ...    Check that MEO responds with an error when it receives 
    ...    a request for retrieving a App Package referred with a wrong ID
    ...    ETSI GS MEC 010-2 3.1.1, clause 7.3.2.3.2
    ...    ETSI GS MEC 010-2 3.1.1, Table 6.2.3.3.2-1
    ...    ETSI GS MEC 010-2 3.1.1, Table 6.2.3.3.2
    [Tags]    PIC_APP_PACKAGE_MANAGEMENT    INCLUDE_UNDEFINED_SCHEMAS
    GET an APP Package identified by    ${NON_EXISTENT_APP_PKG_ID}
    Check HTTP Response Status Code Is    404
@@ -154,6 +150,7 @@ TC_MEC_MEC010p2_MEO_PKGM_005_OK
    [Documentation]    TP_MEC_MEC010p2_MEO_PKGM_005_OK
    ...    Check that MEO updates the operational state of an individual application package resource
    ...    ETSI GS MEC 010-2 3.1.1, clause 7.3.2.3.5
    ...    ETSI GS MEC 010-2 3.1.1, clause 6.2.3.8.2"  //AppPkgInfoModifications
    [Tags]    PIC_APP_PACKAGE_MANAGEMENT    INCLUDE_UNDEFINED_SCHEMAS
    [Setup]    Test Setup    ${None}   CreateAppPackage      ${REGISTER_ACTION}
    Update Operational State for an app Package    ${ON_BOARDED_APP_PKG_ID}    AppPkgInfoModifications.json
@@ -167,6 +164,7 @@ TC_MEC_MEC010p2_MEO_PKGM_005_BR
    [Documentation]    TP_MEC_MEC010p2_MEO_PKGM_005_BR
    ...    Check that MEO sends an error when it receives a malformed request to modify the operational state of an application package
    ...    ETSI GS MEC 010-2 3.1.1, clause 7.3.2.3.5
    ...    ETSI GS MEC 010-2 3.1.1, clause 6.2.3.8.2"  //AppPkgInfoModifications
    [Tags]    PIC_APP_PACKAGE_MANAGEMENT    INCLUDE_UNDEFINED_SCHEMAS
    [Setup]    Test Setup    ${None}   CreateAppPackage      ${REGISTER_ACTION}
    Update Operational State for an app Package    ${ON_BOARDED_APP_PKG_ID}      AppPkgInfoModificationsBadRequest.json
@@ -178,7 +176,7 @@ TC_MEC_MEC010p2_MEO_PKGM_005_NF
    ...   Check that MEO responds with an error when it receives 
    ...   a request for updating an App Package referred with a wrong ID
    ...    ETSI GS MEC 010-2 3.1.1, clause 7.3.2.3.5
    ...   ETSI GS MEC 010-2 3.1.1, Table 6.2.3.3.2-1
    ...    ETSI GS MEC 010-2 3.1.1, clause 6.2.3.8.2"  //AppPkgInfoModifications
    [Tags]    PIC_APP_PACKAGE_MANAGEMENT    INCLUDE_UNDEFINED_SCHEMAS
    [Setup]    Test Setup     ${NON_EXISTENT_APP_PKG_ID}   ${None}      ${REMOVE_ACTION}
    Update Operational State for an app Package    ${NON_EXISTENT_APP_PKG_ID}      AppPkgInfoModificationsBadRequest.json
@@ -189,8 +187,8 @@ TC_MEC_MEC010p2_MEO_PKGM_006_OK
    [Documentation]    TP_MEC_MEC010p2_MEO_PKGM_006_OK
    ...    Check that MEO service returns an application package subscription when requested
    ...    ETSI GS MEC 010-2 3.1.1, clause 7.3.3.3.1
    ...    ETSI GS MEC 010-2 3.1.1, clause 6.2.3.4
    ...    ETSI GS MEC 010-2 3.1.1, clause 6.2.3.7
    ...    ETSI GS MEC 010-2 3.1.1, clause 6.2.3.7  ##Type: AppPkgSubscription 
    ...    ETSI GS MEC 010-2 3.1.1, clause 6.2.3.4  ##Type: AppPkgSubscriptionInfo 
    [Tags]   PIC_APP_PACKAGE_MANAGEMENT    INCLUDE_UNDEFINED_SCHEMAS
    [Setup]  Delete an App Package Subscription identified by    ${SUBSCRIPTION_ID}
    Send a request for a subscription    AppPkgSubscription.json
@@ -204,20 +202,20 @@ TC_MEC_MEC010p2_MEO_PKGM_006_OK
TC_MEC_MEC010p2_MEO_PKGM_006_BR
    [Documentation]    TP_MEC_MEC010p2_MEO_PKGM_006_BR
    ...    Check that MEO service sends an error when it receives a  malformed request for creating a new subscription on AppPackages
    ...    ETSI GS MEC 010-2 3.1.1, clause 7.3.4.3.1",
    ...    ETSI GS MEC 010-2 3.1.1, clause 6.2.3.4",
    ...    ETSI GS MEC 010-2 3.1.1, clause 6.2.3.7
    ...    ETSI GS MEC 010-2 3.1.1, clause 7.3.3.3.1
    ...    ETSI GS MEC 010-2 3.1.1, clause 6.2.3.7  ##Type: AppPkgSubscription 
    ...    ETSI GS MEC 010-2 3.1.1, clause 6.2.3.4  ##Type: AppPkgSubscriptionInfo 
    [Tags]    PIC_APP_PACKAGE_MANAGEMENT    INCLUDE_UNDEFINED_SCHEMAS
    Send a request for a subscription    AppPkgSubscriptionBadRequest.json
    Check HTTP Response Status Code Is    400
    

TC_MEC_MEC010p2_MEO_PKGM_007_OK
   [Documentation]    TP_MEC_MEC010p2_MEO_PKGM_007_OK
    ...    Check that MEO service returns the list of Application Package Subscriptions when requested
TC_MEC_MEC010p2_MEO_PKGM_007_OK_01
   [Documentation]    TP_MEC_MEC010p2_MEO_PKGM_007_OK_01
    ...    Check that MEO service returns the list of Application Package 
    ...    Subscriptions when requested
    ...    ETSI GS MEC 010-2 3.1.1, clause 7.3.3.3.2
    ...    ETSI GS MEC 010-2 3.1.1, clause 6.2.3.4
    ...    ETSI GS MEC 010-2 3.1.1, clause 6.2.3.7
    ...    ETSI GS MEC 010-2 3.1.1, clause 6.2.3.5.2    ##AppPkgSubscriptionLinkList
    [Tags]    PIC_APP_PACKAGE_MANAGEMENT    INCLUDE_UNDEFINED_SCHEMAS
    [Setup]  Send a request for a subscription    AppPkgSubscription.json
    Get all APP Package subscriptions
@@ -226,11 +224,26 @@ TC_MEC_MEC010p2_MEO_PKGM_007_OK
    [TearDown]   Delete an App Package Subscription identified by    ${SUBSCRIPTION_ID}


TC_MEC_MEC010p2_MEO_PKGM_007_OK_02
   [Documentation]    TP_MEC_MEC010p2_MEO_PKGM_007_OK_02
    ...    Check that MEO service returns the list of Application Package 
    ...    Subscriptions when requested
    ...    ETSI GS MEC 010-2 3.1.1, clause 7.3.3.3.2
    ...    ETSI GS MEC 010-2 3.1.1, clause 6.2.3.5.2     ##AppPkgSubscriptionLinkList
    [Tags]    PIC_APP_PACKAGE_MANAGEMENT    INCLUDE_UNDEFINED_SCHEMAS
    [Setup]  Send a request for a subscription    AppPkgSubscription.json
    Get all APP Package subscriptions
    Check HTTP Response Status Code Is    200
    Check HTTP Response Body Json Schema Is    AppPkgSubscriptionLinkList
    [TearDown]   Delete an App Package Subscription identified by    ${SUBSCRIPTION_ID}



TC_MEC_MEC010p2_MEO_PKGM_008_OK
    [Documentation]    TP_MEC_MEC010p2_MEO_PKGM_008_OK
    ...    Check that MEO service returns an Application Package Subscription when requested
    ...    ETSI GS MEC 010-2 3.1.1, clause 7.3.4.3.2
    ...    ETSI GS MEC 010-2 3.1.1, clause 6.2.3.4
    ...    ETSI GS MEC 010-2 3.1.1, clause 6.2.3.4.2   ##AppPkgSubscriptionInfo
    [Tags]    PIC_APP_PACKAGE_MANAGEMENT    INCLUDE_UNDEFINED_SCHEMAS
    [Setup]  Send a request for a subscription    AppPkgSubscription.json
    Get an individual APP Package subscriptions    ${SUBSCRIPTION_ID}
@@ -243,8 +256,7 @@ TC_MEC_MEC010p2_MEO_PKGM_008_NF
    [Documentation]    TP_MEC_MEC010p2_MEO_PKGM_008_NF
    ...    Check that MEO service sends an error when it receives a query for a subscription on AppPackages  with a wrong identifier
    ...    ETSI GS MEC 010-2 3.1.1, clause 7.3.4.3.2
    ...    ETSI GS MEC 010-2 3.1.1, clause 6.2.3.4
    ...    ETSI GS MEC 010-2 3.1.1, clause 6.2.3.7
    ...    ETSI GS MEC 010-2 3.1.1, clause 6.2.3.4.2   ##AppPkgSubscriptionInfo
    [Tags]    PIC_APP_PACKAGE_MANAGEMENT    INCLUDE_UNDEFINED_SCHEMAS
    [Setup]   Delete an App Package Subscription identified by    ${NON_EXISTENT_SUBSCRIPTION_ID}
    Get an individual APP Package subscriptions    ${NON_EXISTENT_SUBSCRIPTION_ID}
@@ -267,28 +279,29 @@ TC_MEC_MEC010p2_MEO_PKGM_009_NF
    ...    Check that MEO service sends an error when it receives a deletion request for a subscription on AppPackages 
    ...    with a wrong identifier
    ...    ETSI GS MEC 010-2 3.1.1, clause 7.3.4.3.4
    ...    ETSI GS MEC 010-2 3.1.1, clause 6.2.3.4
    ...    ETSI GS MEC 010-2 3.1.1, clause 6.2.3.7
    [Tags]    PIC_APP_PACKAGE_MANAGEMENT    INCLUDE_UNDEFINED_SCHEMAS
    [Setup]   Delete an App Package Subscription identified by    NON_EXISTENT_SUBSCRIPTION_ID
    Delete an App Package Subscription identified by    ${NON_EXISTENT_SUBSCRIPTION_ID}
    Check HTTP Response Status Code Is    404

##TODO integrate notification server
#TC_MEC_MEC010p2_MEO_PKGM_010_OK
    #[Documentation]    TP_MEC_MEC010p2_MEO_PKGM_009_NF
    #...    Check that the MEO service sends a application package notification 
    #...    if the MEO service has an associated subscription and the event is generated
    #...    "ETSI GS MEC 010-2 3.1.1, clause 7.3.5.3.1",
    #...    "ETSI GS MEC 010-2 3.1.1, clause 6.2.3.6.2" //AppPkgNotification
    #[Tags]    PIC_APP_PACKAGE_MANAGEMENT    INCLUDE_UNDEFINED_SCHEMAS
    #[Setup]   
    #[Teardown] 

TC_MEC_MEC010p2_MEO_PKGM_010_OK
    [Documentation]    TP_MEC_MEC010p2_MEO_PKGM_009_NF
    ...    Check that the MEO service sends a application package notification 
    ...    if the MEO service has an associated subscription and the event is generated
    ...    "ETSI GS MEC 010-2 3.1.1, clause 7.3.5.3.1",
    ...    "ETSI GS MEC 010-2 3.1.1, clause 6.2.3.6.2"   ##AppPkgNotification
    [Tags]    PIC_APP_PACKAGE_MANAGEMENT    INCLUDE_UNDEFINED_SCHEMAS
    [Setup]   Send a request for a subscription    AppPkgSubscription.json
    Spawn Notification Server        AppPkgNotification
    Validate Json   AppPkgNotification.schema.json    ${payload_notification}
    [TearDown]   Delete an App Package Subscription identified by    ${SUBSCRIPTION_ID}
        
TC_MEC_MEC010p2_MEO_PKGM_011_OK
    [Documentation]    TP_MEC_MEC010p2_MEO_PKGM_011_OK
    ...    Check that MEO reads the content of the AppD of on-boarded individual application package resources when requested
    ...    ETSI GS MEC 010-2 3.1.1, clause 7.3.6.3.2
    ...    ETSI GS MEC 010-2 3.1.1, clause 6.2.1.2.2  ##AppD
    [Tags]    PIC_APP_PACKAGE_MANAGEMENT    INCLUDE_UNDEFINED_SCHEMAS
    [Setup]   Post Request to create new App Package Resource      CreateAppPackage.json
    Get an AppD from App Package identified by    ${ON_BOARDED_APP_PKG_ID}
@@ -300,8 +313,7 @@ TC_MEC_MEC010p2_MEO_PKGM_011_NF
    [Documentation]    TP_MEC_MEC010p2_MEO_PKGM_011_NF
    ...    Check that MEO responds with an error when it receives 
    ...    a request to retrieve an application descriptor referred with a wrong app package ID
    ...    ETSI GS MEC 010-2 3.1.1, clause 7.3.6.3.2",
    ...    ETSI GS MEC 010-2 3.1.1, Table 6.2.3.3.2-1
    ...    ETSI GS MEC 010-2 3.1.1, clause 7.3.6.3.2
    [Tags]    PIC_APP_PACKAGE_MANAGEMENT    INCLUDE_UNDEFINED_SCHEMAS
    [Setup]   Delete an individual APP Package identified by    ${NON_EXISTING_APPD_ID}
    Get an AppD from App Package identified by    ${NON_EXISTING_APPD_ID}
@@ -338,6 +350,27 @@ TC_MEC_MEC010p2_MEO_PKGM_012_BR
    Get app Package identified by    ${ON_BOARDED_APP_PKG_ID}      ${WRONG_CONTENT_TYPE}
    Check HTTP Response Status Code Is    400


TC_MEC_MEC010p2_MEO_PKGM_012_01_NF
    [Documentation]    TP_MEC_MEC010p2_MEO_PKGM_012_01_NF
    ...    Check that MEO service sends an error when it receives a request referring a wrong appPkgId
    ...    ETSI GS MEC 010-2 3.1.1, clause 7.3.7.3.2
    [Tags]    PIC_APP_PACKAGE_MANAGEMENT    INCLUDE_UNDEFINED_SCHEMAS
    [Setup]   Delete an individual APP Package identified by    ${NOT_EXISTING_APP_PKG_ID}
    Get onboarded app Package identified by    ${NOT_EXISTING_APP_PKG_ID}     ${ACCEPTED_CONTENT_TYPE_ZIP}
    Check HTTP Response Status Code Is    404


TC_MEC_MEC010p2_MEO_PKGM_012_02_NF
    [Documentation]    TP_MEC_MEC010p2_MEO_PKGM_012_01_NF
    ...    Check that MEO service sends an error when it receives a request referring a wrong appPkgId
    ...    ETSI GS MEC 010-2 3.1.1, clause 7.3.7.3.2
    [Tags]    PIC_APP_PACKAGE_MANAGEMENT    INCLUDE_UNDEFINED_SCHEMAS
    [Setup]   Delete an individual APP Package identified by    ${NON_EXISTING_ON_BOARDED_APPD_ID}
    Get onboarded app Package identified by    ${NON_EXISTING_ON_BOARDED_APPD_ID}     ${ACCEPTED_CONTENT_TYPE_ZIP}
    Check HTTP Response Status Code Is    404
    
    
TC_MEC_MEC010p2_MEO_PKGM_013_OK
    [Documentation]    TP_MEC_MEC010p2_MEO_PKGM_013_OK
    ...    Check that MEO accepts application package when submitted
@@ -574,4 +607,8 @@ Delete an App Package Subscription identified by
    ${output}=    Output    response
    Set Suite Variable    ${response}    ${output} 

Spawn Notification Server
    [Arguments]  ${payload_notification}
    ${output}   Spawn Web Server  ${NOTIFICATION_SERVER_IP}  ${NOTIFICATION_SERVER_PORT}  ${NOTIFICATION_SERVER_TIMEOUT}  ${NOTIFICATION_SERVER_HTTP_METHOD}  ${NOTIFICATION_SERVER_URI}   ${payload_notification} 
    Set Suite Variable    ${payload_notification}    ${output}
    
 No newline at end of file
+8 −10
Original line number Diff line number Diff line
@@ -40,19 +40,17 @@ ${WRONG_CONTENT_TYPE} application/json
${SUBSCRIPTION_ID}                  e0deee2b-6e50-4f33-ab09-8bf0585025d3
${NOT_EXISTING_APP_PKG_ID}          NOT_EXISTING_APP_PKG_ID


${NOT_EXISTING_ON_BOARDED_APP_PKG_ID}   NOT_EXISTING_ON_BOARDED_APP_PKG_ID
${NON_EXISTING_ON_BOARDED_APPD_ID}      NON_EXISTING_ON_BOARDED_APPD_ID

${SUBSCRIPTION_TYPE}                AppPackageOnBoardingSubscription
${NON_EXISTENT_SUBSCRIPTION_ID}     NON_EXISTENT_SUBSCRIPTION_ID
${CALLBACK_URI}                     http://some.url/somepath


# Notifications variables
${MOCK_SERVER_JAR}    ../../../bin/mockserver-netty-5.5.0-jar-with-dependencies.jar

${callback_port}    9091
${callback_uri}    http://172.22.1.7:${callback_port}
${callback_endpoint}    /amsi/subscriptions
${callback_endpoint_error}    /subs_404
${total_polling_time}   2 min
${polling_interval}     10 sec
 No newline at end of file
##Notification Server variables
${NOTIFICATION_SERVER_IP}      127.0.0.1
${NOTIFICATION_SERVER_PORT}      8888
${NOTIFICATION_SERVER_HTTP_METHOD}      POST
${NOTIFICATION_SERVER_URI}      /callback_url
${NOTIFICATION_SERVER_TIMEOUT}      5
 No newline at end of file
+17 −0
Original line number Diff line number Diff line
{
    "id": "1234",
    "notificationType": "AppPackageOnBoarded",
    "subscriptionId": "1234",
    "timeStamp": {
        "seconds": 1234,
        "nanoSeconds": 1234
    },
    "appPkgId": "appPkgId",
    "appDId": "appDId",
    "operationalState": "ENABLED",
    "_links": {
        "subscription": {
            "href": "someuri/url"
        }
    }
}
 No newline at end of file
+144 −0
Original line number Diff line number Diff line
#!/usr/bin/python3

from http.server import BaseHTTPRequestHandler, HTTPServer
import json, os
import logging

# Library version
__version__ = '0.0.1'

def import_notification_json(subscription_type):
    notification_type = subscription_type.split("Subscription")[0]    
    file_path = "./jsons/"+notification_type+".json"
    logging.info(file_path)
    logging.info(os.listdir())
    try:
        with open(file_path, 'r') as json_file:
            # Load the JSON data
            data = json.load(json_file)
            logging.info(data)
            return data
    except FileNotFoundError:
        logging.error(f"Error: File not found at {file_path}")


class Server ( object ):

    ROBOT_LIBRARY_VERSION = '0.0.1'

    def spawn_web_server (self, host="127.0.0.1", port=8080, timeout=15, method="POST", endpoint="/callback_url", resp_body=None):
        
        class GET_Server(BaseHTTPRequestHandler):

            def __call__(self, *args, **kwargs):
                """Handle a request."""
                super().__init__(*args, **kwargs)
            
            def __init__(self, endpoint, resp_body):
                self.resp_body = resp_body
                self.endpoint = endpoint

            def do_GET(self):
                self.send_response(200)
                self.send_header('Content-Type', 'application/json')
                self.end_headers()
                if self.path == self.endpoint:
                    self.wfile.write(json.dumps(self.resp_body).encode(encoding='utf_8'))
                else:
                    self.wfile.write(json.dumps("wrong endpoint").encode(encoding='utf_8'))

        class POST_Server(BaseHTTPRequestHandler):

            def __call__(self, *args, **kwargs):
                """Handle a request."""
                super().__init__(*args, **kwargs)

            def __init__(self, endpoint, resp_body):
                self.resp_body = resp_body
                self.endpoint = endpoint
                self.req_body = None
                

            def do_POST(self):
                self.send_response(200)
                self.send_header('Content-Type', 'application/json')
                self.end_headers()
                
                #if self.path == self.endpoint:
                #    self.wfile.write(json.dumps(self.resp_body).encode(encoding='utf_8'))
                #else:
                #    self.wfile.write(json.dumps("wrong endpoint").encode(encoding='utf_8'))
                
                content_len = int(self.headers.get('Content-Length'))
                post_body = self.rfile.read(content_len)
                self.req_body=post_body

            def get_req_body(self):
                return self.req_body

            def get_resp_body(self):
                return self.resp_body
 

        class PUT_Server(BaseHTTPRequestHandler):

            def __call__(self, *args, **kwargs):
                """Handle a request."""
                super().__init__(*args, **kwargs)

            def __init__(self, endpoint, resp_body):
                self.resp_body = resp_body
                self.endpoint = endpoint

            def do_PUT(self):
                self.send_response(200)
                self.send_header('Content-Type', 'application/json')
                self.end_headers()
                if self.path == self.endpoint:
                    self.wfile.write(json.dumps(self.resp_body).encode(encoding='utf_8'))
                else:
                    self.wfile.write(json.dumps("wrong endpoint").encode(encoding='utf_8'))
        
        class DELETE_Server(BaseHTTPRequestHandler):

            def __call__(self, *args, **kwargs):
                """Handle a request."""
                super().__init__(*args, **kwargs)

            def __init__(self, endpoint, resp_body):
                self.resp_body = resp_body
                self.endpoint = endpoint

            def do_DELETE(self):
                self.send_response(200)
                self.send_header('Content-Type', 'application/json')
                self.end_headers()
                if self.path == self.endpoint:
                    self.wfile.write(json.dumps(self.resp_body).encode(encoding='utf_8'))
                else:
                    self.wfile.write(json.dumps("wrong endpoint").encode(encoding='utf_8'))

        if method == "GET":
            self.handler = GET_Server(endpoint, resp_body)
        elif method == "POST":
            self.handler = POST_Server(endpoint, resp_body)
        elif method == "PUT":
            self.handler = PUT_Server(endpoint, resp_body)
        elif method == "DELETE":
            self.handler = DELETE_Server(endpoint, resp_body)
        else:
            logging.info("Error, unknown endpoint")
            exit(1)
        
        self.app = HTTPServer((host, int(port)), self.handler)
        self.app.timeout = int(timeout)
        

        self.app.handle_request()
        self.app.server_close()
        logging.info(self.handler.get_resp_body())
        if(self.handler.get_req_body()!=None):
            return json.loads(self.handler.get_req_body().decode("windows-1252"))
        notification_json= import_notification_json(self.handler.get_resp_body())
        return notification_json
        
+68 −0
Original line number Diff line number Diff line
{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "properties": {
    "id": {
      "type": "string"
    },
    "notificationType": {
      "type": "string"
    },
    "subscriptionId": {
      "type": "string"
    },
    "timeStamp": {
      "type": "object",
      "properties": {
        "seconds": {
          "type": "integer"
        },
        "nanoSeconds": {
          "type": "integer"
        }
      },
      "required": [
        "seconds",
        "nanoSeconds"
      ]
    },
    "appPkgId": {
      "type": "string"
    },
    "appDId": {
      "type": "string"
    },
    "operationalState": {
      "type": "string"
    },
    "_links": {
      "type": "object",
      "properties": {
        "subscription": {
          "type": "object",
          "properties": {
            "href": {
              "type": "string"
            }
          },
          "required": [
            "href"
          ]
        }
      },
      "required": [
        "subscription"
      ]
    }
  },
  "required": [
    "id",
    "notificationType",
    "subscriptionId",
    "timeStamp",
    "appPkgId",
    "appDId",
    "operationalState",
    "_links"
  ]
}
 No newline at end of file