diff --git a/sap/cli/checkin.py b/sap/cli/checkin.py index 55e85a4c..de940b63 100644 --- a/sap/cli/checkin.py +++ b/sap/cli/checkin.py @@ -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""" @@ -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) diff --git a/test/unit/fixtures_cli_checkin.py b/test/unit/fixtures_cli_checkin.py index 496b5ca8..d95b8cb8 100644 --- a/test/unit/fixtures_cli_checkin.py +++ b/test/unit/fixtures_cli_checkin.py @@ -145,6 +145,40 @@ ''' +FUNCTION_GROUP_XML_NO_RFC = ''' + + + + Test function group + + TEST_INCLUDE + + + + TEST_FUNCTION_MODULE + Test function module + + + ABAP_PACKAGE + '' + X + DEVCLASS + + + + + + + ABAP_PACKAGE + P + + + + + + +''' + FUNCTION_MODULE_CODE_ABAPGIT = '''FUNCTION ztest_function_module. *"---------------------------------------------------------------------- *"*"Local Interface: diff --git a/test/unit/test_sap_cli_checkin.py b/test/unit/test_sap_cli_checkin.py index 8cad556b..3bf192dd 100644 --- a/test/unit/test_sap_cli_checkin.py +++ b/test/unit/test_sap_cli_checkin.py @@ -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 @@ -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') @@ -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') @@ -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):