Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Usage Reports): add "created_by_email_id" to Offer schema #274

Merged
merged 5 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions ibm_platform_services/usage_reports_v4.py
Original file line number Diff line number Diff line change
Expand Up @@ -2171,6 +2171,7 @@ class Offer:
:param float credits_total: The total credits before applying the offer.
:param str offer_template: The template with which the offer was generated.
:param datetime valid_from: The date from which the offer is valid.
:param str created_by_email_id: The offer's creator's email id.
:param datetime expires_on: The date until the offer is valid.
:param OfferCredits credits: Credit information related to an offer.
"""
Expand All @@ -2181,6 +2182,7 @@ def __init__(
credits_total: float,
offer_template: str,
valid_from: datetime,
created_by_email_id: str,
expires_on: datetime,
credits: 'OfferCredits',
) -> None:
Expand All @@ -2191,13 +2193,15 @@ def __init__(
:param float credits_total: The total credits before applying the offer.
:param str offer_template: The template with which the offer was generated.
:param datetime valid_from: The date from which the offer is valid.
:param str created_by_email_id: The offer's creator's email id.
:param datetime expires_on: The date until the offer is valid.
:param OfferCredits credits: Credit information related to an offer.
"""
self.offer_id = offer_id
self.credits_total = credits_total
self.offer_template = offer_template
self.valid_from = valid_from
self.created_by_email_id = created_by_email_id
self.expires_on = expires_on
self.credits = credits

