Skip to content

Commit

Permalink
checkin: fix function module processing type
Browse files Browse the repository at this point in the history
Upon checkin of function group, take into account REMOTE_CALL settings.
To change the processing type of function module, first it needs to be
created. Afterwards its attributes can be edited.

---v2
Fix lint errors by moving the creation of function module to separate
function.
  • Loading branch information
palubaj authored and jfilak committed Aug 29, 2023
1 parent 77ab5ab commit 2839463
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 11 deletions.
30 changes: 22 additions & 8 deletions sap/cli/checkin.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,27 @@ def _write_function_source_code(path_prefix, adt_object, corrnr=None):
_write_source_file(source_code, adt_object, corrnr)


def create_function_module(connection, func, function_group, metadata, corrnr):
"""Create Function Module"""

function_module = sap.adt.FunctionModule(connection, func.FUNCNAME, function_group.name, metadata=metadata)
function_module.description = func.SHORT_TEXT

sap.cli.core.printout('Creating Function Module:', function_module.name)
try:
function_module.create(corrnr)
except sap.adt.errors.ExceptionResourceAlreadyExists as err:
mod_log().info(err.message)

if func.REMOTE_CALL == 'R':
function_module.processing_type = 'rfc'
lock_handle = function_module.lock()
with function_module.open_editor(lock_handle, corrnr) as fn_editor:
fn_editor.push()

return function_module


def checkin_fugr(connection, repo_obj, corrnr=None):
"""Checkin ADT Function Group"""

Expand Down Expand Up @@ -540,16 +561,9 @@ def checkin_fugr(connection, repo_obj, corrnr=None):
_write_adt_object_source_file(repo_obj.path[:-4], include_obj, corrnr=corrnr)

for func in functions:
function_module = sap.adt.FunctionModule(connection, func.FUNCNAME, function_group.name, metadata=metadata)
function_module.description = func.SHORT_TEXT
function_module = create_function_module(connection, func, function_group, metadata, corrnr)
abap_objs_inactive.append(function_module)

sap.cli.core.printout('Creating Function Module:', function_module.name)
try:
function_module.create(corrnr)
except sap.adt.errors.ExceptionResourceAlreadyExists as err:
mod_log().info(err.message)

sap.cli.core.printout('Writing Function Module:', function_module.name)
_write_function_source_code(repo_obj.path[:-4], function_module, corrnr=corrnr)

Expand Down
34 changes: 34 additions & 0 deletions test/unit/fixtures_cli_checkin.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,40 @@
</asx:abap>
</abapGit>'''

FUNCTION_GROUP_XML_NO_RFC = '''<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_FUGR" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<AREAT>Test function group</AREAT>
<INCLUDES>
<SOBJ_NAME>TEST_INCLUDE</SOBJ_NAME>
</INCLUDES>
<FUNCTIONS>
<item>
<FUNCNAME>TEST_FUNCTION_MODULE</FUNCNAME>
<SHORT_TEXT>Test function module</SHORT_TEXT>
<IMPORT>
<RSIMP>
<PARAMETER>ABAP_PACKAGE</PARAMETER>
<DEFAULT>&apos;&apos;</DEFAULT>
<OPTIONAL>X</OPTIONAL>
<TYP>DEVCLASS</TYP>
</RSIMP>
</IMPORT>
<TABLES>
</TABLES>
<DOCUMENTATION>
<RSFDO>
<PARAMETER>ABAP_PACKAGE</PARAMETER>
<KIND>P</KIND>
</RSFDO>
</DOCUMENTATION>
</item>
</FUNCTIONS>
</asx:values>
</asx:abap>
</abapGit>'''

FUNCTION_MODULE_CODE_ABAPGIT = '''FUNCTION ztest_function_module.
*"----------------------------------------------------------------------
*"*"Local Interface:
Expand Down
21 changes: 18 additions & 3 deletions test/unit/test_sap_cli_checkin.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from fixtures_abap import ABAP_GIT_DEFAULT_XML
from fixtures_cli_checkin import PACKAGE_DEVC_XML, CLAS_XML, INTF_XML, PROG_XML, INCLUDE_XML, INVALID_TYPE_XML, FUNCTION_GROUP_XML, \
FUNCTION_MODULE_CODE_ABAPGIT, FUNCTION_MODULE_CODE_ADT, FUNCTION_MODULE_CODE_NO_PARAMS_ABAPGIT, FUNCTION_MODULE_CODE_NO_PARAMS_ADT,\
FUNCTION_MODULE_CODE_ALL_PARAMS_ABAPGIT, FUNCTION_MODULE_CODE_ALL_PARAMS_ADT
FUNCTION_MODULE_CODE_ALL_PARAMS_ABAPGIT, FUNCTION_MODULE_CODE_ALL_PARAMS_ADT, FUNCTION_GROUP_XML_NO_RFC
from infra import generate_parse_args


Expand Down Expand Up @@ -908,6 +908,7 @@ def setUp(self):
self.fake_function_group.return_value = self.function_group

self.function_module = MagicMock()
self.function_module.lock.return_value = 'lock_handle'
self.function_module_editor = MagicMock()
self.function_module_editor.__enter__.return_value = self.function_module_editor
self.fake_function_module = self.patch('sap.adt.FunctionModule')
Expand Down Expand Up @@ -1015,7 +1016,11 @@ def test_checkin_fugr(self):
self.assertEqual(self.function_module.description, 'Test function module')
self.function_include.create.assert_called_once_with(None)

self.function_module.open_editor.assert_called_once_with(corrnr=None)
self.assertEqual(self.function_module.processing_type, 'rfc')

self.function_module.open_editor.assert_any_call('lock_handle', None)
self.function_module.open_editor.assert_any_call(corrnr=None)
self.assertEqual(self.function_module.open_editor.call_count, 2)
self.function_module_editor.write.assert_called_once_with(FUNCTION_MODULE_CODE_ADT)
self.function_include.open_editor.assert_called_once_with(corrnr=None)
self.function_include_editor.write.assert_called_once_with('Test include body')
Expand All @@ -1040,7 +1045,17 @@ def test_checkin_fugr_with_corrnr(self):
self.function_include.create.assert_called_once_with(corrnr)

self.function_include.open_editor.assert_called_once_with(corrnr=corrnr)
self.function_module.open_editor.assert_called_once_with(corrnr=corrnr)
self.function_module.open_editor.assert_any_call('lock_handle', corrnr)
self.function_module.open_editor.assert_any_call(corrnr=corrnr)
self.assertEqual(self.function_module.open_editor.call_count, 2)

def test_checkin_fugr_no_rfc(self):
self.fake_open.side_effect = [StringIOFile(FUNCTION_GROUP_XML_NO_RFC), StringIOFile('Test include'),
StringIOFile('Test function module')]

inactive_objects = sap.cli.checkin.checkin_fugr(self.connection, self.fugr_object)
self.assertEqual(inactive_objects, [self.function_group, self.function_include, self.function_module])
self.assertTrue(isinstance(self.function_module.processing_type, MagicMock)) # processing_type is MagicMock => is not defined

@patch('sap.cli.checkin.mod_log')
def test_checkin_fugr_already_created(self, fake_mod_log):
Expand Down

0 comments on commit 2839463

Please sign in to comment.