|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +# (C) Copyright IBM Corp. 2026. |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | + |
| 16 | +""" |
| 17 | +Examples for AccountManagementV4 |
| 18 | +""" |
| 19 | + |
| 20 | +from ibm_cloud_sdk_core import ApiException, read_external_sources |
| 21 | +import os |
| 22 | +import pytest |
| 23 | +from ibm_platform_services.account_management_v4 import * |
| 24 | + |
| 25 | +# |
| 26 | +# This file provides an example of how to use the account_management service. |
| 27 | +# |
| 28 | +# The following configuration properties are assumed to be defined: |
| 29 | +# ACCOUNT_MANAGEMENT_URL=<service base url> |
| 30 | +# ACCOUNT_MANAGEMENT_AUTH_TYPE=iam |
| 31 | +# ACCOUNT_MANAGEMENT_APIKEY=<IAM apikey> |
| 32 | +# ACCOUNT_MANAGEMENT_AUTH_URL=<IAM token service base URL - omit this if using the production environment> |
| 33 | +# ACCOUNT_MANAGEMENT_ACCOUNT_ID=<account id> |
| 34 | +# |
| 35 | +# These configuration properties can be exported as environment variables, or stored |
| 36 | +# in a configuration file and then: |
| 37 | +# export IBM_CREDENTIALS_FILE=<name of configuration file> |
| 38 | +# |
| 39 | +config_file = 'account_management_v4.env' |
| 40 | + |
| 41 | +account_management_service = None |
| 42 | + |
| 43 | +config = None |
| 44 | + |
| 45 | +account_id = None |
| 46 | + |
| 47 | +############################################################################## |
| 48 | +# Start of Examples for Service: AccountManagementV4 |
| 49 | +############################################################################## |
| 50 | +# region |
| 51 | +class TestAccountManagementV4Examples: |
| 52 | + """ |
| 53 | + Example Test Class for AccountManagementV4 |
| 54 | + """ |
| 55 | + |
| 56 | + @classmethod |
| 57 | + def setup_class(cls): |
| 58 | + global account_management_service |
| 59 | + if os.path.exists(config_file): |
| 60 | + os.environ['IBM_CREDENTIALS_FILE'] = config_file |
| 61 | + |
| 62 | + # begin-common |
| 63 | + |
| 64 | + account_management_service = AccountManagementV4.new_instance( |
| 65 | + ) |
| 66 | + |
| 67 | + # end-common |
| 68 | + assert account_management_service is not None |
| 69 | + |
| 70 | + # Load the configuration |
| 71 | + global config |
| 72 | + config = read_external_sources(AccountManagementV4.DEFAULT_SERVICE_NAME) |
| 73 | + global account_id |
| 74 | + account_id = config['ACCOUNT_ID'] |
| 75 | + print('Setup complete.') |
| 76 | + |
| 77 | + needscredentials = pytest.mark.skipif( |
| 78 | + not os.path.exists(config_file), reason="External configuration not available, skipping..." |
| 79 | + ) |
| 80 | + |
| 81 | + @needscredentials |
| 82 | + def test_get_account_example(self): |
| 83 | + """ |
| 84 | + get_account request example |
| 85 | + """ |
| 86 | + try: |
| 87 | + print('\nget_account() result:') |
| 88 | + |
| 89 | + # begin-getAccount |
| 90 | + |
| 91 | + response = account_management_service.get_account( |
| 92 | + account_id=account_id, |
| 93 | + ) |
| 94 | + account_response = response.get_result() |
| 95 | + |
| 96 | + print(json.dumps(account_response, indent=2)) |
| 97 | + |
| 98 | + # end-getAccount |
| 99 | + |
| 100 | + except ApiException as e: |
| 101 | + pytest.fail(str(e)) |
| 102 | + |
| 103 | + |
| 104 | +# endregion |
| 105 | +############################################################################## |
| 106 | +# End of Examples for Service: AccountManagementV4 |
| 107 | +############################################################################## |
0 commit comments