|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +# (C) Copyright IBM Corp. 2020. |
| 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 | +Examples for EnterpriseBillingUnitsV1 |
| 17 | +""" |
| 18 | + |
| 19 | +import os |
| 20 | +import pytest |
| 21 | +import json |
| 22 | +from ibm_cloud_sdk_core import ApiException, read_external_sources |
| 23 | +from ibm_platform_services.enterprise_billing_units_v1 import * |
| 24 | + |
| 25 | +# |
| 26 | +# This file provides an example of how to use the Enterprise Billing Units service. |
| 27 | +# |
| 28 | +# The following configuration properties are assumed to be defined in the external configuration file: |
| 29 | +# ENTERPRISE_BILLING_UNITS_URL=<service url> |
| 30 | +# ENTERPRISE_BILLING_UNITS_AUTHTYPE=iam |
| 31 | +# ENTERPRISE_BILLING_UNITS_APIKEY=<your iam apikey> |
| 32 | +# ENTERPRISE_BILLING_UNITS_AUTH_URL=<IAM token service URL - omit this if using the production environment> |
| 33 | +# ENTERPRISE_BILLING_UNITS_ENTERPRISE_ID=<id of enterprise to use for examples> |
| 34 | +# ENTERPRISE_BILLING_UNITS_BILLING_UNIT_ID=<id of billing unit to use for examples> |
| 35 | +# |
| 36 | +# Config file name |
| 37 | +config_file = 'enterprise_billing_units.env' |
| 38 | + |
| 39 | +enterprise_billing_units_service = None |
| 40 | + |
| 41 | +config = None |
| 42 | + |
| 43 | +enterprise_id = None |
| 44 | +billing_unit_id = None |
| 45 | + |
| 46 | + |
| 47 | +############################################################################## |
| 48 | +# Start of Examples for Service: EnterpriseBillingUnitsV1 |
| 49 | +############################################################################## |
| 50 | +# region |
| 51 | +class TestEnterpriseBillingUnitsV1Examples(): |
| 52 | + """ |
| 53 | + Example Test Class for EnterpriseBillingUnitsV1 |
| 54 | + """ |
| 55 | + @classmethod |
| 56 | + def setup_class(cls): |
| 57 | + global enterprise_billing_units_service |
| 58 | + if os.path.exists(config_file): |
| 59 | + os.environ['IBM_CREDENTIALS_FILE'] = config_file |
| 60 | + |
| 61 | + # begin-common |
| 62 | + |
| 63 | + enterprise_billing_units_service = EnterpriseBillingUnitsV1.new_instance( |
| 64 | + ) |
| 65 | + |
| 66 | + # end-common |
| 67 | + assert enterprise_billing_units_service is not None |
| 68 | + |
| 69 | + # Load the configuration |
| 70 | + |
| 71 | + global config, enterprise_id, billing_unit_id |
| 72 | + config = read_external_sources( |
| 73 | + EnterpriseBillingUnitsV1.DEFAULT_SERVICE_NAME) |
| 74 | + |
| 75 | + enterprise_id = config['ENTERPRISE_ID'] |
| 76 | + billing_unit_id = config['BILLING_UNIT_ID'] |
| 77 | + |
| 78 | + print('Setup complete.') |
| 79 | + |
| 80 | + needscredentials = pytest.mark.skipif( |
| 81 | + not os.path.exists(config_file), |
| 82 | + reason="External configuration not available, skipping...") |
| 83 | + |
| 84 | + @needscredentials |
| 85 | + def test_get_billing_unit_example(self): |
| 86 | + """ |
| 87 | + get_billing_unit request example |
| 88 | + """ |
| 89 | + try: |
| 90 | + global billing_unit_id |
| 91 | + # begin-get_billing_unit |
| 92 | + |
| 93 | + billing_unit = enterprise_billing_units_service.get_billing_unit( |
| 94 | + billing_unit_id=billing_unit_id).get_result() |
| 95 | + |
| 96 | + print(json.dumps(billing_unit, indent=2)) |
| 97 | + |
| 98 | + # end-get_billing_unit |
| 99 | + |
| 100 | + except ApiException as e: |
| 101 | + pytest.fail(str(e)) |
| 102 | + |
| 103 | + @needscredentials |
| 104 | + def test_list_billing_units_example(self): |
| 105 | + """ |
| 106 | + list_billing_units request example |
| 107 | + """ |
| 108 | + try: |
| 109 | + global enterprise_id |
| 110 | + # begin-list_billing_units |
| 111 | + |
| 112 | + billing_units_list = enterprise_billing_units_service.list_billing_units( |
| 113 | + enterprise_id=enterprise_id).get_result() |
| 114 | + |
| 115 | + print(json.dumps(billing_units_list, indent=2)) |
| 116 | + |
| 117 | + # end-list_billing_units |
| 118 | + |
| 119 | + except ApiException as e: |
| 120 | + pytest.fail(str(e)) |
| 121 | + |
| 122 | + @needscredentials |
| 123 | + def test_list_billing_options_example(self): |
| 124 | + """ |
| 125 | + list_billing_options request example |
| 126 | + """ |
| 127 | + try: |
| 128 | + global billing_unit_id |
| 129 | + # begin-list_billing_options |
| 130 | + |
| 131 | + billing_options_list = enterprise_billing_units_service.list_billing_options( |
| 132 | + billing_unit_id=billing_unit_id).get_result() |
| 133 | + |
| 134 | + print(json.dumps(billing_options_list, indent=2)) |
| 135 | + |
| 136 | + # end-list_billing_options |
| 137 | + |
| 138 | + except ApiException as e: |
| 139 | + pytest.fail(str(e)) |
| 140 | + |
| 141 | + @needscredentials |
| 142 | + def test_get_credit_pools_example(self): |
| 143 | + """ |
| 144 | + get_credit_pools request example |
| 145 | + """ |
| 146 | + try: |
| 147 | + global billing_unit_id |
| 148 | + # begin-get_credit_pools |
| 149 | + |
| 150 | + credit_pools_list = enterprise_billing_units_service.get_credit_pools( |
| 151 | + billing_unit_id=billing_unit_id, type='PLATFORM').get_result() |
| 152 | + |
| 153 | + print(json.dumps(credit_pools_list, indent=2)) |
| 154 | + |
| 155 | + # end-get_credit_pools |
| 156 | + |
| 157 | + except ApiException as e: |
| 158 | + pytest.fail(str(e)) |
| 159 | + |
| 160 | + |
| 161 | +# endregion |
| 162 | +############################################################################## |
| 163 | +# End of Examples for Service: EnterpriseBillingUnitsV1 |
| 164 | +############################################################################## |
0 commit comments