diff --git a/doc/commands/strust.md b/doc/commands/strust.md index f140d28..79e060e 100644 --- a/doc/commands/strust.md +++ b/doc/commands/strust.md @@ -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 diff --git a/sap/cli/strust.py b/sap/cli/strust.py index d333544..6f23db5 100644 --- a/sap/cli/strust.py +++ b/sap/cli/strust.py @@ -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) ) @@ -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', diff --git a/test/unit/test_sap_cli_strust.py b/test/unit/test_sap_cli_strust.py index 58e2467..e7ad86d 100644 --- a/test/unit/test_sap_cli_strust.py +++ b/test/unit/test_sap_cli_strust.py @@ -1049,7 +1049,10 @@ 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', @@ -1057,6 +1060,7 @@ def test_createidentity_with_storage_ok(self): 'PSE_CONTEXT': 'SSLS', 'PSE_APPLIC': 'DFAULT', 'PSE_DESCRIPT': 'Identity Description', + 'SPRSL': '1', }, IV_REPLACE_EXISTING_APPL='-', ) @@ -1064,7 +1068,10 @@ def test_createidentity_with_storage_ok(self): 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', @@ -1072,6 +1079,7 @@ def test_createidentity_with_identity_ok(self): 'PSE_CONTEXT': 'SSLC', 'PSE_APPLIC': '100_SD', 'PSE_DESCRIPT': 'Identity Description', + 'SPRSL': '1', }, IV_REPLACE_EXISTING_APPL='-', ) @@ -1079,7 +1087,11 @@ def test_createidentity_with_identity_ok(self): 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', @@ -1087,10 +1099,29 @@ def test_createidentity_with_replace_ok(self): '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()