Example #1
0
    def test_server_error(self):
        server = Server(config={'debug': True}, **config._sections['gateway'])
        test = _Testing()

        # Install two functions
        func_desc_conn = self.conn.get_function_description("STFC_CONNECTION")
        server.install_function(
            func_desc_conn,
            my_sftc_connection_error
        )

        with self.assertRaises(ABAPApplicationError) as run:
            test.invoke_srv_function("STFC_CONNECTION", REQUTEXT="EXCEPTION")
        self.assertEqual(run.exception.code, 5, "rc")
        self.assertEqual(run.exception.key, "BAD_EXCEPTION_HAPPENED")

        with self.assertRaises(ABAPApplicationError) as run:
            test.invoke_srv_function("STFC_CONNECTION", REQUTEXT="EXCEPTION_MESSAGE")
        self.assertEqual(run.exception.code, 5, "rc")
        self.assertEqual(run.exception.key, "BAD_EXCEPTION_W_MSG")
        self.assertEqual(run.exception.msg_class, "SR")
        self.assertEqual(run.exception.msg_type, "E")
        self.assertEqual(run.exception.msg_number, "007")
        self.assertEqual(run.exception.msg_v1, "V1 text")

        with self.assertRaises(ABAPRuntimeError) as run:
            test.invoke_srv_function("STFC_CONNECTION", REQUTEXT="MESSAGE")
        self.assertEqual(run.exception.code, 4, "rc")
        self.assertEqual(run.exception.msg_class, "SM")
        self.assertEqual(run.exception.msg_type, "E")
        self.assertEqual(run.exception.msg_number, "107")
        self.assertEqual(run.exception.msg_v1, "V1 text (ABAP_MESSAGE)")

        with self.assertRaises(ExternalRuntimeError) as run:
            test.invoke_srv_function("STFC_CONNECTION", REQUTEXT="FAILURE")
        self.assertEqual(run.exception.code, 15, "rc")
        self.assertEqual(run.exception.message[:9], "Something")

        with self.assertRaises(ExternalRuntimeError) as run:
            test.invoke_srv_function("STFC_CONNECTION", REQUTEXT="INVALID")
        self.assertEqual(run.exception.code, 15, "rc")
        self.assertEqual(run.exception.message[:7], "Invalid")
Example #2
0
    def test_server_error(self):
        server = Server(config={'debug': True}, **config._sections['gateway'])
        test = _Testing()

        # Install two functions
        func_desc_conn = self.conn.get_function_description("STFC_CONNECTION")
        server.install_function(
            func_desc_conn,
            my_sftc_connection_error
        )

        with self.assertRaises(ABAPApplicationError) as run:
            test.invoke_srv_function("STFC_CONNECTION", REQUTEXT="EXCEPTION")
        self.assertEqual(run.exception.code, 5, "rc")
        self.assertEqual(run.exception.key, "BAD_EXCEPTION_HAPPENED")

        with self.assertRaises(ABAPApplicationError) as run:
            test.invoke_srv_function("STFC_CONNECTION", REQUTEXT="EXCEPTION_MESSAGE")
        self.assertEqual(run.exception.code, 5, "rc")
        self.assertEqual(run.exception.key, "BAD_EXCEPTION_W_MSG")
        self.assertEqual(run.exception.msg_class, "SR")
        self.assertEqual(run.exception.msg_type, "E")
        self.assertEqual(run.exception.msg_number, "007")
        self.assertEqual(run.exception.msg_v1, "V1 text")

        with self.assertRaises(ABAPRuntimeError) as run:
            test.invoke_srv_function("STFC_CONNECTION", REQUTEXT="MESSAGE")
        self.assertEqual(run.exception.code, 4, "rc")
        self.assertEqual(run.exception.msg_class, "SM")
        self.assertEqual(run.exception.msg_type, "E")
        self.assertEqual(run.exception.msg_number, "107")
        self.assertEqual(run.exception.msg_v1, "V1 text (ABAP_MESSAGE)")

        with self.assertRaises(ExternalRuntimeError) as run:
            test.invoke_srv_function("STFC_CONNECTION", REQUTEXT="FAILURE")
        self.assertEqual(run.exception.code, 15, "rc")
        self.assertEqual(run.exception.message[:9], "Something")

        with self.assertRaises(ExternalRuntimeError) as run:
            test.invoke_srv_function("STFC_CONNECTION", REQUTEXT="INVALID")
        self.assertEqual(run.exception.code, 15, "rc")
        self.assertEqual(run.exception.message[:7], "Invalid")
