Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_unit_destroy(self):
self.assertFalse(self.conn.get_connection_attributes()['active_unit'], u"No active TA (base condition).")
unit = self.conn.initialize_unit(background=False)
with self.assertRaises(pyrfc.RFCError) as e: # missing transaction
self.conn.destroy_unit(unit)
self.assertEqual(e.exception.message, u"No transaction handle for this connection available.")
unit = self.conn.initialize_unit(background=False)
idoc = self._get_idoc_desc(41)
with self.assertRaises(pyrfc.RFCError) as e: # already destroyed transaction
self.conn.fill_and_submit_unit(unit, [(u"IDOC_INBOUND_ASYNCHRONOUS", idoc)])
self.conn.destroy_unit(unit)
self.conn.destroy_unit(unit)
self.assertEqual(e.exception.message, u"No transaction handle for this connection available.")
unit = self.conn.initialize_unit(background=False)
idoc = self._get_idoc_desc(42)
with self.assertRaises(pyrfc.RFCError) as e: # already confirmed transaction
self.conn.fill_and_submit_unit(unit, [(u"IDOC_INBOUND_ASYNCHRONOUS", idoc)])
self.conn.confirm_unit(unit)
self.conn.destroy_unit(unit)
self.assertEqual(e.exception.message, u"No transaction handle for this connection available.")
def test_unit_destroy(self):
self.assertFalse(self.conn.get_connection_attributes()['active_unit'], u"No active TA (base condition).")
unit = self.conn.initialize_unit(background=False)
with self.assertRaises(pyrfc.RFCError) as e: # missing transaction
self.conn.destroy_unit(unit)
self.assertEqual(e.exception.message, u"No transaction handle for this connection available.")
unit = self.conn.initialize_unit(background=False)
idoc = self._get_idoc_desc(41)
with self.assertRaises(pyrfc.RFCError) as e: # already destroyed transaction
self.conn.fill_and_submit_unit(unit, [(u"IDOC_INBOUND_ASYNCHRONOUS", idoc)])
self.conn.destroy_unit(unit)
self.conn.destroy_unit(unit)
self.assertEqual(e.exception.message, u"No transaction handle for this connection available.")
unit = self.conn.initialize_unit(background=False)
idoc = self._get_idoc_desc(42)
with self.assertRaises(pyrfc.RFCError) as e: # already confirmed transaction
self.conn.fill_and_submit_unit(unit, [(u"IDOC_INBOUND_ASYNCHRONOUS", idoc)])
self.conn.confirm_unit(unit)
def setUpClass(cls):
# print "Os cwd", os.getcwd()
# print "Config", config
## print config._sections.items()
cls.conn = pyrfc.Connection(**config._sections['connection'])
def test_no_connection_params(self):
try:
pyrfc.Connection()
except pyrfc.RFCError as ex:
assert ex.args[0] == "Connection parameters missing"
def test_config_parameter(self):
# rstrip test
conn = pyrfc.Connection(config={"rstrip": False}, **config_sections["coevi51"])
hello = u"Hällo SAP!" + u" " * 245
result = conn.call("STFC_CONNECTION", REQUTEXT=hello)
# Test with rstrip=False (input length=255 char)
assert result["ECHOTEXT"] == hello
result = conn.call("STFC_CONNECTION", REQUTEXT=hello.rstrip())
# Test with rstrip=False (input length=10 char)
assert result["ECHOTEXT"] == hello
conn.close()
# dtime test
conn = pyrfc.Connection(config={"dtime": True}, **config_sections["coevi51"])
dates = conn.call("BAPI_USER_GET_DETAIL", USERNAME="demo")["LASTMODIFIED"]
assert type(dates["MODDATE"]) is datetime.date
assert type(dates["MODTIME"]) is datetime.time
del conn
conn = pyrfc.Connection(**config_sections["coevi51"])
dates = conn.call("BAPI_USER_GET_DETAIL", USERNAME="demo")["LASTMODIFIED"]
def test_collect(self):
self.engine.get_user_connection(user, passwd)
poolsize_pre = self.engine._size
normal_conn = pyrfc.Connection(user=user, passwd=passwd, **params)
self.engine.collect(user, normal_conn)
self.assertEqual(poolsize_pre+1, self.engine._size)
self.conn.call("RFC_RAISE_ERROR", METHOD="1", MESSAGETYPE="E")
except pyrfc.ABAPApplicationError as ex:
error = get_error(ex)
assert error["code"] == 5
assert error["key"] == "RAISE_EXCEPTION"
assert error["msg_class"] == u"SR"
assert error["msg_type"] == "E"
assert error["msg_number"] == "006"
# Assures that the connection handle is correctly synchronized
self.conn.call("RFC_PING")
# '2_E': 'ABAPApplicationError-5-RAISE_EXCEPTION- Number:000-True',
# cf. ExceptionTest.c (l. 65ff)
try:
self.conn.call("RFC_RAISE_ERROR", METHOD="2", MESSAGETYPE="E")
except pyrfc.ABAPApplicationError as ex:
error = get_error(ex)
assert error["code"] == 5
assert error["key"] == "RAISE_EXCEPTION"
assert error["msg_number"] == "006"
self.conn.call("RFC_PING")
def my_sftc_connection_error(request_context, REQUTEXT):
# depending on the REQUTEXT value, raises errors.
if REQUTEXT == 'EXCEPTION':
raise ABAPApplicationError(key='BAD_EXCEPTION_HAPPENED')
elif REQUTEXT == '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 REQUTEXT == 'MESSAGE':
raise ABAPRuntimeError(
msg_class='SM', # message id or class
msg_type='E', # out of e.g. 'E', 'A' or 'X'
msg_number='107', # 3 char numeric string
msg_v1='V1 text (ABAP_MESSAGE)'
)
elif REQUTEXT == 'FAILURE':
raise ExternalRuntimeError("Something very bad happened.")
def test_RFC_RAISE_ERROR_AbapApplicationError_E1(self):
# Comment: cf. result_print of the error_test.py
# '1_E': 'ABAPApplicationError-5-RAISE_EXCEPTION-ID:SR Type:E Number:006 STRING-True',
# cf. ExceptionTest.c (l. 75ff)
try:
self.conn.call("RFC_RAISE_ERROR", METHOD="1", MESSAGETYPE="E")
except pyrfc.ABAPApplicationError as ex:
assert self.conn.alive == True
error = get_error(ex)
assert error["code"] == 5
assert error["key"] == "RAISE_EXCEPTION"
assert error["msg_class"] == u"SR"
assert error["msg_type"] == "E"
assert error["msg_number"] == "006"
def test_call_non_existing_RFM(self):
try:
self.conn.call("undefined")
except pyrfc.ABAPApplicationError as ex:
error = get_error(ex)
assert error["code"] == 5
assert error["key"] == "FU_NOT_FOUND"
assert error["message"][0] == "ID:FL Type:E Number:046 undefined"