ConvertCountryCodeCountryName
Convert country name to country code or country code to country name. Only one of 'country_code' or 'country_name' can be provided. Example: Input: { "country_code": "US" } Output: { "United States" } Another Example: Input: { "country_name": "United States" } Output: { "US" }.
python · Common Scripts
Details
| ID | ConvertCountryCodeCountryName |
|---|---|
| Language | python |
| From Version | 6.5.0 |
| Docker Image | demisto/python3:3.12.13.10404775 |
| Tags | transformer |
README
Convert country name to country code or country code to country name.
Only one of ‘country_code’ or ‘country_name’ can be provided.
Example:
Input: { “country_code”: “US” }
Output: { “United States” }
Another Example:
Input: { “country_name”: “United States” }
Output: { “US” }
Script Data
| Name | Description |
|---|---|
| Script Type | python3 |
| Tags | transformer |
| Cortex XSOAR Version | 5.0.0 |
Inputs
| Argument Name | Description |
|---|---|
| country_code | Country Code Alpha 2 (Example: US) |
| country_name | Country Name |
Outputs
There are no outputs for this script.
import ConvertCountryCodeCountryName import demistomock as demisto import pytest upper_country_code = ("IL", None, "Israel") lower_country_code = ("il", None, "Israel") mixed_country_code = ("tT", None, "Trinidad and Tobago") regular_country_name = (None, "Kenya", "KE") lower_long_country_name = (None, "trinidad and tobago", "TT") @pytest.mark.parametrize( "country_code, country_name, expected_result", [ upper_country_code, lower_country_code, mixed_country_code, regular_country_name, lower_long_country_name, ], ) def test_valid_convert_country_code_country_name(mocker, country_code, country_name, expected_result): mocker.patch.object(demisto, "args", return_value={"country_code": country_code, "country_name": country_name}) return_results_mocker = mocker.patch.object(ConvertCountryCodeCountryName, "return_results") ConvertCountryCodeCountryName.main() return_results_mocker.assert_called_once_with(expected_result) both_provided = ("IL", "Israel", "Only one of country_code or country_name can be provided.") invalid_country_code = ("invalid", None, "Invalid Country Code") invalid_country_name = (None, "Invalid", "Invalid Country Name") @pytest.mark.parametrize( "country_code, country_name, expected_error", [ both_provided, invalid_country_code, invalid_country_name, ], ) def test_invalid_convert_country_code_country_name(mocker, country_code, country_name, expected_error): mocker.patch.object(demisto, "args", return_value={"country_code": country_code, "country_name": country_name}) return_error_mocker = mocker.patch.object(ConvertCountryCodeCountryName, "return_error") ConvertCountryCodeCountryName.main() return_error_mocker.assert_called_once_with(f"Failed to execute ConvertCountryCodeCountryName. Error: {expected_error}")