Skip to content

Commit

Permalink
feat(Usage Reports): re-gen service to pickup changes to Instance Rep…
Browse files Browse the repository at this point in the history
…orts (#258)

* add VolumeDiscount and VolumeCost

Signed-off-by: Jonathan Date-chong <[email protected]>
  • Loading branch information
Jdatechong authored Jun 18, 2024
1 parent 8767a68 commit 87a3e6f
Show file tree
Hide file tree
Showing 4 changed files with 367 additions and 142 deletions.
134 changes: 86 additions & 48 deletions examples/test_usage_reports_v4_examples.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# (C) Copyright IBM Corp. 2020.
# (C) Copyright IBM Corp. 2024.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -17,9 +17,9 @@
Examples for UsageReportsV4
"""

from ibm_cloud_sdk_core import ApiException, read_external_sources
import os
import pytest
from ibm_cloud_sdk_core import ApiException, read_external_sources
from ibm_platform_services.usage_reports_v4 import *

#
Expand Down Expand Up @@ -54,12 +54,11 @@
snapshot_date_from = None
snapshot_date_to = None


##############################################################################
# Start of Examples for Service: UsageReportsV4
##############################################################################
# region


class TestUsageReportsV4Examples:
"""
Example Test Class for UsageReportsV4
Expand Down Expand Up @@ -129,11 +128,14 @@ def test_get_account_summary_example(self):
"""
try:
print('\nget_account_summary() result:')

# begin-get_account_summary

account_summary = usage_reports_service.get_account_summary(
account_id=account_id, billingmonth=billing_month
).get_result()
response = usage_reports_service.get_account_summary(
account_id=account_id,
billingmonth=billing_month,
)
account_summary = response.get_result()

print(json.dumps(account_summary, indent=2))

Expand All @@ -149,11 +151,14 @@ def test_get_account_usage_example(self):
"""
try:
print('\nget_account_usage() result:')

# begin-get_account_usage

account_usage = usage_reports_service.get_account_usage(
account_id=account_id, billingmonth=billing_month
).get_result()
response = usage_reports_service.get_account_usage(
account_id=account_id,
billingmonth=billing_month,
)
account_usage = response.get_result()

print(json.dumps(account_usage, indent=2))

Expand All @@ -169,11 +174,15 @@ def test_get_resource_group_usage_example(self):
"""
try:
print('\nget_resource_group_usage() result:')

# begin-get_resource_group_usage

resource_group_usage = usage_reports_service.get_resource_group_usage(
account_id=account_id, resource_group_id=resource_group_id, billingmonth=billing_month
).get_result()
response = usage_reports_service.get_resource_group_usage(
account_id=account_id,
resource_group_id=resource_group_id,
billingmonth=billing_month,
)
resource_group_usage = response.get_result()

print(json.dumps(resource_group_usage, indent=2))

Expand All @@ -182,43 +191,30 @@ def test_get_resource_group_usage_example(self):
except ApiException as e:
pytest.fail(str(e))

@needscredentials
def test_get_org_usage_example(self):
"""
get_org_usage request example
"""
try:
print('\nget_org_usage() result:')
# begin-get_org_usage

org_usage = usage_reports_service.get_org_usage(
account_id=account_id, organization_id=org_id, billingmonth=billing_month
).get_result()

print(json.dumps(org_usage, indent=2))

# end-get_org_usage

except ApiException as e:
pytest.fail(str(e))

@needscredentials
def test_get_resource_usage_account_example(self):
"""
get_resource_usage_account request example
"""
try:
print('\nget_resource_usage_account() result:')

# begin-get_resource_usage_account

instances_usage = usage_reports_service.get_resource_usage_account(
account_id=account_id, billingmonth=billing_month
).get_result()
all_results = []
pager = GetResourceUsageAccountPager(
client=usage_reports_service,
account_id=account_id,
billingmonth=billing_month,
)
while pager.has_next():
next_page = pager.get_next()
assert next_page is not None
all_results.extend(next_page)

print(json.dumps(instances_usage, indent=2))
print(json.dumps(all_results, indent=2))

# end-get_resource_usage_account

except ApiException as e:
pytest.fail(str(e))

Expand All @@ -229,16 +225,24 @@ def test_get_resource_usage_resource_group_example(self):
"""
try:
print('\nget_resource_usage_resource_group() result:')

# begin-get_resource_usage_resource_group

instances_usage = usage_reports_service.get_resource_usage_resource_group(
account_id=account_id, resource_group_id=resource_group_id, billingmonth=billing_month
).get_result()
all_results = []
pager = GetResourceUsageResourceGroupPager(
client=usage_reports_service,
account_id=account_id,
resource_group_id=resource_group_id,
billingmonth=billing_month,
)
while pager.has_next():
next_page = pager.get_next()
assert next_page is not None
all_results.extend(next_page)

print(json.dumps(instances_usage, indent=2))
print(json.dumps(all_results, indent=2))

# end-get_resource_usage_resource_group

except ApiException as e:
pytest.fail(str(e))

Expand All @@ -249,15 +253,43 @@ def test_get_resource_usage_org_example(self):
"""
try:
print('\nget_resource_usage_org() result:')

# begin-get_resource_usage_org

instances_usage = usage_reports_service.get_resource_usage_org(
all_results = []
pager = GetResourceUsageOrgPager(
client=usage_reports_service,
account_id=account_id,
organization_id=org_id,
billingmonth=billing_month,
)
while pager.has_next():
next_page = pager.get_next()
assert next_page is not None
all_results.extend(next_page)

print(json.dumps(all_results, indent=2))

# end-get_resource_usage_org
except ApiException as e:
pytest.fail(str(e))

@needscredentials
def test_get_org_usage_example(self):
"""
get_org_usage request example
"""
try:
print('\nget_org_usage() result:')
# begin-get_org_usage

org_usage = usage_reports_service.get_org_usage(
account_id=account_id, organization_id=org_id, billingmonth=billing_month
).get_result()

print(json.dumps(instances_usage, indent=2))
print(json.dumps(org_usage, indent=2))

# end-get_resource_usage_org
# end-get_org_usage

except ApiException as e:
pytest.fail(str(e))
Expand All @@ -269,6 +301,7 @@ def test_create_reports_snapshot_config_example(self):
"""
try:
print('\ncreate_reports_snapshot_config() result:')

# begin-create_reports_snapshot_config

response = usage_reports_service.create_reports_snapshot_config(
Expand All @@ -293,6 +326,7 @@ def test_get_reports_snapshot_config_example(self):
"""
try:
print('\nget_reports_snapshot_config() result:')

# begin-get_reports_snapshot_config

response = usage_reports_service.get_reports_snapshot_config(
Expand All @@ -314,10 +348,12 @@ def test_update_reports_snapshot_config_example(self):
"""
try:
print('\nupdate_reports_snapshot_config() result:')

# begin-update_reports_snapshot_config

response = usage_reports_service.update_reports_snapshot_config(
account_id=account_id, report_types=["account_summary", "enterprise_summary"]
account_id=account_id,
report_types=["account_summary", "enterprise_summary"],
)
snapshot_config = response.get_result()

Expand All @@ -335,6 +371,7 @@ def test_validate_reports_snapshot_config_example(self):
"""
try:
print('\nvalidate_reports_snapshot_config() result:')

# begin-validate_reports_snapshot_config

response = usage_reports_service.validate_reports_snapshot_config(
Expand All @@ -359,7 +396,9 @@ def test_get_reports_snapshot_example(self):
"""
try:
print('\nget_reports_snapshot() result:')

# begin-get_reports_snapshot

all_results = []
pager = GetReportsSnapshotPager(
client=usage_reports_service,
Expand All @@ -377,7 +416,6 @@ def test_get_reports_snapshot_example(self):
print(json.dumps(all_results, indent=2))

# end-get_reports_snapshot

except ApiException as e:
pytest.fail(str(e))

Expand Down
Loading

0 comments on commit 87a3e6f

Please sign in to comment.