Expand All @@ -2221,6 +2225,10 @@ def from_dict(cls, _dict: Dict) -> 'Offer':
args['valid_from'] = string_to_datetime(valid_from)
else:
raise ValueError('Required property \'valid_from\' not present in Offer JSON')
if (created_by_email_id := _dict.get('created_by_email_id')) is not None:
args['created_by_email_id'] = created_by_email_id
else:
raise ValueError('Required property \'created_by_email_id\' not present in Offer JSON')
if (expires_on := _dict.get('expires_on')) is not None:
args['expires_on'] = string_to_datetime(expires_on)
else:
Expand All @@ -2247,6 +2255,8 @@ def to_dict(self) -> Dict:
_dict['offer_template'] = self.offer_template
if hasattr(self, 'valid_from') and self.valid_from is not None:
_dict['valid_from'] = datetime_to_string(self.valid_from)
if hasattr(self, 'created_by_email_id') and self.created_by_email_id is not None:
_dict['created_by_email_id'] = self.created_by_email_id
if hasattr(self, 'expires_on') and self.expires_on is not None:
_dict['expires_on'] = datetime_to_string(self.expires_on)
if hasattr(self, 'credits') and self.credits is not None:
Expand Down
6 changes: 4 additions & 2 deletions test/unit/test_usage_reports_v4.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def test_get_account_summary_all_params(self):
"""
# Set up mock
url = preprocess_url('/v4/accounts/testString/summary/testString')
mock_response = '{"account_id": "account_id", "account_resources": [{"resource_id": "resource_id", "catalog_id": "catalog_id", "resource_name": "resource_name", "billable_cost": 13, "billable_rated_cost": 19, "non_billable_cost": 17, "non_billable_rated_cost": 23, "plans": [{"plan_id": "plan_id", "plan_name": "plan_name", "pricing_region": "pricing_region", "pricing_plan_id": "pricing_plan_id", "billable": true, "cost": 4, "rated_cost": 10, "usage": [{"metric": "UP-TIME", "metric_name": "UP-TIME", "quantity": 711.11, "rateable_quantity": 700, "cost": 123.45, "rated_cost": 130.0, "price": ["anyValue"], "unit": "HOURS", "unit_name": "HOURS", "non_chargeable": true, "discounts": [{"ref": "Discount-d27beddb-111b-4bbf-8cb1-b770f531c1a9", "name": "platform-discount", "display_name": "Platform Service Discount", "discount": 5}], "volume_discount": 15, "volume_cost": 11}], "discounts": [{"ref": "Discount-d27beddb-111b-4bbf-8cb1-b770f531c1a9", "name": "platform-discount", "display_name": "Platform Service Discount", "discount": 5}], "pending": true}], "discounts": [{"ref": "Discount-d27beddb-111b-4bbf-8cb1-b770f531c1a9", "name": "platform-discount", "display_name": "Platform Service Discount", "discount": 5}]}], "month": "month", "billing_country_code": "billing_country_code", "billing_currency_code": "billing_currency_code", "resources": {"billable_cost": 13, "non_billable_cost": 17}, "offers": [{"offer_id": "offer_id", "credits_total": 13, "offer_template": "offer_template", "valid_from": "2019-01-01T12:00:00.000Z", "expires_on": "2019-01-01T12:00:00.000Z", "credits": {"starting_balance": 16, "used": 4, "balance": 7}}], "support": [{"cost": 4, "type": "type", "overage": 7}], "support_resources": ["anyValue"], "subscription": {"overage": 7, "subscriptions": [{"subscription_id": "subscription_id", "charge_agreement_number": "charge_agreement_number", "type": "type", "subscription_amount": 19, "start": "2019-01-01T12:00:00.000Z", "end": "2019-01-01T12:00:00.000Z", "credits_total": 13, "terms": [{"start": "2019-01-01T12:00:00.000Z", "end": "2019-01-01T12:00:00.000Z", "credits": {"total": 5, "starting_balance": 16, "used": 4, "balance": 7}}]}]}}'
mock_response = '{"account_id": "account_id", "account_resources": [{"resource_id": "resource_id", "catalog_id": "catalog_id", "resource_name": "resource_name", "billable_cost": 13, "billable_rated_cost": 19, "non_billable_cost": 17, "non_billable_rated_cost": 23, "plans": [{"plan_id": "plan_id", "plan_name": "plan_name", "pricing_region": "pricing_region", "pricing_plan_id": "pricing_plan_id", "billable": true, "cost": 4, "rated_cost": 10, "usage": [{"metric": "UP-TIME", "metric_name": "UP-TIME", "quantity": 711.11, "rateable_quantity": 700, "cost": 123.45, "rated_cost": 130.0, "price": ["anyValue"], "unit": "HOURS", "unit_name": "HOURS", "non_chargeable": true, "discounts": [{"ref": "Discount-d27beddb-111b-4bbf-8cb1-b770f531c1a9", "name": "platform-discount", "display_name": "Platform Service Discount", "discount": 5}], "volume_discount": 15, "volume_cost": 11}], "discounts": [{"ref": "Discount-d27beddb-111b-4bbf-8cb1-b770f531c1a9", "name": "platform-discount", "display_name": "Platform Service Discount", "discount": 5}], "pending": true}], "discounts": [{"ref": "Discount-d27beddb-111b-4bbf-8cb1-b770f531c1a9", "name": "platform-discount", "display_name": "Platform Service Discount", "discount": 5}]}], "month": "month", "billing_country_code": "billing_country_code", "billing_currency_code": "billing_currency_code", "resources": {"billable_cost": 13, "non_billable_cost": 17}, "offers": [{"offer_id": "offer_id", "credits_total": 13, "offer_template": "offer_template", "valid_from": "2019-01-01T12:00:00.000Z", "created_by_email_id": "created_by_email_id", "expires_on": "2019-01-01T12:00:00.000Z", "credits": {"starting_balance": 16, "used": 4, "balance": 7}}], "support": [{"cost": 4, "type": "type", "overage": 7}], "support_resources": ["anyValue"], "subscription": {"overage": 7, "subscriptions": [{"subscription_id": "subscription_id", "charge_agreement_number": "charge_agreement_number", "type": "type", "subscription_amount": 19, "start": "2019-01-01T12:00:00.000Z", "end": "2019-01-01T12:00:00.000Z", "credits_total": 13, "terms": [{"start": "2019-01-01T12:00:00.000Z", "end": "2019-01-01T12:00:00.000Z", "credits": {"total": 5, "starting_balance": 16, "used": 4, "balance": 7}}]}]}}'
responses.add(
responses.GET,
url,
Expand Down Expand Up @@ -148,7 +148,7 @@ def test_get_account_summary_value_error(self):
"""
# Set up mock
url = preprocess_url('/v4/accounts/testString/summary/testString')
mock_response = '{"account_id": "account_id", "account_resources": [{"resource_id": "resource_id", "catalog_id": "catalog_id", "resource_name": "resource_name", "billable_cost": 13, "billable_rated_cost": 19, "non_billable_cost": 17, "non_billable_rated_cost": 23, "plans": [{"plan_id": "plan_id", "plan_name": "plan_name", "pricing_region": "pricing_region", "pricing_plan_id": "pricing_plan_id", "billable": true, "cost": 4, "rated_cost": 10, "usage": [{"metric": "UP-TIME", "metric_name": "UP-TIME", "quantity": 711.11, "rateable_quantity": 700, "cost": 123.45, "rated_cost": 130.0, "price": ["anyValue"], "unit": "HOURS", "unit_name": "HOURS", "non_chargeable": true, "discounts": [{"ref": "Discount-d27beddb-111b-4bbf-8cb1-b770f531c1a9", "name": "platform-discount", "display_name": "Platform Service Discount", "discount": 5}], "volume_discount": 15, "volume_cost": 11}], "discounts": [{"ref": "Discount-d27beddb-111b-4bbf-8cb1-b770f531c1a9", "name": "platform-discount", "display_name": "Platform Service Discount", "discount": 5}], "pending": true}], "discounts": [{"ref": "Discount-d27beddb-111b-4bbf-8cb1-b770f531c1a9", "name": "platform-discount", "display_name": "Platform Service Discount", "discount": 5}]}], "month": "month", "billing_country_code": "billing_country_code", "billing_currency_code": "billing_currency_code", "resources": {"billable_cost": 13, "non_billable_cost": 17}, "offers": [{"offer_id": "offer_id", "credits_total": 13, "offer_template": "offer_template", "valid_from": "2019-01-01T12:00:00.000Z", "expires_on": "2019-01-01T12:00:00.000Z", "credits": {"starting_balance": 16, "used": 4, "balance": 7}}], "support": [{"cost": 4, "type": "type", "overage": 7}], "support_resources": ["anyValue"], "subscription": {"overage": 7, "subscriptions": [{"subscription_id": "subscription_id", "charge_agreement_number": "charge_agreement_number", "type": "type", "subscription_amount": 19, "start": "2019-01-01T12:00:00.000Z", "end": "2019-01-01T12:00:00.000Z", "credits_total": 13, "terms": [{"start": "2019-01-01T12:00:00.000Z", "end": "2019-01-01T12:00:00.000Z", "credits": {"total": 5, "starting_balance": 16, "used": 4, "balance": 7}}]}]}}'
mock_response = '{"account_id": "account_id", "account_resources": [{"resource_id": "resource_id", "catalog_id": "catalog_id", "resource_name": "resource_name", "billable_cost": 13, "billable_rated_cost": 19, "non_billable_cost": 17, "non_billable_rated_cost": 23, "plans": [{"plan_id": "plan_id", "plan_name": "plan_name", "pricing_region": "pricing_region", "pricing_plan_id": "pricing_plan_id", "billable": true, "cost": 4, "rated_cost": 10, "usage": [{"metric": "UP-TIME", "metric_name": "UP-TIME", "quantity": 711.11, "rateable_quantity": 700, "cost": 123.45, "rated_cost": 130.0, "price": ["anyValue"], "unit": "HOURS", "unit_name": "HOURS", "non_chargeable": true, "discounts": [{"ref": "Discount-d27beddb-111b-4bbf-8cb1-b770f531c1a9", "name": "platform-discount", "display_name": "Platform Service Discount", "discount": 5}], "volume_discount": 15, "volume_cost": 11}], "discounts": [{"ref": "Discount-d27beddb-111b-4bbf-8cb1-b770f531c1a9", "name": "platform-discount", "display_name": "Platform Service Discount", "discount": 5}], "pending": true}], "discounts": [{"ref": "Discount-d27beddb-111b-4bbf-8cb1-b770f531c1a9", "name": "platform-discount", "display_name": "Platform Service Discount", "discount": 5}]}], "month": "month", "billing_country_code": "billing_country_code", "billing_currency_code": "billing_currency_code", "resources": {"billable_cost": 13, "non_billable_cost": 17}, "offers": [{"offer_id": "offer_id", "credits_total": 13, "offer_template": "offer_template", "valid_from": "2019-01-01T12:00:00.000Z", "created_by_email_id": "created_by_email_id", "expires_on": "2019-01-01T12:00:00.000Z", "credits": {"starting_balance": 16, "used": 4, "balance": 7}}], "support": [{"cost": 4, "type": "type", "overage": 7}], "support_resources": ["anyValue"], "subscription": {"overage": 7, "subscriptions": [{"subscription_id": "subscription_id", "charge_agreement_number": "charge_agreement_number", "type": "type", "subscription_amount": 19, "start": "2019-01-01T12:00:00.000Z", "end": "2019-01-01T12:00:00.000Z", "credits_total": 13, "terms": [{"start": "2019-01-01T12:00:00.000Z", "end": "2019-01-01T12:00:00.000Z", "credits": {"total": 5, "starting_balance": 16, "used": 4, "balance": 7}}]}]}}'
responses.add(
responses.GET,
url,
Expand Down Expand Up @@ -2255,6 +2255,7 @@ def test_account_summary_serialization(self):
offer_model['credits_total'] = 72.5
offer_model['offer_template'] = 'testString'
offer_model['valid_from'] = '2019-01-01T12:00:00Z'
offer_model['created_by_email_id'] = 'testString'
offer_model['expires_on'] = '2019-01-01T12:00:00Z'
offer_model['credits'] = offer_credits_model

Expand Down Expand Up @@ -2745,6 +2746,7 @@ def test_offer_serialization(self):
offer_model_json['credits_total'] = 72.5
offer_model_json['offer_template'] = 'testString'
offer_model_json['valid_from'] = '2019-01-01T12:00:00Z'
offer_model_json['created_by_email_id'] = 'testString'
offer_model_json['expires_on'] = '2019-01-01T12:00:00Z'
offer_model_json['credits'] = offer_credits_model

Expand Down