Example #3
0
    def test_server(self):
        server = Server(config={'debug': True}, **config._sections['gateway'])
        test = _Testing()

        # Install two functions
        func_desc_conn = self.conn.get_function_description("STFC_CONNECTION")
        server.install_function(func_desc_conn, my_stfc_connection)
        func_desc_chan = self.conn.get_function_description("STFC_CHANGING")
        server.install_function(func_desc_chan, my_stfc_changing)

        # Lookup test
        func_desc_invalid = test.get_srv_func_desc("NOT_VALID")
        self.assertEqual(
            func_desc_invalid, 17,
            "Return code for unknown func_desc should be RFC_NOT_FOUND (17).")

        func_desc_conn2 = test.get_srv_func_desc("STFC_CONNECTION")
        self.assertEqual(pickle.dumps(func_desc_conn),
                         pickle.dumps(func_desc_conn2))

        func_desc_chan2 = test.get_srv_func_desc("STFC_CHANGING")
        self.assertEqual(pickle.dumps(func_desc_chan),
                         pickle.dumps(func_desc_chan2))

        # Invocation test
        result = test.invoke_srv_function("STFC_CONNECTION",
                                          REQUTEXT="request_text")
        self.assertEqual(result['ECHOTEXT'], "request_text")
        self.assertEqual(result['RESPTEXT'], u"Local server here.")

        result = test.invoke_srv_function("STFC_CHANGING",
                                          START_VALUE=23,
                                          COUNTER=7)
        self.assertEqual(result['COUNTER'], 17)  # COUNTER = COUNTER + 10
        self.assertEqual(result['RESULT'],
                         40)  # RESULT = START_VALUE + (COUNTER + 10)

        server.close()
Example #4
0
    def test_server(self):
        server = Server(config={'debug': True}, **config._sections['gateway'])
        test = _Testing()

        # Install two functions
        func_desc_conn = self.conn.get_function_description("STFC_CONNECTION")
        server.install_function(
            func_desc_conn,
            my_stfc_connection
        )
        func_desc_chan = self.conn.get_function_description("STFC_CHANGING")
        server.install_function(
            func_desc_chan,
            my_stfc_changing
        )

        # Lookup test
        func_desc_invalid = test.get_srv_func_desc("NOT_VALID")
        self.assertEqual(func_desc_invalid, 17, "Return code for unknown func_desc should be RFC_NOT_FOUND (17).")

        func_desc_conn2 = test.get_srv_func_desc("STFC_CONNECTION")
        self.assertEqual(pickle.dumps(func_desc_conn), pickle.dumps(func_desc_conn2))

        func_desc_chan2 = test.get_srv_func_desc("STFC_CHANGING")
        self.assertEqual(pickle.dumps(func_desc_chan), pickle.dumps(func_desc_chan2))

        # Invocation test
        result = test.invoke_srv_function("STFC_CONNECTION", REQUTEXT="request_text")
        self.assertEqual(result['ECHOTEXT'], "request_text")
        self.assertEqual(result['RESPTEXT'], u"Local server here.")

        result = test.invoke_srv_function("STFC_CHANGING", START_VALUE=23, COUNTER=7)
        self.assertEqual(result['COUNTER'], 17) # COUNTER = COUNTER + 10
        self.assertEqual(result['RESULT'], 40) # RESULT = START_VALUE + (COUNTER + 10)

        server.close()
Example #5
0
config = ConfigParser()
config.read('sapnwrfc.cfg')


# Callback function
def my_stfc_connection(request_context, REQUTEXT=""):
    return {
        'ECHOTEXT':
        REQUTEXT,
        'RESPTEXT':
        u"Python server here. Connection attributes are: "
        u"User '{user}' from system '{sysId}', client '{client}', "
        u"host '{partnerHost}'".format(
            **request_context['connection_attributes'])
    }


