Skip to content

Commit

Permalink
cli: add the language arg for identity description
Browse files Browse the repository at this point in the history
  • Loading branch information
jfilak committed Jan 4, 2024
1 parent c275826 commit c0f6528
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
3 changes: 2 additions & 1 deletion doc/commands/strust.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,14 @@ Creates a new (or replaces an existing) STRUST Identity. The description will be
language settings.

```bash
sapcli strust createidentity [-i|--identity IDENTITY] [-s|--storage STORAGE] [-d|--description DESCRIPTION] [--overwrite]
sapcli strust createidentity [-i|--identity IDENTITY] [-s|--storage STORAGE] [-d|--description DESCRIPTION] [-l|--language-iso-code LANG-ISO-639] [--overwrite]
```

**Parameters**:
- `--identity`: STRUST identity (PSE context + PSE application). **(Mutually exclusive with the option --storage)**
- `--storage`: Predefined STRUST identities. **(Mutually exclusive with the option --identity)**
- `--description`: Identity Description. **(optional)**
- `--language-iso-code`: Language of Identity Description - if not given, the language will be deduced from the current system locale. **(optional)**
- `--overwrite`: Overwrite the existing Identity, default is `False`. **(optional)**

# getcsr
Expand Down
5 changes: 4 additions & 1 deletion sap/cli/strust.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ def _get_ssl_storage_from_args(connection, args):
connection,
identity.pse_context,
identity.pse_applic,
description=getattr(args, 'description', None)
description=getattr(args, 'description', None),
lang_iso_code=getattr(args, 'language_iso_code', None)
)


Expand Down Expand Up @@ -144,6 +145,8 @@ def createpse(connection, args):
return 0


@CommandGroup.argument('-l', '--language-iso-code', type=str,
help='ISO code of language of Identity description (default: the current system locale')
@CommandGroup.argument('-d', '--description', type=str, help='Identity description')
@CommandGroup.argument('--overwrite', help='Overwrite the existing STRUST Identity', action='store_true', default=False)
@CommandGroup.argument('-s', '--storage', default=None, help='Mutually exclusive with the option -i',
Expand Down
37 changes: 34 additions & 3 deletions test/unit/test_sap_cli_strust.py
Original file line number Diff line number Diff line change
Expand Up @@ -1049,48 +1049,79 @@ def createidentity(self, *test_args):
def test_createidentity_with_storage_ok(self):
self.mock_connection.call.return_value = {'ET_BAPIRET2':[]}

self.createidentity('-s', 'server_standard', '--description', 'Identity Description')
self.createidentity(
'-s', 'server_standard',
'--description', 'Identity Description',
'-l', 'zh')

self.mock_connection.call.assert_called_once_with(
'SSFR_IDENTITY_CREATE',
IS_STRUST_IDENTITY={
'PSE_CONTEXT': 'SSLS',
'PSE_APPLIC': 'DFAULT',
'PSE_DESCRIPT': 'Identity Description',
'SPRSL': '1',
},
IV_REPLACE_EXISTING_APPL='-',
)

def test_createidentity_with_identity_ok(self):
self.mock_connection.call.return_value = {'ET_BAPIRET2':[]}

self.createidentity('-i', 'SSLC/100_SD', '--description', 'Identity Description')
self.createidentity(
'-i', 'SSLC/100_SD',
'--description', 'Identity Description',
'-l', 'zh')

self.mock_connection.call.assert_called_once_with(
'SSFR_IDENTITY_CREATE',
IS_STRUST_IDENTITY={
'PSE_CONTEXT': 'SSLC',
'PSE_APPLIC': '100_SD',
'PSE_DESCRIPT': 'Identity Description',
'SPRSL': '1',
},
IV_REPLACE_EXISTING_APPL='-',
)

def test_createidentity_with_replace_ok(self):
self.mock_connection.call.return_value = {'ET_BAPIRET2':[]}

self.createidentity('-s', 'server_standard', '--description', 'Identity Description', '--overwrite')
self.createidentity(
'-s', 'server_standard',
'--description', 'Identity Description',
'--language-iso-code', 'zh',
'--overwrite')

self.mock_connection.call.assert_called_once_with(
'SSFR_IDENTITY_CREATE',
IS_STRUST_IDENTITY={
'PSE_CONTEXT': 'SSLS',
'PSE_APPLIC': 'DFAULT',
'PSE_DESCRIPT': 'Identity Description',
'SPRSL': '1',
},
IV_REPLACE_EXISTING_APPL='X',
)

def test_createidentity_with_language_from_locale(self):
self.mock_connection.call.return_value = {'ET_BAPIRET2':[]}

with patch('sap.platform.language.getlocale', return_value=('zh_CN', 'UTF-8')):
self.createidentity(
'-s', 'server_standard',
'--description', 'Identity Description')

self.mock_connection.call.assert_called_once_with(
'SSFR_IDENTITY_CREATE',
IS_STRUST_IDENTITY={
'PSE_CONTEXT': 'SSLS',
'PSE_APPLIC': 'DFAULT',
'PSE_DESCRIPT': 'Identity Description',
'SPRSL': '1',
},
IV_REPLACE_EXISTING_APPL='-',
)

if __name__ == '__main__':
unittest.main()

0 comments on commit c0f6528

Please sign in to comment.