|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +# (C) Copyright IBM Corp. 2024. |
| 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 PartnerBillingUnitsV1 |
| 18 | +""" |
| 19 | + |
| 20 | +from ibm_cloud_sdk_core import ApiException, read_external_sources |
| 21 | +import os |
| 22 | +import pytest |
| 23 | +from ibm_platform_services.partner_billing_units_v1 import * |
| 24 | + |
| 25 | +# |
| 26 | +# This file provides an example of how to use the Partner Billing Units service. |
| 27 | +# |
| 28 | +# The following configuration properties are assumed to be defined: |
| 29 | +# PARTNER_BILLING_UNITS_URL=<service base url> |
| 30 | +# PARTNER_BILLING_UNITS_AUTH_TYPE=iam |
| 31 | +# PARTNER_BILLING_UNITS_APIKEY=<IAM apikey> |
| 32 | +# PARTNER_BILLING_UNITS_AUTH_URL=<IAM token service base URL - omit this if using the production environment> |
| 33 | +# PARTNER_BILLING_UNITS_PARTNER_ID=<Enterprise ID of the distributor or reseller for which the report is requested> |
| 34 | +# PARTNER_BILLING_UNITS_CUSTOMER_ID=<Enterprise ID of the customer for which the report is requested> |
| 35 | +# PARTNER_BILLING_UNITS_RESELLER_ID=<Enterprise ID of the reseller for which the report is requested> |
| 36 | +# PARTNER_BILLING_UNITS_BILLING_MONTH=<The billing month (yyyy-mm) for which usage report will be retrieved> |
| 37 | +# |
| 38 | +# These configuration properties can be exported as environment variables, or stored |
| 39 | +# in a configuration file and then: |
| 40 | +# export IBM_CREDENTIALS_FILE=<name of configuration file> |
| 41 | +# |
| 42 | +config_file = 'partner_billing_units_v1.env' |
| 43 | + |
| 44 | +partner_billing_units_service = None |
| 45 | + |
| 46 | +config = None |
| 47 | +partner_id = None |
| 48 | +billing_month = None |
| 49 | + |
| 50 | + |
| 51 | +############################################################################## |
| 52 | +# Start of Examples for Service: PartnerBillingUnitsV1 |
| 53 | +############################################################################## |
| 54 | +# region |
| 55 | +class TestPartnerBillingUnitsV1Examples: |
| 56 | + """ |
| 57 | + Example Test Class for PartnerBillingUnitsV1 |
| 58 | + """ |
| 59 | + |
| 60 | + @classmethod |
| 61 | + def setup_class(cls): |
| 62 | + global partner_billing_units_service |
| 63 | + if os.path.exists(config_file): |
| 64 | + os.environ['IBM_CREDENTIALS_FILE'] = config_file |
| 65 | + |
| 66 | + # begin-common |
| 67 | + |
| 68 | + partner_billing_units_service = PartnerBillingUnitsV1.new_instance() |
| 69 | + |
| 70 | + # end-common |
| 71 | + assert partner_billing_units_service is not None |
| 72 | + |
| 73 | + # Load the configuration |
| 74 | + global config |
| 75 | + config = read_external_sources(PartnerBillingUnitsV1.DEFAULT_SERVICE_NAME) |
| 76 | + |
| 77 | + # Retrieve and verify some additional test-related config properties. |
| 78 | + global partner_id |
| 79 | + partner_id = config.get("PARTNER_ID") |
| 80 | + |
| 81 | + global billing_month |
| 82 | + billing_month = config.get("BILLING_MONTH") |
| 83 | + |
| 84 | + assert partner_id is not None |
| 85 | + assert billing_month is not None |
| 86 | + |
| 87 | + print('Setup complete.') |
| 88 | + |
| 89 | + needscredentials = pytest.mark.skipif( |
| 90 | + not os.path.exists(config_file), reason="External configuration not available, skipping..." |
| 91 | + ) |
| 92 | + |
| 93 | + @needscredentials |
| 94 | + def test_get_billing_options_example(self): |
| 95 | + """ |
| 96 | + get_billing_options request example |
| 97 | + """ |
| 98 | + try: |
| 99 | + print('\nget_billing_options() result:') |
| 100 | + # begin-get_billing_options |
| 101 | + |
| 102 | + response = partner_billing_units_service.get_billing_options( |
| 103 | + partner_id=partner_id, |
| 104 | + date=billing_month, |
| 105 | + ) |
| 106 | + billing_options_summary = response.get_result() |
| 107 | + |
| 108 | + print(json.dumps(billing_options_summary, indent=2)) |
| 109 | + |
| 110 | + # end-get_billing_options |
| 111 | + |
| 112 | + except ApiException as e: |
| 113 | + pytest.fail(str(e)) |
| 114 | + |
| 115 | + @needscredentials |
| 116 | + def test_get_credit_pools_report_example(self): |
| 117 | + """ |
| 118 | + get_credit_pools_report request example |
| 119 | + """ |
| 120 | + try: |
| 121 | + print('\nget_credit_pools_report() result:') |
| 122 | + # begin-get_credit_pools_report |
| 123 | + |
| 124 | + response = partner_billing_units_service.get_credit_pools_report( |
| 125 | + partner_id=partner_id, |
| 126 | + date=billing_month, |
| 127 | + ) |
| 128 | + credit_pools_report_summary = response.get_result() |
| 129 | + |
| 130 | + print(json.dumps(credit_pools_report_summary, indent=2)) |
| 131 | + |
| 132 | + # end-get_credit_pools_report |
| 133 | + |
| 134 | + except ApiException as e: |
| 135 | + pytest.fail(str(e)) |
| 136 | + |
| 137 | + |
| 138 | +# endregion |
| 139 | +############################################################################## |
| 140 | +# End of Examples for Service: PartnerBillingUnitsV1 |
| 141 | +############################################################################## |
0 commit comments