# Open a connection for retrieving the metadata of 'STFC_CONNECTION'
params_connection = config._sections['connection']
conn = Connection(**params_connection)
func_desc_stfc_connection = conn.get_function_description("STFC_CONNECTION")

# Instantiate server with gateway information for registering, and
# install a function.
params_gateway = config._sections['gateway']
server = Server(**params_gateway)
server.install_function(func_desc_stfc_connection, my_stfc_connection)
print "--- Server registration and serving ---"
server.serve(20)
Example #6
0
def my_stfc_changing(
        request_context,
        **kwargs):  # TODO: Maybe only expect import/changing/tables values.
    print("my_stfc_changing was called with arguments: {}".format(kwargs))
    start_value = kwargs['START_VALUE']
    counter = kwargs['COUNTER']
    return {
        'START_VALUE': start_value,
        'COUNTER': counter + 2,
        'RESULT': start_value + 2 * counter
    }


func_desc_stfc_changing = conn.get_function_description("STFC_CHANGING")
server.install_function(func_desc_stfc_changing, my_stfc_changing)


def my_raise_error(request_context, REQUTEXT):
    ERRTYPE = REQUTEXT
    if ERRTYPE == 'EXCEPTION':
        raise ABAPApplicationError(key='BAD_EXCEPTION_HAPPENED')
    elif ERRTYPE == 'EXCEPTION_MESSAGE':
        raise ABAPApplicationError(
            key='BAD_EXCEPTION_W_MSG',
            msg_class='SR',  # message id or class
            msg_type='E',  # out of e.g. 'E', 'A' or 'X'
            msg_number='007',  # 3 char numeric
            msg_v1='V1 text'  # 50 char
        )
    elif ERRTYPE == 'MESSAGE':
Example #7
0
        'RESPTEXT': u"Local server here."
    }
# func_desc_stfc_connection = conn.get_function_description("STFC_CONNECTION")
# server.install_function(func_desc_stfc_connection, my_stfc_connection)

def my_stfc_changing(request_context, **kwargs): # TODO: Maybe only expect import/changing/tables values.
    print "my_stfc_changing was called with arguments: {}".format(kwargs)
    start_value = kwargs['START_VALUE']
    counter = kwargs['COUNTER']
    return {
        'START_VALUE': start_value,
        'COUNTER': counter + 2,
        'RESULT': start_value + 2*counter
    }
func_desc_stfc_changing = conn.get_function_description("STFC_CHANGING")
server.install_function(func_desc_stfc_changing, my_stfc_changing)

def my_raise_error(request_context, REQUTEXT):
    ERRTYPE = REQUTEXT
    if ERRTYPE == 'EXCEPTION':
        raise ABAPApplicationError(key='BAD_EXCEPTION_HAPPENED')
    elif ERRTYPE == 'EXCEPTION_MESSAGE':
        raise ABAPApplicationError(key='BAD_EXCEPTION_W_MSG',
            msg_class='SR', # message id or class
            msg_type='E', # out of e.g. 'E', 'A' or 'X'
            msg_number='007', # 3 char numeric
            msg_v1='V1 text' # 50 char
        )
    elif ERRTYPE == 'MESSAGE':
        raise ABAPRuntimeError(
            msg_class='SM', # message id or class
import signal
import sys



config = ConfigParser()
config.read('sapnwrfc.cfg')

# Callback function
def my_stfc_connection(request_context, REQUTEXT=""):
    return {
        'ECHOTEXT': REQUTEXT,
        'RESPTEXT': u"Python server here. Connection attributes are: "
                    u"User '{user}' from system '{sysId}', client '{client}', "
                    u"host '{partnerHost}'".format(**request_context['connection_attributes'])
    }

# Open a connection for retrieving the metadata of 'STFC_CONNECTION'
params_connection = config._sections['connection']
conn = Connection(**params_connection)
func_desc_stfc_connection = conn.get_function_description("STFC_CONNECTION")

# Instantiate server with gateway information for registering, and
# install a function.
params_gateway = config._sections['gateway']
server = Server(**params_gateway)
server.install_function(func_desc_stfc_connection, my_stfc_connection)
print "--- Server registration and serving ---"
server.serve(20)