From f554964c3952913bb2219e438b933f7148d6f9a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81kos=20Sztremi?= Date: Thu, 23 Apr 2026 13:39:27 +0200 Subject: [PATCH 1/8] feat (Platform Notifications): add platform notifications to the sdk MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ákos Sztremi --- ...test_platform_notifications_v1_examples.py | 385 +++ .../platform_notifications_v1.py | 2812 +++++++++++++++++ .../test_platform_notifications_v1.py | 299 ++ test/unit/test_platform_notifications_v1.py | 2374 ++++++++++++++ 4 files changed, 5870 insertions(+) create mode 100644 examples/test_platform_notifications_v1_examples.py create mode 100644 ibm_platform_services/platform_notifications_v1.py create mode 100644 test/integration/test_platform_notifications_v1.py create mode 100644 test/unit/test_platform_notifications_v1.py diff --git a/examples/test_platform_notifications_v1_examples.py b/examples/test_platform_notifications_v1_examples.py new file mode 100644 index 00000000..a86e0a67 --- /dev/null +++ b/examples/test_platform_notifications_v1_examples.py @@ -0,0 +1,385 @@ +# -*- coding: utf-8 -*- +# (C) Copyright IBM Corp. 2026. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +""" +Examples for PlatformNotificationsV1 +""" + +from ibm_cloud_sdk_core import ApiException, read_external_sources +import os +import pytest +from ibm_platform_services.platform_notifications_v1 import * + +# +# This file provides an example of how to use the Platform Notifications service. +# +# The following configuration properties are assumed to be defined: +# PLATFORM_NOTIFICATIONS_URL= +# PLATFORM_NOTIFICATIONS_AUTH_TYPE=iam +# PLATFORM_NOTIFICATIONS_APIKEY= +# PLATFORM_NOTIFICATIONS_AUTH_URL= +# +# These configuration properties can be exported as environment variables, or stored +# in a configuration file and then: +# export IBM_CREDENTIALS_FILE= +# +config_file = 'platform_notifications_v1.env' + +platform_notifications_service = None + +config = None + + +############################################################################## +# Start of Examples for Service: PlatformNotificationsV1 +############################################################################## +# region +class TestPlatformNotificationsV1Examples: + """ + Example Test Class for PlatformNotificationsV1 + """ + + @classmethod + def setup_class(cls): + global platform_notifications_service + if os.path.exists(config_file): + os.environ['IBM_CREDENTIALS_FILE'] = config_file + + # begin-common + + platform_notifications_service = PlatformNotificationsV1.new_instance( + ) + + # end-common + assert platform_notifications_service is not None + + # Load the configuration + global config + config = read_external_sources(PlatformNotificationsV1.DEFAULT_SERVICE_NAME) + + print('Setup complete.') + + needscredentials = pytest.mark.skipif( + not os.path.exists(config_file), reason="External configuration not available, skipping..." + ) + + @needscredentials + def test_list_distribution_list_destinations_example(self): + """ + list_distribution_list_destinations request example + """ + try: + print('\nlist_distribution_list_destinations() result:') + + # begin-list_distribution_list_destinations + + response = platform_notifications_service.list_distribution_list_destinations( + account_id='a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6', + ) + add_destination_collection = response.get_result() + + print(json.dumps(add_destination_collection, indent=2)) + + # end-list_distribution_list_destinations + + except ApiException as e: + pytest.fail(str(e)) + + @needscredentials + def test_create_distribution_list_destination_example(self): + """ + create_distribution_list_destination request example + """ + try: + print('\ncreate_distribution_list_destination() result:') + + # begin-create_distribution_list_destination + + add_destination_prototype_model = { + 'destination_id': '12345678-1234-1234-1234-123456789012', + 'destination_type': 'event_notifications', + } + + response = platform_notifications_service.create_distribution_list_destination( + account_id='a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6', + add_destination_prototype=add_destination_prototype_model, + ) + add_destination = response.get_result() + + print(json.dumps(add_destination, indent=2)) + + # end-create_distribution_list_destination + + except ApiException as e: + pytest.fail(str(e)) + + @needscredentials + def test_get_distribution_list_destination_example(self): + """ + get_distribution_list_destination request example + """ + try: + print('\nget_distribution_list_destination() result:') + + # begin-get_distribution_list_destination + + response = platform_notifications_service.get_distribution_list_destination( + account_id='a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6', + destination_id='12345678-1234-1234-1234-123456789012', + ) + add_destination = response.get_result() + + print(json.dumps(add_destination, indent=2)) + + # end-get_distribution_list_destination + + except ApiException as e: + pytest.fail(str(e)) + + @needscredentials + def test_test_distribution_list_destination_example(self): + """ + test_distribution_list_destination request example + """ + try: + print('\ntest_distribution_list_destination() result:') + + # begin-test_distribution_list_destination + + test_destination_request_body_prototype_model = { + 'destination_type': 'event_notifications', + 'notification_type': 'incident', + } + + response = platform_notifications_service.test_distribution_list_destination( + account_id='a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6', + destination_id='12345678-1234-1234-1234-123456789012', + test_destination_request_body_prototype=test_destination_request_body_prototype_model, + ) + test_destination_response_body = response.get_result() + + print(json.dumps(test_destination_response_body, indent=2)) + + # end-test_distribution_list_destination + + except ApiException as e: + pytest.fail(str(e)) + + @needscredentials + def test_create_preferences_example(self): + """ + create_preferences request example + """ + try: + print('\ncreate_preferences() result:') + + # begin-create_preferences + + preference_value_with_updates_model = { + 'channels': ['email'], + 'updates': True, + } + + preference_value_without_updates_model = { + 'channels': ['email'], + } + + response = platform_notifications_service.create_preferences( + iam_id='IBMid-1234567890', + incident_severity1=preference_value_with_updates_model, + ordering_review=preference_value_without_updates_model, + account_id='a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6', + ) + preferences_object = response.get_result() + + print(json.dumps(preferences_object, indent=2)) + + # end-create_preferences + + except ApiException as e: + pytest.fail(str(e)) + + @needscredentials + def test_get_preferences_example(self): + """ + get_preferences request example + """ + try: + print('\nget_preferences() result:') + + # begin-get_preferences + + response = platform_notifications_service.get_preferences( + iam_id='IBMid-1234567890', + account_id='a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6', + ) + preferences_object = response.get_result() + + print(json.dumps(preferences_object, indent=2)) + + # end-get_preferences + + except ApiException as e: + pytest.fail(str(e)) + + @needscredentials + def test_replace_notification_preferences_example(self): + """ + replace_notification_preferences request example + """ + try: + print('\nreplace_notification_preferences() result:') + + # begin-replace_notification_preferences + + preference_value_with_updates_model = { + 'channels': ['email'], + 'updates': True, + } + + preference_value_without_updates_model = { + 'channels': ['email'], + } + + response = platform_notifications_service.replace_notification_preferences( + iam_id='IBMid-1234567890', + incident_severity1=preference_value_with_updates_model, + ordering_review=preference_value_without_updates_model, + account_id='a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6', + ) + preferences_object = response.get_result() + + print(json.dumps(preferences_object, indent=2)) + + # end-replace_notification_preferences + + except ApiException as e: + pytest.fail(str(e)) + + @needscredentials + def test_list_notifications_example(self): + """ + list_notifications request example + """ + try: + print('\nlist_notifications() result:') + + # begin-list_notifications + + all_results = [] + pager = NotificationsPager( + client=platform_notifications_service, + account_id='a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6', + limit=50, + ) + 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-list_notifications + except ApiException as e: + pytest.fail(str(e)) + + @needscredentials + def test_get_acknowledgement_example(self): + """ + get_acknowledgement request example + """ + try: + print('\nget_acknowledgement() result:') + + # begin-get_acknowledgement + + response = platform_notifications_service.get_acknowledgement( + account_id='1369339417d906e5620b8d861d40cfd7', + ) + acknowledgement = response.get_result() + + print(json.dumps(acknowledgement, indent=2)) + + # end-get_acknowledgement + + except ApiException as e: + pytest.fail(str(e)) + + @needscredentials + def test_replace_notification_acknowledgement_example(self): + """ + replace_notification_acknowledgement request example + """ + try: + print('\nreplace_notification_acknowledgement() result:') + + # begin-replace_notification_acknowledgement + + response = platform_notifications_service.replace_notification_acknowledgement( + last_acknowledged_id='1772804159452', + account_id='1369339417d906e5620b8d861d40cfd7', + ) + acknowledgement = response.get_result() + + print(json.dumps(acknowledgement, indent=2)) + + # end-replace_notification_acknowledgement + + except ApiException as e: + pytest.fail(str(e)) + + @needscredentials + def test_delete_distribution_list_destination_example(self): + """ + delete_distribution_list_destination request example + """ + try: + # begin-delete_distribution_list_destination + + response = platform_notifications_service.delete_distribution_list_destination( + account_id='a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6', + destination_id='12345678-1234-1234-1234-123456789012', + ) + + # end-delete_distribution_list_destination + print('\ndelete_distribution_list_destination() response status code: ', response.get_status_code()) + + except ApiException as e: + pytest.fail(str(e)) + + @needscredentials + def test_delete_notification_preferences_example(self): + """ + delete_notification_preferences request example + """ + try: + # begin-delete_notification_preferences + + response = platform_notifications_service.delete_notification_preferences( + iam_id='IBMid-1234567890', + account_id='a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6', + ) + + # end-delete_notification_preferences + print('\ndelete_notification_preferences() response status code: ', response.get_status_code()) + + except ApiException as e: + pytest.fail(str(e)) + + +# endregion +############################################################################## +# End of Examples for Service: PlatformNotificationsV1 +############################################################################## diff --git a/ibm_platform_services/platform_notifications_v1.py b/ibm_platform_services/platform_notifications_v1.py new file mode 100644 index 00000000..02454629 --- /dev/null +++ b/ibm_platform_services/platform_notifications_v1.py @@ -0,0 +1,2812 @@ +# coding: utf-8 + +# (C) Copyright IBM Corp. 2026. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# IBM OpenAPI SDK Code Generator Version: 3.108.0-56772134-20251111-102802 + +""" +**This API is currently in beta and subject to change.** +API for managing notification distribution lists for IBM Cloud accounts. + +API Version: 1.0.0 +""" + +from enum import Enum +from typing import Dict, List, Optional +import json +import sys + +from ibm_cloud_sdk_core import BaseService, DetailedResponse +from ibm_cloud_sdk_core.authenticators.authenticator import Authenticator +from ibm_cloud_sdk_core.get_authenticator import get_authenticator_from_environment +from ibm_cloud_sdk_core.utils import convert_model + +from .common import get_sdk_headers + +############################################################################## +# Service +############################################################################## + + +class PlatformNotificationsV1(BaseService): + """The Platform Notifications V1 service.""" + + DEFAULT_SERVICE_URL = 'https://notifications.cloud.ibm.com/api' + DEFAULT_SERVICE_NAME = 'platform_notifications' + + @classmethod + def new_instance( + cls, + service_name: str = DEFAULT_SERVICE_NAME, + ) -> 'PlatformNotificationsV1': + """ + Return a new client for the Platform Notifications service using the + specified parameters and external configuration. + """ + authenticator = get_authenticator_from_environment(service_name) + service = cls( + authenticator + ) + service.configure_service(service_name) + return service + + def __init__( + self, + authenticator: Authenticator = None, + ) -> None: + """ + Construct a new client for the Platform Notifications service. + + :param Authenticator authenticator: The authenticator specifies the authentication mechanism. + Get up to date information from https://github.com/IBM/python-sdk-core/blob/main/README.md + about initializing the authenticator of your choice. + """ + BaseService.__init__(self, service_url=self.DEFAULT_SERVICE_URL, authenticator=authenticator) + + ######################### + # Distribution Lists + ######################### + + def list_distribution_list_destinations( + self, + account_id: str, + **kwargs, + ) -> DetailedResponse: + """ + Get all destination entries. + + Retrieve all destinations in the distribution list for the specified account. + + :param str account_id: The IBM Cloud account ID. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse with `dict` result representing a `AddDestinationCollection` object + """ + + if not account_id: + raise ValueError('account_id must be provided') + headers = {} + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='list_distribution_list_destinations', + ) + headers.update(sdk_headers) + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + del kwargs['headers'] + headers['Accept'] = 'application/json' + + path_param_keys = ['account_id'] + path_param_values = self.encode_path_vars(account_id) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/v1/distribution_lists/{account_id}/destinations'.format(**path_param_dict) + request = self.prepare_request( + method='GET', + url=url, + headers=headers, + ) + + response = self.send(request, **kwargs) + return response + + def create_distribution_list_destination( + self, + account_id: str, + add_destination_prototype: 'AddDestinationPrototype', + **kwargs, + ) -> DetailedResponse: + """ + Add a destination entry. + + Add a destination entry to the distribution list. A maximum of 10 destination + entries per destination type. In terms of enterprise accounts, you can provide an + Event Notifications destination that is from a different account than the + distribution list account, provided these two accounts are from the same + enterprise and the user has permission to manage the Event Notifications + destinations on both accounts. + + :param str account_id: The IBM Cloud account ID. + :param AddDestinationPrototype add_destination_prototype: + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse with `dict` result representing a `AddDestination` object + """ + + if not account_id: + raise ValueError('account_id must be provided') + if add_destination_prototype is None: + raise ValueError('add_destination_prototype must be provided') + if isinstance(add_destination_prototype, AddDestinationPrototype): + add_destination_prototype = convert_model(add_destination_prototype) + headers = {} + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='create_distribution_list_destination', + ) + headers.update(sdk_headers) + + data = json.dumps(add_destination_prototype) + headers['content-type'] = 'application/json' + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + del kwargs['headers'] + headers['Accept'] = 'application/json' + + path_param_keys = ['account_id'] + path_param_values = self.encode_path_vars(account_id) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/v1/distribution_lists/{account_id}/destinations'.format(**path_param_dict) + request = self.prepare_request( + method='POST', + url=url, + headers=headers, + data=data, + ) + + response = self.send(request, **kwargs) + return response + + def get_distribution_list_destination( + self, + account_id: str, + destination_id: str, + **kwargs, + ) -> DetailedResponse: + """ + Get a destination entry. + + Retrieve a specific destination from the distribution list of the account. + + :param str account_id: The IBM Cloud account ID. + :param str destination_id: The ID of the destination. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse with `dict` result representing a `AddDestination` object + """ + + if not account_id: + raise ValueError('account_id must be provided') + if not destination_id: + raise ValueError('destination_id must be provided') + headers = {} + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='get_distribution_list_destination', + ) + headers.update(sdk_headers) + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + del kwargs['headers'] + headers['Accept'] = 'application/json' + + path_param_keys = ['account_id', 'destination_id'] + path_param_values = self.encode_path_vars(account_id, destination_id) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/v1/distribution_lists/{account_id}/destinations/{destination_id}'.format(**path_param_dict) + request = self.prepare_request( + method='GET', + url=url, + headers=headers, + ) + + response = self.send(request, **kwargs) + return response + + def delete_distribution_list_destination( + self, + account_id: str, + destination_id: str, + **kwargs, + ) -> DetailedResponse: + """ + Delete destination entry. + + Remove a destination entry. + + :param str account_id: The IBM Cloud account ID. + :param str destination_id: The ID of the destination. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse + """ + + if not account_id: + raise ValueError('account_id must be provided') + if not destination_id: + raise ValueError('destination_id must be provided') + headers = {} + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='delete_distribution_list_destination', + ) + headers.update(sdk_headers) + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + del kwargs['headers'] + + path_param_keys = ['account_id', 'destination_id'] + path_param_values = self.encode_path_vars(account_id, destination_id) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/v1/distribution_lists/{account_id}/destinations/{destination_id}'.format(**path_param_dict) + request = self.prepare_request( + method='DELETE', + url=url, + headers=headers, + ) + + response = self.send(request, **kwargs) + return response + + def test_distribution_list_destination( + self, + account_id: str, + destination_id: str, + test_destination_request_body_prototype: 'TestDestinationRequestBodyPrototype', + **kwargs, + ) -> DetailedResponse: + """ + Test destination entry. + + Send a test notification to a destination in the distribution list. This allows + you to verify that the destination is properly configured and can receive + notifications. + + :param str account_id: The IBM Cloud account ID. + :param str destination_id: The ID of the destination. + :param TestDestinationRequestBodyPrototype + test_destination_request_body_prototype: + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse with `dict` result representing a `TestDestinationResponseBody` object + """ + + if not account_id: + raise ValueError('account_id must be provided') + if not destination_id: + raise ValueError('destination_id must be provided') + if test_destination_request_body_prototype is None: + raise ValueError('test_destination_request_body_prototype must be provided') + if isinstance(test_destination_request_body_prototype, TestDestinationRequestBodyPrototype): + test_destination_request_body_prototype = convert_model(test_destination_request_body_prototype) + headers = {} + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='test_distribution_list_destination', + ) + headers.update(sdk_headers) + + data = json.dumps(test_destination_request_body_prototype) + headers['content-type'] = 'application/json' + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + del kwargs['headers'] + headers['Accept'] = 'application/json' + + path_param_keys = ['account_id', 'destination_id'] + path_param_values = self.encode_path_vars(account_id, destination_id) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/v1/distribution_lists/{account_id}/destinations/{destination_id}/test'.format(**path_param_dict) + request = self.prepare_request( + method='POST', + url=url, + headers=headers, + data=data, + ) + + response = self.send(request, **kwargs) + return response + + ######################### + # User Preferences + ######################### + + def create_preferences( + self, + iam_id: str, + *, + incident_severity1: Optional['PreferenceValueWithUpdates'] = None, + incident_severity2: Optional['PreferenceValueWithUpdates'] = None, + incident_severity3: Optional['PreferenceValueWithUpdates'] = None, + incident_severity4: Optional['PreferenceValueWithUpdates'] = None, + maintenance_high: Optional['PreferenceValueWithUpdates'] = None, + maintenance_medium: Optional['PreferenceValueWithUpdates'] = None, + maintenance_low: Optional['PreferenceValueWithUpdates'] = None, + announcements_major: Optional['PreferenceValueWithoutUpdates'] = None, + announcements_minor: Optional['PreferenceValueWithoutUpdates'] = None, + security_normal: Optional['PreferenceValueWithoutUpdates'] = None, + account_normal: Optional['PreferenceValueWithoutUpdates'] = None, + billing_and_usage_order: Optional['PreferenceValueWithoutUpdates'] = None, + billing_and_usage_invoices: Optional['PreferenceValueWithoutUpdates'] = None, + billing_and_usage_payments: Optional['PreferenceValueWithoutUpdates'] = None, + billing_and_usage_subscriptions_and_promo_codes: Optional['PreferenceValueWithoutUpdates'] = None, + billing_and_usage_spending_alerts: Optional['PreferenceValueWithoutUpdates'] = None, + resourceactivity_normal: Optional['PreferenceValueWithoutUpdates'] = None, + ordering_review: Optional['PreferenceValueWithoutUpdates'] = None, + ordering_approved: Optional['PreferenceValueWithoutUpdates'] = None, + ordering_approved_vsi: Optional['PreferenceValueWithoutUpdates'] = None, + ordering_approved_server: Optional['PreferenceValueWithoutUpdates'] = None, + provisioning_reload_complete: Optional['PreferenceValueWithoutUpdates'] = None, + provisioning_complete_vsi: Optional['PreferenceValueWithoutUpdates'] = None, + provisioning_complete_server: Optional['PreferenceValueWithoutUpdates'] = None, + account_id: Optional[str] = None, + **kwargs, + ) -> DetailedResponse: + """ + Create communication preferences. + + Create communication preferences for the specified account. + + :param str iam_id: The IAM ID of the user. Must match the IAM ID in the + bearer token. + :param PreferenceValueWithUpdates incident_severity1: (optional) Preference + settings for notification types that support updates. + :param PreferenceValueWithUpdates incident_severity2: (optional) Preference + settings for notification types that support updates. + :param PreferenceValueWithUpdates incident_severity3: (optional) Preference + settings for notification types that support updates. + :param PreferenceValueWithUpdates incident_severity4: (optional) Preference + settings for notification types that support updates. + :param PreferenceValueWithUpdates maintenance_high: (optional) Preference + settings for notification types that support updates. + :param PreferenceValueWithUpdates maintenance_medium: (optional) Preference + settings for notification types that support updates. + :param PreferenceValueWithUpdates maintenance_low: (optional) Preference + settings for notification types that support updates. + :param PreferenceValueWithoutUpdates announcements_major: (optional) + Preference settings for notification types that do not support updates. + :param PreferenceValueWithoutUpdates announcements_minor: (optional) + Preference settings for notification types that do not support updates. + :param PreferenceValueWithoutUpdates security_normal: (optional) Preference + settings for notification types that do not support updates. + :param PreferenceValueWithoutUpdates account_normal: (optional) Preference + settings for notification types that do not support updates. + :param PreferenceValueWithoutUpdates billing_and_usage_order: (optional) + Preference settings for notification types that do not support updates. + :param PreferenceValueWithoutUpdates billing_and_usage_invoices: (optional) + Preference settings for notification types that do not support updates. + :param PreferenceValueWithoutUpdates billing_and_usage_payments: (optional) + Preference settings for notification types that do not support updates. + :param PreferenceValueWithoutUpdates + billing_and_usage_subscriptions_and_promo_codes: (optional) Preference + settings for notification types that do not support updates. + :param PreferenceValueWithoutUpdates billing_and_usage_spending_alerts: + (optional) Preference settings for notification types that do not support + updates. + :param PreferenceValueWithoutUpdates resourceactivity_normal: (optional) + Preference settings for notification types that do not support updates. + :param PreferenceValueWithoutUpdates ordering_review: (optional) Preference + settings for notification types that do not support updates. + :param PreferenceValueWithoutUpdates ordering_approved: (optional) + Preference settings for notification types that do not support updates. + :param PreferenceValueWithoutUpdates ordering_approved_vsi: (optional) + Preference settings for notification types that do not support updates. + :param PreferenceValueWithoutUpdates ordering_approved_server: (optional) + Preference settings for notification types that do not support updates. + :param PreferenceValueWithoutUpdates provisioning_reload_complete: + (optional) Preference settings for notification types that do not support + updates. + :param PreferenceValueWithoutUpdates provisioning_complete_vsi: (optional) + Preference settings for notification types that do not support updates. + :param PreferenceValueWithoutUpdates provisioning_complete_server: + (optional) Preference settings for notification types that do not support + updates. + :param str account_id: (optional) The IBM Cloud account ID. If not + provided, the account ID from the bearer token will be used. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse with `dict` result representing a `PreferencesObject` object + """ + + if not iam_id: + raise ValueError('iam_id must be provided') + if incident_severity1 is not None: + incident_severity1 = convert_model(incident_severity1) + if incident_severity2 is not None: + incident_severity2 = convert_model(incident_severity2) + if incident_severity3 is not None: + incident_severity3 = convert_model(incident_severity3) + if incident_severity4 is not None: + incident_severity4 = convert_model(incident_severity4) + if maintenance_high is not None: + maintenance_high = convert_model(maintenance_high) + if maintenance_medium is not None: + maintenance_medium = convert_model(maintenance_medium) + if maintenance_low is not None: + maintenance_low = convert_model(maintenance_low) + if announcements_major is not None: + announcements_major = convert_model(announcements_major) + if announcements_minor is not None: + announcements_minor = convert_model(announcements_minor) + if security_normal is not None: + security_normal = convert_model(security_normal) + if account_normal is not None: + account_normal = convert_model(account_normal) + if billing_and_usage_order is not None: + billing_and_usage_order = convert_model(billing_and_usage_order) + if billing_and_usage_invoices is not None: + billing_and_usage_invoices = convert_model(billing_and_usage_invoices) + if billing_and_usage_payments is not None: + billing_and_usage_payments = convert_model(billing_and_usage_payments) + if billing_and_usage_subscriptions_and_promo_codes is not None: + billing_and_usage_subscriptions_and_promo_codes = convert_model(billing_and_usage_subscriptions_and_promo_codes) + if billing_and_usage_spending_alerts is not None: + billing_and_usage_spending_alerts = convert_model(billing_and_usage_spending_alerts) + if resourceactivity_normal is not None: + resourceactivity_normal = convert_model(resourceactivity_normal) + if ordering_review is not None: + ordering_review = convert_model(ordering_review) + if ordering_approved is not None: + ordering_approved = convert_model(ordering_approved) + if ordering_approved_vsi is not None: + ordering_approved_vsi = convert_model(ordering_approved_vsi) + if ordering_approved_server is not None: + ordering_approved_server = convert_model(ordering_approved_server) + if provisioning_reload_complete is not None: + provisioning_reload_complete = convert_model(provisioning_reload_complete) + if provisioning_complete_vsi is not None: + provisioning_complete_vsi = convert_model(provisioning_complete_vsi) + if provisioning_complete_server is not None: + provisioning_complete_server = convert_model(provisioning_complete_server) + headers = {} + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='create_preferences', + ) + headers.update(sdk_headers) + + params = { + 'account_id': account_id, + } + + data = { + 'incident_severity1': incident_severity1, + 'incident_severity2': incident_severity2, + 'incident_severity3': incident_severity3, + 'incident_severity4': incident_severity4, + 'maintenance_high': maintenance_high, + 'maintenance_medium': maintenance_medium, + 'maintenance_low': maintenance_low, + 'announcements_major': announcements_major, + 'announcements_minor': announcements_minor, + 'security_normal': security_normal, + 'account_normal': account_normal, + 'billing_and_usage_order': billing_and_usage_order, + 'billing_and_usage_invoices': billing_and_usage_invoices, + 'billing_and_usage_payments': billing_and_usage_payments, + 'billing_and_usage_subscriptions_and_promo_codes': billing_and_usage_subscriptions_and_promo_codes, + 'billing_and_usage_spending_alerts': billing_and_usage_spending_alerts, + 'resourceactivity_normal': resourceactivity_normal, + 'ordering_review': ordering_review, + 'ordering_approved': ordering_approved, + 'ordering_approved_vsi': ordering_approved_vsi, + 'ordering_approved_server': ordering_approved_server, + 'provisioning_reload_complete': provisioning_reload_complete, + 'provisioning_complete_vsi': provisioning_complete_vsi, + 'provisioning_complete_server': provisioning_complete_server, + } + data = {k: v for (k, v) in data.items() if v is not None} + data = json.dumps(data) + headers['content-type'] = 'application/json' + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + del kwargs['headers'] + headers['Accept'] = 'application/json' + + path_param_keys = ['iam_id'] + path_param_values = self.encode_path_vars(iam_id) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/v1/notifications/{iam_id}/preferences'.format(**path_param_dict) + request = self.prepare_request( + method='POST', + url=url, + headers=headers, + params=params, + data=data, + ) + + response = self.send(request, **kwargs) + return response + + def get_preferences( + self, + iam_id: str, + *, + account_id: Optional[str] = None, + **kwargs, + ) -> DetailedResponse: + """ + Get all communication preferences for a user in an account. + + Retrieve all communication preferences of a user in an account. + + :param str iam_id: The IAM ID of the user. Must match the IAM ID in the + bearer token. + :param str account_id: (optional) The IBM Cloud account ID. If not + provided, the account ID from the bearer token will be used. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse with `dict` result representing a `PreferencesObject` object + """ + + if not iam_id: + raise ValueError('iam_id must be provided') + headers = {} + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='get_preferences', + ) + headers.update(sdk_headers) + + params = { + 'account_id': account_id, + } + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + del kwargs['headers'] + headers['Accept'] = 'application/json' + + path_param_keys = ['iam_id'] + path_param_values = self.encode_path_vars(iam_id) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/v1/notifications/{iam_id}/preferences'.format(**path_param_dict) + request = self.prepare_request( + method='GET', + url=url, + headers=headers, + params=params, + ) + + response = self.send(request, **kwargs) + return response + + def replace_notification_preferences( + self, + iam_id: str, + *, + incident_severity1: Optional['PreferenceValueWithUpdates'] = None, + incident_severity2: Optional['PreferenceValueWithUpdates'] = None, + incident_severity3: Optional['PreferenceValueWithUpdates'] = None, + incident_severity4: Optional['PreferenceValueWithUpdates'] = None, + maintenance_high: Optional['PreferenceValueWithUpdates'] = None, + maintenance_medium: Optional['PreferenceValueWithUpdates'] = None, + maintenance_low: Optional['PreferenceValueWithUpdates'] = None, + announcements_major: Optional['PreferenceValueWithoutUpdates'] = None, + announcements_minor: Optional['PreferenceValueWithoutUpdates'] = None, + security_normal: Optional['PreferenceValueWithoutUpdates'] = None, + account_normal: Optional['PreferenceValueWithoutUpdates'] = None, + billing_and_usage_order: Optional['PreferenceValueWithoutUpdates'] = None, + billing_and_usage_invoices: Optional['PreferenceValueWithoutUpdates'] = None, + billing_and_usage_payments: Optional['PreferenceValueWithoutUpdates'] = None, + billing_and_usage_subscriptions_and_promo_codes: Optional['PreferenceValueWithoutUpdates'] = None, + billing_and_usage_spending_alerts: Optional['PreferenceValueWithoutUpdates'] = None, + resourceactivity_normal: Optional['PreferenceValueWithoutUpdates'] = None, + ordering_review: Optional['PreferenceValueWithoutUpdates'] = None, + ordering_approved: Optional['PreferenceValueWithoutUpdates'] = None, + ordering_approved_vsi: Optional['PreferenceValueWithoutUpdates'] = None, + ordering_approved_server: Optional['PreferenceValueWithoutUpdates'] = None, + provisioning_reload_complete: Optional['PreferenceValueWithoutUpdates'] = None, + provisioning_complete_vsi: Optional['PreferenceValueWithoutUpdates'] = None, + provisioning_complete_server: Optional['PreferenceValueWithoutUpdates'] = None, + account_id: Optional[str] = None, + **kwargs, + ) -> DetailedResponse: + """ + Update communication preferences. + + Update communication preferences for the specified account. + + :param str iam_id: The IAM ID of the user. Must match the IAM ID in the + bearer token. + :param PreferenceValueWithUpdates incident_severity1: (optional) Preference + settings for notification types that support updates. + :param PreferenceValueWithUpdates incident_severity2: (optional) Preference + settings for notification types that support updates. + :param PreferenceValueWithUpdates incident_severity3: (optional) Preference + settings for notification types that support updates. + :param PreferenceValueWithUpdates incident_severity4: (optional) Preference + settings for notification types that support updates. + :param PreferenceValueWithUpdates maintenance_high: (optional) Preference + settings for notification types that support updates. + :param PreferenceValueWithUpdates maintenance_medium: (optional) Preference + settings for notification types that support updates. + :param PreferenceValueWithUpdates maintenance_low: (optional) Preference + settings for notification types that support updates. + :param PreferenceValueWithoutUpdates announcements_major: (optional) + Preference settings for notification types that do not support updates. + :param PreferenceValueWithoutUpdates announcements_minor: (optional) + Preference settings for notification types that do not support updates. + :param PreferenceValueWithoutUpdates security_normal: (optional) Preference + settings for notification types that do not support updates. + :param PreferenceValueWithoutUpdates account_normal: (optional) Preference + settings for notification types that do not support updates. + :param PreferenceValueWithoutUpdates billing_and_usage_order: (optional) + Preference settings for notification types that do not support updates. + :param PreferenceValueWithoutUpdates billing_and_usage_invoices: (optional) + Preference settings for notification types that do not support updates. + :param PreferenceValueWithoutUpdates billing_and_usage_payments: (optional) + Preference settings for notification types that do not support updates. + :param PreferenceValueWithoutUpdates + billing_and_usage_subscriptions_and_promo_codes: (optional) Preference + settings for notification types that do not support updates. + :param PreferenceValueWithoutUpdates billing_and_usage_spending_alerts: + (optional) Preference settings for notification types that do not support + updates. + :param PreferenceValueWithoutUpdates resourceactivity_normal: (optional) + Preference settings for notification types that do not support updates. + :param PreferenceValueWithoutUpdates ordering_review: (optional) Preference + settings for notification types that do not support updates. + :param PreferenceValueWithoutUpdates ordering_approved: (optional) + Preference settings for notification types that do not support updates. + :param PreferenceValueWithoutUpdates ordering_approved_vsi: (optional) + Preference settings for notification types that do not support updates. + :param PreferenceValueWithoutUpdates ordering_approved_server: (optional) + Preference settings for notification types that do not support updates. + :param PreferenceValueWithoutUpdates provisioning_reload_complete: + (optional) Preference settings for notification types that do not support + updates. + :param PreferenceValueWithoutUpdates provisioning_complete_vsi: (optional) + Preference settings for notification types that do not support updates. + :param PreferenceValueWithoutUpdates provisioning_complete_server: + (optional) Preference settings for notification types that do not support + updates. + :param str account_id: (optional) The IBM Cloud account ID. If not + provided, the account ID from the bearer token will be used. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse with `dict` result representing a `PreferencesObject` object + """ + + if not iam_id: + raise ValueError('iam_id must be provided') + if incident_severity1 is not None: + incident_severity1 = convert_model(incident_severity1) + if incident_severity2 is not None: + incident_severity2 = convert_model(incident_severity2) + if incident_severity3 is not None: + incident_severity3 = convert_model(incident_severity3) + if incident_severity4 is not None: + incident_severity4 = convert_model(incident_severity4) + if maintenance_high is not None: + maintenance_high = convert_model(maintenance_high) + if maintenance_medium is not None: + maintenance_medium = convert_model(maintenance_medium) + if maintenance_low is not None: + maintenance_low = convert_model(maintenance_low) + if announcements_major is not None: + announcements_major = convert_model(announcements_major) + if announcements_minor is not None: + announcements_minor = convert_model(announcements_minor) + if security_normal is not None: + security_normal = convert_model(security_normal) + if account_normal is not None: + account_normal = convert_model(account_normal) + if billing_and_usage_order is not None: + billing_and_usage_order = convert_model(billing_and_usage_order) + if billing_and_usage_invoices is not None: + billing_and_usage_invoices = convert_model(billing_and_usage_invoices) + if billing_and_usage_payments is not None: + billing_and_usage_payments = convert_model(billing_and_usage_payments) + if billing_and_usage_subscriptions_and_promo_codes is not None: + billing_and_usage_subscriptions_and_promo_codes = convert_model(billing_and_usage_subscriptions_and_promo_codes) + if billing_and_usage_spending_alerts is not None: + billing_and_usage_spending_alerts = convert_model(billing_and_usage_spending_alerts) + if resourceactivity_normal is not None: + resourceactivity_normal = convert_model(resourceactivity_normal) + if ordering_review is not None: + ordering_review = convert_model(ordering_review) + if ordering_approved is not None: + ordering_approved = convert_model(ordering_approved) + if ordering_approved_vsi is not None: + ordering_approved_vsi = convert_model(ordering_approved_vsi) + if ordering_approved_server is not None: + ordering_approved_server = convert_model(ordering_approved_server) + if provisioning_reload_complete is not None: + provisioning_reload_complete = convert_model(provisioning_reload_complete) + if provisioning_complete_vsi is not None: + provisioning_complete_vsi = convert_model(provisioning_complete_vsi) + if provisioning_complete_server is not None: + provisioning_complete_server = convert_model(provisioning_complete_server) + headers = {} + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='replace_notification_preferences', + ) + headers.update(sdk_headers) + + params = { + 'account_id': account_id, + } + + data = { + 'incident_severity1': incident_severity1, + 'incident_severity2': incident_severity2, + 'incident_severity3': incident_severity3, + 'incident_severity4': incident_severity4, + 'maintenance_high': maintenance_high, + 'maintenance_medium': maintenance_medium, + 'maintenance_low': maintenance_low, + 'announcements_major': announcements_major, + 'announcements_minor': announcements_minor, + 'security_normal': security_normal, + 'account_normal': account_normal, + 'billing_and_usage_order': billing_and_usage_order, + 'billing_and_usage_invoices': billing_and_usage_invoices, + 'billing_and_usage_payments': billing_and_usage_payments, + 'billing_and_usage_subscriptions_and_promo_codes': billing_and_usage_subscriptions_and_promo_codes, + 'billing_and_usage_spending_alerts': billing_and_usage_spending_alerts, + 'resourceactivity_normal': resourceactivity_normal, + 'ordering_review': ordering_review, + 'ordering_approved': ordering_approved, + 'ordering_approved_vsi': ordering_approved_vsi, + 'ordering_approved_server': ordering_approved_server, + 'provisioning_reload_complete': provisioning_reload_complete, + 'provisioning_complete_vsi': provisioning_complete_vsi, + 'provisioning_complete_server': provisioning_complete_server, + } + data = {k: v for (k, v) in data.items() if v is not None} + data = json.dumps(data) + headers['content-type'] = 'application/json' + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + del kwargs['headers'] + headers['Accept'] = 'application/json' + + path_param_keys = ['iam_id'] + path_param_values = self.encode_path_vars(iam_id) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/v1/notifications/{iam_id}/preferences'.format(**path_param_dict) + request = self.prepare_request( + method='PUT', + url=url, + headers=headers, + params=params, + data=data, + ) + + response = self.send(request, **kwargs) + return response + + def delete_notification_preferences( + self, + iam_id: str, + *, + account_id: Optional[str] = None, + **kwargs, + ) -> DetailedResponse: + """ + Resets all preferences to their default values. + + Delete all communication preferences for the specified account, and resets all + preferences to their default values. + + :param str iam_id: The IAM ID of the user. Must match the IAM ID in the + bearer token. + :param str account_id: (optional) The IBM Cloud account ID. If not + provided, the account ID from the bearer token will be used. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse + """ + + if not iam_id: + raise ValueError('iam_id must be provided') + headers = {} + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='delete_notification_preferences', + ) + headers.update(sdk_headers) + + params = { + 'account_id': account_id, + } + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + del kwargs['headers'] + + path_param_keys = ['iam_id'] + path_param_values = self.encode_path_vars(iam_id) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/v1/notifications/{iam_id}/preferences'.format(**path_param_dict) + request = self.prepare_request( + method='DELETE', + url=url, + headers=headers, + params=params, + ) + + response = self.send(request, **kwargs) + return response + + ######################### + # Notifications + ######################### + + def list_notifications( + self, + *, + account_id: Optional[str] = None, + start: Optional[str] = None, + limit: Optional[int] = None, + **kwargs, + ) -> DetailedResponse: + """ + Get user notifications. + + Retrieve all notifications for the requested user. + + :param str account_id: (optional) The IBM Cloud account ID. If not + provided, the account ID from the bearer token will be used. + :param str start: (optional) An opaque page token that specifies the + resource to start the page on or after. If unspecified, the first page of + results is returned. + :param int limit: (optional) The maximum number of items to return per + page. If unspecified, a default limit of 50 is used. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse with `dict` result representing a `NotificationCollection` object + """ + + headers = {} + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='list_notifications', + ) + headers.update(sdk_headers) + + params = { + 'account_id': account_id, + 'start': start, + 'limit': limit, + } + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + del kwargs['headers'] + headers['Accept'] = 'application/json' + + url = '/v1/notifications' + request = self.prepare_request( + method='GET', + url=url, + headers=headers, + params=params, + ) + + response = self.send(request, **kwargs) + return response + + def get_acknowledgement( + self, + *, + account_id: Optional[str] = None, + **kwargs, + ) -> DetailedResponse: + """ + Get user's last acknowledged notification Id. + + Retrieve the ID of the last notification acknowledged by the user for a specific + account. + + :param str account_id: (optional) The account ID to retrieve + acknowledgement for. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse with `dict` result representing a `Acknowledgement` object + """ + + headers = {} + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='get_acknowledgement', + ) + headers.update(sdk_headers) + + params = { + 'account_id': account_id, + } + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + del kwargs['headers'] + headers['Accept'] = 'application/json' + + url = '/v1/notifications/acknowledgement' + request = self.prepare_request( + method='GET', + url=url, + headers=headers, + params=params, + ) + + response = self.send(request, **kwargs) + return response + + def replace_notification_acknowledgement( + self, + last_acknowledged_id: str, + *, + account_id: Optional[str] = None, + **kwargs, + ) -> DetailedResponse: + """ + Update user's last acknowledged notification. + + Update the ID of the last notification acknowledged by the user for a specific + account. + + :param str last_acknowledged_id: The ID of a notification. + :param str account_id: (optional) The account ID to update acknowledgement + for. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse with `dict` result representing a `Acknowledgement` object + """ + + if last_acknowledged_id is None: + raise ValueError('last_acknowledged_id must be provided') + headers = {} + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='replace_notification_acknowledgement', + ) + headers.update(sdk_headers) + + params = { + 'account_id': account_id, + } + + data = { + 'last_acknowledged_id': last_acknowledged_id, + } + data = {k: v for (k, v) in data.items() if v is not None} + data = json.dumps(data) + headers['content-type'] = 'application/json' + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + del kwargs['headers'] + headers['Accept'] = 'application/json' + + url = '/v1/notifications/acknowledgement' + request = self.prepare_request( + method='PUT', + url=url, + headers=headers, + params=params, + data=data, + ) + + response = self.send(request, **kwargs) + return response + + +############################################################################## +# Models +############################################################################## + + +class AddDestination: + """ + AddDestination. + + """ + + def __init__( + self, + ) -> None: + """ + Initialize a AddDestination object. + + """ + msg = "Cannot instantiate base class. Instead, instantiate one of the defined subclasses: {0}".format( + ", ".join(['AddDestinationEventNotificationDestination']) + ) + raise Exception(msg) + + @classmethod + def from_dict(cls, _dict: Dict) -> 'AddDestination': + """Initialize a AddDestination object from a json dictionary.""" + disc_class = cls._get_class_by_discriminator(_dict) + if disc_class != cls: + return disc_class.from_dict(_dict) + msg = "Cannot convert dictionary into an instance of base class 'AddDestination'. The discriminator value should map to a valid subclass: {1}".format( + ", ".join(['AddDestinationEventNotificationDestination']) + ) + raise Exception(msg) + + @classmethod + def _from_dict(cls, _dict: Dict): + """Initialize a AddDestination object from a json dictionary.""" + return cls.from_dict(_dict) + + @classmethod + def _get_class_by_discriminator(cls, _dict: Dict) -> object: + mapping = {} + mapping['event_notifications'] = 'AddDestinationEventNotificationDestination' + disc_value = _dict.get('destination_type') + if disc_value is None: + raise ValueError('Discriminator property \'destination_type\' not found in AddDestination JSON') + class_name = mapping.get(disc_value, disc_value) + try: + disc_class = getattr(sys.modules[__name__], class_name) + except AttributeError: + disc_class = cls + if isinstance(disc_class, object): + return disc_class + raise TypeError('%s is not a discriminator class' % class_name) + + +class AddDestinationCollection: + """ + List of destinations in the distribution list. + + :param List[AddDestination] destinations: Array of destination entries. + """ + + def __init__( + self, + destinations: List['AddDestination'], + ) -> None: + """ + Initialize a AddDestinationCollection object. + + :param List[AddDestination] destinations: Array of destination entries. + """ + self.destinations = destinations + + @classmethod + def from_dict(cls, _dict: Dict) -> 'AddDestinationCollection': + """Initialize a AddDestinationCollection object from a json dictionary.""" + args = {} + if (destinations := _dict.get('destinations')) is not None: + args['destinations'] = [AddDestination.from_dict(v) for v in destinations] + else: + raise ValueError('Required property \'destinations\' not present in AddDestinationCollection JSON') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a AddDestinationCollection object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'destinations') and self.destinations is not None: + destinations_list = [] + for v in self.destinations: + if isinstance(v, dict): + destinations_list.append(v) + else: + destinations_list.append(v.to_dict()) + _dict['destinations'] = destinations_list + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this AddDestinationCollection object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'AddDestinationCollection') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'AddDestinationCollection') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + +class AddDestinationPrototype: + """ + AddDestinationPrototype. + + """ + + def __init__( + self, + ) -> None: + """ + Initialize a AddDestinationPrototype object. + + """ + msg = "Cannot instantiate base class. Instead, instantiate one of the defined subclasses: {0}".format( + ", ".join(['AddDestinationPrototypeEventNotificationDestinationPrototype']) + ) + raise Exception(msg) + + @classmethod + def from_dict(cls, _dict: Dict) -> 'AddDestinationPrototype': + """Initialize a AddDestinationPrototype object from a json dictionary.""" + disc_class = cls._get_class_by_discriminator(_dict) + if disc_class != cls: + return disc_class.from_dict(_dict) + msg = "Cannot convert dictionary into an instance of base class 'AddDestinationPrototype'. The discriminator value should map to a valid subclass: {1}".format( + ", ".join(['AddDestinationPrototypeEventNotificationDestinationPrototype']) + ) + raise Exception(msg) + + @classmethod + def _from_dict(cls, _dict: Dict): + """Initialize a AddDestinationPrototype object from a json dictionary.""" + return cls.from_dict(_dict) + + @classmethod + def _get_class_by_discriminator(cls, _dict: Dict) -> object: + mapping = {} + mapping['event_notifications'] = 'AddDestinationPrototypeEventNotificationDestinationPrototype' + disc_value = _dict.get('destination_type') + if disc_value is None: + raise ValueError('Discriminator property \'destination_type\' not found in AddDestinationPrototype JSON') + class_name = mapping.get(disc_value, disc_value) + try: + disc_class = getattr(sys.modules[__name__], class_name) + except AttributeError: + disc_class = cls + if isinstance(disc_class, object): + return disc_class + raise TypeError('%s is not a discriminator class' % class_name) + + +class Notification: + """ + A notification entry. + + :param str title: The title of the notification. + :param str body: The body content of the notification. + :param str id: The unique identifier for the notification. + :param str category: The category of the notification. + :param List[str] component_names: Array of component/service names affected by + this notification. + :param int start_time: The start time of the notification in Unix timestamp + (milliseconds). + :param bool is_global: Indicates if the notification is global. + :param str state: The current state of the notification. + :param List[str] regions: Array of region identifiers affected by this + notification. + :param List[str] crn_masks: Array of CRN masks that define the scope of affected + resources. + :param str record_id: (optional) The record identifier for tracking purposes. + :param str source_id: (optional) The source identifier of the notification. + :param str completion_code: The completion code of the notification. + :param int end_time: (optional) The end time of the notification in Unix + timestamp (milliseconds). + :param int update_time: The last update time of the notification in Unix + timestamp (milliseconds). + :param int severity: The severity level of the notification (0-3). The display + value depends on the notification type: + **Incidents:** + - 1 = Severity 1 + - 2 = Severity 2 + - 3 = Severity 3 + - 0 = Severity 4 + **Maintenance:** + - 1 = High + - 2 = Medium + - 3 = Low + **Announcements:** + - 1 = Major + - 0 = Minor. + :param str lucene_query: (optional) Lucene query string for filtering affected + resources. Only present when instance targets are specified and resource_link is + not available. Mutually exclusive with resource_link. + :param str resource_link: (optional) Link to additional resource information or + documentation. Takes precedence over lucene_query when both are available. + Mutually exclusive with lucene_query. + """ + + def __init__( + self, + title: str, + body: str, + id: str, + category: str, + component_names: List[str], + start_time: int, + is_global: bool, + state: str, + regions: List[str], + crn_masks: List[str], + completion_code: str, + update_time: int, + severity: int, + *, + record_id: Optional[str] = None, + source_id: Optional[str] = None, + end_time: Optional[int] = None, + lucene_query: Optional[str] = None, + resource_link: Optional[str] = None, + ) -> None: + """ + Initialize a Notification object. + + :param str title: The title of the notification. + :param str body: The body content of the notification. + :param str id: The unique identifier for the notification. + :param str category: The category of the notification. + :param List[str] component_names: Array of component/service names affected + by this notification. + :param int start_time: The start time of the notification in Unix timestamp + (milliseconds). + :param bool is_global: Indicates if the notification is global. + :param str state: The current state of the notification. + :param List[str] regions: Array of region identifiers affected by this + notification. + :param List[str] crn_masks: Array of CRN masks that define the scope of + affected resources. + :param str completion_code: The completion code of the notification. + :param int update_time: The last update time of the notification in Unix + timestamp (milliseconds). + :param int severity: The severity level of the notification (0-3). The + display value depends on the notification type: + **Incidents:** + - 1 = Severity 1 + - 2 = Severity 2 + - 3 = Severity 3 + - 0 = Severity 4 + **Maintenance:** + - 1 = High + - 2 = Medium + - 3 = Low + **Announcements:** + - 1 = Major + - 0 = Minor. + :param str record_id: (optional) The record identifier for tracking + purposes. + :param str source_id: (optional) The source identifier of the notification. + :param int end_time: (optional) The end time of the notification in Unix + timestamp (milliseconds). + :param str lucene_query: (optional) Lucene query string for filtering + affected resources. Only present when instance targets are specified and + resource_link is not available. Mutually exclusive with resource_link. + :param str resource_link: (optional) Link to additional resource + information or documentation. Takes precedence over lucene_query when both + are available. Mutually exclusive with lucene_query. + """ + self.title = title + self.body = body + self.id = id + self.category = category + self.component_names = component_names + self.start_time = start_time + self.is_global = is_global + self.state = state + self.regions = regions + self.crn_masks = crn_masks + self.record_id = record_id + self.source_id = source_id + self.completion_code = completion_code + self.end_time = end_time + self.update_time = update_time + self.severity = severity + self.lucene_query = lucene_query + self.resource_link = resource_link + + @classmethod + def from_dict(cls, _dict: Dict) -> 'Notification': + """Initialize a Notification object from a json dictionary.""" + args = {} + if (title := _dict.get('title')) is not None: + args['title'] = title + else: + raise ValueError('Required property \'title\' not present in Notification JSON') + if (body := _dict.get('body')) is not None: + args['body'] = body + else: + raise ValueError('Required property \'body\' not present in Notification JSON') + if (id := _dict.get('id')) is not None: + args['id'] = id + else: + raise ValueError('Required property \'id\' not present in Notification JSON') + if (category := _dict.get('category')) is not None: + args['category'] = category + else: + raise ValueError('Required property \'category\' not present in Notification JSON') + if (component_names := _dict.get('component_names')) is not None: + args['component_names'] = component_names + else: + raise ValueError('Required property \'component_names\' not present in Notification JSON') + if (start_time := _dict.get('start_time')) is not None: + args['start_time'] = start_time + else: + raise ValueError('Required property \'start_time\' not present in Notification JSON') + if (is_global := _dict.get('is_global')) is not None: + args['is_global'] = is_global + else: + raise ValueError('Required property \'is_global\' not present in Notification JSON') + if (state := _dict.get('state')) is not None: + args['state'] = state + else: + raise ValueError('Required property \'state\' not present in Notification JSON') + if (regions := _dict.get('regions')) is not None: + args['regions'] = regions + else: + raise ValueError('Required property \'regions\' not present in Notification JSON') + if (crn_masks := _dict.get('crn_masks')) is not None: + args['crn_masks'] = crn_masks + else: + raise ValueError('Required property \'crn_masks\' not present in Notification JSON') + if (record_id := _dict.get('record_id')) is not None: + args['record_id'] = record_id + if (source_id := _dict.get('source_id')) is not None: + args['source_id'] = source_id + if (completion_code := _dict.get('completion_code')) is not None: + args['completion_code'] = completion_code + else: + raise ValueError('Required property \'completion_code\' not present in Notification JSON') + if (end_time := _dict.get('end_time')) is not None: + args['end_time'] = end_time + if (update_time := _dict.get('update_time')) is not None: + args['update_time'] = update_time + else: + raise ValueError('Required property \'update_time\' not present in Notification JSON') + if (severity := _dict.get('severity')) is not None: + args['severity'] = severity + else: + raise ValueError('Required property \'severity\' not present in Notification JSON') + if (lucene_query := _dict.get('lucene_query')) is not None: + args['lucene_query'] = lucene_query + if (resource_link := _dict.get('resource_link')) is not None: + args['resource_link'] = resource_link + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a Notification object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'title') and self.title is not None: + _dict['title'] = self.title + if hasattr(self, 'body') and self.body is not None: + _dict['body'] = self.body + if hasattr(self, 'id') and self.id is not None: + _dict['id'] = self.id + if hasattr(self, 'category') and self.category is not None: + _dict['category'] = self.category + if hasattr(self, 'component_names') and self.component_names is not None: + _dict['component_names'] = self.component_names + if hasattr(self, 'start_time') and self.start_time is not None: + _dict['start_time'] = self.start_time + if hasattr(self, 'is_global') and self.is_global is not None: + _dict['is_global'] = self.is_global + if hasattr(self, 'state') and self.state is not None: + _dict['state'] = self.state + if hasattr(self, 'regions') and self.regions is not None: + _dict['regions'] = self.regions + if hasattr(self, 'crn_masks') and self.crn_masks is not None: + _dict['crn_masks'] = self.crn_masks + if hasattr(self, 'record_id') and self.record_id is not None: + _dict['record_id'] = self.record_id + if hasattr(self, 'source_id') and self.source_id is not None: + _dict['source_id'] = self.source_id + if hasattr(self, 'completion_code') and self.completion_code is not None: + _dict['completion_code'] = self.completion_code + if hasattr(self, 'end_time') and self.end_time is not None: + _dict['end_time'] = self.end_time + if hasattr(self, 'update_time') and self.update_time is not None: + _dict['update_time'] = self.update_time + if hasattr(self, 'severity') and self.severity is not None: + _dict['severity'] = self.severity + if hasattr(self, 'lucene_query') and self.lucene_query is not None: + _dict['lucene_query'] = self.lucene_query + if hasattr(self, 'resource_link') and self.resource_link is not None: + _dict['resource_link'] = self.resource_link + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this Notification object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'Notification') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'Notification') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + class CategoryEnum(str, Enum): + """ + The category of the notification. + """ + + INCIDENT = 'incident' + MAINTENANCE = 'maintenance' + ANNOUNCEMENTS = 'announcements' + SECURITY_BULLETINS = 'security_bulletins' + SECURITY = 'security' + RESOURCE = 'resource' + BILLING_AND_USAGE = 'billing_and_usage' + ORDERING = 'ordering' + PROVISIONING = 'provisioning' + ACCOUNT = 'account' + + + class StateEnum(str, Enum): + """ + The current state of the notification. + """ + + NEW = 'new' + IN_PROGRESS = 'in-progress' + COMPLETE = 'complete' + RESOLVED = 'resolved' + + + class CompletionCodeEnum(str, Enum): + """ + The completion code of the notification. + """ + + SUCCESSFUL = 'successful' + FAILED = 'failed' + CANCELLED = 'cancelled' + + + +class NotificationCollection: + """ + Collection of user notifications with token-based pagination metadata. + + :param int limit: The maximum number of items returned in this response. + :param int total_count: The total number of notifications in the collection. + :param PaginationLink first: A pagination link object containing the URL to a + page. + :param PaginationLinkWithToken previous: (optional) A pagination link object + with a page token. Used for next, previous, and last page links. + :param PaginationLinkWithToken next: (optional) A pagination link object with a + page token. Used for next, previous, and last page links. + :param PaginationLinkWithToken last: (optional) A pagination link object with a + page token. Used for next, previous, and last page links. + :param List[Notification] notifications: Array of notification entries. + """ + + def __init__( + self, + limit: int, + total_count: int, + first: 'PaginationLink', + notifications: List['Notification'], + *, + previous: Optional['PaginationLinkWithToken'] = None, + next: Optional['PaginationLinkWithToken'] = None, + last: Optional['PaginationLinkWithToken'] = None, + ) -> None: + """ + Initialize a NotificationCollection object. + + :param int limit: The maximum number of items returned in this response. + :param int total_count: The total number of notifications in the + collection. + :param PaginationLink first: A pagination link object containing the URL to + a page. + :param List[Notification] notifications: Array of notification entries. + :param PaginationLinkWithToken previous: (optional) A pagination link + object with a page token. Used for next, previous, and last page links. + :param PaginationLinkWithToken next: (optional) A pagination link object + with a page token. Used for next, previous, and last page links. + :param PaginationLinkWithToken last: (optional) A pagination link object + with a page token. Used for next, previous, and last page links. + """ + self.limit = limit + self.total_count = total_count + self.first = first + self.previous = previous + self.next = next + self.last = last + self.notifications = notifications + + @classmethod + def from_dict(cls, _dict: Dict) -> 'NotificationCollection': + """Initialize a NotificationCollection object from a json dictionary.""" + args = {} + if (limit := _dict.get('limit')) is not None: + args['limit'] = limit + else: + raise ValueError('Required property \'limit\' not present in NotificationCollection JSON') + if (total_count := _dict.get('total_count')) is not None: + args['total_count'] = total_count + else: + raise ValueError('Required property \'total_count\' not present in NotificationCollection JSON') + if (first := _dict.get('first')) is not None: + args['first'] = PaginationLink.from_dict(first) + else: + raise ValueError('Required property \'first\' not present in NotificationCollection JSON') + if (previous := _dict.get('previous')) is not None: + args['previous'] = PaginationLinkWithToken.from_dict(previous) + if (next := _dict.get('next')) is not None: + args['next'] = PaginationLinkWithToken.from_dict(next) + if (last := _dict.get('last')) is not None: + args['last'] = PaginationLinkWithToken.from_dict(last) + if (notifications := _dict.get('notifications')) is not None: + args['notifications'] = [Notification.from_dict(v) for v in notifications] + else: + raise ValueError('Required property \'notifications\' not present in NotificationCollection JSON') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a NotificationCollection object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'limit') and self.limit is not None: + _dict['limit'] = self.limit + if hasattr(self, 'total_count') and self.total_count is not None: + _dict['total_count'] = self.total_count + if hasattr(self, 'first') and self.first is not None: + if isinstance(self.first, dict): + _dict['first'] = self.first + else: + _dict['first'] = self.first.to_dict() + if hasattr(self, 'previous') and self.previous is not None: + if isinstance(self.previous, dict): + _dict['previous'] = self.previous + else: + _dict['previous'] = self.previous.to_dict() + if hasattr(self, 'next') and self.next is not None: + if isinstance(self.next, dict): + _dict['next'] = self.next + else: + _dict['next'] = self.next.to_dict() + if hasattr(self, 'last') and self.last is not None: + if isinstance(self.last, dict): + _dict['last'] = self.last + else: + _dict['last'] = self.last.to_dict() + if hasattr(self, 'notifications') and self.notifications is not None: + notifications_list = [] + for v in self.notifications: + if isinstance(v, dict): + notifications_list.append(v) + else: + notifications_list.append(v.to_dict()) + _dict['notifications'] = notifications_list + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this NotificationCollection object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'NotificationCollection') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'NotificationCollection') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + +class PaginationLink: + """ + A pagination link object containing the URL to a page. + + :param str href: Complete URL to the page. + """ + + def __init__( + self, + href: str, + ) -> None: + """ + Initialize a PaginationLink object. + + :param str href: Complete URL to the page. + """ + self.href = href + + @classmethod + def from_dict(cls, _dict: Dict) -> 'PaginationLink': + """Initialize a PaginationLink object from a json dictionary.""" + args = {} + if (href := _dict.get('href')) is not None: + args['href'] = href + else: + raise ValueError('Required property \'href\' not present in PaginationLink JSON') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a PaginationLink object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'href') and self.href is not None: + _dict['href'] = self.href + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this PaginationLink object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'PaginationLink') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'PaginationLink') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + +class PaginationLinkWithToken: + """ + A pagination link object with a page token. Used for next, previous, and last page + links. + + :param str href: Complete URL to the page. + :param str start: Opaque page token that can be used to retrieve the page. + """ + + def __init__( + self, + href: str, + start: str, + ) -> None: + """ + Initialize a PaginationLinkWithToken object. + + :param str href: Complete URL to the page. + :param str start: Opaque page token that can be used to retrieve the page. + """ + self.href = href + self.start = start + + @classmethod + def from_dict(cls, _dict: Dict) -> 'PaginationLinkWithToken': + """Initialize a PaginationLinkWithToken object from a json dictionary.""" + args = {} + if (href := _dict.get('href')) is not None: + args['href'] = href + else: + raise ValueError('Required property \'href\' not present in PaginationLinkWithToken JSON') + if (start := _dict.get('start')) is not None: + args['start'] = start + else: + raise ValueError('Required property \'start\' not present in PaginationLinkWithToken JSON') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a PaginationLinkWithToken object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'href') and self.href is not None: + _dict['href'] = self.href + if hasattr(self, 'start') and self.start is not None: + _dict['start'] = self.start + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this PaginationLinkWithToken object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'PaginationLinkWithToken') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'PaginationLinkWithToken') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + +class PreferenceValueWithUpdates: + """ + Preference settings for notification types that support updates. + + :param List[str] channels: Array of communication channels for this preference. + :param bool updates: (optional) Whether to receive updates for this preference. + Optional, defaults to false if not provided. + """ + + def __init__( + self, + channels: List[str], + *, + updates: Optional[bool] = None, + ) -> None: + """ + Initialize a PreferenceValueWithUpdates object. + + :param List[str] channels: Array of communication channels for this + preference. + :param bool updates: (optional) Whether to receive updates for this + preference. Optional, defaults to false if not provided. + """ + self.channels = channels + self.updates = updates + + @classmethod + def from_dict(cls, _dict: Dict) -> 'PreferenceValueWithUpdates': + """Initialize a PreferenceValueWithUpdates object from a json dictionary.""" + args = {} + if (channels := _dict.get('channels')) is not None: + args['channels'] = channels + else: + raise ValueError('Required property \'channels\' not present in PreferenceValueWithUpdates JSON') + if (updates := _dict.get('updates')) is not None: + args['updates'] = updates + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a PreferenceValueWithUpdates object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'channels') and self.channels is not None: + _dict['channels'] = self.channels + if hasattr(self, 'updates') and self.updates is not None: + _dict['updates'] = self.updates + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this PreferenceValueWithUpdates object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'PreferenceValueWithUpdates') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'PreferenceValueWithUpdates') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + class ChannelsEnum(str, Enum): + """ + channels. + """ + + EMAIL = 'email' + + + +class PreferenceValueWithoutUpdates: + """ + Preference settings for notification types that do not support updates. + + :param List[str] channels: Array of communication channels for this preference. + """ + + def __init__( + self, + channels: List[str], + ) -> None: + """ + Initialize a PreferenceValueWithoutUpdates object. + + :param List[str] channels: Array of communication channels for this + preference. + """ + self.channels = channels + + @classmethod + def from_dict(cls, _dict: Dict) -> 'PreferenceValueWithoutUpdates': + """Initialize a PreferenceValueWithoutUpdates object from a json dictionary.""" + args = {} + if (channels := _dict.get('channels')) is not None: + args['channels'] = channels + else: + raise ValueError('Required property \'channels\' not present in PreferenceValueWithoutUpdates JSON') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a PreferenceValueWithoutUpdates object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'channels') and self.channels is not None: + _dict['channels'] = self.channels + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this PreferenceValueWithoutUpdates object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'PreferenceValueWithoutUpdates') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'PreferenceValueWithoutUpdates') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + class ChannelsEnum(str, Enum): + """ + channels. + """ + + EMAIL = 'email' + + + +class PreferencesObject: + """ + User communication preferences object. Only include preferences where communication is + desired; absence of a key means no communication for that preference type. + + :param PreferenceValueWithUpdates incident_severity1: (optional) Preference + settings for notification types that support updates. + :param PreferenceValueWithUpdates incident_severity2: (optional) Preference + settings for notification types that support updates. + :param PreferenceValueWithUpdates incident_severity3: (optional) Preference + settings for notification types that support updates. + :param PreferenceValueWithUpdates incident_severity4: (optional) Preference + settings for notification types that support updates. + :param PreferenceValueWithUpdates maintenance_high: (optional) Preference + settings for notification types that support updates. + :param PreferenceValueWithUpdates maintenance_medium: (optional) Preference + settings for notification types that support updates. + :param PreferenceValueWithUpdates maintenance_low: (optional) Preference + settings for notification types that support updates. + :param PreferenceValueWithoutUpdates announcements_major: (optional) Preference + settings for notification types that do not support updates. + :param PreferenceValueWithoutUpdates announcements_minor: (optional) Preference + settings for notification types that do not support updates. + :param PreferenceValueWithoutUpdates security_normal: (optional) Preference + settings for notification types that do not support updates. + :param PreferenceValueWithoutUpdates account_normal: (optional) Preference + settings for notification types that do not support updates. + :param PreferenceValueWithoutUpdates billing_and_usage_order: (optional) + Preference settings for notification types that do not support updates. + :param PreferenceValueWithoutUpdates billing_and_usage_invoices: (optional) + Preference settings for notification types that do not support updates. + :param PreferenceValueWithoutUpdates billing_and_usage_payments: (optional) + Preference settings for notification types that do not support updates. + :param PreferenceValueWithoutUpdates + billing_and_usage_subscriptions_and_promo_codes: (optional) Preference settings + for notification types that do not support updates. + :param PreferenceValueWithoutUpdates billing_and_usage_spending_alerts: + (optional) Preference settings for notification types that do not support + updates. + :param PreferenceValueWithoutUpdates resourceactivity_normal: (optional) + Preference settings for notification types that do not support updates. + :param PreferenceValueWithoutUpdates ordering_review: (optional) Preference + settings for notification types that do not support updates. + :param PreferenceValueWithoutUpdates ordering_approved: (optional) Preference + settings for notification types that do not support updates. + :param PreferenceValueWithoutUpdates ordering_approved_vsi: (optional) + Preference settings for notification types that do not support updates. + :param PreferenceValueWithoutUpdates ordering_approved_server: (optional) + Preference settings for notification types that do not support updates. + :param PreferenceValueWithoutUpdates provisioning_reload_complete: (optional) + Preference settings for notification types that do not support updates. + :param PreferenceValueWithoutUpdates provisioning_complete_vsi: (optional) + Preference settings for notification types that do not support updates. + :param PreferenceValueWithoutUpdates provisioning_complete_server: (optional) + Preference settings for notification types that do not support updates. + """ + + def __init__( + self, + *, + incident_severity1: Optional['PreferenceValueWithUpdates'] = None, + incident_severity2: Optional['PreferenceValueWithUpdates'] = None, + incident_severity3: Optional['PreferenceValueWithUpdates'] = None, + incident_severity4: Optional['PreferenceValueWithUpdates'] = None, + maintenance_high: Optional['PreferenceValueWithUpdates'] = None, + maintenance_medium: Optional['PreferenceValueWithUpdates'] = None, + maintenance_low: Optional['PreferenceValueWithUpdates'] = None, + announcements_major: Optional['PreferenceValueWithoutUpdates'] = None, + announcements_minor: Optional['PreferenceValueWithoutUpdates'] = None, + security_normal: Optional['PreferenceValueWithoutUpdates'] = None, + account_normal: Optional['PreferenceValueWithoutUpdates'] = None, + billing_and_usage_order: Optional['PreferenceValueWithoutUpdates'] = None, + billing_and_usage_invoices: Optional['PreferenceValueWithoutUpdates'] = None, + billing_and_usage_payments: Optional['PreferenceValueWithoutUpdates'] = None, + billing_and_usage_subscriptions_and_promo_codes: Optional['PreferenceValueWithoutUpdates'] = None, + billing_and_usage_spending_alerts: Optional['PreferenceValueWithoutUpdates'] = None, + resourceactivity_normal: Optional['PreferenceValueWithoutUpdates'] = None, + ordering_review: Optional['PreferenceValueWithoutUpdates'] = None, + ordering_approved: Optional['PreferenceValueWithoutUpdates'] = None, + ordering_approved_vsi: Optional['PreferenceValueWithoutUpdates'] = None, + ordering_approved_server: Optional['PreferenceValueWithoutUpdates'] = None, + provisioning_reload_complete: Optional['PreferenceValueWithoutUpdates'] = None, + provisioning_complete_vsi: Optional['PreferenceValueWithoutUpdates'] = None, + provisioning_complete_server: Optional['PreferenceValueWithoutUpdates'] = None, + ) -> None: + """ + Initialize a PreferencesObject object. + + :param PreferenceValueWithUpdates incident_severity1: (optional) Preference + settings for notification types that support updates. + :param PreferenceValueWithUpdates incident_severity2: (optional) Preference + settings for notification types that support updates. + :param PreferenceValueWithUpdates incident_severity3: (optional) Preference + settings for notification types that support updates. + :param PreferenceValueWithUpdates incident_severity4: (optional) Preference + settings for notification types that support updates. + :param PreferenceValueWithUpdates maintenance_high: (optional) Preference + settings for notification types that support updates. + :param PreferenceValueWithUpdates maintenance_medium: (optional) Preference + settings for notification types that support updates. + :param PreferenceValueWithUpdates maintenance_low: (optional) Preference + settings for notification types that support updates. + :param PreferenceValueWithoutUpdates announcements_major: (optional) + Preference settings for notification types that do not support updates. + :param PreferenceValueWithoutUpdates announcements_minor: (optional) + Preference settings for notification types that do not support updates. + :param PreferenceValueWithoutUpdates security_normal: (optional) Preference + settings for notification types that do not support updates. + :param PreferenceValueWithoutUpdates account_normal: (optional) Preference + settings for notification types that do not support updates. + :param PreferenceValueWithoutUpdates billing_and_usage_order: (optional) + Preference settings for notification types that do not support updates. + :param PreferenceValueWithoutUpdates billing_and_usage_invoices: (optional) + Preference settings for notification types that do not support updates. + :param PreferenceValueWithoutUpdates billing_and_usage_payments: (optional) + Preference settings for notification types that do not support updates. + :param PreferenceValueWithoutUpdates + billing_and_usage_subscriptions_and_promo_codes: (optional) Preference + settings for notification types that do not support updates. + :param PreferenceValueWithoutUpdates billing_and_usage_spending_alerts: + (optional) Preference settings for notification types that do not support + updates. + :param PreferenceValueWithoutUpdates resourceactivity_normal: (optional) + Preference settings for notification types that do not support updates. + :param PreferenceValueWithoutUpdates ordering_review: (optional) Preference + settings for notification types that do not support updates. + :param PreferenceValueWithoutUpdates ordering_approved: (optional) + Preference settings for notification types that do not support updates. + :param PreferenceValueWithoutUpdates ordering_approved_vsi: (optional) + Preference settings for notification types that do not support updates. + :param PreferenceValueWithoutUpdates ordering_approved_server: (optional) + Preference settings for notification types that do not support updates. + :param PreferenceValueWithoutUpdates provisioning_reload_complete: + (optional) Preference settings for notification types that do not support + updates. + :param PreferenceValueWithoutUpdates provisioning_complete_vsi: (optional) + Preference settings for notification types that do not support updates. + :param PreferenceValueWithoutUpdates provisioning_complete_server: + (optional) Preference settings for notification types that do not support + updates. + """ + self.incident_severity1 = incident_severity1 + self.incident_severity2 = incident_severity2 + self.incident_severity3 = incident_severity3 + self.incident_severity4 = incident_severity4 + self.maintenance_high = maintenance_high + self.maintenance_medium = maintenance_medium + self.maintenance_low = maintenance_low + self.announcements_major = announcements_major + self.announcements_minor = announcements_minor + self.security_normal = security_normal + self.account_normal = account_normal + self.billing_and_usage_order = billing_and_usage_order + self.billing_and_usage_invoices = billing_and_usage_invoices + self.billing_and_usage_payments = billing_and_usage_payments + self.billing_and_usage_subscriptions_and_promo_codes = billing_and_usage_subscriptions_and_promo_codes + self.billing_and_usage_spending_alerts = billing_and_usage_spending_alerts + self.resourceactivity_normal = resourceactivity_normal + self.ordering_review = ordering_review + self.ordering_approved = ordering_approved + self.ordering_approved_vsi = ordering_approved_vsi + self.ordering_approved_server = ordering_approved_server + self.provisioning_reload_complete = provisioning_reload_complete + self.provisioning_complete_vsi = provisioning_complete_vsi + self.provisioning_complete_server = provisioning_complete_server + + @classmethod + def from_dict(cls, _dict: Dict) -> 'PreferencesObject': + """Initialize a PreferencesObject object from a json dictionary.""" + args = {} + if (incident_severity1 := _dict.get('incident_severity1')) is not None: + args['incident_severity1'] = PreferenceValueWithUpdates.from_dict(incident_severity1) + if (incident_severity2 := _dict.get('incident_severity2')) is not None: + args['incident_severity2'] = PreferenceValueWithUpdates.from_dict(incident_severity2) + if (incident_severity3 := _dict.get('incident_severity3')) is not None: + args['incident_severity3'] = PreferenceValueWithUpdates.from_dict(incident_severity3) + if (incident_severity4 := _dict.get('incident_severity4')) is not None: + args['incident_severity4'] = PreferenceValueWithUpdates.from_dict(incident_severity4) + if (maintenance_high := _dict.get('maintenance_high')) is not None: + args['maintenance_high'] = PreferenceValueWithUpdates.from_dict(maintenance_high) + if (maintenance_medium := _dict.get('maintenance_medium')) is not None: + args['maintenance_medium'] = PreferenceValueWithUpdates.from_dict(maintenance_medium) + if (maintenance_low := _dict.get('maintenance_low')) is not None: + args['maintenance_low'] = PreferenceValueWithUpdates.from_dict(maintenance_low) + if (announcements_major := _dict.get('announcements_major')) is not None: + args['announcements_major'] = PreferenceValueWithoutUpdates.from_dict(announcements_major) + if (announcements_minor := _dict.get('announcements_minor')) is not None: + args['announcements_minor'] = PreferenceValueWithoutUpdates.from_dict(announcements_minor) + if (security_normal := _dict.get('security_normal')) is not None: + args['security_normal'] = PreferenceValueWithoutUpdates.from_dict(security_normal) + if (account_normal := _dict.get('account_normal')) is not None: + args['account_normal'] = PreferenceValueWithoutUpdates.from_dict(account_normal) + if (billing_and_usage_order := _dict.get('billing_and_usage_order')) is not None: + args['billing_and_usage_order'] = PreferenceValueWithoutUpdates.from_dict(billing_and_usage_order) + if (billing_and_usage_invoices := _dict.get('billing_and_usage_invoices')) is not None: + args['billing_and_usage_invoices'] = PreferenceValueWithoutUpdates.from_dict(billing_and_usage_invoices) + if (billing_and_usage_payments := _dict.get('billing_and_usage_payments')) is not None: + args['billing_and_usage_payments'] = PreferenceValueWithoutUpdates.from_dict(billing_and_usage_payments) + if (billing_and_usage_subscriptions_and_promo_codes := _dict.get('billing_and_usage_subscriptions_and_promo_codes')) is not None: + args['billing_and_usage_subscriptions_and_promo_codes'] = PreferenceValueWithoutUpdates.from_dict(billing_and_usage_subscriptions_and_promo_codes) + if (billing_and_usage_spending_alerts := _dict.get('billing_and_usage_spending_alerts')) is not None: + args['billing_and_usage_spending_alerts'] = PreferenceValueWithoutUpdates.from_dict(billing_and_usage_spending_alerts) + if (resourceactivity_normal := _dict.get('resourceactivity_normal')) is not None: + args['resourceactivity_normal'] = PreferenceValueWithoutUpdates.from_dict(resourceactivity_normal) + if (ordering_review := _dict.get('ordering_review')) is not None: + args['ordering_review'] = PreferenceValueWithoutUpdates.from_dict(ordering_review) + if (ordering_approved := _dict.get('ordering_approved')) is not None: + args['ordering_approved'] = PreferenceValueWithoutUpdates.from_dict(ordering_approved) + if (ordering_approved_vsi := _dict.get('ordering_approved_vsi')) is not None: + args['ordering_approved_vsi'] = PreferenceValueWithoutUpdates.from_dict(ordering_approved_vsi) + if (ordering_approved_server := _dict.get('ordering_approved_server')) is not None: + args['ordering_approved_server'] = PreferenceValueWithoutUpdates.from_dict(ordering_approved_server) + if (provisioning_reload_complete := _dict.get('provisioning_reload_complete')) is not None: + args['provisioning_reload_complete'] = PreferenceValueWithoutUpdates.from_dict(provisioning_reload_complete) + if (provisioning_complete_vsi := _dict.get('provisioning_complete_vsi')) is not None: + args['provisioning_complete_vsi'] = PreferenceValueWithoutUpdates.from_dict(provisioning_complete_vsi) + if (provisioning_complete_server := _dict.get('provisioning_complete_server')) is not None: + args['provisioning_complete_server'] = PreferenceValueWithoutUpdates.from_dict(provisioning_complete_server) + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a PreferencesObject object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'incident_severity1') and self.incident_severity1 is not None: + if isinstance(self.incident_severity1, dict): + _dict['incident_severity1'] = self.incident_severity1 + else: + _dict['incident_severity1'] = self.incident_severity1.to_dict() + if hasattr(self, 'incident_severity2') and self.incident_severity2 is not None: + if isinstance(self.incident_severity2, dict): + _dict['incident_severity2'] = self.incident_severity2 + else: + _dict['incident_severity2'] = self.incident_severity2.to_dict() + if hasattr(self, 'incident_severity3') and self.incident_severity3 is not None: + if isinstance(self.incident_severity3, dict): + _dict['incident_severity3'] = self.incident_severity3 + else: + _dict['incident_severity3'] = self.incident_severity3.to_dict() + if hasattr(self, 'incident_severity4') and self.incident_severity4 is not None: + if isinstance(self.incident_severity4, dict): + _dict['incident_severity4'] = self.incident_severity4 + else: + _dict['incident_severity4'] = self.incident_severity4.to_dict() + if hasattr(self, 'maintenance_high') and self.maintenance_high is not None: + if isinstance(self.maintenance_high, dict): + _dict['maintenance_high'] = self.maintenance_high + else: + _dict['maintenance_high'] = self.maintenance_high.to_dict() + if hasattr(self, 'maintenance_medium') and self.maintenance_medium is not None: + if isinstance(self.maintenance_medium, dict): + _dict['maintenance_medium'] = self.maintenance_medium + else: + _dict['maintenance_medium'] = self.maintenance_medium.to_dict() + if hasattr(self, 'maintenance_low') and self.maintenance_low is not None: + if isinstance(self.maintenance_low, dict): + _dict['maintenance_low'] = self.maintenance_low + else: + _dict['maintenance_low'] = self.maintenance_low.to_dict() + if hasattr(self, 'announcements_major') and self.announcements_major is not None: + if isinstance(self.announcements_major, dict): + _dict['announcements_major'] = self.announcements_major + else: + _dict['announcements_major'] = self.announcements_major.to_dict() + if hasattr(self, 'announcements_minor') and self.announcements_minor is not None: + if isinstance(self.announcements_minor, dict): + _dict['announcements_minor'] = self.announcements_minor + else: + _dict['announcements_minor'] = self.announcements_minor.to_dict() + if hasattr(self, 'security_normal') and self.security_normal is not None: + if isinstance(self.security_normal, dict): + _dict['security_normal'] = self.security_normal + else: + _dict['security_normal'] = self.security_normal.to_dict() + if hasattr(self, 'account_normal') and self.account_normal is not None: + if isinstance(self.account_normal, dict): + _dict['account_normal'] = self.account_normal + else: + _dict['account_normal'] = self.account_normal.to_dict() + if hasattr(self, 'billing_and_usage_order') and self.billing_and_usage_order is not None: + if isinstance(self.billing_and_usage_order, dict): + _dict['billing_and_usage_order'] = self.billing_and_usage_order + else: + _dict['billing_and_usage_order'] = self.billing_and_usage_order.to_dict() + if hasattr(self, 'billing_and_usage_invoices') and self.billing_and_usage_invoices is not None: + if isinstance(self.billing_and_usage_invoices, dict): + _dict['billing_and_usage_invoices'] = self.billing_and_usage_invoices + else: + _dict['billing_and_usage_invoices'] = self.billing_and_usage_invoices.to_dict() + if hasattr(self, 'billing_and_usage_payments') and self.billing_and_usage_payments is not None: + if isinstance(self.billing_and_usage_payments, dict): + _dict['billing_and_usage_payments'] = self.billing_and_usage_payments + else: + _dict['billing_and_usage_payments'] = self.billing_and_usage_payments.to_dict() + if hasattr(self, 'billing_and_usage_subscriptions_and_promo_codes') and self.billing_and_usage_subscriptions_and_promo_codes is not None: + if isinstance(self.billing_and_usage_subscriptions_and_promo_codes, dict): + _dict['billing_and_usage_subscriptions_and_promo_codes'] = self.billing_and_usage_subscriptions_and_promo_codes + else: + _dict['billing_and_usage_subscriptions_and_promo_codes'] = self.billing_and_usage_subscriptions_and_promo_codes.to_dict() + if hasattr(self, 'billing_and_usage_spending_alerts') and self.billing_and_usage_spending_alerts is not None: + if isinstance(self.billing_and_usage_spending_alerts, dict): + _dict['billing_and_usage_spending_alerts'] = self.billing_and_usage_spending_alerts + else: + _dict['billing_and_usage_spending_alerts'] = self.billing_and_usage_spending_alerts.to_dict() + if hasattr(self, 'resourceactivity_normal') and self.resourceactivity_normal is not None: + if isinstance(self.resourceactivity_normal, dict): + _dict['resourceactivity_normal'] = self.resourceactivity_normal + else: + _dict['resourceactivity_normal'] = self.resourceactivity_normal.to_dict() + if hasattr(self, 'ordering_review') and self.ordering_review is not None: + if isinstance(self.ordering_review, dict): + _dict['ordering_review'] = self.ordering_review + else: + _dict['ordering_review'] = self.ordering_review.to_dict() + if hasattr(self, 'ordering_approved') and self.ordering_approved is not None: + if isinstance(self.ordering_approved, dict): + _dict['ordering_approved'] = self.ordering_approved + else: + _dict['ordering_approved'] = self.ordering_approved.to_dict() + if hasattr(self, 'ordering_approved_vsi') and self.ordering_approved_vsi is not None: + if isinstance(self.ordering_approved_vsi, dict): + _dict['ordering_approved_vsi'] = self.ordering_approved_vsi + else: + _dict['ordering_approved_vsi'] = self.ordering_approved_vsi.to_dict() + if hasattr(self, 'ordering_approved_server') and self.ordering_approved_server is not None: + if isinstance(self.ordering_approved_server, dict): + _dict['ordering_approved_server'] = self.ordering_approved_server + else: + _dict['ordering_approved_server'] = self.ordering_approved_server.to_dict() + if hasattr(self, 'provisioning_reload_complete') and self.provisioning_reload_complete is not None: + if isinstance(self.provisioning_reload_complete, dict): + _dict['provisioning_reload_complete'] = self.provisioning_reload_complete + else: + _dict['provisioning_reload_complete'] = self.provisioning_reload_complete.to_dict() + if hasattr(self, 'provisioning_complete_vsi') and self.provisioning_complete_vsi is not None: + if isinstance(self.provisioning_complete_vsi, dict): + _dict['provisioning_complete_vsi'] = self.provisioning_complete_vsi + else: + _dict['provisioning_complete_vsi'] = self.provisioning_complete_vsi.to_dict() + if hasattr(self, 'provisioning_complete_server') and self.provisioning_complete_server is not None: + if isinstance(self.provisioning_complete_server, dict): + _dict['provisioning_complete_server'] = self.provisioning_complete_server + else: + _dict['provisioning_complete_server'] = self.provisioning_complete_server.to_dict() + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this PreferencesObject object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'PreferencesObject') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'PreferencesObject') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + +class TestDestinationRequestBodyPrototype: + """ + TestDestinationRequestBodyPrototype. + + """ + + def __init__( + self, + ) -> None: + """ + Initialize a TestDestinationRequestBodyPrototype object. + + """ + msg = "Cannot instantiate base class. Instead, instantiate one of the defined subclasses: {0}".format( + ", ".join(['TestDestinationRequestBodyPrototypeTestEventNotificationDestinationRequestBodyPrototype']) + ) + raise Exception(msg) + + @classmethod + def from_dict(cls, _dict: Dict) -> 'TestDestinationRequestBodyPrototype': + """Initialize a TestDestinationRequestBodyPrototype object from a json dictionary.""" + disc_class = cls._get_class_by_discriminator(_dict) + if disc_class != cls: + return disc_class.from_dict(_dict) + msg = "Cannot convert dictionary into an instance of base class 'TestDestinationRequestBodyPrototype'. The discriminator value should map to a valid subclass: {1}".format( + ", ".join(['TestDestinationRequestBodyPrototypeTestEventNotificationDestinationRequestBodyPrototype']) + ) + raise Exception(msg) + + @classmethod + def _from_dict(cls, _dict: Dict): + """Initialize a TestDestinationRequestBodyPrototype object from a json dictionary.""" + return cls.from_dict(_dict) + + @classmethod + def _get_class_by_discriminator(cls, _dict: Dict) -> object: + mapping = {} + mapping['event_notifications'] = 'TestDestinationRequestBodyPrototypeTestEventNotificationDestinationRequestBodyPrototype' + disc_value = _dict.get('destination_type') + if disc_value is None: + raise ValueError('Discriminator property \'destination_type\' not found in TestDestinationRequestBodyPrototype JSON') + class_name = mapping.get(disc_value, disc_value) + try: + disc_class = getattr(sys.modules[__name__], class_name) + except AttributeError: + disc_class = cls + if isinstance(disc_class, object): + return disc_class + raise TypeError('%s is not a discriminator class' % class_name) + + +class TestDestinationResponseBody: + """ + Response from the test notification endpoint. + + :param str message: The status message that indicates the test result. + """ + + def __init__( + self, + message: str, + ) -> None: + """ + Initialize a TestDestinationResponseBody object. + + :param str message: The status message that indicates the test result. + """ + self.message = message + + @classmethod + def from_dict(cls, _dict: Dict) -> 'TestDestinationResponseBody': + """Initialize a TestDestinationResponseBody object from a json dictionary.""" + args = {} + if (message := _dict.get('message')) is not None: + args['message'] = message + else: + raise ValueError('Required property \'message\' not present in TestDestinationResponseBody JSON') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a TestDestinationResponseBody object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'message') and self.message is not None: + _dict['message'] = self.message + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this TestDestinationResponseBody object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'TestDestinationResponseBody') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'TestDestinationResponseBody') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + +class Acknowledgement: + """ + Status indicating whether the user has unread notifications. + + :param bool has_unread: Indicates whether the user has unread notifications. + :param str latest_notification_id: The ID of the most recent notification + available to the user. + :param str last_acknowledged_id: The ID of the last notification acknowledged by + the user. + """ + + def __init__( + self, + has_unread: bool, + latest_notification_id: str, + last_acknowledged_id: str, + ) -> None: + """ + Initialize a Acknowledgement object. + + :param bool has_unread: Indicates whether the user has unread + notifications. + :param str latest_notification_id: The ID of the most recent notification + available to the user. + :param str last_acknowledged_id: The ID of the last notification + acknowledged by the user. + """ + self.has_unread = has_unread + self.latest_notification_id = latest_notification_id + self.last_acknowledged_id = last_acknowledged_id + + @classmethod + def from_dict(cls, _dict: Dict) -> 'Acknowledgement': + """Initialize a Acknowledgement object from a json dictionary.""" + args = {} + if (has_unread := _dict.get('has_unread')) is not None: + args['has_unread'] = has_unread + else: + raise ValueError('Required property \'has_unread\' not present in Acknowledgement JSON') + if (latest_notification_id := _dict.get('latest_notification_id')) is not None: + args['latest_notification_id'] = latest_notification_id + else: + raise ValueError('Required property \'latest_notification_id\' not present in Acknowledgement JSON') + if (last_acknowledged_id := _dict.get('last_acknowledged_id')) is not None: + args['last_acknowledged_id'] = last_acknowledged_id + else: + raise ValueError('Required property \'last_acknowledged_id\' not present in Acknowledgement JSON') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a Acknowledgement object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'has_unread') and self.has_unread is not None: + _dict['has_unread'] = self.has_unread + if hasattr(self, 'latest_notification_id') and self.latest_notification_id is not None: + _dict['latest_notification_id'] = self.latest_notification_id + if hasattr(self, 'last_acknowledged_id') and self.last_acknowledged_id is not None: + _dict['last_acknowledged_id'] = self.last_acknowledged_id + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this Acknowledgement object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'Acknowledgement') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'Acknowledgement') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + +class AddDestinationPrototypeEventNotificationDestinationPrototype(AddDestinationPrototype): + """ + Prototype for creating an Event Notifications destination entry. + + :param str destination_id: The GUID of the Event Notifications instance. + :param str destination_type: The type of the destination. + """ + + def __init__( + self, + destination_id: str, + destination_type: str, + ) -> None: + """ + Initialize a AddDestinationPrototypeEventNotificationDestinationPrototype object. + + :param str destination_id: The GUID of the Event Notifications instance. + :param str destination_type: The type of the destination. + """ + # pylint: disable=super-init-not-called + self.destination_id = destination_id + self.destination_type = destination_type + + @classmethod + def from_dict(cls, _dict: Dict) -> 'AddDestinationPrototypeEventNotificationDestinationPrototype': + """Initialize a AddDestinationPrototypeEventNotificationDestinationPrototype object from a json dictionary.""" + args = {} + if (destination_id := _dict.get('destination_id')) is not None: + args['destination_id'] = destination_id + else: + raise ValueError('Required property \'destination_id\' not present in AddDestinationPrototypeEventNotificationDestinationPrototype JSON') + if (destination_type := _dict.get('destination_type')) is not None: + args['destination_type'] = destination_type + else: + raise ValueError('Required property \'destination_type\' not present in AddDestinationPrototypeEventNotificationDestinationPrototype JSON') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a AddDestinationPrototypeEventNotificationDestinationPrototype object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'destination_id') and self.destination_id is not None: + _dict['destination_id'] = self.destination_id + if hasattr(self, 'destination_type') and self.destination_type is not None: + _dict['destination_type'] = self.destination_type + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this AddDestinationPrototypeEventNotificationDestinationPrototype object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'AddDestinationPrototypeEventNotificationDestinationPrototype') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'AddDestinationPrototypeEventNotificationDestinationPrototype') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + class DestinationTypeEnum(str, Enum): + """ + The type of the destination. + """ + + EVENT_NOTIFICATIONS = 'event_notifications' + + + +class AddDestinationEventNotificationDestination(AddDestination): + """ + An Event Notifications destination entry in the distribution list. + + :param str destination_id: The GUID of the Event Notifications instance. + :param str destination_type: The type of the destination. + """ + + def __init__( + self, + destination_id: str, + destination_type: str, + ) -> None: + """ + Initialize a AddDestinationEventNotificationDestination object. + + :param str destination_id: The GUID of the Event Notifications instance. + :param str destination_type: The type of the destination. + """ + # pylint: disable=super-init-not-called + self.destination_id = destination_id + self.destination_type = destination_type + + @classmethod + def from_dict(cls, _dict: Dict) -> 'AddDestinationEventNotificationDestination': + """Initialize a AddDestinationEventNotificationDestination object from a json dictionary.""" + args = {} + if (destination_id := _dict.get('destination_id')) is not None: + args['destination_id'] = destination_id + else: + raise ValueError('Required property \'destination_id\' not present in AddDestinationEventNotificationDestination JSON') + if (destination_type := _dict.get('destination_type')) is not None: + args['destination_type'] = destination_type + else: + raise ValueError('Required property \'destination_type\' not present in AddDestinationEventNotificationDestination JSON') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a AddDestinationEventNotificationDestination object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'destination_id') and self.destination_id is not None: + _dict['destination_id'] = self.destination_id + if hasattr(self, 'destination_type') and self.destination_type is not None: + _dict['destination_type'] = self.destination_type + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this AddDestinationEventNotificationDestination object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'AddDestinationEventNotificationDestination') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'AddDestinationEventNotificationDestination') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + class DestinationTypeEnum(str, Enum): + """ + The type of the destination. + """ + + EVENT_NOTIFICATIONS = 'event_notifications' + + + +class TestDestinationRequestBodyPrototypeTestEventNotificationDestinationRequestBodyPrototype(TestDestinationRequestBodyPrototype): + """ + Request body for testing an Event Notifications destination. + + :param str destination_type: The type of the destination. + :param str notification_type: The type of the notification to test. + """ + + def __init__( + self, + destination_type: str, + notification_type: str, + ) -> None: + """ + Initialize a TestDestinationRequestBodyPrototypeTestEventNotificationDestinationRequestBodyPrototype object. + + :param str destination_type: The type of the destination. + :param str notification_type: The type of the notification to test. + """ + # pylint: disable=super-init-not-called + self.destination_type = destination_type + self.notification_type = notification_type + + @classmethod + def from_dict(cls, _dict: Dict) -> 'TestDestinationRequestBodyPrototypeTestEventNotificationDestinationRequestBodyPrototype': + """Initialize a TestDestinationRequestBodyPrototypeTestEventNotificationDestinationRequestBodyPrototype object from a json dictionary.""" + args = {} + if (destination_type := _dict.get('destination_type')) is not None: + args['destination_type'] = destination_type + else: + raise ValueError('Required property \'destination_type\' not present in TestDestinationRequestBodyPrototypeTestEventNotificationDestinationRequestBodyPrototype JSON') + if (notification_type := _dict.get('notification_type')) is not None: + args['notification_type'] = notification_type + else: + raise ValueError('Required property \'notification_type\' not present in TestDestinationRequestBodyPrototypeTestEventNotificationDestinationRequestBodyPrototype JSON') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a TestDestinationRequestBodyPrototypeTestEventNotificationDestinationRequestBodyPrototype object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'destination_type') and self.destination_type is not None: + _dict['destination_type'] = self.destination_type + if hasattr(self, 'notification_type') and self.notification_type is not None: + _dict['notification_type'] = self.notification_type + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this TestDestinationRequestBodyPrototypeTestEventNotificationDestinationRequestBodyPrototype object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'TestDestinationRequestBodyPrototypeTestEventNotificationDestinationRequestBodyPrototype') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'TestDestinationRequestBodyPrototypeTestEventNotificationDestinationRequestBodyPrototype') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + class DestinationTypeEnum(str, Enum): + """ + The type of the destination. + """ + + EVENT_NOTIFICATIONS = 'event_notifications' + + + class NotificationTypeEnum(str, Enum): + """ + The type of the notification to test. + """ + + INCIDENT = 'incident' + ANNOUNCEMENTS = 'announcements' + MAINTENANCE = 'maintenance' + SECURITY_BULLETINS = 'security_bulletins' + RESOURCE = 'resource' + BILLING_AND_USAGE = 'billing_and_usage' + + +############################################################################## +# Pagers +############################################################################## + + +class NotificationsPager: + """ + NotificationsPager can be used to simplify the use of the "list_notifications" method. + """ + + def __init__( + self, + *, + client: PlatformNotificationsV1, + account_id: str = None, + limit: int = None, + ) -> None: + """ + Initialize a NotificationsPager object. + :param str account_id: (optional) The IBM Cloud account ID. If not + provided, the account ID from the bearer token will be used. + :param int limit: (optional) The maximum number of items to return per + page. If unspecified, a default limit of 50 is used. + """ + self._has_next = True + self._client = client + self._page_context = {'next': None} + self._account_id = account_id + self._limit = limit + + def has_next(self) -> bool: + """ + Returns true if there are potentially more results to be retrieved. + """ + return self._has_next + + def get_next(self) -> List[dict]: + """ + Returns the next page of results. + :return: A List[dict], where each element is a dict that represents an instance of Notification. + :rtype: List[dict] + """ + if not self.has_next(): + raise StopIteration(message='No more results available') + + result = self._client.list_notifications( + account_id=self._account_id, + limit=self._limit, + start=self._page_context.get('next'), + ).get_result() + + next = None + next_page_link = result.get('next') + if next_page_link is not None: + next = next_page_link.get('start') + self._page_context['next'] = next + if next is None: + self._has_next = False + + return result.get('notifications') + + def get_all(self) -> List[dict]: + """ + Returns all results by invoking get_next() repeatedly + until all pages of results have been retrieved. + :return: A List[dict], where each element is a dict that represents an instance of Notification. + :rtype: List[dict] + """ + results = [] + while self.has_next(): + next_page = self.get_next() + results.extend(next_page) + return results diff --git a/test/integration/test_platform_notifications_v1.py b/test/integration/test_platform_notifications_v1.py new file mode 100644 index 00000000..36fd3bd9 --- /dev/null +++ b/test/integration/test_platform_notifications_v1.py @@ -0,0 +1,299 @@ +# -*- coding: utf-8 -*- +# (C) Copyright IBM Corp. 2026. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +""" +Integration Tests for PlatformNotificationsV1 +""" + +from ibm_cloud_sdk_core import * +import os +import pytest +from ibm_platform_services.platform_notifications_v1 import * + +# Config file name +config_file = 'platform_notifications_v1.env' + +account_id = '' +destination_id = '' +iam_id = '' +service_url = '' + +class TestPlatformNotificationsV1: + """ + Integration Test Class for PlatformNotificationsV1 + """ + + @classmethod + def setup_class(cls): + if os.path.exists(config_file): + os.environ['IBM_CREDENTIALS_FILE'] = config_file + + cls.platform_notifications_service = PlatformNotificationsV1.new_instance( + ) + assert cls.platform_notifications_service is not None + + cls.config = read_external_sources(PlatformNotificationsV1.DEFAULT_SERVICE_NAME) + global account_id, destination_id, iam_id, service_url + account_id = cls.config['ACCOUNT_ID'] + destination_id = cls.config['DESTINATION_ID'] + iam_id = cls.config['IAM_ID'] + service_url = cls.config['SERVICE_URL'] + assert cls.config is not None + + # Set service URL if provided in config + if service_url: + cls.platform_notifications_service.set_service_url(service_url) + + cls.platform_notifications_service.enable_retries() + + print('Setup complete.') + + needscredentials = pytest.mark.skipif( + not os.path.exists(config_file), reason="External configuration not available, skipping..." + ) + + @needscredentials + def test_test_distribution_list_destination(self): + # Construct a dict representation of a TestDestinationRequestBodyPrototypeTestEventNotificationDestinationRequestBodyPrototype model + test_destination_request_body_prototype_model = { + 'destination_type': 'event_notifications', + 'notification_type': 'incident', + } + + response = self.platform_notifications_service.test_distribution_list_destination( + account_id=account_id, + destination_id=destination_id, + test_destination_request_body_prototype=test_destination_request_body_prototype_model, + ) + + assert response.get_status_code() == 200 + test_destination_response_body = response.get_result() + assert test_destination_response_body is not None + + @needscredentials + def test_delete_distribution_list_destination(self): + response = self.platform_notifications_service.delete_distribution_list_destination( + account_id=account_id, + destination_id=destination_id, + ) + + assert response.get_status_code() == 204 + + @needscredentials + def test_create_distribution_list_destination(self): + # Construct a dict representation of a AddDestinationPrototypeEventNotificationDestinationPrototype model + add_destination_prototype_model = { + 'destination_id': destination_id, + 'destination_type': 'event_notifications', + } + + response = self.platform_notifications_service.create_distribution_list_destination( + account_id=account_id, + add_destination_prototype=add_destination_prototype_model, + ) + + assert response.get_status_code() == 201 + add_destination = response.get_result() + assert add_destination is not None + + @needscredentials + def test_list_distribution_list_destinations(self): + response = self.platform_notifications_service.list_distribution_list_destinations( + account_id=account_id, + ) + + assert response.get_status_code() == 200 + add_destination_collection = response.get_result() + assert add_destination_collection is not None + + @needscredentials + def test_get_distribution_list_destination(self): + response = self.platform_notifications_service.get_distribution_list_destination( + account_id=account_id, + destination_id=destination_id, + ) + + assert response.get_status_code() == 200 + add_destination = response.get_result() + assert add_destination is not None + + @needscredentials + def test_create_preferences(self): + # Construct a dict representation of a PreferenceValueWithUpdates model + preference_value_with_updates_model = { + 'channels': ['email'], + 'updates': True, + } + # Construct a dict representation of a PreferenceValueWithoutUpdates model + preference_value_without_updates_model = { + 'channels': ['email'], + } + + response = self.platform_notifications_service.create_preferences( + iam_id=iam_id, + incident_severity1=preference_value_with_updates_model, + incident_severity2=preference_value_with_updates_model, + incident_severity3=preference_value_with_updates_model, + incident_severity4=preference_value_with_updates_model, + maintenance_high=preference_value_with_updates_model, + maintenance_medium=preference_value_with_updates_model, + maintenance_low=preference_value_with_updates_model, + announcements_major=preference_value_without_updates_model, + announcements_minor=preference_value_without_updates_model, + security_normal=preference_value_without_updates_model, + account_normal=preference_value_without_updates_model, + billing_and_usage_order=preference_value_without_updates_model, + billing_and_usage_invoices=preference_value_without_updates_model, + billing_and_usage_payments=preference_value_without_updates_model, + billing_and_usage_subscriptions_and_promo_codes=preference_value_without_updates_model, + billing_and_usage_spending_alerts=preference_value_without_updates_model, + resourceactivity_normal=preference_value_without_updates_model, + ordering_review=preference_value_without_updates_model, + ordering_approved=preference_value_without_updates_model, + ordering_approved_vsi=preference_value_without_updates_model, + ordering_approved_server=preference_value_without_updates_model, + provisioning_reload_complete=preference_value_without_updates_model, + provisioning_complete_vsi=preference_value_without_updates_model, + provisioning_complete_server=preference_value_without_updates_model, + account_id=account_id, + ) + + assert response.get_status_code() == 201 + preferences_object = response.get_result() + assert preferences_object is not None + + @needscredentials + def test_get_preferences(self): + response = self.platform_notifications_service.get_preferences( + iam_id=iam_id, + account_id=account_id, + ) + + assert response.get_status_code() == 200 + preferences_object = response.get_result() + assert preferences_object is not None + + @needscredentials + def test_replace_notification_preferences(self): + # Construct a dict representation of a PreferenceValueWithUpdates model + preference_value_with_updates_model = { + 'channels': ['email'], + 'updates': True, + } + # Construct a dict representation of a PreferenceValueWithoutUpdates model + preference_value_without_updates_model = { + 'channels': ['email'], + } + + response = self.platform_notifications_service.replace_notification_preferences( + iam_id=iam_id, + incident_severity1=preference_value_with_updates_model, + incident_severity2=preference_value_with_updates_model, + incident_severity3=preference_value_with_updates_model, + incident_severity4=preference_value_with_updates_model, + maintenance_high=preference_value_with_updates_model, + maintenance_medium=preference_value_with_updates_model, + maintenance_low=preference_value_with_updates_model, + announcements_major=preference_value_without_updates_model, + announcements_minor=preference_value_without_updates_model, + security_normal=preference_value_without_updates_model, + account_normal=preference_value_without_updates_model, + billing_and_usage_order=preference_value_without_updates_model, + billing_and_usage_invoices=preference_value_without_updates_model, + billing_and_usage_payments=preference_value_without_updates_model, + billing_and_usage_subscriptions_and_promo_codes=preference_value_without_updates_model, + billing_and_usage_spending_alerts=preference_value_without_updates_model, + resourceactivity_normal=preference_value_without_updates_model, + ordering_review=preference_value_without_updates_model, + ordering_approved=preference_value_without_updates_model, + ordering_approved_vsi=preference_value_without_updates_model, + ordering_approved_server=preference_value_without_updates_model, + provisioning_reload_complete=preference_value_without_updates_model, + provisioning_complete_vsi=preference_value_without_updates_model, + provisioning_complete_server=preference_value_without_updates_model, + account_id=account_id, + ) + + assert response.get_status_code() == 200 + preferences_object = response.get_result() + assert preferences_object is not None + + @needscredentials + def test_list_notifications(self): + response = self.platform_notifications_service.list_notifications( + account_id=account_id, + ) + + assert response.get_status_code() == 200 + notification_collection = response.get_result() + assert notification_collection is not None + + @needscredentials + def test_list_notifications_with_pager(self): + all_results = [] + + # Test get_next(). + pager = NotificationsPager( + client=self.platform_notifications_service, + account_id=account_id, + limit=50, + ) + while pager.has_next(): + next_page = pager.get_next() + assert next_page is not None + all_results.extend(next_page) + + # Test get_all(). + pager = NotificationsPager( + client=self.platform_notifications_service, + account_id=account_id, + limit=50, + ) + all_items = pager.get_all() + assert all_items is not None + + assert len(all_results) == len(all_items) + print(f'\nlist_notifications() returned a total of {len(all_results)} items(s) using NotificationsPager.') + + @needscredentials + def test_get_acknowledgement(self): + response = self.platform_notifications_service.get_acknowledgement( + account_id=account_id, + ) + + assert response.get_status_code() == 200 + acknowledgement = response.get_result() + assert acknowledgement is not None + + @needscredentials + def test_replace_notification_acknowledgement(self): + response = self.platform_notifications_service.replace_notification_acknowledgement( + last_acknowledged_id='1772804159452', + account_id=account_id, + ) + + assert response.get_status_code() == 200 + acknowledgement = response.get_result() + assert acknowledgement is not None + + + @needscredentials + def test_delete_notification_preferences(self): + response = self.platform_notifications_service.delete_notification_preferences( + iam_id=iam_id, + account_id=account_id, + ) + + assert response.get_status_code() == 204 diff --git a/test/unit/test_platform_notifications_v1.py b/test/unit/test_platform_notifications_v1.py new file mode 100644 index 00000000..1c81391a --- /dev/null +++ b/test/unit/test_platform_notifications_v1.py @@ -0,0 +1,2374 @@ +# -*- coding: utf-8 -*- +# (C) Copyright IBM Corp. 2026. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +""" +Unit Tests for PlatformNotificationsV1 +""" + +from ibm_cloud_sdk_core.authenticators.no_auth_authenticator import NoAuthAuthenticator +import inspect +import json +import os +import pytest +import re +import requests +import responses +import urllib +from ibm_platform_services.platform_notifications_v1 import * + + +_service = PlatformNotificationsV1( + authenticator=NoAuthAuthenticator() +) + +_base_url = 'https://notifications.cloud.ibm.com/api' +_service.set_service_url(_base_url) + + +def preprocess_url(operation_path: str): + """ + Returns the request url associated with the specified operation path. + This will be base_url concatenated with a quoted version of operation_path. + The returned request URL is used to register the mock response so it needs + to match the request URL that is formed by the requests library. + """ + + # Form the request URL from the base URL and operation path. + request_url = _base_url + operation_path + + # If the request url does NOT end with a /, then just return it as-is. + # Otherwise, return a regular expression that matches one or more trailing /. + if not request_url.endswith('/'): + return request_url + return re.compile(request_url.rstrip('/') + '/+') + + +############################################################################## +# Start of Service: DistributionLists +############################################################################## +# region + + +class TestNewInstance: + """ + Test Class for new_instance + """ + + def test_new_instance(self): + """ + new_instance() + """ + os.environ['TEST_SERVICE_AUTH_TYPE'] = 'noAuth' + + service = PlatformNotificationsV1.new_instance( + service_name='TEST_SERVICE', + ) + + assert service is not None + assert isinstance(service, PlatformNotificationsV1) + + def test_new_instance_without_authenticator(self): + """ + new_instance_without_authenticator() + """ + with pytest.raises(ValueError, match='authenticator must be provided'): + service = PlatformNotificationsV1.new_instance( + service_name='TEST_SERVICE_NOT_FOUND', + ) + + +class TestListDistributionListDestinations: + """ + Test Class for list_distribution_list_destinations + """ + + @responses.activate + def test_list_distribution_list_destinations_all_params(self): + """ + list_distribution_list_destinations() + """ + # Set up mock + url = preprocess_url('/v1/distribution_lists/a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6/destinations') + mock_response = '{"destinations": [{"destination_id": "12345678-1234-1234-1234-123456789012", "destination_type": "event_notifications"}]}' + responses.add( + responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200, + ) + + # Set up parameter values + account_id = 'a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6' + + # Invoke method + response = _service.list_distribution_list_destinations( + account_id, + headers={}, + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + + def test_list_distribution_list_destinations_all_params_with_retries(self): + # Enable retries and run test_list_distribution_list_destinations_all_params. + _service.enable_retries() + self.test_list_distribution_list_destinations_all_params() + + # Disable retries and run test_list_distribution_list_destinations_all_params. + _service.disable_retries() + self.test_list_distribution_list_destinations_all_params() + + @responses.activate + def test_list_distribution_list_destinations_value_error(self): + """ + test_list_distribution_list_destinations_value_error() + """ + # Set up mock + url = preprocess_url('/v1/distribution_lists/a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6/destinations') + mock_response = '{"destinations": [{"destination_id": "12345678-1234-1234-1234-123456789012", "destination_type": "event_notifications"}]}' + responses.add( + responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200, + ) + + # Set up parameter values + account_id = 'a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6' + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "account_id": account_id, + } + for param in req_param_dict.keys(): + req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} + with pytest.raises(ValueError): + _service.list_distribution_list_destinations(**req_copy) + + def test_list_distribution_list_destinations_value_error_with_retries(self): + # Enable retries and run test_list_distribution_list_destinations_value_error. + _service.enable_retries() + self.test_list_distribution_list_destinations_value_error() + + # Disable retries and run test_list_distribution_list_destinations_value_error. + _service.disable_retries() + self.test_list_distribution_list_destinations_value_error() + + +class TestCreateDistributionListDestination: + """ + Test Class for create_distribution_list_destination + """ + + @responses.activate + def test_create_distribution_list_destination_all_params(self): + """ + create_distribution_list_destination() + """ + # Set up mock + url = preprocess_url('/v1/distribution_lists/a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6/destinations') + mock_response = '{"destination_id": "12345678-1234-1234-1234-123456789012", "destination_type": "event_notifications"}' + responses.add( + responses.POST, + url, + body=mock_response, + content_type='application/json', + status=201, + ) + + # Construct a dict representation of a AddDestinationPrototypeEventNotificationDestinationPrototype model + add_destination_prototype_model = {} + add_destination_prototype_model['destination_id'] = '12345678-1234-1234-1234-123456789012' + add_destination_prototype_model['destination_type'] = 'event_notifications' + + # Set up parameter values + account_id = 'a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6' + add_destination_prototype = add_destination_prototype_model + + # Invoke method + response = _service.create_distribution_list_destination( + account_id, + add_destination_prototype, + headers={}, + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 201 + # Validate body params + req_body = json.loads(str(responses.calls[0].request.body, 'utf-8')) + assert req_body == add_destination_prototype + + def test_create_distribution_list_destination_all_params_with_retries(self): + # Enable retries and run test_create_distribution_list_destination_all_params. + _service.enable_retries() + self.test_create_distribution_list_destination_all_params() + + # Disable retries and run test_create_distribution_list_destination_all_params. + _service.disable_retries() + self.test_create_distribution_list_destination_all_params() + + @responses.activate + def test_create_distribution_list_destination_value_error(self): + """ + test_create_distribution_list_destination_value_error() + """ + # Set up mock + url = preprocess_url('/v1/distribution_lists/a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6/destinations') + mock_response = '{"destination_id": "12345678-1234-1234-1234-123456789012", "destination_type": "event_notifications"}' + responses.add( + responses.POST, + url, + body=mock_response, + content_type='application/json', + status=201, + ) + + # Construct a dict representation of a AddDestinationPrototypeEventNotificationDestinationPrototype model + add_destination_prototype_model = {} + add_destination_prototype_model['destination_id'] = '12345678-1234-1234-1234-123456789012' + add_destination_prototype_model['destination_type'] = 'event_notifications' + + # Set up parameter values + account_id = 'a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6' + add_destination_prototype = add_destination_prototype_model + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "account_id": account_id, + "add_destination_prototype": add_destination_prototype, + } + for param in req_param_dict.keys(): + req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} + with pytest.raises(ValueError): + _service.create_distribution_list_destination(**req_copy) + + def test_create_distribution_list_destination_value_error_with_retries(self): + # Enable retries and run test_create_distribution_list_destination_value_error. + _service.enable_retries() + self.test_create_distribution_list_destination_value_error() + + # Disable retries and run test_create_distribution_list_destination_value_error. + _service.disable_retries() + self.test_create_distribution_list_destination_value_error() + + +class TestGetDistributionListDestination: + """ + Test Class for get_distribution_list_destination + """ + + @responses.activate + def test_get_distribution_list_destination_all_params(self): + """ + get_distribution_list_destination() + """ + # Set up mock + url = preprocess_url('/v1/distribution_lists/a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6/destinations/12345678-1234-1234-1234-123456789012') + mock_response = '{"destination_id": "12345678-1234-1234-1234-123456789012", "destination_type": "event_notifications"}' + responses.add( + responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200, + ) + + # Set up parameter values + account_id = 'a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6' + destination_id = '12345678-1234-1234-1234-123456789012' + + # Invoke method + response = _service.get_distribution_list_destination( + account_id, + destination_id, + headers={}, + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + + def test_get_distribution_list_destination_all_params_with_retries(self): + # Enable retries and run test_get_distribution_list_destination_all_params. + _service.enable_retries() + self.test_get_distribution_list_destination_all_params() + + # Disable retries and run test_get_distribution_list_destination_all_params. + _service.disable_retries() + self.test_get_distribution_list_destination_all_params() + + @responses.activate + def test_get_distribution_list_destination_value_error(self): + """ + test_get_distribution_list_destination_value_error() + """ + # Set up mock + url = preprocess_url('/v1/distribution_lists/a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6/destinations/12345678-1234-1234-1234-123456789012') + mock_response = '{"destination_id": "12345678-1234-1234-1234-123456789012", "destination_type": "event_notifications"}' + responses.add( + responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200, + ) + + # Set up parameter values + account_id = 'a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6' + destination_id = '12345678-1234-1234-1234-123456789012' + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "account_id": account_id, + "destination_id": destination_id, + } + for param in req_param_dict.keys(): + req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} + with pytest.raises(ValueError): + _service.get_distribution_list_destination(**req_copy) + + def test_get_distribution_list_destination_value_error_with_retries(self): + # Enable retries and run test_get_distribution_list_destination_value_error. + _service.enable_retries() + self.test_get_distribution_list_destination_value_error() + + # Disable retries and run test_get_distribution_list_destination_value_error. + _service.disable_retries() + self.test_get_distribution_list_destination_value_error() + + +class TestDeleteDistributionListDestination: + """ + Test Class for delete_distribution_list_destination + """ + + @responses.activate + def test_delete_distribution_list_destination_all_params(self): + """ + delete_distribution_list_destination() + """ + # Set up mock + url = preprocess_url('/v1/distribution_lists/a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6/destinations/12345678-1234-1234-1234-123456789012') + responses.add( + responses.DELETE, + url, + status=204, + ) + + # Set up parameter values + account_id = 'a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6' + destination_id = '12345678-1234-1234-1234-123456789012' + + # Invoke method + response = _service.delete_distribution_list_destination( + account_id, + destination_id, + headers={}, + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 204 + + def test_delete_distribution_list_destination_all_params_with_retries(self): + # Enable retries and run test_delete_distribution_list_destination_all_params. + _service.enable_retries() + self.test_delete_distribution_list_destination_all_params() + + # Disable retries and run test_delete_distribution_list_destination_all_params. + _service.disable_retries() + self.test_delete_distribution_list_destination_all_params() + + @responses.activate + def test_delete_distribution_list_destination_value_error(self): + """ + test_delete_distribution_list_destination_value_error() + """ + # Set up mock + url = preprocess_url('/v1/distribution_lists/a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6/destinations/12345678-1234-1234-1234-123456789012') + responses.add( + responses.DELETE, + url, + status=204, + ) + + # Set up parameter values + account_id = 'a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6' + destination_id = '12345678-1234-1234-1234-123456789012' + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "account_id": account_id, + "destination_id": destination_id, + } + for param in req_param_dict.keys(): + req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} + with pytest.raises(ValueError): + _service.delete_distribution_list_destination(**req_copy) + + def test_delete_distribution_list_destination_value_error_with_retries(self): + # Enable retries and run test_delete_distribution_list_destination_value_error. + _service.enable_retries() + self.test_delete_distribution_list_destination_value_error() + + # Disable retries and run test_delete_distribution_list_destination_value_error. + _service.disable_retries() + self.test_delete_distribution_list_destination_value_error() + + +class TestTestDistributionListDestination: + """ + Test Class for test_distribution_list_destination + """ + + @responses.activate + def test_test_distribution_list_destination_all_params(self): + """ + test_distribution_list_destination() + """ + # Set up mock + url = preprocess_url('/v1/distribution_lists/a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6/destinations/12345678-1234-1234-1234-123456789012/test') + mock_response = '{"message": "success"}' + responses.add( + responses.POST, + url, + body=mock_response, + content_type='application/json', + status=200, + ) + + # Construct a dict representation of a TestDestinationRequestBodyPrototypeTestEventNotificationDestinationRequestBodyPrototype model + test_destination_request_body_prototype_model = {} + test_destination_request_body_prototype_model['destination_type'] = 'event_notifications' + test_destination_request_body_prototype_model['notification_type'] = 'incident' + + # Set up parameter values + account_id = 'a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6' + destination_id = '12345678-1234-1234-1234-123456789012' + test_destination_request_body_prototype = test_destination_request_body_prototype_model + + # Invoke method + response = _service.test_distribution_list_destination( + account_id, + destination_id, + test_destination_request_body_prototype, + headers={}, + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + # Validate body params + req_body = json.loads(str(responses.calls[0].request.body, 'utf-8')) + assert req_body == test_destination_request_body_prototype + + def test_test_distribution_list_destination_all_params_with_retries(self): + # Enable retries and run test_test_distribution_list_destination_all_params. + _service.enable_retries() + self.test_test_distribution_list_destination_all_params() + + # Disable retries and run test_test_distribution_list_destination_all_params. + _service.disable_retries() + self.test_test_distribution_list_destination_all_params() + + @responses.activate + def test_test_distribution_list_destination_value_error(self): + """ + test_test_distribution_list_destination_value_error() + """ + # Set up mock + url = preprocess_url('/v1/distribution_lists/a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6/destinations/12345678-1234-1234-1234-123456789012/test') + mock_response = '{"message": "success"}' + responses.add( + responses.POST, + url, + body=mock_response, + content_type='application/json', + status=200, + ) + + # Construct a dict representation of a TestDestinationRequestBodyPrototypeTestEventNotificationDestinationRequestBodyPrototype model + test_destination_request_body_prototype_model = {} + test_destination_request_body_prototype_model['destination_type'] = 'event_notifications' + test_destination_request_body_prototype_model['notification_type'] = 'incident' + + # Set up parameter values + account_id = 'a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6' + destination_id = '12345678-1234-1234-1234-123456789012' + test_destination_request_body_prototype = test_destination_request_body_prototype_model + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "account_id": account_id, + "destination_id": destination_id, + "test_destination_request_body_prototype": test_destination_request_body_prototype, + } + for param in req_param_dict.keys(): + req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} + with pytest.raises(ValueError): + _service.test_distribution_list_destination(**req_copy) + + def test_test_distribution_list_destination_value_error_with_retries(self): + # Enable retries and run test_test_distribution_list_destination_value_error. + _service.enable_retries() + self.test_test_distribution_list_destination_value_error() + + # Disable retries and run test_test_distribution_list_destination_value_error. + _service.disable_retries() + self.test_test_distribution_list_destination_value_error() + + +# endregion +############################################################################## +# End of Service: DistributionLists +############################################################################## + +############################################################################## +# Start of Service: UserPreferences +############################################################################## +# region + + +class TestNewInstance: + """ + Test Class for new_instance + """ + + def test_new_instance(self): + """ + new_instance() + """ + os.environ['TEST_SERVICE_AUTH_TYPE'] = 'noAuth' + + service = PlatformNotificationsV1.new_instance( + service_name='TEST_SERVICE', + ) + + assert service is not None + assert isinstance(service, PlatformNotificationsV1) + + def test_new_instance_without_authenticator(self): + """ + new_instance_without_authenticator() + """ + with pytest.raises(ValueError, match='authenticator must be provided'): + service = PlatformNotificationsV1.new_instance( + service_name='TEST_SERVICE_NOT_FOUND', + ) + + +class TestCreatePreferences: + """ + Test Class for create_preferences + """ + + @responses.activate + def test_create_preferences_all_params(self): + """ + create_preferences() + """ + # Set up mock + url = preprocess_url('/v1/notifications/IBMid-1234567890/preferences') + mock_response = '{"incident_severity1": {"channels": ["email"], "updates": true}, "incident_severity2": {"channels": ["email"], "updates": true}, "incident_severity3": {"channels": ["email"], "updates": true}, "incident_severity4": {"channels": ["email"], "updates": true}, "maintenance_high": {"channels": ["email"], "updates": true}, "maintenance_medium": {"channels": ["email"], "updates": true}, "maintenance_low": {"channels": ["email"], "updates": true}, "announcements_major": {"channels": ["email"]}, "announcements_minor": {"channels": ["email"]}, "security_normal": {"channels": ["email"]}, "account_normal": {"channels": ["email"]}, "billing_and_usage_order": {"channels": ["email"]}, "billing_and_usage_invoices": {"channels": ["email"]}, "billing_and_usage_payments": {"channels": ["email"]}, "billing_and_usage_subscriptions_and_promo_codes": {"channels": ["email"]}, "billing_and_usage_spending_alerts": {"channels": ["email"]}, "resourceactivity_normal": {"channels": ["email"]}, "ordering_review": {"channels": ["email"]}, "ordering_approved": {"channels": ["email"]}, "ordering_approved_vsi": {"channels": ["email"]}, "ordering_approved_server": {"channels": ["email"]}, "provisioning_reload_complete": {"channels": ["email"]}, "provisioning_complete_vsi": {"channels": ["email"]}, "provisioning_complete_server": {"channels": ["email"]}}' + responses.add( + responses.POST, + url, + body=mock_response, + content_type='application/json', + status=201, + ) + + # Construct a dict representation of a PreferenceValueWithUpdates model + preference_value_with_updates_model = {} + preference_value_with_updates_model['channels'] = ['email'] + preference_value_with_updates_model['updates'] = True + + # Construct a dict representation of a PreferenceValueWithoutUpdates model + preference_value_without_updates_model = {} + preference_value_without_updates_model['channels'] = ['email'] + + # Set up parameter values + iam_id = 'IBMid-1234567890' + incident_severity1 = preference_value_with_updates_model + incident_severity2 = preference_value_with_updates_model + incident_severity3 = preference_value_with_updates_model + incident_severity4 = preference_value_with_updates_model + maintenance_high = preference_value_with_updates_model + maintenance_medium = preference_value_with_updates_model + maintenance_low = preference_value_with_updates_model + announcements_major = preference_value_without_updates_model + announcements_minor = preference_value_without_updates_model + security_normal = preference_value_without_updates_model + account_normal = preference_value_without_updates_model + billing_and_usage_order = preference_value_without_updates_model + billing_and_usage_invoices = preference_value_without_updates_model + billing_and_usage_payments = preference_value_without_updates_model + billing_and_usage_subscriptions_and_promo_codes = preference_value_without_updates_model + billing_and_usage_spending_alerts = preference_value_without_updates_model + resourceactivity_normal = preference_value_without_updates_model + ordering_review = preference_value_without_updates_model + ordering_approved = preference_value_without_updates_model + ordering_approved_vsi = preference_value_without_updates_model + ordering_approved_server = preference_value_without_updates_model + provisioning_reload_complete = preference_value_without_updates_model + provisioning_complete_vsi = preference_value_without_updates_model + provisioning_complete_server = preference_value_without_updates_model + account_id = 'a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6' + + # Invoke method + response = _service.create_preferences( + iam_id, + incident_severity1=incident_severity1, + incident_severity2=incident_severity2, + incident_severity3=incident_severity3, + incident_severity4=incident_severity4, + maintenance_high=maintenance_high, + maintenance_medium=maintenance_medium, + maintenance_low=maintenance_low, + announcements_major=announcements_major, + announcements_minor=announcements_minor, + security_normal=security_normal, + account_normal=account_normal, + billing_and_usage_order=billing_and_usage_order, + billing_and_usage_invoices=billing_and_usage_invoices, + billing_and_usage_payments=billing_and_usage_payments, + billing_and_usage_subscriptions_and_promo_codes=billing_and_usage_subscriptions_and_promo_codes, + billing_and_usage_spending_alerts=billing_and_usage_spending_alerts, + resourceactivity_normal=resourceactivity_normal, + ordering_review=ordering_review, + ordering_approved=ordering_approved, + ordering_approved_vsi=ordering_approved_vsi, + ordering_approved_server=ordering_approved_server, + provisioning_reload_complete=provisioning_reload_complete, + provisioning_complete_vsi=provisioning_complete_vsi, + provisioning_complete_server=provisioning_complete_server, + account_id=account_id, + headers={}, + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 201 + # Validate query params + query_string = responses.calls[0].request.url.split('?', 1)[1] + query_string = urllib.parse.unquote_plus(query_string) + assert 'account_id={}'.format(account_id) in query_string + # Validate body params + req_body = json.loads(str(responses.calls[0].request.body, 'utf-8')) + assert req_body['incident_severity1'] == preference_value_with_updates_model + assert req_body['incident_severity2'] == preference_value_with_updates_model + assert req_body['incident_severity3'] == preference_value_with_updates_model + assert req_body['incident_severity4'] == preference_value_with_updates_model + assert req_body['maintenance_high'] == preference_value_with_updates_model + assert req_body['maintenance_medium'] == preference_value_with_updates_model + assert req_body['maintenance_low'] == preference_value_with_updates_model + assert req_body['announcements_major'] == preference_value_without_updates_model + assert req_body['announcements_minor'] == preference_value_without_updates_model + assert req_body['security_normal'] == preference_value_without_updates_model + assert req_body['account_normal'] == preference_value_without_updates_model + assert req_body['billing_and_usage_order'] == preference_value_without_updates_model + assert req_body['billing_and_usage_invoices'] == preference_value_without_updates_model + assert req_body['billing_and_usage_payments'] == preference_value_without_updates_model + assert req_body['billing_and_usage_subscriptions_and_promo_codes'] == preference_value_without_updates_model + assert req_body['billing_and_usage_spending_alerts'] == preference_value_without_updates_model + assert req_body['resourceactivity_normal'] == preference_value_without_updates_model + assert req_body['ordering_review'] == preference_value_without_updates_model + assert req_body['ordering_approved'] == preference_value_without_updates_model + assert req_body['ordering_approved_vsi'] == preference_value_without_updates_model + assert req_body['ordering_approved_server'] == preference_value_without_updates_model + assert req_body['provisioning_reload_complete'] == preference_value_without_updates_model + assert req_body['provisioning_complete_vsi'] == preference_value_without_updates_model + assert req_body['provisioning_complete_server'] == preference_value_without_updates_model + + def test_create_preferences_all_params_with_retries(self): + # Enable retries and run test_create_preferences_all_params. + _service.enable_retries() + self.test_create_preferences_all_params() + + # Disable retries and run test_create_preferences_all_params. + _service.disable_retries() + self.test_create_preferences_all_params() + + @responses.activate + def test_create_preferences_required_params(self): + """ + test_create_preferences_required_params() + """ + # Set up mock + url = preprocess_url('/v1/notifications/IBMid-1234567890/preferences') + mock_response = '{"incident_severity1": {"channels": ["email"], "updates": true}, "incident_severity2": {"channels": ["email"], "updates": true}, "incident_severity3": {"channels": ["email"], "updates": true}, "incident_severity4": {"channels": ["email"], "updates": true}, "maintenance_high": {"channels": ["email"], "updates": true}, "maintenance_medium": {"channels": ["email"], "updates": true}, "maintenance_low": {"channels": ["email"], "updates": true}, "announcements_major": {"channels": ["email"]}, "announcements_minor": {"channels": ["email"]}, "security_normal": {"channels": ["email"]}, "account_normal": {"channels": ["email"]}, "billing_and_usage_order": {"channels": ["email"]}, "billing_and_usage_invoices": {"channels": ["email"]}, "billing_and_usage_payments": {"channels": ["email"]}, "billing_and_usage_subscriptions_and_promo_codes": {"channels": ["email"]}, "billing_and_usage_spending_alerts": {"channels": ["email"]}, "resourceactivity_normal": {"channels": ["email"]}, "ordering_review": {"channels": ["email"]}, "ordering_approved": {"channels": ["email"]}, "ordering_approved_vsi": {"channels": ["email"]}, "ordering_approved_server": {"channels": ["email"]}, "provisioning_reload_complete": {"channels": ["email"]}, "provisioning_complete_vsi": {"channels": ["email"]}, "provisioning_complete_server": {"channels": ["email"]}}' + responses.add( + responses.POST, + url, + body=mock_response, + content_type='application/json', + status=201, + ) + + # Construct a dict representation of a PreferenceValueWithUpdates model + preference_value_with_updates_model = {} + preference_value_with_updates_model['channels'] = ['email'] + preference_value_with_updates_model['updates'] = True + + # Construct a dict representation of a PreferenceValueWithoutUpdates model + preference_value_without_updates_model = {} + preference_value_without_updates_model['channels'] = ['email'] + + # Set up parameter values + iam_id = 'IBMid-1234567890' + incident_severity1 = preference_value_with_updates_model + incident_severity2 = preference_value_with_updates_model + incident_severity3 = preference_value_with_updates_model + incident_severity4 = preference_value_with_updates_model + maintenance_high = preference_value_with_updates_model + maintenance_medium = preference_value_with_updates_model + maintenance_low = preference_value_with_updates_model + announcements_major = preference_value_without_updates_model + announcements_minor = preference_value_without_updates_model + security_normal = preference_value_without_updates_model + account_normal = preference_value_without_updates_model + billing_and_usage_order = preference_value_without_updates_model + billing_and_usage_invoices = preference_value_without_updates_model + billing_and_usage_payments = preference_value_without_updates_model + billing_and_usage_subscriptions_and_promo_codes = preference_value_without_updates_model + billing_and_usage_spending_alerts = preference_value_without_updates_model + resourceactivity_normal = preference_value_without_updates_model + ordering_review = preference_value_without_updates_model + ordering_approved = preference_value_without_updates_model + ordering_approved_vsi = preference_value_without_updates_model + ordering_approved_server = preference_value_without_updates_model + provisioning_reload_complete = preference_value_without_updates_model + provisioning_complete_vsi = preference_value_without_updates_model + provisioning_complete_server = preference_value_without_updates_model + + # Invoke method + response = _service.create_preferences( + iam_id, + incident_severity1=incident_severity1, + incident_severity2=incident_severity2, + incident_severity3=incident_severity3, + incident_severity4=incident_severity4, + maintenance_high=maintenance_high, + maintenance_medium=maintenance_medium, + maintenance_low=maintenance_low, + announcements_major=announcements_major, + announcements_minor=announcements_minor, + security_normal=security_normal, + account_normal=account_normal, + billing_and_usage_order=billing_and_usage_order, + billing_and_usage_invoices=billing_and_usage_invoices, + billing_and_usage_payments=billing_and_usage_payments, + billing_and_usage_subscriptions_and_promo_codes=billing_and_usage_subscriptions_and_promo_codes, + billing_and_usage_spending_alerts=billing_and_usage_spending_alerts, + resourceactivity_normal=resourceactivity_normal, + ordering_review=ordering_review, + ordering_approved=ordering_approved, + ordering_approved_vsi=ordering_approved_vsi, + ordering_approved_server=ordering_approved_server, + provisioning_reload_complete=provisioning_reload_complete, + provisioning_complete_vsi=provisioning_complete_vsi, + provisioning_complete_server=provisioning_complete_server, + headers={}, + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 201 + # Validate body params + req_body = json.loads(str(responses.calls[0].request.body, 'utf-8')) + assert req_body['incident_severity1'] == preference_value_with_updates_model + assert req_body['incident_severity2'] == preference_value_with_updates_model + assert req_body['incident_severity3'] == preference_value_with_updates_model + assert req_body['incident_severity4'] == preference_value_with_updates_model + assert req_body['maintenance_high'] == preference_value_with_updates_model + assert req_body['maintenance_medium'] == preference_value_with_updates_model + assert req_body['maintenance_low'] == preference_value_with_updates_model + assert req_body['announcements_major'] == preference_value_without_updates_model + assert req_body['announcements_minor'] == preference_value_without_updates_model + assert req_body['security_normal'] == preference_value_without_updates_model + assert req_body['account_normal'] == preference_value_without_updates_model + assert req_body['billing_and_usage_order'] == preference_value_without_updates_model + assert req_body['billing_and_usage_invoices'] == preference_value_without_updates_model + assert req_body['billing_and_usage_payments'] == preference_value_without_updates_model + assert req_body['billing_and_usage_subscriptions_and_promo_codes'] == preference_value_without_updates_model + assert req_body['billing_and_usage_spending_alerts'] == preference_value_without_updates_model + assert req_body['resourceactivity_normal'] == preference_value_without_updates_model + assert req_body['ordering_review'] == preference_value_without_updates_model + assert req_body['ordering_approved'] == preference_value_without_updates_model + assert req_body['ordering_approved_vsi'] == preference_value_without_updates_model + assert req_body['ordering_approved_server'] == preference_value_without_updates_model + assert req_body['provisioning_reload_complete'] == preference_value_without_updates_model + assert req_body['provisioning_complete_vsi'] == preference_value_without_updates_model + assert req_body['provisioning_complete_server'] == preference_value_without_updates_model + + def test_create_preferences_required_params_with_retries(self): + # Enable retries and run test_create_preferences_required_params. + _service.enable_retries() + self.test_create_preferences_required_params() + + # Disable retries and run test_create_preferences_required_params. + _service.disable_retries() + self.test_create_preferences_required_params() + + @responses.activate + def test_create_preferences_value_error(self): + """ + test_create_preferences_value_error() + """ + # Set up mock + url = preprocess_url('/v1/notifications/IBMid-1234567890/preferences') + mock_response = '{"incident_severity1": {"channels": ["email"], "updates": true}, "incident_severity2": {"channels": ["email"], "updates": true}, "incident_severity3": {"channels": ["email"], "updates": true}, "incident_severity4": {"channels": ["email"], "updates": true}, "maintenance_high": {"channels": ["email"], "updates": true}, "maintenance_medium": {"channels": ["email"], "updates": true}, "maintenance_low": {"channels": ["email"], "updates": true}, "announcements_major": {"channels": ["email"]}, "announcements_minor": {"channels": ["email"]}, "security_normal": {"channels": ["email"]}, "account_normal": {"channels": ["email"]}, "billing_and_usage_order": {"channels": ["email"]}, "billing_and_usage_invoices": {"channels": ["email"]}, "billing_and_usage_payments": {"channels": ["email"]}, "billing_and_usage_subscriptions_and_promo_codes": {"channels": ["email"]}, "billing_and_usage_spending_alerts": {"channels": ["email"]}, "resourceactivity_normal": {"channels": ["email"]}, "ordering_review": {"channels": ["email"]}, "ordering_approved": {"channels": ["email"]}, "ordering_approved_vsi": {"channels": ["email"]}, "ordering_approved_server": {"channels": ["email"]}, "provisioning_reload_complete": {"channels": ["email"]}, "provisioning_complete_vsi": {"channels": ["email"]}, "provisioning_complete_server": {"channels": ["email"]}}' + responses.add( + responses.POST, + url, + body=mock_response, + content_type='application/json', + status=201, + ) + + # Construct a dict representation of a PreferenceValueWithUpdates model + preference_value_with_updates_model = {} + preference_value_with_updates_model['channels'] = ['email'] + preference_value_with_updates_model['updates'] = True + + # Construct a dict representation of a PreferenceValueWithoutUpdates model + preference_value_without_updates_model = {} + preference_value_without_updates_model['channels'] = ['email'] + + # Set up parameter values + iam_id = 'IBMid-1234567890' + incident_severity1 = preference_value_with_updates_model + incident_severity2 = preference_value_with_updates_model + incident_severity3 = preference_value_with_updates_model + incident_severity4 = preference_value_with_updates_model + maintenance_high = preference_value_with_updates_model + maintenance_medium = preference_value_with_updates_model + maintenance_low = preference_value_with_updates_model + announcements_major = preference_value_without_updates_model + announcements_minor = preference_value_without_updates_model + security_normal = preference_value_without_updates_model + account_normal = preference_value_without_updates_model + billing_and_usage_order = preference_value_without_updates_model + billing_and_usage_invoices = preference_value_without_updates_model + billing_and_usage_payments = preference_value_without_updates_model + billing_and_usage_subscriptions_and_promo_codes = preference_value_without_updates_model + billing_and_usage_spending_alerts = preference_value_without_updates_model + resourceactivity_normal = preference_value_without_updates_model + ordering_review = preference_value_without_updates_model + ordering_approved = preference_value_without_updates_model + ordering_approved_vsi = preference_value_without_updates_model + ordering_approved_server = preference_value_without_updates_model + provisioning_reload_complete = preference_value_without_updates_model + provisioning_complete_vsi = preference_value_without_updates_model + provisioning_complete_server = preference_value_without_updates_model + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "iam_id": iam_id, + } + for param in req_param_dict.keys(): + req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} + with pytest.raises(ValueError): + _service.create_preferences(**req_copy) + + def test_create_preferences_value_error_with_retries(self): + # Enable retries and run test_create_preferences_value_error. + _service.enable_retries() + self.test_create_preferences_value_error() + + # Disable retries and run test_create_preferences_value_error. + _service.disable_retries() + self.test_create_preferences_value_error() + + +class TestGetPreferences: + """ + Test Class for get_preferences + """ + + @responses.activate + def test_get_preferences_all_params(self): + """ + get_preferences() + """ + # Set up mock + url = preprocess_url('/v1/notifications/IBMid-1234567890/preferences') + mock_response = '{"incident_severity1": {"channels": ["email"], "updates": true}, "incident_severity2": {"channels": ["email"], "updates": true}, "incident_severity3": {"channels": ["email"], "updates": true}, "incident_severity4": {"channels": ["email"], "updates": true}, "maintenance_high": {"channels": ["email"], "updates": true}, "maintenance_medium": {"channels": ["email"], "updates": true}, "maintenance_low": {"channels": ["email"], "updates": true}, "announcements_major": {"channels": ["email"]}, "announcements_minor": {"channels": ["email"]}, "security_normal": {"channels": ["email"]}, "account_normal": {"channels": ["email"]}, "billing_and_usage_order": {"channels": ["email"]}, "billing_and_usage_invoices": {"channels": ["email"]}, "billing_and_usage_payments": {"channels": ["email"]}, "billing_and_usage_subscriptions_and_promo_codes": {"channels": ["email"]}, "billing_and_usage_spending_alerts": {"channels": ["email"]}, "resourceactivity_normal": {"channels": ["email"]}, "ordering_review": {"channels": ["email"]}, "ordering_approved": {"channels": ["email"]}, "ordering_approved_vsi": {"channels": ["email"]}, "ordering_approved_server": {"channels": ["email"]}, "provisioning_reload_complete": {"channels": ["email"]}, "provisioning_complete_vsi": {"channels": ["email"]}, "provisioning_complete_server": {"channels": ["email"]}}' + responses.add( + responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200, + ) + + # Set up parameter values + iam_id = 'IBMid-1234567890' + account_id = 'a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6' + + # Invoke method + response = _service.get_preferences( + iam_id, + account_id=account_id, + headers={}, + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + # Validate query params + query_string = responses.calls[0].request.url.split('?', 1)[1] + query_string = urllib.parse.unquote_plus(query_string) + assert 'account_id={}'.format(account_id) in query_string + + def test_get_preferences_all_params_with_retries(self): + # Enable retries and run test_get_preferences_all_params. + _service.enable_retries() + self.test_get_preferences_all_params() + + # Disable retries and run test_get_preferences_all_params. + _service.disable_retries() + self.test_get_preferences_all_params() + + @responses.activate + def test_get_preferences_required_params(self): + """ + test_get_preferences_required_params() + """ + # Set up mock + url = preprocess_url('/v1/notifications/IBMid-1234567890/preferences') + mock_response = '{"incident_severity1": {"channels": ["email"], "updates": true}, "incident_severity2": {"channels": ["email"], "updates": true}, "incident_severity3": {"channels": ["email"], "updates": true}, "incident_severity4": {"channels": ["email"], "updates": true}, "maintenance_high": {"channels": ["email"], "updates": true}, "maintenance_medium": {"channels": ["email"], "updates": true}, "maintenance_low": {"channels": ["email"], "updates": true}, "announcements_major": {"channels": ["email"]}, "announcements_minor": {"channels": ["email"]}, "security_normal": {"channels": ["email"]}, "account_normal": {"channels": ["email"]}, "billing_and_usage_order": {"channels": ["email"]}, "billing_and_usage_invoices": {"channels": ["email"]}, "billing_and_usage_payments": {"channels": ["email"]}, "billing_and_usage_subscriptions_and_promo_codes": {"channels": ["email"]}, "billing_and_usage_spending_alerts": {"channels": ["email"]}, "resourceactivity_normal": {"channels": ["email"]}, "ordering_review": {"channels": ["email"]}, "ordering_approved": {"channels": ["email"]}, "ordering_approved_vsi": {"channels": ["email"]}, "ordering_approved_server": {"channels": ["email"]}, "provisioning_reload_complete": {"channels": ["email"]}, "provisioning_complete_vsi": {"channels": ["email"]}, "provisioning_complete_server": {"channels": ["email"]}}' + responses.add( + responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200, + ) + + # Set up parameter values + iam_id = 'IBMid-1234567890' + + # Invoke method + response = _service.get_preferences( + iam_id, + headers={}, + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + + def test_get_preferences_required_params_with_retries(self): + # Enable retries and run test_get_preferences_required_params. + _service.enable_retries() + self.test_get_preferences_required_params() + + # Disable retries and run test_get_preferences_required_params. + _service.disable_retries() + self.test_get_preferences_required_params() + + @responses.activate + def test_get_preferences_value_error(self): + """ + test_get_preferences_value_error() + """ + # Set up mock + url = preprocess_url('/v1/notifications/IBMid-1234567890/preferences') + mock_response = '{"incident_severity1": {"channels": ["email"], "updates": true}, "incident_severity2": {"channels": ["email"], "updates": true}, "incident_severity3": {"channels": ["email"], "updates": true}, "incident_severity4": {"channels": ["email"], "updates": true}, "maintenance_high": {"channels": ["email"], "updates": true}, "maintenance_medium": {"channels": ["email"], "updates": true}, "maintenance_low": {"channels": ["email"], "updates": true}, "announcements_major": {"channels": ["email"]}, "announcements_minor": {"channels": ["email"]}, "security_normal": {"channels": ["email"]}, "account_normal": {"channels": ["email"]}, "billing_and_usage_order": {"channels": ["email"]}, "billing_and_usage_invoices": {"channels": ["email"]}, "billing_and_usage_payments": {"channels": ["email"]}, "billing_and_usage_subscriptions_and_promo_codes": {"channels": ["email"]}, "billing_and_usage_spending_alerts": {"channels": ["email"]}, "resourceactivity_normal": {"channels": ["email"]}, "ordering_review": {"channels": ["email"]}, "ordering_approved": {"channels": ["email"]}, "ordering_approved_vsi": {"channels": ["email"]}, "ordering_approved_server": {"channels": ["email"]}, "provisioning_reload_complete": {"channels": ["email"]}, "provisioning_complete_vsi": {"channels": ["email"]}, "provisioning_complete_server": {"channels": ["email"]}}' + responses.add( + responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200, + ) + + # Set up parameter values + iam_id = 'IBMid-1234567890' + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "iam_id": iam_id, + } + for param in req_param_dict.keys(): + req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} + with pytest.raises(ValueError): + _service.get_preferences(**req_copy) + + def test_get_preferences_value_error_with_retries(self): + # Enable retries and run test_get_preferences_value_error. + _service.enable_retries() + self.test_get_preferences_value_error() + + # Disable retries and run test_get_preferences_value_error. + _service.disable_retries() + self.test_get_preferences_value_error() + + +class TestReplaceNotificationPreferences: + """ + Test Class for replace_notification_preferences + """ + + @responses.activate + def test_replace_notification_preferences_all_params(self): + """ + replace_notification_preferences() + """ + # Set up mock + url = preprocess_url('/v1/notifications/IBMid-1234567890/preferences') + mock_response = '{"incident_severity1": {"channels": ["email"], "updates": true}, "incident_severity2": {"channels": ["email"], "updates": true}, "incident_severity3": {"channels": ["email"], "updates": true}, "incident_severity4": {"channels": ["email"], "updates": true}, "maintenance_high": {"channels": ["email"], "updates": true}, "maintenance_medium": {"channels": ["email"], "updates": true}, "maintenance_low": {"channels": ["email"], "updates": true}, "announcements_major": {"channels": ["email"]}, "announcements_minor": {"channels": ["email"]}, "security_normal": {"channels": ["email"]}, "account_normal": {"channels": ["email"]}, "billing_and_usage_order": {"channels": ["email"]}, "billing_and_usage_invoices": {"channels": ["email"]}, "billing_and_usage_payments": {"channels": ["email"]}, "billing_and_usage_subscriptions_and_promo_codes": {"channels": ["email"]}, "billing_and_usage_spending_alerts": {"channels": ["email"]}, "resourceactivity_normal": {"channels": ["email"]}, "ordering_review": {"channels": ["email"]}, "ordering_approved": {"channels": ["email"]}, "ordering_approved_vsi": {"channels": ["email"]}, "ordering_approved_server": {"channels": ["email"]}, "provisioning_reload_complete": {"channels": ["email"]}, "provisioning_complete_vsi": {"channels": ["email"]}, "provisioning_complete_server": {"channels": ["email"]}}' + responses.add( + responses.PUT, + url, + body=mock_response, + content_type='application/json', + status=200, + ) + + # Construct a dict representation of a PreferenceValueWithUpdates model + preference_value_with_updates_model = {} + preference_value_with_updates_model['channels'] = ['email'] + preference_value_with_updates_model['updates'] = True + + # Construct a dict representation of a PreferenceValueWithoutUpdates model + preference_value_without_updates_model = {} + preference_value_without_updates_model['channels'] = ['email'] + + # Set up parameter values + iam_id = 'IBMid-1234567890' + incident_severity1 = preference_value_with_updates_model + incident_severity2 = preference_value_with_updates_model + incident_severity3 = preference_value_with_updates_model + incident_severity4 = preference_value_with_updates_model + maintenance_high = preference_value_with_updates_model + maintenance_medium = preference_value_with_updates_model + maintenance_low = preference_value_with_updates_model + announcements_major = preference_value_without_updates_model + announcements_minor = preference_value_without_updates_model + security_normal = preference_value_without_updates_model + account_normal = preference_value_without_updates_model + billing_and_usage_order = preference_value_without_updates_model + billing_and_usage_invoices = preference_value_without_updates_model + billing_and_usage_payments = preference_value_without_updates_model + billing_and_usage_subscriptions_and_promo_codes = preference_value_without_updates_model + billing_and_usage_spending_alerts = preference_value_without_updates_model + resourceactivity_normal = preference_value_without_updates_model + ordering_review = preference_value_without_updates_model + ordering_approved = preference_value_without_updates_model + ordering_approved_vsi = preference_value_without_updates_model + ordering_approved_server = preference_value_without_updates_model + provisioning_reload_complete = preference_value_without_updates_model + provisioning_complete_vsi = preference_value_without_updates_model + provisioning_complete_server = preference_value_without_updates_model + account_id = 'a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6' + + # Invoke method + response = _service.replace_notification_preferences( + iam_id, + incident_severity1=incident_severity1, + incident_severity2=incident_severity2, + incident_severity3=incident_severity3, + incident_severity4=incident_severity4, + maintenance_high=maintenance_high, + maintenance_medium=maintenance_medium, + maintenance_low=maintenance_low, + announcements_major=announcements_major, + announcements_minor=announcements_minor, + security_normal=security_normal, + account_normal=account_normal, + billing_and_usage_order=billing_and_usage_order, + billing_and_usage_invoices=billing_and_usage_invoices, + billing_and_usage_payments=billing_and_usage_payments, + billing_and_usage_subscriptions_and_promo_codes=billing_and_usage_subscriptions_and_promo_codes, + billing_and_usage_spending_alerts=billing_and_usage_spending_alerts, + resourceactivity_normal=resourceactivity_normal, + ordering_review=ordering_review, + ordering_approved=ordering_approved, + ordering_approved_vsi=ordering_approved_vsi, + ordering_approved_server=ordering_approved_server, + provisioning_reload_complete=provisioning_reload_complete, + provisioning_complete_vsi=provisioning_complete_vsi, + provisioning_complete_server=provisioning_complete_server, + account_id=account_id, + headers={}, + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + # Validate query params + query_string = responses.calls[0].request.url.split('?', 1)[1] + query_string = urllib.parse.unquote_plus(query_string) + assert 'account_id={}'.format(account_id) in query_string + # Validate body params + req_body = json.loads(str(responses.calls[0].request.body, 'utf-8')) + assert req_body['incident_severity1'] == preference_value_with_updates_model + assert req_body['incident_severity2'] == preference_value_with_updates_model + assert req_body['incident_severity3'] == preference_value_with_updates_model + assert req_body['incident_severity4'] == preference_value_with_updates_model + assert req_body['maintenance_high'] == preference_value_with_updates_model + assert req_body['maintenance_medium'] == preference_value_with_updates_model + assert req_body['maintenance_low'] == preference_value_with_updates_model + assert req_body['announcements_major'] == preference_value_without_updates_model + assert req_body['announcements_minor'] == preference_value_without_updates_model + assert req_body['security_normal'] == preference_value_without_updates_model + assert req_body['account_normal'] == preference_value_without_updates_model + assert req_body['billing_and_usage_order'] == preference_value_without_updates_model + assert req_body['billing_and_usage_invoices'] == preference_value_without_updates_model + assert req_body['billing_and_usage_payments'] == preference_value_without_updates_model + assert req_body['billing_and_usage_subscriptions_and_promo_codes'] == preference_value_without_updates_model + assert req_body['billing_and_usage_spending_alerts'] == preference_value_without_updates_model + assert req_body['resourceactivity_normal'] == preference_value_without_updates_model + assert req_body['ordering_review'] == preference_value_without_updates_model + assert req_body['ordering_approved'] == preference_value_without_updates_model + assert req_body['ordering_approved_vsi'] == preference_value_without_updates_model + assert req_body['ordering_approved_server'] == preference_value_without_updates_model + assert req_body['provisioning_reload_complete'] == preference_value_without_updates_model + assert req_body['provisioning_complete_vsi'] == preference_value_without_updates_model + assert req_body['provisioning_complete_server'] == preference_value_without_updates_model + + def test_replace_notification_preferences_all_params_with_retries(self): + # Enable retries and run test_replace_notification_preferences_all_params. + _service.enable_retries() + self.test_replace_notification_preferences_all_params() + + # Disable retries and run test_replace_notification_preferences_all_params. + _service.disable_retries() + self.test_replace_notification_preferences_all_params() + + @responses.activate + def test_replace_notification_preferences_required_params(self): + """ + test_replace_notification_preferences_required_params() + """ + # Set up mock + url = preprocess_url('/v1/notifications/IBMid-1234567890/preferences') + mock_response = '{"incident_severity1": {"channels": ["email"], "updates": true}, "incident_severity2": {"channels": ["email"], "updates": true}, "incident_severity3": {"channels": ["email"], "updates": true}, "incident_severity4": {"channels": ["email"], "updates": true}, "maintenance_high": {"channels": ["email"], "updates": true}, "maintenance_medium": {"channels": ["email"], "updates": true}, "maintenance_low": {"channels": ["email"], "updates": true}, "announcements_major": {"channels": ["email"]}, "announcements_minor": {"channels": ["email"]}, "security_normal": {"channels": ["email"]}, "account_normal": {"channels": ["email"]}, "billing_and_usage_order": {"channels": ["email"]}, "billing_and_usage_invoices": {"channels": ["email"]}, "billing_and_usage_payments": {"channels": ["email"]}, "billing_and_usage_subscriptions_and_promo_codes": {"channels": ["email"]}, "billing_and_usage_spending_alerts": {"channels": ["email"]}, "resourceactivity_normal": {"channels": ["email"]}, "ordering_review": {"channels": ["email"]}, "ordering_approved": {"channels": ["email"]}, "ordering_approved_vsi": {"channels": ["email"]}, "ordering_approved_server": {"channels": ["email"]}, "provisioning_reload_complete": {"channels": ["email"]}, "provisioning_complete_vsi": {"channels": ["email"]}, "provisioning_complete_server": {"channels": ["email"]}}' + responses.add( + responses.PUT, + url, + body=mock_response, + content_type='application/json', + status=200, + ) + + # Construct a dict representation of a PreferenceValueWithUpdates model + preference_value_with_updates_model = {} + preference_value_with_updates_model['channels'] = ['email'] + preference_value_with_updates_model['updates'] = True + + # Construct a dict representation of a PreferenceValueWithoutUpdates model + preference_value_without_updates_model = {} + preference_value_without_updates_model['channels'] = ['email'] + + # Set up parameter values + iam_id = 'IBMid-1234567890' + incident_severity1 = preference_value_with_updates_model + incident_severity2 = preference_value_with_updates_model + incident_severity3 = preference_value_with_updates_model + incident_severity4 = preference_value_with_updates_model + maintenance_high = preference_value_with_updates_model + maintenance_medium = preference_value_with_updates_model + maintenance_low = preference_value_with_updates_model + announcements_major = preference_value_without_updates_model + announcements_minor = preference_value_without_updates_model + security_normal = preference_value_without_updates_model + account_normal = preference_value_without_updates_model + billing_and_usage_order = preference_value_without_updates_model + billing_and_usage_invoices = preference_value_without_updates_model + billing_and_usage_payments = preference_value_without_updates_model + billing_and_usage_subscriptions_and_promo_codes = preference_value_without_updates_model + billing_and_usage_spending_alerts = preference_value_without_updates_model + resourceactivity_normal = preference_value_without_updates_model + ordering_review = preference_value_without_updates_model + ordering_approved = preference_value_without_updates_model + ordering_approved_vsi = preference_value_without_updates_model + ordering_approved_server = preference_value_without_updates_model + provisioning_reload_complete = preference_value_without_updates_model + provisioning_complete_vsi = preference_value_without_updates_model + provisioning_complete_server = preference_value_without_updates_model + + # Invoke method + response = _service.replace_notification_preferences( + iam_id, + incident_severity1=incident_severity1, + incident_severity2=incident_severity2, + incident_severity3=incident_severity3, + incident_severity4=incident_severity4, + maintenance_high=maintenance_high, + maintenance_medium=maintenance_medium, + maintenance_low=maintenance_low, + announcements_major=announcements_major, + announcements_minor=announcements_minor, + security_normal=security_normal, + account_normal=account_normal, + billing_and_usage_order=billing_and_usage_order, + billing_and_usage_invoices=billing_and_usage_invoices, + billing_and_usage_payments=billing_and_usage_payments, + billing_and_usage_subscriptions_and_promo_codes=billing_and_usage_subscriptions_and_promo_codes, + billing_and_usage_spending_alerts=billing_and_usage_spending_alerts, + resourceactivity_normal=resourceactivity_normal, + ordering_review=ordering_review, + ordering_approved=ordering_approved, + ordering_approved_vsi=ordering_approved_vsi, + ordering_approved_server=ordering_approved_server, + provisioning_reload_complete=provisioning_reload_complete, + provisioning_complete_vsi=provisioning_complete_vsi, + provisioning_complete_server=provisioning_complete_server, + headers={}, + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + # Validate body params + req_body = json.loads(str(responses.calls[0].request.body, 'utf-8')) + assert req_body['incident_severity1'] == preference_value_with_updates_model + assert req_body['incident_severity2'] == preference_value_with_updates_model + assert req_body['incident_severity3'] == preference_value_with_updates_model + assert req_body['incident_severity4'] == preference_value_with_updates_model + assert req_body['maintenance_high'] == preference_value_with_updates_model + assert req_body['maintenance_medium'] == preference_value_with_updates_model + assert req_body['maintenance_low'] == preference_value_with_updates_model + assert req_body['announcements_major'] == preference_value_without_updates_model + assert req_body['announcements_minor'] == preference_value_without_updates_model + assert req_body['security_normal'] == preference_value_without_updates_model + assert req_body['account_normal'] == preference_value_without_updates_model + assert req_body['billing_and_usage_order'] == preference_value_without_updates_model + assert req_body['billing_and_usage_invoices'] == preference_value_without_updates_model + assert req_body['billing_and_usage_payments'] == preference_value_without_updates_model + assert req_body['billing_and_usage_subscriptions_and_promo_codes'] == preference_value_without_updates_model + assert req_body['billing_and_usage_spending_alerts'] == preference_value_without_updates_model + assert req_body['resourceactivity_normal'] == preference_value_without_updates_model + assert req_body['ordering_review'] == preference_value_without_updates_model + assert req_body['ordering_approved'] == preference_value_without_updates_model + assert req_body['ordering_approved_vsi'] == preference_value_without_updates_model + assert req_body['ordering_approved_server'] == preference_value_without_updates_model + assert req_body['provisioning_reload_complete'] == preference_value_without_updates_model + assert req_body['provisioning_complete_vsi'] == preference_value_without_updates_model + assert req_body['provisioning_complete_server'] == preference_value_without_updates_model + + def test_replace_notification_preferences_required_params_with_retries(self): + # Enable retries and run test_replace_notification_preferences_required_params. + _service.enable_retries() + self.test_replace_notification_preferences_required_params() + + # Disable retries and run test_replace_notification_preferences_required_params. + _service.disable_retries() + self.test_replace_notification_preferences_required_params() + + @responses.activate + def test_replace_notification_preferences_value_error(self): + """ + test_replace_notification_preferences_value_error() + """ + # Set up mock + url = preprocess_url('/v1/notifications/IBMid-1234567890/preferences') + mock_response = '{"incident_severity1": {"channels": ["email"], "updates": true}, "incident_severity2": {"channels": ["email"], "updates": true}, "incident_severity3": {"channels": ["email"], "updates": true}, "incident_severity4": {"channels": ["email"], "updates": true}, "maintenance_high": {"channels": ["email"], "updates": true}, "maintenance_medium": {"channels": ["email"], "updates": true}, "maintenance_low": {"channels": ["email"], "updates": true}, "announcements_major": {"channels": ["email"]}, "announcements_minor": {"channels": ["email"]}, "security_normal": {"channels": ["email"]}, "account_normal": {"channels": ["email"]}, "billing_and_usage_order": {"channels": ["email"]}, "billing_and_usage_invoices": {"channels": ["email"]}, "billing_and_usage_payments": {"channels": ["email"]}, "billing_and_usage_subscriptions_and_promo_codes": {"channels": ["email"]}, "billing_and_usage_spending_alerts": {"channels": ["email"]}, "resourceactivity_normal": {"channels": ["email"]}, "ordering_review": {"channels": ["email"]}, "ordering_approved": {"channels": ["email"]}, "ordering_approved_vsi": {"channels": ["email"]}, "ordering_approved_server": {"channels": ["email"]}, "provisioning_reload_complete": {"channels": ["email"]}, "provisioning_complete_vsi": {"channels": ["email"]}, "provisioning_complete_server": {"channels": ["email"]}}' + responses.add( + responses.PUT, + url, + body=mock_response, + content_type='application/json', + status=200, + ) + + # Construct a dict representation of a PreferenceValueWithUpdates model + preference_value_with_updates_model = {} + preference_value_with_updates_model['channels'] = ['email'] + preference_value_with_updates_model['updates'] = True + + # Construct a dict representation of a PreferenceValueWithoutUpdates model + preference_value_without_updates_model = {} + preference_value_without_updates_model['channels'] = ['email'] + + # Set up parameter values + iam_id = 'IBMid-1234567890' + incident_severity1 = preference_value_with_updates_model + incident_severity2 = preference_value_with_updates_model + incident_severity3 = preference_value_with_updates_model + incident_severity4 = preference_value_with_updates_model + maintenance_high = preference_value_with_updates_model + maintenance_medium = preference_value_with_updates_model + maintenance_low = preference_value_with_updates_model + announcements_major = preference_value_without_updates_model + announcements_minor = preference_value_without_updates_model + security_normal = preference_value_without_updates_model + account_normal = preference_value_without_updates_model + billing_and_usage_order = preference_value_without_updates_model + billing_and_usage_invoices = preference_value_without_updates_model + billing_and_usage_payments = preference_value_without_updates_model + billing_and_usage_subscriptions_and_promo_codes = preference_value_without_updates_model + billing_and_usage_spending_alerts = preference_value_without_updates_model + resourceactivity_normal = preference_value_without_updates_model + ordering_review = preference_value_without_updates_model + ordering_approved = preference_value_without_updates_model + ordering_approved_vsi = preference_value_without_updates_model + ordering_approved_server = preference_value_without_updates_model + provisioning_reload_complete = preference_value_without_updates_model + provisioning_complete_vsi = preference_value_without_updates_model + provisioning_complete_server = preference_value_without_updates_model + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "iam_id": iam_id, + } + for param in req_param_dict.keys(): + req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} + with pytest.raises(ValueError): + _service.replace_notification_preferences(**req_copy) + + def test_replace_notification_preferences_value_error_with_retries(self): + # Enable retries and run test_replace_notification_preferences_value_error. + _service.enable_retries() + self.test_replace_notification_preferences_value_error() + + # Disable retries and run test_replace_notification_preferences_value_error. + _service.disable_retries() + self.test_replace_notification_preferences_value_error() + + +class TestDeleteNotificationPreferences: + """ + Test Class for delete_notification_preferences + """ + + @responses.activate + def test_delete_notification_preferences_all_params(self): + """ + delete_notification_preferences() + """ + # Set up mock + url = preprocess_url('/v1/notifications/IBMid-1234567890/preferences') + responses.add( + responses.DELETE, + url, + status=204, + ) + + # Set up parameter values + iam_id = 'IBMid-1234567890' + account_id = 'a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6' + + # Invoke method + response = _service.delete_notification_preferences( + iam_id, + account_id=account_id, + headers={}, + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 204 + # Validate query params + query_string = responses.calls[0].request.url.split('?', 1)[1] + query_string = urllib.parse.unquote_plus(query_string) + assert 'account_id={}'.format(account_id) in query_string + + def test_delete_notification_preferences_all_params_with_retries(self): + # Enable retries and run test_delete_notification_preferences_all_params. + _service.enable_retries() + self.test_delete_notification_preferences_all_params() + + # Disable retries and run test_delete_notification_preferences_all_params. + _service.disable_retries() + self.test_delete_notification_preferences_all_params() + + @responses.activate + def test_delete_notification_preferences_required_params(self): + """ + test_delete_notification_preferences_required_params() + """ + # Set up mock + url = preprocess_url('/v1/notifications/IBMid-1234567890/preferences') + responses.add( + responses.DELETE, + url, + status=204, + ) + + # Set up parameter values + iam_id = 'IBMid-1234567890' + + # Invoke method + response = _service.delete_notification_preferences( + iam_id, + headers={}, + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 204 + + def test_delete_notification_preferences_required_params_with_retries(self): + # Enable retries and run test_delete_notification_preferences_required_params. + _service.enable_retries() + self.test_delete_notification_preferences_required_params() + + # Disable retries and run test_delete_notification_preferences_required_params. + _service.disable_retries() + self.test_delete_notification_preferences_required_params() + + @responses.activate + def test_delete_notification_preferences_value_error(self): + """ + test_delete_notification_preferences_value_error() + """ + # Set up mock + url = preprocess_url('/v1/notifications/IBMid-1234567890/preferences') + responses.add( + responses.DELETE, + url, + status=204, + ) + + # Set up parameter values + iam_id = 'IBMid-1234567890' + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "iam_id": iam_id, + } + for param in req_param_dict.keys(): + req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} + with pytest.raises(ValueError): + _service.delete_notification_preferences(**req_copy) + + def test_delete_notification_preferences_value_error_with_retries(self): + # Enable retries and run test_delete_notification_preferences_value_error. + _service.enable_retries() + self.test_delete_notification_preferences_value_error() + + # Disable retries and run test_delete_notification_preferences_value_error. + _service.disable_retries() + self.test_delete_notification_preferences_value_error() + + +# endregion +############################################################################## +# End of Service: UserPreferences +############################################################################## + +############################################################################## +# Start of Service: Notifications +############################################################################## +# region + + +class TestNewInstance: + """ + Test Class for new_instance + """ + + def test_new_instance(self): + """ + new_instance() + """ + os.environ['TEST_SERVICE_AUTH_TYPE'] = 'noAuth' + + service = PlatformNotificationsV1.new_instance( + service_name='TEST_SERVICE', + ) + + assert service is not None + assert isinstance(service, PlatformNotificationsV1) + + def test_new_instance_without_authenticator(self): + """ + new_instance_without_authenticator() + """ + with pytest.raises(ValueError, match='authenticator must be provided'): + service = PlatformNotificationsV1.new_instance( + service_name='TEST_SERVICE_NOT_FOUND', + ) + + +class TestListNotifications: + """ + Test Class for list_notifications + """ + + @responses.activate + def test_list_notifications_all_params(self): + """ + list_notifications() + """ + # Set up mock + url = preprocess_url('/v1/notifications') + mock_response = '{"limit": 50, "total_count": 232, "first": {"href": "https://api.example.com/v1/notifications?limit=50"}, "previous": {"href": "https://api.example.com/v1/notifications?start=3fe78a36b9aa7f26&limit=50", "start": "3fe78a36b9aa7f26"}, "next": {"href": "https://api.example.com/v1/notifications?start=3fe78a36b9aa7f26&limit=50", "start": "3fe78a36b9aa7f26"}, "last": {"href": "https://api.example.com/v1/notifications?start=3fe78a36b9aa7f26&limit=50", "start": "3fe78a36b9aa7f26"}, "notifications": [{"title": "System Maintenance Scheduled", "body": "Scheduled maintenance will occur on March 15th from 10:00 AM to 11:00 AM UTC.", "id": "12345", "category": "maintenance", "component_names": ["component_names"], "start_time": 1771791490, "is_global": false, "state": "new", "regions": ["regions"], "crn_masks": ["crn_masks"], "record_id": "rec-67890", "source_id": "src-11111", "completion_code": "successful", "end_time": 1771791490, "update_time": 1771791490, "severity": 2, "lucene_query": "region:us-south AND service_name:event-notifications", "resource_link": "https://cloud.ibm.com/status/incident/12345"}]}' + responses.add( + responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200, + ) + + # Set up parameter values + account_id = 'a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6' + start = '3fe78a36b9aa7f26' + limit = 50 + + # Invoke method + response = _service.list_notifications( + account_id=account_id, + start=start, + limit=limit, + headers={}, + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + # Validate query params + query_string = responses.calls[0].request.url.split('?', 1)[1] + query_string = urllib.parse.unquote_plus(query_string) + assert 'account_id={}'.format(account_id) in query_string + assert 'start={}'.format(start) in query_string + assert 'limit={}'.format(limit) in query_string + + def test_list_notifications_all_params_with_retries(self): + # Enable retries and run test_list_notifications_all_params. + _service.enable_retries() + self.test_list_notifications_all_params() + + # Disable retries and run test_list_notifications_all_params. + _service.disable_retries() + self.test_list_notifications_all_params() + + @responses.activate + def test_list_notifications_required_params(self): + """ + test_list_notifications_required_params() + """ + # Set up mock + url = preprocess_url('/v1/notifications') + mock_response = '{"limit": 50, "total_count": 232, "first": {"href": "https://api.example.com/v1/notifications?limit=50"}, "previous": {"href": "https://api.example.com/v1/notifications?start=3fe78a36b9aa7f26&limit=50", "start": "3fe78a36b9aa7f26"}, "next": {"href": "https://api.example.com/v1/notifications?start=3fe78a36b9aa7f26&limit=50", "start": "3fe78a36b9aa7f26"}, "last": {"href": "https://api.example.com/v1/notifications?start=3fe78a36b9aa7f26&limit=50", "start": "3fe78a36b9aa7f26"}, "notifications": [{"title": "System Maintenance Scheduled", "body": "Scheduled maintenance will occur on March 15th from 10:00 AM to 11:00 AM UTC.", "id": "12345", "category": "maintenance", "component_names": ["component_names"], "start_time": 1771791490, "is_global": false, "state": "new", "regions": ["regions"], "crn_masks": ["crn_masks"], "record_id": "rec-67890", "source_id": "src-11111", "completion_code": "successful", "end_time": 1771791490, "update_time": 1771791490, "severity": 2, "lucene_query": "region:us-south AND service_name:event-notifications", "resource_link": "https://cloud.ibm.com/status/incident/12345"}]}' + responses.add( + responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200, + ) + + # Invoke method + response = _service.list_notifications() + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + + def test_list_notifications_required_params_with_retries(self): + # Enable retries and run test_list_notifications_required_params. + _service.enable_retries() + self.test_list_notifications_required_params() + + # Disable retries and run test_list_notifications_required_params. + _service.disable_retries() + self.test_list_notifications_required_params() + + @responses.activate + def test_list_notifications_with_pager_get_next(self): + """ + test_list_notifications_with_pager_get_next() + """ + # Set up a two-page mock response + url = preprocess_url('/v1/notifications') + mock_response1 = '{"next":{"start":"1"},"total_count":2,"limit":1,"notifications":[{"title":"System Maintenance Scheduled","body":"Scheduled maintenance will occur on March 15th from 10:00 AM to 11:00 AM UTC.","id":"12345","category":"maintenance","component_names":["component_names"],"start_time":1771791490,"is_global":false,"state":"new","regions":["regions"],"crn_masks":["crn_masks"],"record_id":"rec-67890","source_id":"src-11111","completion_code":"successful","end_time":1771791490,"update_time":1771791490,"severity":2,"lucene_query":"region:us-south AND service_name:event-notifications","resource_link":"https://cloud.ibm.com/status/incident/12345"}]}' + mock_response2 = '{"total_count":2,"limit":1,"notifications":[{"title":"System Maintenance Scheduled","body":"Scheduled maintenance will occur on March 15th from 10:00 AM to 11:00 AM UTC.","id":"12345","category":"maintenance","component_names":["component_names"],"start_time":1771791490,"is_global":false,"state":"new","regions":["regions"],"crn_masks":["crn_masks"],"record_id":"rec-67890","source_id":"src-11111","completion_code":"successful","end_time":1771791490,"update_time":1771791490,"severity":2,"lucene_query":"region:us-south AND service_name:event-notifications","resource_link":"https://cloud.ibm.com/status/incident/12345"}]}' + responses.add( + responses.GET, + url, + body=mock_response1, + content_type='application/json', + status=200, + ) + responses.add( + responses.GET, + url, + body=mock_response2, + content_type='application/json', + status=200, + ) + + # Exercise the pager class for this operation + all_results = [] + pager = NotificationsPager( + client=_service, + account_id='a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6', + limit=50, + ) + while pager.has_next(): + next_page = pager.get_next() + assert next_page is not None + all_results.extend(next_page) + assert len(all_results) == 2 + + @responses.activate + def test_list_notifications_with_pager_get_all(self): + """ + test_list_notifications_with_pager_get_all() + """ + # Set up a two-page mock response + url = preprocess_url('/v1/notifications') + mock_response1 = '{"next":{"start":"1"},"total_count":2,"limit":1,"notifications":[{"title":"System Maintenance Scheduled","body":"Scheduled maintenance will occur on March 15th from 10:00 AM to 11:00 AM UTC.","id":"12345","category":"maintenance","component_names":["component_names"],"start_time":1771791490,"is_global":false,"state":"new","regions":["regions"],"crn_masks":["crn_masks"],"record_id":"rec-67890","source_id":"src-11111","completion_code":"successful","end_time":1771791490,"update_time":1771791490,"severity":2,"lucene_query":"region:us-south AND service_name:event-notifications","resource_link":"https://cloud.ibm.com/status/incident/12345"}]}' + mock_response2 = '{"total_count":2,"limit":1,"notifications":[{"title":"System Maintenance Scheduled","body":"Scheduled maintenance will occur on March 15th from 10:00 AM to 11:00 AM UTC.","id":"12345","category":"maintenance","component_names":["component_names"],"start_time":1771791490,"is_global":false,"state":"new","regions":["regions"],"crn_masks":["crn_masks"],"record_id":"rec-67890","source_id":"src-11111","completion_code":"successful","end_time":1771791490,"update_time":1771791490,"severity":2,"lucene_query":"region:us-south AND service_name:event-notifications","resource_link":"https://cloud.ibm.com/status/incident/12345"}]}' + responses.add( + responses.GET, + url, + body=mock_response1, + content_type='application/json', + status=200, + ) + responses.add( + responses.GET, + url, + body=mock_response2, + content_type='application/json', + status=200, + ) + + # Exercise the pager class for this operation + pager = NotificationsPager( + client=_service, + account_id='a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6', + limit=50, + ) + all_results = pager.get_all() + assert all_results is not None + assert len(all_results) == 2 + + +class TestGetAcknowledgement: + """ + Test Class for get_acknowledgement + """ + + @responses.activate + def test_get_acknowledgement_all_params(self): + """ + get_acknowledgement() + """ + # Set up mock + url = preprocess_url('/v1/notifications/acknowledgement') + mock_response = '{"has_unread": true, "latest_notification_id": "1678901234000", "last_acknowledged_id": "1678800000000"}' + responses.add( + responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200, + ) + + # Set up parameter values + account_id = '1369339417d906e5620b8d861d40cfd7' + + # Invoke method + response = _service.get_acknowledgement( + account_id=account_id, + headers={}, + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + # Validate query params + query_string = responses.calls[0].request.url.split('?', 1)[1] + query_string = urllib.parse.unquote_plus(query_string) + assert 'account_id={}'.format(account_id) in query_string + + def test_get_acknowledgement_all_params_with_retries(self): + # Enable retries and run test_get_acknowledgement_all_params. + _service.enable_retries() + self.test_get_acknowledgement_all_params() + + # Disable retries and run test_get_acknowledgement_all_params. + _service.disable_retries() + self.test_get_acknowledgement_all_params() + + @responses.activate + def test_get_acknowledgement_required_params(self): + """ + test_get_acknowledgement_required_params() + """ + # Set up mock + url = preprocess_url('/v1/notifications/acknowledgement') + mock_response = '{"has_unread": true, "latest_notification_id": "1678901234000", "last_acknowledged_id": "1678800000000"}' + responses.add( + responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200, + ) + + # Invoke method + response = _service.get_acknowledgement() + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + + def test_get_acknowledgement_required_params_with_retries(self): + # Enable retries and run test_get_acknowledgement_required_params. + _service.enable_retries() + self.test_get_acknowledgement_required_params() + + # Disable retries and run test_get_acknowledgement_required_params. + _service.disable_retries() + self.test_get_acknowledgement_required_params() + + +class TestReplaceNotificationAcknowledgement: + """ + Test Class for replace_notification_acknowledgement + """ + + @responses.activate + def test_replace_notification_acknowledgement_all_params(self): + """ + replace_notification_acknowledgement() + """ + # Set up mock + url = preprocess_url('/v1/notifications/acknowledgement') + mock_response = '{"has_unread": true, "latest_notification_id": "1678901234000", "last_acknowledged_id": "1678800000000"}' + responses.add( + responses.PUT, + url, + body=mock_response, + content_type='application/json', + status=200, + ) + + # Set up parameter values + last_acknowledged_id = '1772804159452' + account_id = '1369339417d906e5620b8d861d40cfd7' + + # Invoke method + response = _service.replace_notification_acknowledgement( + last_acknowledged_id, + account_id=account_id, + headers={}, + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + # Validate query params + query_string = responses.calls[0].request.url.split('?', 1)[1] + query_string = urllib.parse.unquote_plus(query_string) + assert 'account_id={}'.format(account_id) in query_string + # Validate body params + req_body = json.loads(str(responses.calls[0].request.body, 'utf-8')) + assert req_body['last_acknowledged_id'] == '1772804159452' + + def test_replace_notification_acknowledgement_all_params_with_retries(self): + # Enable retries and run test_replace_notification_acknowledgement_all_params. + _service.enable_retries() + self.test_replace_notification_acknowledgement_all_params() + + # Disable retries and run test_replace_notification_acknowledgement_all_params. + _service.disable_retries() + self.test_replace_notification_acknowledgement_all_params() + + @responses.activate + def test_replace_notification_acknowledgement_required_params(self): + """ + test_replace_notification_acknowledgement_required_params() + """ + # Set up mock + url = preprocess_url('/v1/notifications/acknowledgement') + mock_response = '{"has_unread": true, "latest_notification_id": "1678901234000", "last_acknowledged_id": "1678800000000"}' + responses.add( + responses.PUT, + url, + body=mock_response, + content_type='application/json', + status=200, + ) + + # Set up parameter values + last_acknowledged_id = '1772804159452' + + # Invoke method + response = _service.replace_notification_acknowledgement( + last_acknowledged_id, + headers={}, + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + # Validate body params + req_body = json.loads(str(responses.calls[0].request.body, 'utf-8')) + assert req_body['last_acknowledged_id'] == '1772804159452' + + def test_replace_notification_acknowledgement_required_params_with_retries(self): + # Enable retries and run test_replace_notification_acknowledgement_required_params. + _service.enable_retries() + self.test_replace_notification_acknowledgement_required_params() + + # Disable retries and run test_replace_notification_acknowledgement_required_params. + _service.disable_retries() + self.test_replace_notification_acknowledgement_required_params() + + @responses.activate + def test_replace_notification_acknowledgement_value_error(self): + """ + test_replace_notification_acknowledgement_value_error() + """ + # Set up mock + url = preprocess_url('/v1/notifications/acknowledgement') + mock_response = '{"has_unread": true, "latest_notification_id": "1678901234000", "last_acknowledged_id": "1678800000000"}' + responses.add( + responses.PUT, + url, + body=mock_response, + content_type='application/json', + status=200, + ) + + # Set up parameter values + last_acknowledged_id = '1772804159452' + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "last_acknowledged_id": last_acknowledged_id, + } + for param in req_param_dict.keys(): + req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} + with pytest.raises(ValueError): + _service.replace_notification_acknowledgement(**req_copy) + + def test_replace_notification_acknowledgement_value_error_with_retries(self): + # Enable retries and run test_replace_notification_acknowledgement_value_error. + _service.enable_retries() + self.test_replace_notification_acknowledgement_value_error() + + # Disable retries and run test_replace_notification_acknowledgement_value_error. + _service.disable_retries() + self.test_replace_notification_acknowledgement_value_error() + + +# endregion +############################################################################## +# End of Service: Notifications +############################################################################## + + +############################################################################## +# Start of Model Tests +############################################################################## +# region + + +class TestModel_AddDestinationCollection: + """ + Test Class for AddDestinationCollection + """ + + def test_add_destination_collection_serialization(self): + """ + Test serialization/deserialization for AddDestinationCollection + """ + + # Construct dict forms of any model objects needed in order to build this model. + + add_destination_model = {} # AddDestinationEventNotificationDestination + add_destination_model['destination_id'] = '12345678-1234-1234-1234-123456789012' + add_destination_model['destination_type'] = 'event_notifications' + + # Construct a json representation of a AddDestinationCollection model + add_destination_collection_model_json = {} + add_destination_collection_model_json['destinations'] = [add_destination_model] + + # Construct a model instance of AddDestinationCollection by calling from_dict on the json representation + add_destination_collection_model = AddDestinationCollection.from_dict(add_destination_collection_model_json) + assert add_destination_collection_model != False + + # Construct a model instance of AddDestinationCollection by calling from_dict on the json representation + add_destination_collection_model_dict = AddDestinationCollection.from_dict(add_destination_collection_model_json).__dict__ + add_destination_collection_model2 = AddDestinationCollection(**add_destination_collection_model_dict) + + # Verify the model instances are equivalent + assert add_destination_collection_model == add_destination_collection_model2 + + # Convert model instance back to dict and verify no loss of data + add_destination_collection_model_json2 = add_destination_collection_model.to_dict() + assert add_destination_collection_model_json2 == add_destination_collection_model_json + + +class TestModel_Notification: + """ + Test Class for Notification + """ + + def test_notification_serialization(self): + """ + Test serialization/deserialization for Notification + """ + + # Construct a json representation of a Notification model + notification_model_json = {} + notification_model_json['title'] = 'System Maintenance Scheduled' + notification_model_json['body'] = 'Scheduled maintenance will occur on March 15th from 10:00 AM to 11:00 AM UTC.' + notification_model_json['id'] = '12345' + notification_model_json['category'] = 'maintenance' + notification_model_json['component_names'] = ['event-notifications', 'ibm-cloud'] + notification_model_json['start_time'] = 1771791490 + notification_model_json['is_global'] = False + notification_model_json['state'] = 'new' + notification_model_json['regions'] = ['us-south', 'us-east'] + notification_model_json['crn_masks'] = ['crn:v1:staging:public:event-notifications:us-south:::'] + notification_model_json['record_id'] = 'rec-67890' + notification_model_json['source_id'] = 'src-11111' + notification_model_json['completion_code'] = 'successful' + notification_model_json['end_time'] = 1771791490 + notification_model_json['update_time'] = 1771791490 + notification_model_json['severity'] = 2 + notification_model_json['lucene_query'] = 'region:us-south AND service_name:event-notifications' + notification_model_json['resource_link'] = 'https://cloud.ibm.com/status/incident/12345' + + # Construct a model instance of Notification by calling from_dict on the json representation + notification_model = Notification.from_dict(notification_model_json) + assert notification_model != False + + # Construct a model instance of Notification by calling from_dict on the json representation + notification_model_dict = Notification.from_dict(notification_model_json).__dict__ + notification_model2 = Notification(**notification_model_dict) + + # Verify the model instances are equivalent + assert notification_model == notification_model2 + + # Convert model instance back to dict and verify no loss of data + notification_model_json2 = notification_model.to_dict() + assert notification_model_json2 == notification_model_json + + +class TestModel_NotificationCollection: + """ + Test Class for NotificationCollection + """ + + def test_notification_collection_serialization(self): + """ + Test serialization/deserialization for NotificationCollection + """ + + # Construct dict forms of any model objects needed in order to build this model. + + pagination_link_model = {} # PaginationLink + pagination_link_model['href'] = 'https://api.example.com/v1/notifications?limit=50' + + pagination_link_with_token_model = {} # PaginationLinkWithToken + pagination_link_with_token_model['href'] = 'https://api.example.com/v1/notifications?start=3fe78a36b9aa7f26&limit=50' + pagination_link_with_token_model['start'] = '3fe78a36b9aa7f26' + + notification_model = {} # Notification + notification_model['title'] = 'System Maintenance Scheduled' + notification_model['body'] = 'Scheduled maintenance will occur on March 15th from 10:00 AM to 11:00 AM UTC.' + notification_model['id'] = '12345' + notification_model['category'] = 'maintenance' + notification_model['component_names'] = ['event-notifications', 'ibm-cloud'] + notification_model['start_time'] = 1771791490 + notification_model['is_global'] = False + notification_model['state'] = 'new' + notification_model['regions'] = ['us-south', 'us-east'] + notification_model['crn_masks'] = ['crn:v1:staging:public:event-notifications:us-south:::'] + notification_model['record_id'] = 'rec-67890' + notification_model['source_id'] = 'src-11111' + notification_model['completion_code'] = 'successful' + notification_model['end_time'] = 1771791490 + notification_model['update_time'] = 1771791490 + notification_model['severity'] = 2 + notification_model['lucene_query'] = 'region:us-south AND service_name:event-notifications' + notification_model['resource_link'] = 'https://cloud.ibm.com/status/incident/12345' + + # Construct a json representation of a NotificationCollection model + notification_collection_model_json = {} + notification_collection_model_json['limit'] = 50 + notification_collection_model_json['total_count'] = 232 + notification_collection_model_json['first'] = pagination_link_model + notification_collection_model_json['previous'] = pagination_link_with_token_model + notification_collection_model_json['next'] = pagination_link_with_token_model + notification_collection_model_json['last'] = pagination_link_with_token_model + notification_collection_model_json['notifications'] = [notification_model] + + # Construct a model instance of NotificationCollection by calling from_dict on the json representation + notification_collection_model = NotificationCollection.from_dict(notification_collection_model_json) + assert notification_collection_model != False + + # Construct a model instance of NotificationCollection by calling from_dict on the json representation + notification_collection_model_dict = NotificationCollection.from_dict(notification_collection_model_json).__dict__ + notification_collection_model2 = NotificationCollection(**notification_collection_model_dict) + + # Verify the model instances are equivalent + assert notification_collection_model == notification_collection_model2 + + # Convert model instance back to dict and verify no loss of data + notification_collection_model_json2 = notification_collection_model.to_dict() + assert notification_collection_model_json2 == notification_collection_model_json + + +class TestModel_PaginationLink: + """ + Test Class for PaginationLink + """ + + def test_pagination_link_serialization(self): + """ + Test serialization/deserialization for PaginationLink + """ + + # Construct a json representation of a PaginationLink model + pagination_link_model_json = {} + pagination_link_model_json['href'] = 'https://api.example.com/v1/notifications?limit=50' + + # Construct a model instance of PaginationLink by calling from_dict on the json representation + pagination_link_model = PaginationLink.from_dict(pagination_link_model_json) + assert pagination_link_model != False + + # Construct a model instance of PaginationLink by calling from_dict on the json representation + pagination_link_model_dict = PaginationLink.from_dict(pagination_link_model_json).__dict__ + pagination_link_model2 = PaginationLink(**pagination_link_model_dict) + + # Verify the model instances are equivalent + assert pagination_link_model == pagination_link_model2 + + # Convert model instance back to dict and verify no loss of data + pagination_link_model_json2 = pagination_link_model.to_dict() + assert pagination_link_model_json2 == pagination_link_model_json + + +class TestModel_PaginationLinkWithToken: + """ + Test Class for PaginationLinkWithToken + """ + + def test_pagination_link_with_token_serialization(self): + """ + Test serialization/deserialization for PaginationLinkWithToken + """ + + # Construct a json representation of a PaginationLinkWithToken model + pagination_link_with_token_model_json = {} + pagination_link_with_token_model_json['href'] = 'https://api.example.com/v1/notifications?start=3fe78a36b9aa7f26&limit=50' + pagination_link_with_token_model_json['start'] = '3fe78a36b9aa7f26' + + # Construct a model instance of PaginationLinkWithToken by calling from_dict on the json representation + pagination_link_with_token_model = PaginationLinkWithToken.from_dict(pagination_link_with_token_model_json) + assert pagination_link_with_token_model != False + + # Construct a model instance of PaginationLinkWithToken by calling from_dict on the json representation + pagination_link_with_token_model_dict = PaginationLinkWithToken.from_dict(pagination_link_with_token_model_json).__dict__ + pagination_link_with_token_model2 = PaginationLinkWithToken(**pagination_link_with_token_model_dict) + + # Verify the model instances are equivalent + assert pagination_link_with_token_model == pagination_link_with_token_model2 + + # Convert model instance back to dict and verify no loss of data + pagination_link_with_token_model_json2 = pagination_link_with_token_model.to_dict() + assert pagination_link_with_token_model_json2 == pagination_link_with_token_model_json + + +class TestModel_PreferenceValueWithUpdates: + """ + Test Class for PreferenceValueWithUpdates + """ + + def test_preference_value_with_updates_serialization(self): + """ + Test serialization/deserialization for PreferenceValueWithUpdates + """ + + # Construct a json representation of a PreferenceValueWithUpdates model + preference_value_with_updates_model_json = {} + preference_value_with_updates_model_json['channels'] = ['email'] + preference_value_with_updates_model_json['updates'] = True + + # Construct a model instance of PreferenceValueWithUpdates by calling from_dict on the json representation + preference_value_with_updates_model = PreferenceValueWithUpdates.from_dict(preference_value_with_updates_model_json) + assert preference_value_with_updates_model != False + + # Construct a model instance of PreferenceValueWithUpdates by calling from_dict on the json representation + preference_value_with_updates_model_dict = PreferenceValueWithUpdates.from_dict(preference_value_with_updates_model_json).__dict__ + preference_value_with_updates_model2 = PreferenceValueWithUpdates(**preference_value_with_updates_model_dict) + + # Verify the model instances are equivalent + assert preference_value_with_updates_model == preference_value_with_updates_model2 + + # Convert model instance back to dict and verify no loss of data + preference_value_with_updates_model_json2 = preference_value_with_updates_model.to_dict() + assert preference_value_with_updates_model_json2 == preference_value_with_updates_model_json + + +class TestModel_PreferenceValueWithoutUpdates: + """ + Test Class for PreferenceValueWithoutUpdates + """ + + def test_preference_value_without_updates_serialization(self): + """ + Test serialization/deserialization for PreferenceValueWithoutUpdates + """ + + # Construct a json representation of a PreferenceValueWithoutUpdates model + preference_value_without_updates_model_json = {} + preference_value_without_updates_model_json['channels'] = ['email'] + + # Construct a model instance of PreferenceValueWithoutUpdates by calling from_dict on the json representation + preference_value_without_updates_model = PreferenceValueWithoutUpdates.from_dict(preference_value_without_updates_model_json) + assert preference_value_without_updates_model != False + + # Construct a model instance of PreferenceValueWithoutUpdates by calling from_dict on the json representation + preference_value_without_updates_model_dict = PreferenceValueWithoutUpdates.from_dict(preference_value_without_updates_model_json).__dict__ + preference_value_without_updates_model2 = PreferenceValueWithoutUpdates(**preference_value_without_updates_model_dict) + + # Verify the model instances are equivalent + assert preference_value_without_updates_model == preference_value_without_updates_model2 + + # Convert model instance back to dict and verify no loss of data + preference_value_without_updates_model_json2 = preference_value_without_updates_model.to_dict() + assert preference_value_without_updates_model_json2 == preference_value_without_updates_model_json + + +class TestModel_PreferencesObject: + """ + Test Class for PreferencesObject + """ + + def test_preferences_object_serialization(self): + """ + Test serialization/deserialization for PreferencesObject + """ + + # Construct dict forms of any model objects needed in order to build this model. + + preference_value_with_updates_model = {} # PreferenceValueWithUpdates + preference_value_with_updates_model['channels'] = ['email'] + preference_value_with_updates_model['updates'] = True + + preference_value_without_updates_model = {} # PreferenceValueWithoutUpdates + preference_value_without_updates_model['channels'] = ['email'] + + # Construct a json representation of a PreferencesObject model + preferences_object_model_json = {} + preferences_object_model_json['incident_severity1'] = preference_value_with_updates_model + preferences_object_model_json['incident_severity2'] = preference_value_with_updates_model + preferences_object_model_json['incident_severity3'] = preference_value_with_updates_model + preferences_object_model_json['incident_severity4'] = preference_value_with_updates_model + preferences_object_model_json['maintenance_high'] = preference_value_with_updates_model + preferences_object_model_json['maintenance_medium'] = preference_value_with_updates_model + preferences_object_model_json['maintenance_low'] = preference_value_with_updates_model + preferences_object_model_json['announcements_major'] = preference_value_without_updates_model + preferences_object_model_json['announcements_minor'] = preference_value_without_updates_model + preferences_object_model_json['security_normal'] = preference_value_without_updates_model + preferences_object_model_json['account_normal'] = preference_value_without_updates_model + preferences_object_model_json['billing_and_usage_order'] = preference_value_without_updates_model + preferences_object_model_json['billing_and_usage_invoices'] = preference_value_without_updates_model + preferences_object_model_json['billing_and_usage_payments'] = preference_value_without_updates_model + preferences_object_model_json['billing_and_usage_subscriptions_and_promo_codes'] = preference_value_without_updates_model + preferences_object_model_json['billing_and_usage_spending_alerts'] = preference_value_without_updates_model + preferences_object_model_json['resourceactivity_normal'] = preference_value_without_updates_model + preferences_object_model_json['ordering_review'] = preference_value_without_updates_model + preferences_object_model_json['ordering_approved'] = preference_value_without_updates_model + preferences_object_model_json['ordering_approved_vsi'] = preference_value_without_updates_model + preferences_object_model_json['ordering_approved_server'] = preference_value_without_updates_model + preferences_object_model_json['provisioning_reload_complete'] = preference_value_without_updates_model + preferences_object_model_json['provisioning_complete_vsi'] = preference_value_without_updates_model + preferences_object_model_json['provisioning_complete_server'] = preference_value_without_updates_model + + # Construct a model instance of PreferencesObject by calling from_dict on the json representation + preferences_object_model = PreferencesObject.from_dict(preferences_object_model_json) + assert preferences_object_model != False + + # Construct a model instance of PreferencesObject by calling from_dict on the json representation + preferences_object_model_dict = PreferencesObject.from_dict(preferences_object_model_json).__dict__ + preferences_object_model2 = PreferencesObject(**preferences_object_model_dict) + + # Verify the model instances are equivalent + assert preferences_object_model == preferences_object_model2 + + # Convert model instance back to dict and verify no loss of data + preferences_object_model_json2 = preferences_object_model.to_dict() + assert preferences_object_model_json2 == preferences_object_model_json + + +class TestModel_TestDestinationResponseBody: + """ + Test Class for TestDestinationResponseBody + """ + + def test_test_destination_response_body_serialization(self): + """ + Test serialization/deserialization for TestDestinationResponseBody + """ + + # Construct a json representation of a TestDestinationResponseBody model + test_destination_response_body_model_json = {} + test_destination_response_body_model_json['message'] = 'success' + + # Construct a model instance of TestDestinationResponseBody by calling from_dict on the json representation + test_destination_response_body_model = TestDestinationResponseBody.from_dict(test_destination_response_body_model_json) + assert test_destination_response_body_model != False + + # Construct a model instance of TestDestinationResponseBody by calling from_dict on the json representation + test_destination_response_body_model_dict = TestDestinationResponseBody.from_dict(test_destination_response_body_model_json).__dict__ + test_destination_response_body_model2 = TestDestinationResponseBody(**test_destination_response_body_model_dict) + + # Verify the model instances are equivalent + assert test_destination_response_body_model == test_destination_response_body_model2 + + # Convert model instance back to dict and verify no loss of data + test_destination_response_body_model_json2 = test_destination_response_body_model.to_dict() + assert test_destination_response_body_model_json2 == test_destination_response_body_model_json + + +class TestModel_Acknowledgement: + """ + Test Class for Acknowledgement + """ + + def test_acknowledgement_serialization(self): + """ + Test serialization/deserialization for Acknowledgement + """ + + # Construct a json representation of a Acknowledgement model + acknowledgement_model_json = {} + acknowledgement_model_json['has_unread'] = True + acknowledgement_model_json['latest_notification_id'] = '1678901234000' + acknowledgement_model_json['last_acknowledged_id'] = '1678800000000' + + # Construct a model instance of Acknowledgement by calling from_dict on the json representation + acknowledgement_model = Acknowledgement.from_dict(acknowledgement_model_json) + assert acknowledgement_model != False + + # Construct a model instance of Acknowledgement by calling from_dict on the json representation + acknowledgement_model_dict = Acknowledgement.from_dict(acknowledgement_model_json).__dict__ + acknowledgement_model2 = Acknowledgement(**acknowledgement_model_dict) + + # Verify the model instances are equivalent + assert acknowledgement_model == acknowledgement_model2 + + # Convert model instance back to dict and verify no loss of data + acknowledgement_model_json2 = acknowledgement_model.to_dict() + assert acknowledgement_model_json2 == acknowledgement_model_json + + +class TestModel_AddDestinationPrototypeEventNotificationDestinationPrototype: + """ + Test Class for AddDestinationPrototypeEventNotificationDestinationPrototype + """ + + def test_add_destination_prototype_event_notification_destination_prototype_serialization(self): + """ + Test serialization/deserialization for AddDestinationPrototypeEventNotificationDestinationPrototype + """ + + # Construct a json representation of a AddDestinationPrototypeEventNotificationDestinationPrototype model + add_destination_prototype_event_notification_destination_prototype_model_json = {} + add_destination_prototype_event_notification_destination_prototype_model_json['destination_id'] = '12345678-1234-1234-1234-123456789012' + add_destination_prototype_event_notification_destination_prototype_model_json['destination_type'] = 'event_notifications' + + # Construct a model instance of AddDestinationPrototypeEventNotificationDestinationPrototype by calling from_dict on the json representation + add_destination_prototype_event_notification_destination_prototype_model = AddDestinationPrototypeEventNotificationDestinationPrototype.from_dict(add_destination_prototype_event_notification_destination_prototype_model_json) + assert add_destination_prototype_event_notification_destination_prototype_model != False + + # Construct a model instance of AddDestinationPrototypeEventNotificationDestinationPrototype by calling from_dict on the json representation + add_destination_prototype_event_notification_destination_prototype_model_dict = AddDestinationPrototypeEventNotificationDestinationPrototype.from_dict(add_destination_prototype_event_notification_destination_prototype_model_json).__dict__ + add_destination_prototype_event_notification_destination_prototype_model2 = AddDestinationPrototypeEventNotificationDestinationPrototype(**add_destination_prototype_event_notification_destination_prototype_model_dict) + + # Verify the model instances are equivalent + assert add_destination_prototype_event_notification_destination_prototype_model == add_destination_prototype_event_notification_destination_prototype_model2 + + # Convert model instance back to dict and verify no loss of data + add_destination_prototype_event_notification_destination_prototype_model_json2 = add_destination_prototype_event_notification_destination_prototype_model.to_dict() + assert add_destination_prototype_event_notification_destination_prototype_model_json2 == add_destination_prototype_event_notification_destination_prototype_model_json + + +class TestModel_AddDestinationEventNotificationDestination: + """ + Test Class for AddDestinationEventNotificationDestination + """ + + def test_add_destination_event_notification_destination_serialization(self): + """ + Test serialization/deserialization for AddDestinationEventNotificationDestination + """ + + # Construct a json representation of a AddDestinationEventNotificationDestination model + add_destination_event_notification_destination_model_json = {} + add_destination_event_notification_destination_model_json['destination_id'] = '12345678-1234-1234-1234-123456789012' + add_destination_event_notification_destination_model_json['destination_type'] = 'event_notifications' + + # Construct a model instance of AddDestinationEventNotificationDestination by calling from_dict on the json representation + add_destination_event_notification_destination_model = AddDestinationEventNotificationDestination.from_dict(add_destination_event_notification_destination_model_json) + assert add_destination_event_notification_destination_model != False + + # Construct a model instance of AddDestinationEventNotificationDestination by calling from_dict on the json representation + add_destination_event_notification_destination_model_dict = AddDestinationEventNotificationDestination.from_dict(add_destination_event_notification_destination_model_json).__dict__ + add_destination_event_notification_destination_model2 = AddDestinationEventNotificationDestination(**add_destination_event_notification_destination_model_dict) + + # Verify the model instances are equivalent + assert add_destination_event_notification_destination_model == add_destination_event_notification_destination_model2 + + # Convert model instance back to dict and verify no loss of data + add_destination_event_notification_destination_model_json2 = add_destination_event_notification_destination_model.to_dict() + assert add_destination_event_notification_destination_model_json2 == add_destination_event_notification_destination_model_json + + +class TestModel_TestDestinationRequestBodyPrototypeTestEventNotificationDestinationRequestBodyPrototype: + """ + Test Class for TestDestinationRequestBodyPrototypeTestEventNotificationDestinationRequestBodyPrototype + """ + + def test_test_destination_request_body_prototype_test_event_notification_destination_request_body_prototype_serialization(self): + """ + Test serialization/deserialization for TestDestinationRequestBodyPrototypeTestEventNotificationDestinationRequestBodyPrototype + """ + + # Construct a json representation of a TestDestinationRequestBodyPrototypeTestEventNotificationDestinationRequestBodyPrototype model + test_destination_request_body_prototype_test_event_notification_destination_request_body_prototype_model_json = {} + test_destination_request_body_prototype_test_event_notification_destination_request_body_prototype_model_json['destination_type'] = 'event_notifications' + test_destination_request_body_prototype_test_event_notification_destination_request_body_prototype_model_json['notification_type'] = 'incident' + + # Construct a model instance of TestDestinationRequestBodyPrototypeTestEventNotificationDestinationRequestBodyPrototype by calling from_dict on the json representation + test_destination_request_body_prototype_test_event_notification_destination_request_body_prototype_model = TestDestinationRequestBodyPrototypeTestEventNotificationDestinationRequestBodyPrototype.from_dict(test_destination_request_body_prototype_test_event_notification_destination_request_body_prototype_model_json) + assert test_destination_request_body_prototype_test_event_notification_destination_request_body_prototype_model != False + + # Construct a model instance of TestDestinationRequestBodyPrototypeTestEventNotificationDestinationRequestBodyPrototype by calling from_dict on the json representation + test_destination_request_body_prototype_test_event_notification_destination_request_body_prototype_model_dict = TestDestinationRequestBodyPrototypeTestEventNotificationDestinationRequestBodyPrototype.from_dict(test_destination_request_body_prototype_test_event_notification_destination_request_body_prototype_model_json).__dict__ + test_destination_request_body_prototype_test_event_notification_destination_request_body_prototype_model2 = TestDestinationRequestBodyPrototypeTestEventNotificationDestinationRequestBodyPrototype(**test_destination_request_body_prototype_test_event_notification_destination_request_body_prototype_model_dict) + + # Verify the model instances are equivalent + assert test_destination_request_body_prototype_test_event_notification_destination_request_body_prototype_model == test_destination_request_body_prototype_test_event_notification_destination_request_body_prototype_model2 + + # Convert model instance back to dict and verify no loss of data + test_destination_request_body_prototype_test_event_notification_destination_request_body_prototype_model_json2 = test_destination_request_body_prototype_test_event_notification_destination_request_body_prototype_model.to_dict() + assert test_destination_request_body_prototype_test_event_notification_destination_request_body_prototype_model_json2 == test_destination_request_body_prototype_test_event_notification_destination_request_body_prototype_model_json + + +# endregion +############################################################################## +# End of Model Tests +############################################################################## From 94ac9fd057d27bcefd42fb9dbd62d33325c0d875 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81kos=20Sztremi?= Date: Fri, 24 Apr 2026 10:27:06 +0200 Subject: [PATCH 2/8] test (Platform Notification): Add variable list to integration tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ákos Sztremi --- test/integration/test_platform_notifications_v1.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/integration/test_platform_notifications_v1.py b/test/integration/test_platform_notifications_v1.py index 36fd3bd9..fb8e7694 100644 --- a/test/integration/test_platform_notifications_v1.py +++ b/test/integration/test_platform_notifications_v1.py @@ -23,6 +23,14 @@ from ibm_platform_services.platform_notifications_v1 import * # Config file name +# required variables in platform_notifications_v1.env +# PLATFORM_NOTIFICATIONS_URL +# PLATFORM_NOTIFICATIONS_AUTH_TYPE +# PLATFORM_NOTIFICATIONS_AUTH_URL +# PLATFORM_NOTIFICATIONS_APIKEY +# PLATFORM_NOTIFICATIONS_ACCOUNT_ID +# PLATFORM_NOTIFICATIONS_DESTINATION_ID +# PLATFORM_NOTIFICATIONS_IAM_ID config_file = 'platform_notifications_v1.env' account_id = '' From 55c592888d909940b5f35b96cae1be2cf7303e9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81kos=20Sztremi?= Date: Mon, 27 Apr 2026 14:10:13 +0200 Subject: [PATCH 3/8] feat(Platform Notifications): add docs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ákos Sztremi --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index b0faf4c5..7a87d2d8 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,7 @@ Service Name | Module Name | Service Class Name [IBM Cloud Shell](https://cloud.ibm.com/apidocs/cloudshell?code=python) | ibm_cloud_shell_v1 | IbmCloudShellV1 [Open Service Broker](https://cloud.ibm.com/apidocs/resource-controller/ibm-cloud-osb-api?code=python) | open_service_broker_v1 | OpenServiceBrokerV1 [Partner Management APIs](https://cloud.ibm.com/apidocs/partner-apis/partner?code=python) | partner_management_v1 | PartnerManagementV1 +[Platform Notifications APIs](https://cloud.ibm.com/apidocs/platform-notifications?code=python) | platform_notifications_v1 | PlatformNotificationsV1 [Resource Controller](https://cloud.ibm.com/apidocs/resource-controller/resource-controller?code=python) | resource_controller_v2 | ResourceControllerV2 [Resource Manager](https://cloud.ibm.com/apidocs/resource-controller/resource-manager?code=python) | resource_manager_v2 | ResourceManagerV2 [Usage Metering](https://cloud.ibm.com/apidocs/usage-metering?code=python) | usage_metering_v4 | UsageMeteringV4 From 9d6375c9415faadd0aacadc04db6fac590cf68d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81kos=20Sztremi?= Date: Thu, 7 May 2026 10:36:09 +0200 Subject: [PATCH 4/8] fix (platform notifications): review findings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ákos Sztremi --- ...test_platform_notifications_v1_examples.py | 51 ++-- .../platform_notifications_v1.py | 95 ++++--- .../test_platform_notifications_v1.py | 7 +- test/unit/test_platform_notifications_v1.py | 239 +++++++++++++----- 4 files changed, 277 insertions(+), 115 deletions(-) diff --git a/examples/test_platform_notifications_v1_examples.py b/examples/test_platform_notifications_v1_examples.py index a86e0a67..fe853001 100644 --- a/examples/test_platform_notifications_v1_examples.py +++ b/examples/test_platform_notifications_v1_examples.py @@ -59,8 +59,7 @@ def setup_class(cls): # begin-common - platform_notifications_service = PlatformNotificationsV1.new_instance( - ) + platform_notifications_service = PlatformNotificationsV1.new_instance() # end-common assert platform_notifications_service is not None @@ -68,6 +67,14 @@ def setup_class(cls): # Load the configuration global config config = read_external_sources(PlatformNotificationsV1.DEFAULT_SERVICE_NAME) + global account_id, destination_id, iam_id, service_url + account_id = config['ACCOUNT_ID'] + destination_id = config['DESTINATION_ID'] + iam_id = config['IAM_ID'] + service_url = config['SERVICE_URL'] + # Set service URL if provided in config + if service_url: + platform_notifications_service.set_service_url(service_url) print('Setup complete.') @@ -86,7 +93,7 @@ def test_list_distribution_list_destinations_example(self): # begin-list_distribution_list_destinations response = platform_notifications_service.list_distribution_list_destinations( - account_id='a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6', + account_id=account_id, ) add_destination_collection = response.get_result() @@ -108,12 +115,12 @@ def test_create_distribution_list_destination_example(self): # begin-create_distribution_list_destination add_destination_prototype_model = { - 'destination_id': '12345678-1234-1234-1234-123456789012', + 'destination_id': destination_id, 'destination_type': 'event_notifications', } response = platform_notifications_service.create_distribution_list_destination( - account_id='a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6', + account_id=account_id, add_destination_prototype=add_destination_prototype_model, ) add_destination = response.get_result() @@ -136,8 +143,8 @@ def test_get_distribution_list_destination_example(self): # begin-get_distribution_list_destination response = platform_notifications_service.get_distribution_list_destination( - account_id='a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6', - destination_id='12345678-1234-1234-1234-123456789012', + account_id=account_id, + destination_id=destination_id, ) add_destination = response.get_result() @@ -164,8 +171,8 @@ def test_test_distribution_list_destination_example(self): } response = platform_notifications_service.test_distribution_list_destination( - account_id='a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6', - destination_id='12345678-1234-1234-1234-123456789012', + account_id=account_id, + destination_id=destination_id, test_destination_request_body_prototype=test_destination_request_body_prototype_model, ) test_destination_response_body = response.get_result() @@ -197,10 +204,10 @@ def test_create_preferences_example(self): } response = platform_notifications_service.create_preferences( - iam_id='IBMid-1234567890', + iam_id=iam_id, incident_severity1=preference_value_with_updates_model, ordering_review=preference_value_without_updates_model, - account_id='a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6', + account_id=account_id, ) preferences_object = response.get_result() @@ -222,8 +229,8 @@ def test_get_preferences_example(self): # begin-get_preferences response = platform_notifications_service.get_preferences( - iam_id='IBMid-1234567890', - account_id='a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6', + iam_id=iam_id, + account_id=account_id, ) preferences_object = response.get_result() @@ -254,10 +261,10 @@ def test_replace_notification_preferences_example(self): } response = platform_notifications_service.replace_notification_preferences( - iam_id='IBMid-1234567890', + iam_id=iam_id, incident_severity1=preference_value_with_updates_model, ordering_review=preference_value_without_updates_model, - account_id='a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6', + account_id=account_id, ) preferences_object = response.get_result() @@ -281,7 +288,7 @@ def test_list_notifications_example(self): all_results = [] pager = NotificationsPager( client=platform_notifications_service, - account_id='a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6', + account_id=account_id, limit=50, ) while pager.has_next(): @@ -306,7 +313,7 @@ def test_get_acknowledgement_example(self): # begin-get_acknowledgement response = platform_notifications_service.get_acknowledgement( - account_id='1369339417d906e5620b8d861d40cfd7', + account_id=account_id, ) acknowledgement = response.get_result() @@ -329,7 +336,7 @@ def test_replace_notification_acknowledgement_example(self): response = platform_notifications_service.replace_notification_acknowledgement( last_acknowledged_id='1772804159452', - account_id='1369339417d906e5620b8d861d40cfd7', + account_id=account_id, ) acknowledgement = response.get_result() @@ -349,8 +356,8 @@ def test_delete_distribution_list_destination_example(self): # begin-delete_distribution_list_destination response = platform_notifications_service.delete_distribution_list_destination( - account_id='a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6', - destination_id='12345678-1234-1234-1234-123456789012', + account_id=account_id, + destination_id=destination_id, ) # end-delete_distribution_list_destination @@ -368,8 +375,8 @@ def test_delete_notification_preferences_example(self): # begin-delete_notification_preferences response = platform_notifications_service.delete_notification_preferences( - iam_id='IBMid-1234567890', - account_id='a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6', + iam_id=iam_id, + account_id=account_id, ) # end-delete_notification_preferences diff --git a/ibm_platform_services/platform_notifications_v1.py b/ibm_platform_services/platform_notifications_v1.py index 02454629..10f3ede0 100644 --- a/ibm_platform_services/platform_notifications_v1.py +++ b/ibm_platform_services/platform_notifications_v1.py @@ -56,9 +56,7 @@ def new_instance( specified parameters and external configuration. """ authenticator = get_authenticator_from_environment(service_name) - service = cls( - authenticator - ) + service = cls(authenticator) service.configure_service(service_name) return service @@ -470,7 +468,9 @@ def create_preferences( if billing_and_usage_payments is not None: billing_and_usage_payments = convert_model(billing_and_usage_payments) if billing_and_usage_subscriptions_and_promo_codes is not None: - billing_and_usage_subscriptions_and_promo_codes = convert_model(billing_and_usage_subscriptions_and_promo_codes) + billing_and_usage_subscriptions_and_promo_codes = convert_model( + billing_and_usage_subscriptions_and_promo_codes + ) if billing_and_usage_spending_alerts is not None: billing_and_usage_spending_alerts = convert_model(billing_and_usage_spending_alerts) if resourceactivity_normal is not None: @@ -733,7 +733,9 @@ def replace_notification_preferences( if billing_and_usage_payments is not None: billing_and_usage_payments = convert_model(billing_and_usage_payments) if billing_and_usage_subscriptions_and_promo_codes is not None: - billing_and_usage_subscriptions_and_promo_codes = convert_model(billing_and_usage_subscriptions_and_promo_codes) + billing_and_usage_subscriptions_and_promo_codes = convert_model( + billing_and_usage_subscriptions_and_promo_codes + ) if billing_and_usage_spending_alerts is not None: billing_and_usage_spending_alerts = convert_model(billing_and_usage_spending_alerts) if resourceactivity_normal is not None: @@ -1488,7 +1490,6 @@ class CategoryEnum(str, Enum): PROVISIONING = 'provisioning' ACCOUNT = 'account' - class StateEnum(str, Enum): """ The current state of the notification. @@ -1499,7 +1500,6 @@ class StateEnum(str, Enum): COMPLETE = 'complete' RESOLVED = 'resolved' - class CompletionCodeEnum(str, Enum): """ The completion code of the notification. @@ -1510,7 +1510,6 @@ class CompletionCodeEnum(str, Enum): CANCELLED = 'cancelled' - class NotificationCollection: """ Collection of user notifications with token-based pagination metadata. @@ -1859,7 +1858,6 @@ class ChannelsEnum(str, Enum): EMAIL = 'email' - class PreferenceValueWithoutUpdates: """ Preference settings for notification types that do not support updates. @@ -1927,7 +1925,6 @@ class ChannelsEnum(str, Enum): EMAIL = 'email' - class PreferencesObject: """ User communication preferences object. Only include preferences where communication is @@ -2126,10 +2123,18 @@ def from_dict(cls, _dict: Dict) -> 'PreferencesObject': args['billing_and_usage_invoices'] = PreferenceValueWithoutUpdates.from_dict(billing_and_usage_invoices) if (billing_and_usage_payments := _dict.get('billing_and_usage_payments')) is not None: args['billing_and_usage_payments'] = PreferenceValueWithoutUpdates.from_dict(billing_and_usage_payments) - if (billing_and_usage_subscriptions_and_promo_codes := _dict.get('billing_and_usage_subscriptions_and_promo_codes')) is not None: - args['billing_and_usage_subscriptions_and_promo_codes'] = PreferenceValueWithoutUpdates.from_dict(billing_and_usage_subscriptions_and_promo_codes) + if ( + billing_and_usage_subscriptions_and_promo_codes := _dict.get( + 'billing_and_usage_subscriptions_and_promo_codes' + ) + ) is not None: + args['billing_and_usage_subscriptions_and_promo_codes'] = PreferenceValueWithoutUpdates.from_dict( + billing_and_usage_subscriptions_and_promo_codes + ) if (billing_and_usage_spending_alerts := _dict.get('billing_and_usage_spending_alerts')) is not None: - args['billing_and_usage_spending_alerts'] = PreferenceValueWithoutUpdates.from_dict(billing_and_usage_spending_alerts) + args['billing_and_usage_spending_alerts'] = PreferenceValueWithoutUpdates.from_dict( + billing_and_usage_spending_alerts + ) if (resourceactivity_normal := _dict.get('resourceactivity_normal')) is not None: args['resourceactivity_normal'] = PreferenceValueWithoutUpdates.from_dict(resourceactivity_normal) if (ordering_review := _dict.get('ordering_review')) is not None: @@ -2226,11 +2231,18 @@ def to_dict(self) -> Dict: _dict['billing_and_usage_payments'] = self.billing_and_usage_payments else: _dict['billing_and_usage_payments'] = self.billing_and_usage_payments.to_dict() - if hasattr(self, 'billing_and_usage_subscriptions_and_promo_codes') and self.billing_and_usage_subscriptions_and_promo_codes is not None: + if ( + hasattr(self, 'billing_and_usage_subscriptions_and_promo_codes') + and self.billing_and_usage_subscriptions_and_promo_codes is not None + ): if isinstance(self.billing_and_usage_subscriptions_and_promo_codes, dict): - _dict['billing_and_usage_subscriptions_and_promo_codes'] = self.billing_and_usage_subscriptions_and_promo_codes + _dict['billing_and_usage_subscriptions_and_promo_codes'] = ( + self.billing_and_usage_subscriptions_and_promo_codes + ) else: - _dict['billing_and_usage_subscriptions_and_promo_codes'] = self.billing_and_usage_subscriptions_and_promo_codes.to_dict() + _dict['billing_and_usage_subscriptions_and_promo_codes'] = ( + self.billing_and_usage_subscriptions_and_promo_codes.to_dict() + ) if hasattr(self, 'billing_and_usage_spending_alerts') and self.billing_and_usage_spending_alerts is not None: if isinstance(self.billing_and_usage_spending_alerts, dict): _dict['billing_and_usage_spending_alerts'] = self.billing_and_usage_spending_alerts @@ -2334,10 +2346,14 @@ def _from_dict(cls, _dict: Dict): @classmethod def _get_class_by_discriminator(cls, _dict: Dict) -> object: mapping = {} - mapping['event_notifications'] = 'TestDestinationRequestBodyPrototypeTestEventNotificationDestinationRequestBodyPrototype' + mapping['event_notifications'] = ( + 'TestDestinationRequestBodyPrototypeTestEventNotificationDestinationRequestBodyPrototype' + ) disc_value = _dict.get('destination_type') if disc_value is None: - raise ValueError('Discriminator property \'destination_type\' not found in TestDestinationRequestBodyPrototype JSON') + raise ValueError( + 'Discriminator property \'destination_type\' not found in TestDestinationRequestBodyPrototype JSON' + ) class_name = mapping.get(disc_value, disc_value) try: disc_class = getattr(sys.modules[__name__], class_name) @@ -2521,11 +2537,15 @@ def from_dict(cls, _dict: Dict) -> 'AddDestinationPrototypeEventNotificationDest if (destination_id := _dict.get('destination_id')) is not None: args['destination_id'] = destination_id else: - raise ValueError('Required property \'destination_id\' not present in AddDestinationPrototypeEventNotificationDestinationPrototype JSON') + raise ValueError( + 'Required property \'destination_id\' not present in AddDestinationPrototypeEventNotificationDestinationPrototype JSON' + ) if (destination_type := _dict.get('destination_type')) is not None: args['destination_type'] = destination_type else: - raise ValueError('Required property \'destination_type\' not present in AddDestinationPrototypeEventNotificationDestinationPrototype JSON') + raise ValueError( + 'Required property \'destination_type\' not present in AddDestinationPrototypeEventNotificationDestinationPrototype JSON' + ) return cls(**args) @classmethod @@ -2568,7 +2588,6 @@ class DestinationTypeEnum(str, Enum): EVENT_NOTIFICATIONS = 'event_notifications' - class AddDestinationEventNotificationDestination(AddDestination): """ An Event Notifications destination entry in the distribution list. @@ -2599,11 +2618,15 @@ def from_dict(cls, _dict: Dict) -> 'AddDestinationEventNotificationDestination': if (destination_id := _dict.get('destination_id')) is not None: args['destination_id'] = destination_id else: - raise ValueError('Required property \'destination_id\' not present in AddDestinationEventNotificationDestination JSON') + raise ValueError( + 'Required property \'destination_id\' not present in AddDestinationEventNotificationDestination JSON' + ) if (destination_type := _dict.get('destination_type')) is not None: args['destination_type'] = destination_type else: - raise ValueError('Required property \'destination_type\' not present in AddDestinationEventNotificationDestination JSON') + raise ValueError( + 'Required property \'destination_type\' not present in AddDestinationEventNotificationDestination JSON' + ) return cls(**args) @classmethod @@ -2646,8 +2669,9 @@ class DestinationTypeEnum(str, Enum): EVENT_NOTIFICATIONS = 'event_notifications' - -class TestDestinationRequestBodyPrototypeTestEventNotificationDestinationRequestBodyPrototype(TestDestinationRequestBodyPrototype): +class TestDestinationRequestBodyPrototypeTestEventNotificationDestinationRequestBodyPrototype( + TestDestinationRequestBodyPrototype +): """ Request body for testing an Event Notifications destination. @@ -2671,17 +2695,23 @@ def __init__( self.notification_type = notification_type @classmethod - def from_dict(cls, _dict: Dict) -> 'TestDestinationRequestBodyPrototypeTestEventNotificationDestinationRequestBodyPrototype': + def from_dict( + cls, _dict: Dict + ) -> 'TestDestinationRequestBodyPrototypeTestEventNotificationDestinationRequestBodyPrototype': """Initialize a TestDestinationRequestBodyPrototypeTestEventNotificationDestinationRequestBodyPrototype object from a json dictionary.""" args = {} if (destination_type := _dict.get('destination_type')) is not None: args['destination_type'] = destination_type else: - raise ValueError('Required property \'destination_type\' not present in TestDestinationRequestBodyPrototypeTestEventNotificationDestinationRequestBodyPrototype JSON') + raise ValueError( + 'Required property \'destination_type\' not present in TestDestinationRequestBodyPrototypeTestEventNotificationDestinationRequestBodyPrototype JSON' + ) if (notification_type := _dict.get('notification_type')) is not None: args['notification_type'] = notification_type else: - raise ValueError('Required property \'notification_type\' not present in TestDestinationRequestBodyPrototypeTestEventNotificationDestinationRequestBodyPrototype JSON') + raise ValueError( + 'Required property \'notification_type\' not present in TestDestinationRequestBodyPrototypeTestEventNotificationDestinationRequestBodyPrototype JSON' + ) return cls(**args) @classmethod @@ -2706,13 +2736,17 @@ def __str__(self) -> str: """Return a `str` version of this TestDestinationRequestBodyPrototypeTestEventNotificationDestinationRequestBodyPrototype object.""" return json.dumps(self.to_dict(), indent=2) - def __eq__(self, other: 'TestDestinationRequestBodyPrototypeTestEventNotificationDestinationRequestBodyPrototype') -> bool: + def __eq__( + self, other: 'TestDestinationRequestBodyPrototypeTestEventNotificationDestinationRequestBodyPrototype' + ) -> bool: """Return `true` when self and other are equal, false otherwise.""" if not isinstance(other, self.__class__): return False return self.__dict__ == other.__dict__ - def __ne__(self, other: 'TestDestinationRequestBodyPrototypeTestEventNotificationDestinationRequestBodyPrototype') -> bool: + def __ne__( + self, other: 'TestDestinationRequestBodyPrototypeTestEventNotificationDestinationRequestBodyPrototype' + ) -> bool: """Return `true` when self and other are not equal, false otherwise.""" return not self == other @@ -2723,7 +2757,6 @@ class DestinationTypeEnum(str, Enum): EVENT_NOTIFICATIONS = 'event_notifications' - class NotificationTypeEnum(str, Enum): """ The type of the notification to test. diff --git a/test/integration/test_platform_notifications_v1.py b/test/integration/test_platform_notifications_v1.py index fb8e7694..8b932bcc 100644 --- a/test/integration/test_platform_notifications_v1.py +++ b/test/integration/test_platform_notifications_v1.py @@ -38,6 +38,7 @@ iam_id = '' service_url = '' + class TestPlatformNotificationsV1: """ Integration Test Class for PlatformNotificationsV1 @@ -48,8 +49,7 @@ def setup_class(cls): if os.path.exists(config_file): os.environ['IBM_CREDENTIALS_FILE'] = config_file - cls.platform_notifications_service = PlatformNotificationsV1.new_instance( - ) + cls.platform_notifications_service = PlatformNotificationsV1.new_instance() assert cls.platform_notifications_service is not None cls.config = read_external_sources(PlatformNotificationsV1.DEFAULT_SERVICE_NAME) @@ -98,7 +98,7 @@ def test_delete_distribution_list_destination(self): ) assert response.get_status_code() == 204 - + @needscredentials def test_create_distribution_list_destination(self): # Construct a dict representation of a AddDestinationPrototypeEventNotificationDestinationPrototype model @@ -296,7 +296,6 @@ def test_replace_notification_acknowledgement(self): acknowledgement = response.get_result() assert acknowledgement is not None - @needscredentials def test_delete_notification_preferences(self): response = self.platform_notifications_service.delete_notification_preferences( diff --git a/test/unit/test_platform_notifications_v1.py b/test/unit/test_platform_notifications_v1.py index 1c81391a..48bd03dd 100644 --- a/test/unit/test_platform_notifications_v1.py +++ b/test/unit/test_platform_notifications_v1.py @@ -29,9 +29,7 @@ from ibm_platform_services.platform_notifications_v1 import * -_service = PlatformNotificationsV1( - authenticator=NoAuthAuthenticator() -) +_service = PlatformNotificationsV1(authenticator=NoAuthAuthenticator()) _base_url = 'https://notifications.cloud.ibm.com/api' _service.set_service_url(_base_url) @@ -182,7 +180,9 @@ def test_create_distribution_list_destination_all_params(self): """ # Set up mock url = preprocess_url('/v1/distribution_lists/a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6/destinations') - mock_response = '{"destination_id": "12345678-1234-1234-1234-123456789012", "destination_type": "event_notifications"}' + mock_response = ( + '{"destination_id": "12345678-1234-1234-1234-123456789012", "destination_type": "event_notifications"}' + ) responses.add( responses.POST, url, @@ -230,7 +230,9 @@ def test_create_distribution_list_destination_value_error(self): """ # Set up mock url = preprocess_url('/v1/distribution_lists/a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6/destinations') - mock_response = '{"destination_id": "12345678-1234-1234-1234-123456789012", "destination_type": "event_notifications"}' + mock_response = ( + '{"destination_id": "12345678-1234-1234-1234-123456789012", "destination_type": "event_notifications"}' + ) responses.add( responses.POST, url, @@ -279,8 +281,12 @@ def test_get_distribution_list_destination_all_params(self): get_distribution_list_destination() """ # Set up mock - url = preprocess_url('/v1/distribution_lists/a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6/destinations/12345678-1234-1234-1234-123456789012') - mock_response = '{"destination_id": "12345678-1234-1234-1234-123456789012", "destination_type": "event_notifications"}' + url = preprocess_url( + '/v1/distribution_lists/a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6/destinations/12345678-1234-1234-1234-123456789012' + ) + mock_response = ( + '{"destination_id": "12345678-1234-1234-1234-123456789012", "destination_type": "event_notifications"}' + ) responses.add( responses.GET, url, @@ -319,8 +325,12 @@ def test_get_distribution_list_destination_value_error(self): test_get_distribution_list_destination_value_error() """ # Set up mock - url = preprocess_url('/v1/distribution_lists/a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6/destinations/12345678-1234-1234-1234-123456789012') - mock_response = '{"destination_id": "12345678-1234-1234-1234-123456789012", "destination_type": "event_notifications"}' + url = preprocess_url( + '/v1/distribution_lists/a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6/destinations/12345678-1234-1234-1234-123456789012' + ) + mock_response = ( + '{"destination_id": "12345678-1234-1234-1234-123456789012", "destination_type": "event_notifications"}' + ) responses.add( responses.GET, url, @@ -364,7 +374,9 @@ def test_delete_distribution_list_destination_all_params(self): delete_distribution_list_destination() """ # Set up mock - url = preprocess_url('/v1/distribution_lists/a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6/destinations/12345678-1234-1234-1234-123456789012') + url = preprocess_url( + '/v1/distribution_lists/a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6/destinations/12345678-1234-1234-1234-123456789012' + ) responses.add( responses.DELETE, url, @@ -401,7 +413,9 @@ def test_delete_distribution_list_destination_value_error(self): test_delete_distribution_list_destination_value_error() """ # Set up mock - url = preprocess_url('/v1/distribution_lists/a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6/destinations/12345678-1234-1234-1234-123456789012') + url = preprocess_url( + '/v1/distribution_lists/a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6/destinations/12345678-1234-1234-1234-123456789012' + ) responses.add( responses.DELETE, url, @@ -443,7 +457,9 @@ def test_test_distribution_list_destination_all_params(self): test_distribution_list_destination() """ # Set up mock - url = preprocess_url('/v1/distribution_lists/a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6/destinations/12345678-1234-1234-1234-123456789012/test') + url = preprocess_url( + '/v1/distribution_lists/a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6/destinations/12345678-1234-1234-1234-123456789012/test' + ) mock_response = '{"message": "success"}' responses.add( responses.POST, @@ -493,7 +509,9 @@ def test_test_distribution_list_destination_value_error(self): test_test_distribution_list_destination_value_error() """ # Set up mock - url = preprocess_url('/v1/distribution_lists/a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6/destinations/12345678-1234-1234-1234-123456789012/test') + url = preprocess_url( + '/v1/distribution_lists/a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6/destinations/12345678-1234-1234-1234-123456789012/test' + ) mock_response = '{"message": "success"}' responses.add( responses.POST, @@ -1670,7 +1688,9 @@ def test_get_acknowledgement_all_params(self): """ # Set up mock url = preprocess_url('/v1/notifications/acknowledgement') - mock_response = '{"has_unread": true, "latest_notification_id": "1678901234000", "last_acknowledged_id": "1678800000000"}' + mock_response = ( + '{"has_unread": true, "latest_notification_id": "1678901234000", "last_acknowledged_id": "1678800000000"}' + ) responses.add( responses.GET, url, @@ -1712,7 +1732,9 @@ def test_get_acknowledgement_required_params(self): """ # Set up mock url = preprocess_url('/v1/notifications/acknowledgement') - mock_response = '{"has_unread": true, "latest_notification_id": "1678901234000", "last_acknowledged_id": "1678800000000"}' + mock_response = ( + '{"has_unread": true, "latest_notification_id": "1678901234000", "last_acknowledged_id": "1678800000000"}' + ) responses.add( responses.GET, url, @@ -1750,7 +1772,9 @@ def test_replace_notification_acknowledgement_all_params(self): """ # Set up mock url = preprocess_url('/v1/notifications/acknowledgement') - mock_response = '{"has_unread": true, "latest_notification_id": "1678901234000", "last_acknowledged_id": "1678800000000"}' + mock_response = ( + '{"has_unread": true, "latest_notification_id": "1678901234000", "last_acknowledged_id": "1678800000000"}' + ) responses.add( responses.PUT, url, @@ -1797,7 +1821,9 @@ def test_replace_notification_acknowledgement_required_params(self): """ # Set up mock url = preprocess_url('/v1/notifications/acknowledgement') - mock_response = '{"has_unread": true, "latest_notification_id": "1678901234000", "last_acknowledged_id": "1678800000000"}' + mock_response = ( + '{"has_unread": true, "latest_notification_id": "1678901234000", "last_acknowledged_id": "1678800000000"}' + ) responses.add( responses.PUT, url, @@ -1838,7 +1864,9 @@ def test_replace_notification_acknowledgement_value_error(self): """ # Set up mock url = preprocess_url('/v1/notifications/acknowledgement') - mock_response = '{"has_unread": true, "latest_notification_id": "1678901234000", "last_acknowledged_id": "1678800000000"}' + mock_response = ( + '{"has_unread": true, "latest_notification_id": "1678901234000", "last_acknowledged_id": "1678800000000"}' + ) responses.add( responses.PUT, url, @@ -1906,7 +1934,9 @@ def test_add_destination_collection_serialization(self): assert add_destination_collection_model != False # Construct a model instance of AddDestinationCollection by calling from_dict on the json representation - add_destination_collection_model_dict = AddDestinationCollection.from_dict(add_destination_collection_model_json).__dict__ + add_destination_collection_model_dict = AddDestinationCollection.from_dict( + add_destination_collection_model_json + ).__dict__ add_destination_collection_model2 = AddDestinationCollection(**add_destination_collection_model_dict) # Verify the model instances are equivalent @@ -1930,7 +1960,9 @@ def test_notification_serialization(self): # Construct a json representation of a Notification model notification_model_json = {} notification_model_json['title'] = 'System Maintenance Scheduled' - notification_model_json['body'] = 'Scheduled maintenance will occur on March 15th from 10:00 AM to 11:00 AM UTC.' + notification_model_json['body'] = ( + 'Scheduled maintenance will occur on March 15th from 10:00 AM to 11:00 AM UTC.' + ) notification_model_json['id'] = '12345' notification_model_json['category'] = 'maintenance' notification_model_json['component_names'] = ['event-notifications', 'ibm-cloud'] @@ -1980,7 +2012,9 @@ def test_notification_collection_serialization(self): pagination_link_model['href'] = 'https://api.example.com/v1/notifications?limit=50' pagination_link_with_token_model = {} # PaginationLinkWithToken - pagination_link_with_token_model['href'] = 'https://api.example.com/v1/notifications?start=3fe78a36b9aa7f26&limit=50' + pagination_link_with_token_model['href'] = ( + 'https://api.example.com/v1/notifications?start=3fe78a36b9aa7f26&limit=50' + ) pagination_link_with_token_model['start'] = '3fe78a36b9aa7f26' notification_model = {} # Notification @@ -2018,7 +2052,9 @@ def test_notification_collection_serialization(self): assert notification_collection_model != False # Construct a model instance of NotificationCollection by calling from_dict on the json representation - notification_collection_model_dict = NotificationCollection.from_dict(notification_collection_model_json).__dict__ + notification_collection_model_dict = NotificationCollection.from_dict( + notification_collection_model_json + ).__dict__ notification_collection_model2 = NotificationCollection(**notification_collection_model_dict) # Verify the model instances are equivalent @@ -2071,7 +2107,9 @@ def test_pagination_link_with_token_serialization(self): # Construct a json representation of a PaginationLinkWithToken model pagination_link_with_token_model_json = {} - pagination_link_with_token_model_json['href'] = 'https://api.example.com/v1/notifications?start=3fe78a36b9aa7f26&limit=50' + pagination_link_with_token_model_json['href'] = ( + 'https://api.example.com/v1/notifications?start=3fe78a36b9aa7f26&limit=50' + ) pagination_link_with_token_model_json['start'] = '3fe78a36b9aa7f26' # Construct a model instance of PaginationLinkWithToken by calling from_dict on the json representation @@ -2079,7 +2117,9 @@ def test_pagination_link_with_token_serialization(self): assert pagination_link_with_token_model != False # Construct a model instance of PaginationLinkWithToken by calling from_dict on the json representation - pagination_link_with_token_model_dict = PaginationLinkWithToken.from_dict(pagination_link_with_token_model_json).__dict__ + pagination_link_with_token_model_dict = PaginationLinkWithToken.from_dict( + pagination_link_with_token_model_json + ).__dict__ pagination_link_with_token_model2 = PaginationLinkWithToken(**pagination_link_with_token_model_dict) # Verify the model instances are equivalent @@ -2106,11 +2146,15 @@ def test_preference_value_with_updates_serialization(self): preference_value_with_updates_model_json['updates'] = True # Construct a model instance of PreferenceValueWithUpdates by calling from_dict on the json representation - preference_value_with_updates_model = PreferenceValueWithUpdates.from_dict(preference_value_with_updates_model_json) + preference_value_with_updates_model = PreferenceValueWithUpdates.from_dict( + preference_value_with_updates_model_json + ) assert preference_value_with_updates_model != False # Construct a model instance of PreferenceValueWithUpdates by calling from_dict on the json representation - preference_value_with_updates_model_dict = PreferenceValueWithUpdates.from_dict(preference_value_with_updates_model_json).__dict__ + preference_value_with_updates_model_dict = PreferenceValueWithUpdates.from_dict( + preference_value_with_updates_model_json + ).__dict__ preference_value_with_updates_model2 = PreferenceValueWithUpdates(**preference_value_with_updates_model_dict) # Verify the model instances are equivalent @@ -2136,12 +2180,18 @@ def test_preference_value_without_updates_serialization(self): preference_value_without_updates_model_json['channels'] = ['email'] # Construct a model instance of PreferenceValueWithoutUpdates by calling from_dict on the json representation - preference_value_without_updates_model = PreferenceValueWithoutUpdates.from_dict(preference_value_without_updates_model_json) + preference_value_without_updates_model = PreferenceValueWithoutUpdates.from_dict( + preference_value_without_updates_model_json + ) assert preference_value_without_updates_model != False # Construct a model instance of PreferenceValueWithoutUpdates by calling from_dict on the json representation - preference_value_without_updates_model_dict = PreferenceValueWithoutUpdates.from_dict(preference_value_without_updates_model_json).__dict__ - preference_value_without_updates_model2 = PreferenceValueWithoutUpdates(**preference_value_without_updates_model_dict) + preference_value_without_updates_model_dict = PreferenceValueWithoutUpdates.from_dict( + preference_value_without_updates_model_json + ).__dict__ + preference_value_without_updates_model2 = PreferenceValueWithoutUpdates( + **preference_value_without_updates_model_dict + ) # Verify the model instances are equivalent assert preference_value_without_updates_model == preference_value_without_updates_model2 @@ -2186,7 +2236,9 @@ def test_preferences_object_serialization(self): preferences_object_model_json['billing_and_usage_order'] = preference_value_without_updates_model preferences_object_model_json['billing_and_usage_invoices'] = preference_value_without_updates_model preferences_object_model_json['billing_and_usage_payments'] = preference_value_without_updates_model - preferences_object_model_json['billing_and_usage_subscriptions_and_promo_codes'] = preference_value_without_updates_model + preferences_object_model_json['billing_and_usage_subscriptions_and_promo_codes'] = ( + preference_value_without_updates_model + ) preferences_object_model_json['billing_and_usage_spending_alerts'] = preference_value_without_updates_model preferences_object_model_json['resourceactivity_normal'] = preference_value_without_updates_model preferences_object_model_json['ordering_review'] = preference_value_without_updates_model @@ -2228,11 +2280,15 @@ def test_test_destination_response_body_serialization(self): test_destination_response_body_model_json['message'] = 'success' # Construct a model instance of TestDestinationResponseBody by calling from_dict on the json representation - test_destination_response_body_model = TestDestinationResponseBody.from_dict(test_destination_response_body_model_json) + test_destination_response_body_model = TestDestinationResponseBody.from_dict( + test_destination_response_body_model_json + ) assert test_destination_response_body_model != False # Construct a model instance of TestDestinationResponseBody by calling from_dict on the json representation - test_destination_response_body_model_dict = TestDestinationResponseBody.from_dict(test_destination_response_body_model_json).__dict__ + test_destination_response_body_model_dict = TestDestinationResponseBody.from_dict( + test_destination_response_body_model_json + ).__dict__ test_destination_response_body_model2 = TestDestinationResponseBody(**test_destination_response_body_model_dict) # Verify the model instances are equivalent @@ -2287,23 +2343,47 @@ def test_add_destination_prototype_event_notification_destination_prototype_seri # Construct a json representation of a AddDestinationPrototypeEventNotificationDestinationPrototype model add_destination_prototype_event_notification_destination_prototype_model_json = {} - add_destination_prototype_event_notification_destination_prototype_model_json['destination_id'] = '12345678-1234-1234-1234-123456789012' - add_destination_prototype_event_notification_destination_prototype_model_json['destination_type'] = 'event_notifications' + add_destination_prototype_event_notification_destination_prototype_model_json['destination_id'] = ( + '12345678-1234-1234-1234-123456789012' + ) + add_destination_prototype_event_notification_destination_prototype_model_json['destination_type'] = ( + 'event_notifications' + ) # Construct a model instance of AddDestinationPrototypeEventNotificationDestinationPrototype by calling from_dict on the json representation - add_destination_prototype_event_notification_destination_prototype_model = AddDestinationPrototypeEventNotificationDestinationPrototype.from_dict(add_destination_prototype_event_notification_destination_prototype_model_json) + add_destination_prototype_event_notification_destination_prototype_model = ( + AddDestinationPrototypeEventNotificationDestinationPrototype.from_dict( + add_destination_prototype_event_notification_destination_prototype_model_json + ) + ) assert add_destination_prototype_event_notification_destination_prototype_model != False # Construct a model instance of AddDestinationPrototypeEventNotificationDestinationPrototype by calling from_dict on the json representation - add_destination_prototype_event_notification_destination_prototype_model_dict = AddDestinationPrototypeEventNotificationDestinationPrototype.from_dict(add_destination_prototype_event_notification_destination_prototype_model_json).__dict__ - add_destination_prototype_event_notification_destination_prototype_model2 = AddDestinationPrototypeEventNotificationDestinationPrototype(**add_destination_prototype_event_notification_destination_prototype_model_dict) + add_destination_prototype_event_notification_destination_prototype_model_dict = ( + AddDestinationPrototypeEventNotificationDestinationPrototype.from_dict( + add_destination_prototype_event_notification_destination_prototype_model_json + ).__dict__ + ) + add_destination_prototype_event_notification_destination_prototype_model2 = ( + AddDestinationPrototypeEventNotificationDestinationPrototype( + **add_destination_prototype_event_notification_destination_prototype_model_dict + ) + ) # Verify the model instances are equivalent - assert add_destination_prototype_event_notification_destination_prototype_model == add_destination_prototype_event_notification_destination_prototype_model2 + assert ( + add_destination_prototype_event_notification_destination_prototype_model + == add_destination_prototype_event_notification_destination_prototype_model2 + ) # Convert model instance back to dict and verify no loss of data - add_destination_prototype_event_notification_destination_prototype_model_json2 = add_destination_prototype_event_notification_destination_prototype_model.to_dict() - assert add_destination_prototype_event_notification_destination_prototype_model_json2 == add_destination_prototype_event_notification_destination_prototype_model_json + add_destination_prototype_event_notification_destination_prototype_model_json2 = ( + add_destination_prototype_event_notification_destination_prototype_model.to_dict() + ) + assert ( + add_destination_prototype_event_notification_destination_prototype_model_json2 + == add_destination_prototype_event_notification_destination_prototype_model_json + ) class TestModel_AddDestinationEventNotificationDestination: @@ -2318,23 +2398,41 @@ def test_add_destination_event_notification_destination_serialization(self): # Construct a json representation of a AddDestinationEventNotificationDestination model add_destination_event_notification_destination_model_json = {} - add_destination_event_notification_destination_model_json['destination_id'] = '12345678-1234-1234-1234-123456789012' + add_destination_event_notification_destination_model_json['destination_id'] = ( + '12345678-1234-1234-1234-123456789012' + ) add_destination_event_notification_destination_model_json['destination_type'] = 'event_notifications' # Construct a model instance of AddDestinationEventNotificationDestination by calling from_dict on the json representation - add_destination_event_notification_destination_model = AddDestinationEventNotificationDestination.from_dict(add_destination_event_notification_destination_model_json) + add_destination_event_notification_destination_model = AddDestinationEventNotificationDestination.from_dict( + add_destination_event_notification_destination_model_json + ) assert add_destination_event_notification_destination_model != False # Construct a model instance of AddDestinationEventNotificationDestination by calling from_dict on the json representation - add_destination_event_notification_destination_model_dict = AddDestinationEventNotificationDestination.from_dict(add_destination_event_notification_destination_model_json).__dict__ - add_destination_event_notification_destination_model2 = AddDestinationEventNotificationDestination(**add_destination_event_notification_destination_model_dict) + add_destination_event_notification_destination_model_dict = ( + AddDestinationEventNotificationDestination.from_dict( + add_destination_event_notification_destination_model_json + ).__dict__ + ) + add_destination_event_notification_destination_model2 = AddDestinationEventNotificationDestination( + **add_destination_event_notification_destination_model_dict + ) # Verify the model instances are equivalent - assert add_destination_event_notification_destination_model == add_destination_event_notification_destination_model2 + assert ( + add_destination_event_notification_destination_model + == add_destination_event_notification_destination_model2 + ) # Convert model instance back to dict and verify no loss of data - add_destination_event_notification_destination_model_json2 = add_destination_event_notification_destination_model.to_dict() - assert add_destination_event_notification_destination_model_json2 == add_destination_event_notification_destination_model_json + add_destination_event_notification_destination_model_json2 = ( + add_destination_event_notification_destination_model.to_dict() + ) + assert ( + add_destination_event_notification_destination_model_json2 + == add_destination_event_notification_destination_model_json + ) class TestModel_TestDestinationRequestBodyPrototypeTestEventNotificationDestinationRequestBodyPrototype: @@ -2342,30 +2440,55 @@ class TestModel_TestDestinationRequestBodyPrototypeTestEventNotificationDestinat Test Class for TestDestinationRequestBodyPrototypeTestEventNotificationDestinationRequestBodyPrototype """ - def test_test_destination_request_body_prototype_test_event_notification_destination_request_body_prototype_serialization(self): + def test_test_destination_request_body_prototype_test_event_notification_destination_request_body_prototype_serialization( + self, + ): """ Test serialization/deserialization for TestDestinationRequestBodyPrototypeTestEventNotificationDestinationRequestBodyPrototype """ # Construct a json representation of a TestDestinationRequestBodyPrototypeTestEventNotificationDestinationRequestBodyPrototype model - test_destination_request_body_prototype_test_event_notification_destination_request_body_prototype_model_json = {} - test_destination_request_body_prototype_test_event_notification_destination_request_body_prototype_model_json['destination_type'] = 'event_notifications' - test_destination_request_body_prototype_test_event_notification_destination_request_body_prototype_model_json['notification_type'] = 'incident' + test_destination_request_body_prototype_test_event_notification_destination_request_body_prototype_model_json = ( + {} + ) + test_destination_request_body_prototype_test_event_notification_destination_request_body_prototype_model_json[ + 'destination_type' + ] = 'event_notifications' + test_destination_request_body_prototype_test_event_notification_destination_request_body_prototype_model_json[ + 'notification_type' + ] = 'incident' # Construct a model instance of TestDestinationRequestBodyPrototypeTestEventNotificationDestinationRequestBodyPrototype by calling from_dict on the json representation - test_destination_request_body_prototype_test_event_notification_destination_request_body_prototype_model = TestDestinationRequestBodyPrototypeTestEventNotificationDestinationRequestBodyPrototype.from_dict(test_destination_request_body_prototype_test_event_notification_destination_request_body_prototype_model_json) - assert test_destination_request_body_prototype_test_event_notification_destination_request_body_prototype_model != False + test_destination_request_body_prototype_test_event_notification_destination_request_body_prototype_model = TestDestinationRequestBodyPrototypeTestEventNotificationDestinationRequestBodyPrototype.from_dict( + test_destination_request_body_prototype_test_event_notification_destination_request_body_prototype_model_json + ) + assert ( + test_destination_request_body_prototype_test_event_notification_destination_request_body_prototype_model + != False + ) # Construct a model instance of TestDestinationRequestBodyPrototypeTestEventNotificationDestinationRequestBodyPrototype by calling from_dict on the json representation - test_destination_request_body_prototype_test_event_notification_destination_request_body_prototype_model_dict = TestDestinationRequestBodyPrototypeTestEventNotificationDestinationRequestBodyPrototype.from_dict(test_destination_request_body_prototype_test_event_notification_destination_request_body_prototype_model_json).__dict__ - test_destination_request_body_prototype_test_event_notification_destination_request_body_prototype_model2 = TestDestinationRequestBodyPrototypeTestEventNotificationDestinationRequestBodyPrototype(**test_destination_request_body_prototype_test_event_notification_destination_request_body_prototype_model_dict) + test_destination_request_body_prototype_test_event_notification_destination_request_body_prototype_model_dict = TestDestinationRequestBodyPrototypeTestEventNotificationDestinationRequestBodyPrototype.from_dict( + test_destination_request_body_prototype_test_event_notification_destination_request_body_prototype_model_json + ).__dict__ + test_destination_request_body_prototype_test_event_notification_destination_request_body_prototype_model2 = TestDestinationRequestBodyPrototypeTestEventNotificationDestinationRequestBodyPrototype( + **test_destination_request_body_prototype_test_event_notification_destination_request_body_prototype_model_dict + ) # Verify the model instances are equivalent - assert test_destination_request_body_prototype_test_event_notification_destination_request_body_prototype_model == test_destination_request_body_prototype_test_event_notification_destination_request_body_prototype_model2 + assert ( + test_destination_request_body_prototype_test_event_notification_destination_request_body_prototype_model + == test_destination_request_body_prototype_test_event_notification_destination_request_body_prototype_model2 + ) # Convert model instance back to dict and verify no loss of data - test_destination_request_body_prototype_test_event_notification_destination_request_body_prototype_model_json2 = test_destination_request_body_prototype_test_event_notification_destination_request_body_prototype_model.to_dict() - assert test_destination_request_body_prototype_test_event_notification_destination_request_body_prototype_model_json2 == test_destination_request_body_prototype_test_event_notification_destination_request_body_prototype_model_json + test_destination_request_body_prototype_test_event_notification_destination_request_body_prototype_model_json2 = ( + test_destination_request_body_prototype_test_event_notification_destination_request_body_prototype_model.to_dict() + ) + assert ( + test_destination_request_body_prototype_test_event_notification_destination_request_body_prototype_model_json2 + == test_destination_request_body_prototype_test_event_notification_destination_request_body_prototype_model_json + ) # endregion From 3c1d5cc96ebf71fa84440c512121719af3a1f527 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81kos=20Sztremi?= Date: Thu, 14 May 2026 08:17:07 +0200 Subject: [PATCH 5/8] fix (platform notifications): update detect secrets MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ákos Sztremi --- .secrets.baseline | 60 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 51 insertions(+), 9 deletions(-) diff --git a/.secrets.baseline b/.secrets.baseline index 9913ebe0..6a93eb5e 100644 --- a/.secrets.baseline +++ b/.secrets.baseline @@ -3,7 +3,7 @@ "files": "^.secrets.baseline$", "lines": null }, - "generated_at": "2025-10-30T10:03:11Z", + "generated_at": "2026-05-14T06:14:57Z", "plugins_used": [ { "name": "AWSKeyDetector" @@ -128,7 +128,7 @@ "hashed_secret": "469f62fa9e1c6afe62e8808180668934ee548e8f", "is_secret": false, "is_verified": false, - "line_number": 1874, + "line_number": 1885, "type": "Secret Keyword", "verified_result": null }, @@ -136,7 +136,7 @@ "hashed_secret": "a2190c299b60e882d9fb33736d5e6ab6ffe42708", "is_secret": false, "is_verified": false, - "line_number": 1964, + "line_number": 1975, "type": "Secret Keyword", "verified_result": null } @@ -174,7 +174,7 @@ "hashed_secret": "f0b0b291c4d22d76db59faaeb94802714dd6d884", "is_secret": false, "is_verified": false, - "line_number": 1000, + "line_number": 987, "type": "Hex High Entropy String", "verified_result": null }, @@ -182,7 +182,7 @@ "hashed_secret": "4c41e7a08e8895da0c6066adf33bf389c202b4e2", "is_secret": false, "is_verified": false, - "line_number": 1414, + "line_number": 1400, "type": "Hex High Entropy String", "verified_result": null }, @@ -190,7 +190,7 @@ "hashed_secret": "ca8b3e9d1445b3218e3512da63b05c8f26f181e5", "is_secret": false, "is_verified": false, - "line_number": 1423, + "line_number": 1409, "type": "Hex High Entropy String", "verified_result": null } @@ -278,7 +278,7 @@ "hashed_secret": "d4c3d66fd0c38547a3c7a4c6bdc29c36911bc030", "is_secret": false, "is_verified": false, - "line_number": 1969, + "line_number": 1985, "type": "Secret Keyword", "verified_result": null }, @@ -286,7 +286,7 @@ "hashed_secret": "b8473b86d4c2072ca9b08bd28e373e8253e865c4", "is_secret": false, "is_verified": false, - "line_number": 12008, + "line_number": 13036, "type": "Secret Keyword", "verified_result": null }, @@ -294,7 +294,7 @@ "hashed_secret": "469f62fa9e1c6afe62e8808180668934ee548e8f", "is_secret": false, "is_verified": false, - "line_number": 12086, + "line_number": 13114, "type": "Secret Keyword", "verified_result": null } @@ -309,6 +309,48 @@ "verified_result": null } ], + "test/unit/test_platform_notifications_v1.py": [ + { + "hashed_secret": "5ee95d2008b1f8c711bd529e56f8c0f5a0195c59", + "is_secret": false, + "is_verified": false, + "line_number": 232, + "type": "Base64 High Entropy String", + "verified_result": null + }, + { + "hashed_secret": "25aa406161de00c66d48556243a8674a9e9586fe", + "is_secret": false, + "is_verified": false, + "line_number": 1454, + "type": "Base64 High Entropy String", + "verified_result": null + }, + { + "hashed_secret": "ca15d23a2ccdee96d9e8e0ea5041e091d352266d", + "is_secret": false, + "is_verified": false, + "line_number": 1671, + "type": "Base64 High Entropy String", + "verified_result": null + }, + { + "hashed_secret": "5febf2fb64d0707173c6ff00a670175ea946da23", + "is_secret": false, + "is_verified": false, + "line_number": 1788, + "type": "Hex High Entropy String", + "verified_result": null + }, + { + "hashed_secret": "61bd9cf7208f6ac60767238bddf6275d8b5e0470", + "is_secret": false, + "is_verified": false, + "line_number": 2113, + "type": "Hex High Entropy String", + "verified_result": null + } + ], "test/unit/test_resource_controller_v2.py": [ { "hashed_secret": "0f97a4e707b7424540793cb2078919ee6770e07f", From dabb0c1d261c2526eaaad0431cf7c49a8baf05a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81kos=20Sztremi?= Date: Thu, 28 May 2026 14:55:03 +0200 Subject: [PATCH 6/8] test: fix missing global variables MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ákos Sztremi --- examples/test_platform_notifications_v1_examples.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/examples/test_platform_notifications_v1_examples.py b/examples/test_platform_notifications_v1_examples.py index fe853001..2ca5b9f1 100644 --- a/examples/test_platform_notifications_v1_examples.py +++ b/examples/test_platform_notifications_v1_examples.py @@ -41,6 +41,14 @@ config = None +account_id = None + +destination_id = None + +iam_id = None + +service_url = None + ############################################################################## # Start of Examples for Service: PlatformNotificationsV1 From 6edceee553f4225e926503f69f6e31e4d757be24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81kos=20Sztremi?= Date: Thu, 4 Jun 2026 14:17:38 +0200 Subject: [PATCH 7/8] fix: update acknowledgement endpoints MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ákos Sztremi --- ...test_platform_notifications_v1_examples.py | 144 +- .../platform_notifications_v1.py | 711 +++--- .../test_platform_notifications_v1.py | 153 +- test/unit/test_platform_notifications_v1.py | 1981 ++++++++--------- 4 files changed, 1487 insertions(+), 1502 deletions(-) diff --git a/examples/test_platform_notifications_v1_examples.py b/examples/test_platform_notifications_v1_examples.py index 2ca5b9f1..19d0d69a 100644 --- a/examples/test_platform_notifications_v1_examples.py +++ b/examples/test_platform_notifications_v1_examples.py @@ -90,6 +90,78 @@ def setup_class(cls): not os.path.exists(config_file), reason="External configuration not available, skipping..." ) + @needscredentials + def test_list_notifications_example(self): + """ + list_notifications request example + """ + try: + print('\nlist_notifications() result:') + + # begin-list_notifications + + all_results = [] + pager = NotificationsPager( + client=platform_notifications_service, + account_id=account_id, + limit=50, + ) + 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-list_notifications + except ApiException as e: + pytest.fail(str(e)) + + @needscredentials + def test_get_acknowledgement_example(self): + """ + get_acknowledgement request example + """ + try: + print('\nget_acknowledgement() result:') + + # begin-get_acknowledgement + + response = platform_notifications_service.get_acknowledgement( + account_id=account_id, + ) + acknowledgement = response.get_result() + + print(json.dumps(acknowledgement, indent=2)) + + # end-get_acknowledgement + + except ApiException as e: + pytest.fail(str(e)) + + @needscredentials + def test_replace_notification_acknowledgement_example(self): + """ + replace_notification_acknowledgement request example + """ + try: + print('\nreplace_notification_acknowledgement() result:') + + # begin-replace_notification_acknowledgement + + response = platform_notifications_service.replace_notification_acknowledgement( + last_acknowledged=1772804159452, + account_id=account_id, + ) + acknowledgement = response.get_result() + + print(json.dumps(acknowledgement, indent=2)) + + # end-replace_notification_acknowledgement + + except ApiException as e: + pytest.fail(str(e)) + @needscredentials def test_list_distribution_list_destinations_example(self): """ @@ -283,78 +355,6 @@ def test_replace_notification_preferences_example(self): except ApiException as e: pytest.fail(str(e)) - @needscredentials - def test_list_notifications_example(self): - """ - list_notifications request example - """ - try: - print('\nlist_notifications() result:') - - # begin-list_notifications - - all_results = [] - pager = NotificationsPager( - client=platform_notifications_service, - account_id=account_id, - limit=50, - ) - 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-list_notifications - except ApiException as e: - pytest.fail(str(e)) - - @needscredentials - def test_get_acknowledgement_example(self): - """ - get_acknowledgement request example - """ - try: - print('\nget_acknowledgement() result:') - - # begin-get_acknowledgement - - response = platform_notifications_service.get_acknowledgement( - account_id=account_id, - ) - acknowledgement = response.get_result() - - print(json.dumps(acknowledgement, indent=2)) - - # end-get_acknowledgement - - except ApiException as e: - pytest.fail(str(e)) - - @needscredentials - def test_replace_notification_acknowledgement_example(self): - """ - replace_notification_acknowledgement request example - """ - try: - print('\nreplace_notification_acknowledgement() result:') - - # begin-replace_notification_acknowledgement - - response = platform_notifications_service.replace_notification_acknowledgement( - last_acknowledged_id='1772804159452', - account_id=account_id, - ) - acknowledgement = response.get_result() - - print(json.dumps(acknowledgement, indent=2)) - - # end-replace_notification_acknowledgement - - except ApiException as e: - pytest.fail(str(e)) - @needscredentials def test_delete_distribution_list_destination_example(self): """ diff --git a/ibm_platform_services/platform_notifications_v1.py b/ibm_platform_services/platform_notifications_v1.py index 10f3ede0..9dccae2d 100644 --- a/ibm_platform_services/platform_notifications_v1.py +++ b/ibm_platform_services/platform_notifications_v1.py @@ -17,8 +17,11 @@ # IBM OpenAPI SDK Code Generator Version: 3.108.0-56772134-20251111-102802 """ -**This API is currently in beta and subject to change.** -API for managing notification distribution lists for IBM Cloud accounts. +API for IBM Cloud account notifications, providing capabilities to: +- View notifications +- Get and update acknowledgements +- Manage user communication preferences +- Manage notification distribution lists API Version: 1.0.0 """ @@ -74,7 +77,172 @@ def __init__( BaseService.__init__(self, service_url=self.DEFAULT_SERVICE_URL, authenticator=authenticator) ######################### - # Distribution Lists + # Notifications + ######################### + + def list_notifications( + self, + *, + account_id: Optional[str] = None, + start: Optional[str] = None, + limit: Optional[int] = None, + **kwargs, + ) -> DetailedResponse: + """ + Get user notifications. + + Retrieve all notifications for the requested user. + + :param str account_id: (optional) The IBM Cloud account ID. If not + provided, the account ID from the bearer token will be used. + :param str start: (optional) An opaque page token that specifies the + resource to start the page on or after. If unspecified, the first page of + results is returned. + :param int limit: (optional) The maximum number of items to return per + page. If unspecified, a default limit of 50 is used. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse with `dict` result representing a `NotificationCollection` object + """ + + headers = {} + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='list_notifications', + ) + headers.update(sdk_headers) + + params = { + 'account_id': account_id, + 'start': start, + 'limit': limit, + } + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + del kwargs['headers'] + headers['Accept'] = 'application/json' + + url = '/v1/notifications' + request = self.prepare_request( + method='GET', + url=url, + headers=headers, + params=params, + ) + + response = self.send(request, **kwargs) + return response + + def get_acknowledgement( + self, + *, + account_id: Optional[str] = None, + **kwargs, + ) -> DetailedResponse: + """ + Get acknowledgement. + + Retrieve the ID of the last notification acknowledged by the user for a specific + account. + + :param str account_id: (optional) The IBM Cloud account ID. If not + provided, the account ID from the bearer token will be used. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse with `dict` result representing a `Acknowledgement` object + """ + + headers = {} + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='get_acknowledgement', + ) + headers.update(sdk_headers) + + params = { + 'account_id': account_id, + } + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + del kwargs['headers'] + headers['Accept'] = 'application/json' + + url = '/v1/notifications/acknowledgement' + request = self.prepare_request( + method='GET', + url=url, + headers=headers, + params=params, + ) + + response = self.send(request, **kwargs) + return response + + def replace_notification_acknowledgement( + self, + last_acknowledged: int, + *, + account_id: Optional[str] = None, + **kwargs, + ) -> DetailedResponse: + """ + Update acknowledgement. + + Update the ID of the last notification acknowledged by the user for a specific + account. + + :param int last_acknowledged: The timestamp of the last acknowledgement. + :param str account_id: (optional) The IBM Cloud account ID. If not + provided, the account ID from the bearer token will be used. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse with `dict` result representing a `Acknowledgement` object + """ + + if last_acknowledged is None: + raise ValueError('last_acknowledged must be provided') + headers = {} + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='replace_notification_acknowledgement', + ) + headers.update(sdk_headers) + + params = { + 'account_id': account_id, + } + + data = { + 'last_acknowledged': last_acknowledged, + } + data = {k: v for (k, v) in data.items() if v is not None} + data = json.dumps(data) + headers['content-type'] = 'application/json' + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + del kwargs['headers'] + headers['Accept'] = 'application/json' + + url = '/v1/notifications/acknowledgement' + request = self.prepare_request( + method='PUT', + url=url, + headers=headers, + params=params, + data=data, + ) + + response = self.send(request, **kwargs) + return response + + ######################### + # distributionLists ######################### def list_distribution_list_destinations( @@ -235,7 +403,7 @@ def delete_distribution_list_destination( **kwargs, ) -> DetailedResponse: """ - Delete destination entry. + Delete a destination entry. Remove a destination entry. @@ -283,7 +451,7 @@ def test_distribution_list_destination( **kwargs, ) -> DetailedResponse: """ - Test destination entry. + Test a destination entry. Send a test notification to a destination in the distribution list. This allows you to verify that the destination is properly configured and can receive @@ -337,9 +505,63 @@ def test_distribution_list_destination( return response ######################### - # User Preferences + # userPreferences ######################### + def get_preferences( + self, + iam_id: str, + *, + account_id: Optional[str] = None, + **kwargs, + ) -> DetailedResponse: + """ + Get all communication preferences. + + Retrieve all communication preferences of a user in an account. + + :param str iam_id: The IAM ID of the user. Must match the IAM ID in the + bearer token. + :param str account_id: (optional) The IBM Cloud account ID. If not + provided, the account ID from the bearer token will be used. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse with `dict` result representing a `PreferencesObject` object + """ + + if not iam_id: + raise ValueError('iam_id must be provided') + headers = {} + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='get_preferences', + ) + headers.update(sdk_headers) + + params = { + 'account_id': account_id, + } + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + del kwargs['headers'] + headers['Accept'] = 'application/json' + + path_param_keys = ['iam_id'] + path_param_values = self.encode_path_vars(iam_id) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/v1/notifications/{iam_id}/preferences'.format(**path_param_dict) + request = self.prepare_request( + method='GET', + url=url, + headers=headers, + params=params, + ) + + response = self.send(request, **kwargs) + return response + def create_preferences( self, iam_id: str, @@ -551,60 +773,6 @@ def create_preferences( response = self.send(request, **kwargs) return response - def get_preferences( - self, - iam_id: str, - *, - account_id: Optional[str] = None, - **kwargs, - ) -> DetailedResponse: - """ - Get all communication preferences for a user in an account. - - Retrieve all communication preferences of a user in an account. - - :param str iam_id: The IAM ID of the user. Must match the IAM ID in the - bearer token. - :param str account_id: (optional) The IBM Cloud account ID. If not - provided, the account ID from the bearer token will be used. - :param dict headers: A `dict` containing the request headers - :return: A `DetailedResponse` containing the result, headers and HTTP status code. - :rtype: DetailedResponse with `dict` result representing a `PreferencesObject` object - """ - - if not iam_id: - raise ValueError('iam_id must be provided') - headers = {} - sdk_headers = get_sdk_headers( - service_name=self.DEFAULT_SERVICE_NAME, - service_version='V1', - operation_id='get_preferences', - ) - headers.update(sdk_headers) - - params = { - 'account_id': account_id, - } - - if 'headers' in kwargs: - headers.update(kwargs.get('headers')) - del kwargs['headers'] - headers['Accept'] = 'application/json' - - path_param_keys = ['iam_id'] - path_param_values = self.encode_path_vars(iam_id) - path_param_dict = dict(zip(path_param_keys, path_param_values)) - url = '/v1/notifications/{iam_id}/preferences'.format(**path_param_dict) - request = self.prepare_request( - method='GET', - url=url, - headers=headers, - params=params, - ) - - response = self.send(request, **kwargs) - return response - def replace_notification_preferences( self, iam_id: str, @@ -779,148 +947,89 @@ def replace_notification_preferences( 'security_normal': security_normal, 'account_normal': account_normal, 'billing_and_usage_order': billing_and_usage_order, - 'billing_and_usage_invoices': billing_and_usage_invoices, - 'billing_and_usage_payments': billing_and_usage_payments, - 'billing_and_usage_subscriptions_and_promo_codes': billing_and_usage_subscriptions_and_promo_codes, - 'billing_and_usage_spending_alerts': billing_and_usage_spending_alerts, - 'resourceactivity_normal': resourceactivity_normal, - 'ordering_review': ordering_review, - 'ordering_approved': ordering_approved, - 'ordering_approved_vsi': ordering_approved_vsi, - 'ordering_approved_server': ordering_approved_server, - 'provisioning_reload_complete': provisioning_reload_complete, - 'provisioning_complete_vsi': provisioning_complete_vsi, - 'provisioning_complete_server': provisioning_complete_server, - } - data = {k: v for (k, v) in data.items() if v is not None} - data = json.dumps(data) - headers['content-type'] = 'application/json' - - if 'headers' in kwargs: - headers.update(kwargs.get('headers')) - del kwargs['headers'] - headers['Accept'] = 'application/json' - - path_param_keys = ['iam_id'] - path_param_values = self.encode_path_vars(iam_id) - path_param_dict = dict(zip(path_param_keys, path_param_values)) - url = '/v1/notifications/{iam_id}/preferences'.format(**path_param_dict) - request = self.prepare_request( - method='PUT', - url=url, - headers=headers, - params=params, - data=data, - ) - - response = self.send(request, **kwargs) - return response - - def delete_notification_preferences( - self, - iam_id: str, - *, - account_id: Optional[str] = None, - **kwargs, - ) -> DetailedResponse: - """ - Resets all preferences to their default values. - - Delete all communication preferences for the specified account, and resets all - preferences to their default values. - - :param str iam_id: The IAM ID of the user. Must match the IAM ID in the - bearer token. - :param str account_id: (optional) The IBM Cloud account ID. If not - provided, the account ID from the bearer token will be used. - :param dict headers: A `dict` containing the request headers - :return: A `DetailedResponse` containing the result, headers and HTTP status code. - :rtype: DetailedResponse - """ - - if not iam_id: - raise ValueError('iam_id must be provided') - headers = {} - sdk_headers = get_sdk_headers( - service_name=self.DEFAULT_SERVICE_NAME, - service_version='V1', - operation_id='delete_notification_preferences', - ) - headers.update(sdk_headers) - - params = { - 'account_id': account_id, + 'billing_and_usage_invoices': billing_and_usage_invoices, + 'billing_and_usage_payments': billing_and_usage_payments, + 'billing_and_usage_subscriptions_and_promo_codes': billing_and_usage_subscriptions_and_promo_codes, + 'billing_and_usage_spending_alerts': billing_and_usage_spending_alerts, + 'resourceactivity_normal': resourceactivity_normal, + 'ordering_review': ordering_review, + 'ordering_approved': ordering_approved, + 'ordering_approved_vsi': ordering_approved_vsi, + 'ordering_approved_server': ordering_approved_server, + 'provisioning_reload_complete': provisioning_reload_complete, + 'provisioning_complete_vsi': provisioning_complete_vsi, + 'provisioning_complete_server': provisioning_complete_server, } + data = {k: v for (k, v) in data.items() if v is not None} + data = json.dumps(data) + headers['content-type'] = 'application/json' if 'headers' in kwargs: headers.update(kwargs.get('headers')) del kwargs['headers'] + headers['Accept'] = 'application/json' path_param_keys = ['iam_id'] path_param_values = self.encode_path_vars(iam_id) path_param_dict = dict(zip(path_param_keys, path_param_values)) url = '/v1/notifications/{iam_id}/preferences'.format(**path_param_dict) request = self.prepare_request( - method='DELETE', + method='PUT', url=url, headers=headers, params=params, + data=data, ) response = self.send(request, **kwargs) return response - ######################### - # Notifications - ######################### - - def list_notifications( + def delete_notification_preferences( self, + iam_id: str, *, account_id: Optional[str] = None, - start: Optional[str] = None, - limit: Optional[int] = None, **kwargs, ) -> DetailedResponse: """ - Get user notifications. + Reset all preferences to their default values. - Retrieve all notifications for the requested user. + Delete all communication preferences for the specified account, and reset all + preferences to their default values. + :param str iam_id: The IAM ID of the user. Must match the IAM ID in the + bearer token. :param str account_id: (optional) The IBM Cloud account ID. If not provided, the account ID from the bearer token will be used. - :param str start: (optional) An opaque page token that specifies the - resource to start the page on or after. If unspecified, the first page of - results is returned. - :param int limit: (optional) The maximum number of items to return per - page. If unspecified, a default limit of 50 is used. :param dict headers: A `dict` containing the request headers :return: A `DetailedResponse` containing the result, headers and HTTP status code. - :rtype: DetailedResponse with `dict` result representing a `NotificationCollection` object + :rtype: DetailedResponse """ + if not iam_id: + raise ValueError('iam_id must be provided') headers = {} sdk_headers = get_sdk_headers( service_name=self.DEFAULT_SERVICE_NAME, service_version='V1', - operation_id='list_notifications', + operation_id='delete_notification_preferences', ) headers.update(sdk_headers) params = { 'account_id': account_id, - 'start': start, - 'limit': limit, } if 'headers' in kwargs: headers.update(kwargs.get('headers')) del kwargs['headers'] - headers['Accept'] = 'application/json' - url = '/v1/notifications' + path_param_keys = ['iam_id'] + path_param_values = self.encode_path_vars(iam_id) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/v1/notifications/{iam_id}/preferences'.format(**path_param_dict) request = self.prepare_request( - method='GET', + method='DELETE', url=url, headers=headers, params=params, @@ -929,116 +1038,80 @@ def list_notifications( response = self.send(request, **kwargs) return response - def get_acknowledgement( - self, - *, - account_id: Optional[str] = None, - **kwargs, - ) -> DetailedResponse: - """ - Get user's last acknowledged notification Id. - - Retrieve the ID of the last notification acknowledged by the user for a specific - account. - - :param str account_id: (optional) The account ID to retrieve - acknowledgement for. - :param dict headers: A `dict` containing the request headers - :return: A `DetailedResponse` containing the result, headers and HTTP status code. - :rtype: DetailedResponse with `dict` result representing a `Acknowledgement` object - """ - - headers = {} - sdk_headers = get_sdk_headers( - service_name=self.DEFAULT_SERVICE_NAME, - service_version='V1', - operation_id='get_acknowledgement', - ) - headers.update(sdk_headers) - params = { - 'account_id': account_id, - } +############################################################################## +# Models +############################################################################## - if 'headers' in kwargs: - headers.update(kwargs.get('headers')) - del kwargs['headers'] - headers['Accept'] = 'application/json' - url = '/v1/notifications/acknowledgement' - request = self.prepare_request( - method='GET', - url=url, - headers=headers, - params=params, - ) +class Acknowledgement: + """ + Status indicating whether the user has unread notifications. - response = self.send(request, **kwargs) - return response + :param bool has_unread: Indicates whether the user has unread notifications. + :param int last_acknowledged: The timestamp of the last acknowledgement. + """ - def replace_notification_acknowledgement( + def __init__( self, - last_acknowledged_id: str, - *, - account_id: Optional[str] = None, - **kwargs, - ) -> DetailedResponse: + has_unread: bool, + last_acknowledged: int, + ) -> None: """ - Update user's last acknowledged notification. - - Update the ID of the last notification acknowledged by the user for a specific - account. + Initialize a Acknowledgement object. - :param str last_acknowledged_id: The ID of a notification. - :param str account_id: (optional) The account ID to update acknowledgement - for. - :param dict headers: A `dict` containing the request headers - :return: A `DetailedResponse` containing the result, headers and HTTP status code. - :rtype: DetailedResponse with `dict` result representing a `Acknowledgement` object + :param bool has_unread: Indicates whether the user has unread + notifications. + :param int last_acknowledged: The timestamp of the last acknowledgement. """ + self.has_unread = has_unread + self.last_acknowledged = last_acknowledged - if last_acknowledged_id is None: - raise ValueError('last_acknowledged_id must be provided') - headers = {} - sdk_headers = get_sdk_headers( - service_name=self.DEFAULT_SERVICE_NAME, - service_version='V1', - operation_id='replace_notification_acknowledgement', - ) - headers.update(sdk_headers) - - params = { - 'account_id': account_id, - } + @classmethod + def from_dict(cls, _dict: Dict) -> 'Acknowledgement': + """Initialize a Acknowledgement object from a json dictionary.""" + args = {} + if (has_unread := _dict.get('has_unread')) is not None: + args['has_unread'] = has_unread + else: + raise ValueError('Required property \'has_unread\' not present in Acknowledgement JSON') + if (last_acknowledged := _dict.get('last_acknowledged')) is not None: + args['last_acknowledged'] = last_acknowledged + else: + raise ValueError('Required property \'last_acknowledged\' not present in Acknowledgement JSON') + return cls(**args) - data = { - 'last_acknowledged_id': last_acknowledged_id, - } - data = {k: v for (k, v) in data.items() if v is not None} - data = json.dumps(data) - headers['content-type'] = 'application/json' + @classmethod + def _from_dict(cls, _dict): + """Initialize a Acknowledgement object from a json dictionary.""" + return cls.from_dict(_dict) - if 'headers' in kwargs: - headers.update(kwargs.get('headers')) - del kwargs['headers'] - headers['Accept'] = 'application/json' + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'has_unread') and self.has_unread is not None: + _dict['has_unread'] = self.has_unread + if hasattr(self, 'last_acknowledged') and self.last_acknowledged is not None: + _dict['last_acknowledged'] = self.last_acknowledged + return _dict - url = '/v1/notifications/acknowledgement' - request = self.prepare_request( - method='PUT', - url=url, - headers=headers, - params=params, - data=data, - ) + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() - response = self.send(request, **kwargs) - return response + def __str__(self) -> str: + """Return a `str` version of this Acknowledgement object.""" + return json.dumps(self.to_dict(), indent=2) + def __eq__(self, other: 'Acknowledgement') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ -############################################################################## -# Models -############################################################################## + def __ne__(self, other: 'Acknowledgement') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other class AddDestination: @@ -1218,21 +1291,21 @@ class Notification: :param str category: The category of the notification. :param List[str] component_names: Array of component/service names affected by this notification. - :param int start_time: The start time of the notification in Unix timestamp - (milliseconds). + :param int start_time: (optional) The start time of the notification in Unix + timestamp (seconds). :param bool is_global: Indicates if the notification is global. - :param str state: The current state of the notification. + :param str state: (optional) The current state of the notification. :param List[str] regions: Array of region identifiers affected by this notification. :param List[str] crn_masks: Array of CRN masks that define the scope of affected resources. :param str record_id: (optional) The record identifier for tracking purposes. :param str source_id: (optional) The source identifier of the notification. - :param str completion_code: The completion code of the notification. + :param str completion_code: (optional) The completion code of the notification. :param int end_time: (optional) The end time of the notification in Unix - timestamp (milliseconds). - :param int update_time: The last update time of the notification in Unix - timestamp (milliseconds). + timestamp (seconds). + :param int update_time: (optional) The last update time of the notification in + Unix timestamp (seconds). :param int severity: The severity level of the notification (0-3). The display value depends on the notification type: **Incidents:** @@ -1253,6 +1326,7 @@ class Notification: :param str resource_link: (optional) Link to additional resource information or documentation. Takes precedence over lucene_query when both are available. Mutually exclusive with lucene_query. + :param int creation_timestamp: The timestamp when the notification was created. """ def __init__( @@ -1262,18 +1336,19 @@ def __init__( id: str, category: str, component_names: List[str], - start_time: int, is_global: bool, - state: str, regions: List[str], crn_masks: List[str], - completion_code: str, - update_time: int, severity: int, + creation_timestamp: int, *, + start_time: Optional[int] = None, + state: Optional[str] = None, record_id: Optional[str] = None, source_id: Optional[str] = None, + completion_code: Optional[str] = None, end_time: Optional[int] = None, + update_time: Optional[int] = None, lucene_query: Optional[str] = None, resource_link: Optional[str] = None, ) -> None: @@ -1286,17 +1361,11 @@ def __init__( :param str category: The category of the notification. :param List[str] component_names: Array of component/service names affected by this notification. - :param int start_time: The start time of the notification in Unix timestamp - (milliseconds). :param bool is_global: Indicates if the notification is global. - :param str state: The current state of the notification. :param List[str] regions: Array of region identifiers affected by this notification. :param List[str] crn_masks: Array of CRN masks that define the scope of affected resources. - :param str completion_code: The completion code of the notification. - :param int update_time: The last update time of the notification in Unix - timestamp (milliseconds). :param int severity: The severity level of the notification (0-3). The display value depends on the notification type: **Incidents:** @@ -1311,11 +1380,20 @@ def __init__( **Announcements:** - 1 = Major - 0 = Minor. + :param int creation_timestamp: The timestamp when the notification was + created. + :param int start_time: (optional) The start time of the notification in + Unix timestamp (seconds). + :param str state: (optional) The current state of the notification. :param str record_id: (optional) The record identifier for tracking purposes. :param str source_id: (optional) The source identifier of the notification. + :param str completion_code: (optional) The completion code of the + notification. :param int end_time: (optional) The end time of the notification in Unix - timestamp (milliseconds). + timestamp (seconds). + :param int update_time: (optional) The last update time of the notification + in Unix timestamp (seconds). :param str lucene_query: (optional) Lucene query string for filtering affected resources. Only present when instance targets are specified and resource_link is not available. Mutually exclusive with resource_link. @@ -1341,6 +1419,7 @@ def __init__( self.severity = severity self.lucene_query = lucene_query self.resource_link = resource_link + self.creation_timestamp = creation_timestamp @classmethod def from_dict(cls, _dict: Dict) -> 'Notification': @@ -1368,16 +1447,12 @@ def from_dict(cls, _dict: Dict) -> 'Notification': raise ValueError('Required property \'component_names\' not present in Notification JSON') if (start_time := _dict.get('start_time')) is not None: args['start_time'] = start_time - else: - raise ValueError('Required property \'start_time\' not present in Notification JSON') if (is_global := _dict.get('is_global')) is not None: args['is_global'] = is_global else: raise ValueError('Required property \'is_global\' not present in Notification JSON') if (state := _dict.get('state')) is not None: args['state'] = state - else: - raise ValueError('Required property \'state\' not present in Notification JSON') if (regions := _dict.get('regions')) is not None: args['regions'] = regions else: @@ -1392,14 +1467,10 @@ def from_dict(cls, _dict: Dict) -> 'Notification': args['source_id'] = source_id if (completion_code := _dict.get('completion_code')) is not None: args['completion_code'] = completion_code - else: - raise ValueError('Required property \'completion_code\' not present in Notification JSON') if (end_time := _dict.get('end_time')) is not None: args['end_time'] = end_time if (update_time := _dict.get('update_time')) is not None: args['update_time'] = update_time - else: - raise ValueError('Required property \'update_time\' not present in Notification JSON') if (severity := _dict.get('severity')) is not None: args['severity'] = severity else: @@ -1408,6 +1479,10 @@ def from_dict(cls, _dict: Dict) -> 'Notification': args['lucene_query'] = lucene_query if (resource_link := _dict.get('resource_link')) is not None: args['resource_link'] = resource_link + if (creation_timestamp := _dict.get('creation_timestamp')) is not None: + args['creation_timestamp'] = creation_timestamp + else: + raise ValueError('Required property \'creation_timestamp\' not present in Notification JSON') return cls(**args) @classmethod @@ -1454,6 +1529,8 @@ def to_dict(self) -> Dict: _dict['lucene_query'] = self.lucene_query if hasattr(self, 'resource_link') and self.resource_link is not None: _dict['resource_link'] = self.resource_link + if hasattr(self, 'creation_timestamp') and self.creation_timestamp is not None: + _dict['creation_timestamp'] = self.creation_timestamp return _dict def _to_dict(self): @@ -1655,7 +1732,7 @@ class PaginationLink: """ A pagination link object containing the URL to a page. - :param str href: Complete URL to the page. + :param str href: The full URL path to the page. """ def __init__( @@ -1665,7 +1742,7 @@ def __init__( """ Initialize a PaginationLink object. - :param str href: Complete URL to the page. + :param str href: The full URL path to the page. """ self.href = href @@ -2423,90 +2500,6 @@ def __ne__(self, other: 'TestDestinationResponseBody') -> bool: return not self == other -class Acknowledgement: - """ - Status indicating whether the user has unread notifications. - - :param bool has_unread: Indicates whether the user has unread notifications. - :param str latest_notification_id: The ID of the most recent notification - available to the user. - :param str last_acknowledged_id: The ID of the last notification acknowledged by - the user. - """ - - def __init__( - self, - has_unread: bool, - latest_notification_id: str, - last_acknowledged_id: str, - ) -> None: - """ - Initialize a Acknowledgement object. - - :param bool has_unread: Indicates whether the user has unread - notifications. - :param str latest_notification_id: The ID of the most recent notification - available to the user. - :param str last_acknowledged_id: The ID of the last notification - acknowledged by the user. - """ - self.has_unread = has_unread - self.latest_notification_id = latest_notification_id - self.last_acknowledged_id = last_acknowledged_id - - @classmethod - def from_dict(cls, _dict: Dict) -> 'Acknowledgement': - """Initialize a Acknowledgement object from a json dictionary.""" - args = {} - if (has_unread := _dict.get('has_unread')) is not None: - args['has_unread'] = has_unread - else: - raise ValueError('Required property \'has_unread\' not present in Acknowledgement JSON') - if (latest_notification_id := _dict.get('latest_notification_id')) is not None: - args['latest_notification_id'] = latest_notification_id - else: - raise ValueError('Required property \'latest_notification_id\' not present in Acknowledgement JSON') - if (last_acknowledged_id := _dict.get('last_acknowledged_id')) is not None: - args['last_acknowledged_id'] = last_acknowledged_id - else: - raise ValueError('Required property \'last_acknowledged_id\' not present in Acknowledgement JSON') - return cls(**args) - - @classmethod - def _from_dict(cls, _dict): - """Initialize a Acknowledgement object from a json dictionary.""" - return cls.from_dict(_dict) - - def to_dict(self) -> Dict: - """Return a json dictionary representing this model.""" - _dict = {} - if hasattr(self, 'has_unread') and self.has_unread is not None: - _dict['has_unread'] = self.has_unread - if hasattr(self, 'latest_notification_id') and self.latest_notification_id is not None: - _dict['latest_notification_id'] = self.latest_notification_id - if hasattr(self, 'last_acknowledged_id') and self.last_acknowledged_id is not None: - _dict['last_acknowledged_id'] = self.last_acknowledged_id - return _dict - - def _to_dict(self): - """Return a json dictionary representing this model.""" - return self.to_dict() - - def __str__(self) -> str: - """Return a `str` version of this Acknowledgement object.""" - return json.dumps(self.to_dict(), indent=2) - - def __eq__(self, other: 'Acknowledgement') -> bool: - """Return `true` when self and other are equal, false otherwise.""" - if not isinstance(other, self.__class__): - return False - return self.__dict__ == other.__dict__ - - def __ne__(self, other: 'Acknowledgement') -> bool: - """Return `true` when self and other are not equal, false otherwise.""" - return not self == other - - class AddDestinationPrototypeEventNotificationDestinationPrototype(AddDestinationPrototype): """ Prototype for creating an Event Notifications destination entry. diff --git a/test/integration/test_platform_notifications_v1.py b/test/integration/test_platform_notifications_v1.py index 8b932bcc..d5f612bf 100644 --- a/test/integration/test_platform_notifications_v1.py +++ b/test/integration/test_platform_notifications_v1.py @@ -73,31 +73,73 @@ def setup_class(cls): ) @needscredentials - def test_test_distribution_list_destination(self): - # Construct a dict representation of a TestDestinationRequestBodyPrototypeTestEventNotificationDestinationRequestBodyPrototype model - test_destination_request_body_prototype_model = { - 'destination_type': 'event_notifications', - 'notification_type': 'incident', - } + def test_list_notifications(self): + response = self.platform_notifications_service.list_notifications( + account_id=account_id, + limit=50, + ) - response = self.platform_notifications_service.test_distribution_list_destination( + assert response.get_status_code() == 200 + notification_collection = response.get_result() + assert notification_collection is not None + + @needscredentials + def test_list_notifications_with_pager(self): + all_results = [] + + # Test get_next(). + pager = NotificationsPager( + client=self.platform_notifications_service, + account_id=account_id, + limit=50, + ) + while pager.has_next(): + next_page = pager.get_next() + assert next_page is not None + all_results.extend(next_page) + + # Test get_all(). + pager = NotificationsPager( + client=self.platform_notifications_service, + account_id=account_id, + limit=50, + ) + all_items = pager.get_all() + assert all_items is not None + + assert len(all_results) == len(all_items) + print(f'\nlist_notifications() returned a total of {len(all_results)} items(s) using NotificationsPager.') + + @needscredentials + def test_get_acknowledgement(self): + response = self.platform_notifications_service.get_acknowledgement( account_id=account_id, - destination_id=destination_id, - test_destination_request_body_prototype=test_destination_request_body_prototype_model, ) assert response.get_status_code() == 200 - test_destination_response_body = response.get_result() - assert test_destination_response_body is not None + acknowledgement = response.get_result() + assert acknowledgement is not None @needscredentials - def test_delete_distribution_list_destination(self): - response = self.platform_notifications_service.delete_distribution_list_destination( + def test_replace_notification_acknowledgement(self): + response = self.platform_notifications_service.replace_notification_acknowledgement( + last_acknowledged=1772804159452, account_id=account_id, - destination_id=destination_id, ) - assert response.get_status_code() == 204 + assert response.get_status_code() == 200 + acknowledgement = response.get_result() + assert acknowledgement is not None + + @needscredentials + def test_list_distribution_list_destinations(self): + response = self.platform_notifications_service.list_distribution_list_destinations( + account_id=account_id, + ) + + assert response.get_status_code() == 200 + add_destination_collection = response.get_result() + assert add_destination_collection is not None @needscredentials def test_create_distribution_list_destination(self): @@ -117,25 +159,33 @@ def test_create_distribution_list_destination(self): assert add_destination is not None @needscredentials - def test_list_distribution_list_destinations(self): - response = self.platform_notifications_service.list_distribution_list_destinations( + def test_get_distribution_list_destination(self): + response = self.platform_notifications_service.get_distribution_list_destination( account_id=account_id, + destination_id=destination_id, ) assert response.get_status_code() == 200 - add_destination_collection = response.get_result() - assert add_destination_collection is not None + add_destination = response.get_result() + assert add_destination is not None @needscredentials - def test_get_distribution_list_destination(self): - response = self.platform_notifications_service.get_distribution_list_destination( + def test_test_distribution_list_destination(self): + # Construct a dict representation of a TestDestinationRequestBodyPrototypeTestEventNotificationDestinationRequestBodyPrototype model + test_destination_request_body_prototype_model = { + 'destination_type': 'event_notifications', + 'notification_type': 'incident', + } + + response = self.platform_notifications_service.test_distribution_list_destination( account_id=account_id, destination_id=destination_id, + test_destination_request_body_prototype=test_destination_request_body_prototype_model, ) assert response.get_status_code() == 200 - add_destination = response.get_result() - assert add_destination is not None + test_destination_response_body = response.get_result() + assert test_destination_response_body is not None @needscredentials def test_create_preferences(self): @@ -239,62 +289,13 @@ def test_replace_notification_preferences(self): assert preferences_object is not None @needscredentials - def test_list_notifications(self): - response = self.platform_notifications_service.list_notifications( - account_id=account_id, - ) - - assert response.get_status_code() == 200 - notification_collection = response.get_result() - assert notification_collection is not None - - @needscredentials - def test_list_notifications_with_pager(self): - all_results = [] - - # Test get_next(). - pager = NotificationsPager( - client=self.platform_notifications_service, - account_id=account_id, - limit=50, - ) - while pager.has_next(): - next_page = pager.get_next() - assert next_page is not None - all_results.extend(next_page) - - # Test get_all(). - pager = NotificationsPager( - client=self.platform_notifications_service, - account_id=account_id, - limit=50, - ) - all_items = pager.get_all() - assert all_items is not None - - assert len(all_results) == len(all_items) - print(f'\nlist_notifications() returned a total of {len(all_results)} items(s) using NotificationsPager.') - - @needscredentials - def test_get_acknowledgement(self): - response = self.platform_notifications_service.get_acknowledgement( - account_id=account_id, - ) - - assert response.get_status_code() == 200 - acknowledgement = response.get_result() - assert acknowledgement is not None - - @needscredentials - def test_replace_notification_acknowledgement(self): - response = self.platform_notifications_service.replace_notification_acknowledgement( - last_acknowledged_id='1772804159452', + def test_delete_distribution_list_destination(self): + response = self.platform_notifications_service.delete_distribution_list_destination( account_id=account_id, + destination_id=destination_id, ) - assert response.get_status_code() == 200 - acknowledgement = response.get_result() - assert acknowledgement is not None + assert response.get_status_code() == 204 @needscredentials def test_delete_notification_preferences(self): diff --git a/test/unit/test_platform_notifications_v1.py b/test/unit/test_platform_notifications_v1.py index 48bd03dd..c3866769 100644 --- a/test/unit/test_platform_notifications_v1.py +++ b/test/unit/test_platform_notifications_v1.py @@ -54,7 +54,7 @@ def preprocess_url(operation_path: str): ############################################################################## -# Start of Service: DistributionLists +# Start of Service: Notifications ############################################################################## # region @@ -87,19 +87,19 @@ def test_new_instance_without_authenticator(self): ) -class TestListDistributionListDestinations: +class TestListNotifications: """ - Test Class for list_distribution_list_destinations + Test Class for list_notifications """ @responses.activate - def test_list_distribution_list_destinations_all_params(self): + def test_list_notifications_all_params(self): """ - list_distribution_list_destinations() + list_notifications() """ # Set up mock - url = preprocess_url('/v1/distribution_lists/a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6/destinations') - mock_response = '{"destinations": [{"destination_id": "12345678-1234-1234-1234-123456789012", "destination_type": "event_notifications"}]}' + url = preprocess_url('/v1/notifications') + mock_response = '{"limit": 50, "total_count": 232, "first": {"href": "https://notifications.cloud.ibm.com/api/v1/notifications?limit=50"}, "previous": {"href": "https://notifications.cloud.ibm.com/api/v1/notifications?start=3fe78a36b9aa7f26&limit=50", "start": "3fe78a36b9aa7f26"}, "next": {"href": "https://notifications.cloud.ibm.com/api/v1/notifications?start=3fe78a36b9aa7f26&limit=50", "start": "3fe78a36b9aa7f26"}, "last": {"href": "https://notifications.cloud.ibm.com/api/v1/notifications?start=3fe78a36b9aa7f26&limit=50", "start": "3fe78a36b9aa7f26"}, "notifications": [{"title": "System Maintenance Scheduled", "body": "Scheduled maintenance will occur on March 15th from 10:00 AM to 11:00 AM UTC.", "id": "12345", "category": "maintenance", "component_names": ["component_names"], "start_time": 1771791490, "is_global": false, "state": "new", "regions": ["regions"], "crn_masks": ["crn_masks"], "record_id": "rec-67890", "source_id": "src-11111", "completion_code": "successful", "end_time": 1771791490, "update_time": 1771791490, "severity": 2, "lucene_query": "region:us-south AND service_name:event-notifications", "resource_link": "https://cloud.ibm.com/status/incident/12345", "creation_timestamp": 1772804159452}]}' responses.add( responses.GET, url, @@ -110,34 +110,44 @@ def test_list_distribution_list_destinations_all_params(self): # Set up parameter values account_id = 'a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6' + start = '3fe78a36b9aa7f26' + limit = 50 # Invoke method - response = _service.list_distribution_list_destinations( - account_id, + response = _service.list_notifications( + account_id=account_id, + start=start, + limit=limit, headers={}, ) # Check for correct operation assert len(responses.calls) == 1 assert response.status_code == 200 + # Validate query params + query_string = responses.calls[0].request.url.split('?', 1)[1] + query_string = urllib.parse.unquote_plus(query_string) + assert 'account_id={}'.format(account_id) in query_string + assert 'start={}'.format(start) in query_string + assert 'limit={}'.format(limit) in query_string - def test_list_distribution_list_destinations_all_params_with_retries(self): - # Enable retries and run test_list_distribution_list_destinations_all_params. + def test_list_notifications_all_params_with_retries(self): + # Enable retries and run test_list_notifications_all_params. _service.enable_retries() - self.test_list_distribution_list_destinations_all_params() + self.test_list_notifications_all_params() - # Disable retries and run test_list_distribution_list_destinations_all_params. + # Disable retries and run test_list_notifications_all_params. _service.disable_retries() - self.test_list_distribution_list_destinations_all_params() + self.test_list_notifications_all_params() @responses.activate - def test_list_distribution_list_destinations_value_error(self): + def test_list_notifications_required_params(self): """ - test_list_distribution_list_destinations_value_error() + test_list_notifications_required_params() """ # Set up mock - url = preprocess_url('/v1/distribution_lists/a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6/destinations') - mock_response = '{"destinations": [{"destination_id": "12345678-1234-1234-1234-123456789012", "destination_type": "event_notifications"}]}' + url = preprocess_url('/v1/notifications') + mock_response = '{"limit": 50, "total_count": 232, "first": {"href": "https://notifications.cloud.ibm.com/api/v1/notifications?limit=50"}, "previous": {"href": "https://notifications.cloud.ibm.com/api/v1/notifications?start=3fe78a36b9aa7f26&limit=50", "start": "3fe78a36b9aa7f26"}, "next": {"href": "https://notifications.cloud.ibm.com/api/v1/notifications?start=3fe78a36b9aa7f26&limit=50", "start": "3fe78a36b9aa7f26"}, "last": {"href": "https://notifications.cloud.ibm.com/api/v1/notifications?start=3fe78a36b9aa7f26&limit=50", "start": "3fe78a36b9aa7f26"}, "notifications": [{"title": "System Maintenance Scheduled", "body": "Scheduled maintenance will occur on March 15th from 10:00 AM to 11:00 AM UTC.", "id": "12345", "category": "maintenance", "component_names": ["component_names"], "start_time": 1771791490, "is_global": false, "state": "new", "regions": ["regions"], "crn_masks": ["crn_masks"], "record_id": "rec-67890", "source_id": "src-11111", "completion_code": "successful", "end_time": 1771791490, "update_time": 1771791490, "severity": 2, "lucene_query": "region:us-south AND service_name:event-notifications", "resource_link": "https://cloud.ibm.com/status/incident/12345", "creation_timestamp": 1772804159452}]}' responses.add( responses.GET, url, @@ -146,149 +156,189 @@ def test_list_distribution_list_destinations_value_error(self): status=200, ) - # Set up parameter values - account_id = 'a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6' + # Invoke method + response = _service.list_notifications() - # Pass in all but one required param and check for a ValueError - req_param_dict = { - "account_id": account_id, - } - for param in req_param_dict.keys(): - req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} - with pytest.raises(ValueError): - _service.list_distribution_list_destinations(**req_copy) + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 - def test_list_distribution_list_destinations_value_error_with_retries(self): - # Enable retries and run test_list_distribution_list_destinations_value_error. + def test_list_notifications_required_params_with_retries(self): + # Enable retries and run test_list_notifications_required_params. _service.enable_retries() - self.test_list_distribution_list_destinations_value_error() + self.test_list_notifications_required_params() - # Disable retries and run test_list_distribution_list_destinations_value_error. + # Disable retries and run test_list_notifications_required_params. _service.disable_retries() - self.test_list_distribution_list_destinations_value_error() + self.test_list_notifications_required_params() + @responses.activate + def test_list_notifications_with_pager_get_next(self): + """ + test_list_notifications_with_pager_get_next() + """ + # Set up a two-page mock response + url = preprocess_url('/v1/notifications') + mock_response1 = '{"next":{"start":"1"},"total_count":2,"limit":1,"notifications":[{"title":"System Maintenance Scheduled","body":"Scheduled maintenance will occur on March 15th from 10:00 AM to 11:00 AM UTC.","id":"12345","category":"maintenance","component_names":["component_names"],"start_time":1771791490,"is_global":false,"state":"new","regions":["regions"],"crn_masks":["crn_masks"],"record_id":"rec-67890","source_id":"src-11111","completion_code":"successful","end_time":1771791490,"update_time":1771791490,"severity":2,"lucene_query":"region:us-south AND service_name:event-notifications","resource_link":"https://cloud.ibm.com/status/incident/12345","creation_timestamp":1772804159452}]}' + mock_response2 = '{"total_count":2,"limit":1,"notifications":[{"title":"System Maintenance Scheduled","body":"Scheduled maintenance will occur on March 15th from 10:00 AM to 11:00 AM UTC.","id":"12345","category":"maintenance","component_names":["component_names"],"start_time":1771791490,"is_global":false,"state":"new","regions":["regions"],"crn_masks":["crn_masks"],"record_id":"rec-67890","source_id":"src-11111","completion_code":"successful","end_time":1771791490,"update_time":1771791490,"severity":2,"lucene_query":"region:us-south AND service_name:event-notifications","resource_link":"https://cloud.ibm.com/status/incident/12345","creation_timestamp":1772804159452}]}' + responses.add( + responses.GET, + url, + body=mock_response1, + content_type='application/json', + status=200, + ) + responses.add( + responses.GET, + url, + body=mock_response2, + content_type='application/json', + status=200, + ) -class TestCreateDistributionListDestination: + # Exercise the pager class for this operation + all_results = [] + pager = NotificationsPager( + client=_service, + account_id='a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6', + limit=50, + ) + while pager.has_next(): + next_page = pager.get_next() + assert next_page is not None + all_results.extend(next_page) + assert len(all_results) == 2 + + @responses.activate + def test_list_notifications_with_pager_get_all(self): + """ + test_list_notifications_with_pager_get_all() + """ + # Set up a two-page mock response + url = preprocess_url('/v1/notifications') + mock_response1 = '{"next":{"start":"1"},"total_count":2,"limit":1,"notifications":[{"title":"System Maintenance Scheduled","body":"Scheduled maintenance will occur on March 15th from 10:00 AM to 11:00 AM UTC.","id":"12345","category":"maintenance","component_names":["component_names"],"start_time":1771791490,"is_global":false,"state":"new","regions":["regions"],"crn_masks":["crn_masks"],"record_id":"rec-67890","source_id":"src-11111","completion_code":"successful","end_time":1771791490,"update_time":1771791490,"severity":2,"lucene_query":"region:us-south AND service_name:event-notifications","resource_link":"https://cloud.ibm.com/status/incident/12345","creation_timestamp":1772804159452}]}' + mock_response2 = '{"total_count":2,"limit":1,"notifications":[{"title":"System Maintenance Scheduled","body":"Scheduled maintenance will occur on March 15th from 10:00 AM to 11:00 AM UTC.","id":"12345","category":"maintenance","component_names":["component_names"],"start_time":1771791490,"is_global":false,"state":"new","regions":["regions"],"crn_masks":["crn_masks"],"record_id":"rec-67890","source_id":"src-11111","completion_code":"successful","end_time":1771791490,"update_time":1771791490,"severity":2,"lucene_query":"region:us-south AND service_name:event-notifications","resource_link":"https://cloud.ibm.com/status/incident/12345","creation_timestamp":1772804159452}]}' + responses.add( + responses.GET, + url, + body=mock_response1, + content_type='application/json', + status=200, + ) + responses.add( + responses.GET, + url, + body=mock_response2, + content_type='application/json', + status=200, + ) + + # Exercise the pager class for this operation + pager = NotificationsPager( + client=_service, + account_id='a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6', + limit=50, + ) + all_results = pager.get_all() + assert all_results is not None + assert len(all_results) == 2 + + +class TestGetAcknowledgement: """ - Test Class for create_distribution_list_destination + Test Class for get_acknowledgement """ @responses.activate - def test_create_distribution_list_destination_all_params(self): + def test_get_acknowledgement_all_params(self): """ - create_distribution_list_destination() + get_acknowledgement() """ # Set up mock - url = preprocess_url('/v1/distribution_lists/a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6/destinations') - mock_response = ( - '{"destination_id": "12345678-1234-1234-1234-123456789012", "destination_type": "event_notifications"}' - ) + url = preprocess_url('/v1/notifications/acknowledgement') + mock_response = '{"has_unread": true, "last_acknowledged": 1772804159452}' responses.add( - responses.POST, + responses.GET, url, body=mock_response, content_type='application/json', - status=201, + status=200, ) - # Construct a dict representation of a AddDestinationPrototypeEventNotificationDestinationPrototype model - add_destination_prototype_model = {} - add_destination_prototype_model['destination_id'] = '12345678-1234-1234-1234-123456789012' - add_destination_prototype_model['destination_type'] = 'event_notifications' - # Set up parameter values account_id = 'a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6' - add_destination_prototype = add_destination_prototype_model # Invoke method - response = _service.create_distribution_list_destination( - account_id, - add_destination_prototype, + response = _service.get_acknowledgement( + account_id=account_id, headers={}, ) # Check for correct operation assert len(responses.calls) == 1 - assert response.status_code == 201 - # Validate body params - req_body = json.loads(str(responses.calls[0].request.body, 'utf-8')) - assert req_body == add_destination_prototype + assert response.status_code == 200 + # Validate query params + query_string = responses.calls[0].request.url.split('?', 1)[1] + query_string = urllib.parse.unquote_plus(query_string) + assert 'account_id={}'.format(account_id) in query_string - def test_create_distribution_list_destination_all_params_with_retries(self): - # Enable retries and run test_create_distribution_list_destination_all_params. + def test_get_acknowledgement_all_params_with_retries(self): + # Enable retries and run test_get_acknowledgement_all_params. _service.enable_retries() - self.test_create_distribution_list_destination_all_params() + self.test_get_acknowledgement_all_params() - # Disable retries and run test_create_distribution_list_destination_all_params. + # Disable retries and run test_get_acknowledgement_all_params. _service.disable_retries() - self.test_create_distribution_list_destination_all_params() + self.test_get_acknowledgement_all_params() @responses.activate - def test_create_distribution_list_destination_value_error(self): + def test_get_acknowledgement_required_params(self): """ - test_create_distribution_list_destination_value_error() + test_get_acknowledgement_required_params() """ # Set up mock - url = preprocess_url('/v1/distribution_lists/a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6/destinations') - mock_response = ( - '{"destination_id": "12345678-1234-1234-1234-123456789012", "destination_type": "event_notifications"}' - ) + url = preprocess_url('/v1/notifications/acknowledgement') + mock_response = '{"has_unread": true, "last_acknowledged": 1772804159452}' responses.add( - responses.POST, + responses.GET, url, body=mock_response, content_type='application/json', - status=201, + status=200, ) - # Construct a dict representation of a AddDestinationPrototypeEventNotificationDestinationPrototype model - add_destination_prototype_model = {} - add_destination_prototype_model['destination_id'] = '12345678-1234-1234-1234-123456789012' - add_destination_prototype_model['destination_type'] = 'event_notifications' - - # Set up parameter values - account_id = 'a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6' - add_destination_prototype = add_destination_prototype_model + # Invoke method + response = _service.get_acknowledgement() - # Pass in all but one required param and check for a ValueError - req_param_dict = { - "account_id": account_id, - "add_destination_prototype": add_destination_prototype, - } - for param in req_param_dict.keys(): - req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} - with pytest.raises(ValueError): - _service.create_distribution_list_destination(**req_copy) + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 - def test_create_distribution_list_destination_value_error_with_retries(self): - # Enable retries and run test_create_distribution_list_destination_value_error. + def test_get_acknowledgement_required_params_with_retries(self): + # Enable retries and run test_get_acknowledgement_required_params. _service.enable_retries() - self.test_create_distribution_list_destination_value_error() + self.test_get_acknowledgement_required_params() - # Disable retries and run test_create_distribution_list_destination_value_error. + # Disable retries and run test_get_acknowledgement_required_params. _service.disable_retries() - self.test_create_distribution_list_destination_value_error() + self.test_get_acknowledgement_required_params() -class TestGetDistributionListDestination: +class TestReplaceNotificationAcknowledgement: """ - Test Class for get_distribution_list_destination + Test Class for replace_notification_acknowledgement """ @responses.activate - def test_get_distribution_list_destination_all_params(self): + def test_replace_notification_acknowledgement_all_params(self): """ - get_distribution_list_destination() + replace_notification_acknowledgement() """ # Set up mock - url = preprocess_url( - '/v1/distribution_lists/a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6/destinations/12345678-1234-1234-1234-123456789012' - ) - mock_response = ( - '{"destination_id": "12345678-1234-1234-1234-123456789012", "destination_type": "event_notifications"}' - ) + url = preprocess_url('/v1/notifications/acknowledgement') + mock_response = '{"has_unread": true, "last_acknowledged": 1772804159452}' responses.add( - responses.GET, + responses.PUT, url, body=mock_response, content_type='application/json', @@ -296,43 +346,87 @@ def test_get_distribution_list_destination_all_params(self): ) # Set up parameter values + last_acknowledged = 1772804159452 account_id = 'a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6' - destination_id = '12345678-1234-1234-1234-123456789012' # Invoke method - response = _service.get_distribution_list_destination( - account_id, - destination_id, + response = _service.replace_notification_acknowledgement( + last_acknowledged, + account_id=account_id, headers={}, ) # Check for correct operation assert len(responses.calls) == 1 assert response.status_code == 200 + # Validate query params + query_string = responses.calls[0].request.url.split('?', 1)[1] + query_string = urllib.parse.unquote_plus(query_string) + assert 'account_id={}'.format(account_id) in query_string + # Validate body params + req_body = json.loads(str(responses.calls[0].request.body, 'utf-8')) + assert req_body['last_acknowledged'] == 1772804159452 - def test_get_distribution_list_destination_all_params_with_retries(self): - # Enable retries and run test_get_distribution_list_destination_all_params. - _service.enable_retries() - self.test_get_distribution_list_destination_all_params() - - # Disable retries and run test_get_distribution_list_destination_all_params. + def test_replace_notification_acknowledgement_all_params_with_retries(self): + # Enable retries and run test_replace_notification_acknowledgement_all_params. + _service.enable_retries() + self.test_replace_notification_acknowledgement_all_params() + + # Disable retries and run test_replace_notification_acknowledgement_all_params. _service.disable_retries() - self.test_get_distribution_list_destination_all_params() + self.test_replace_notification_acknowledgement_all_params() @responses.activate - def test_get_distribution_list_destination_value_error(self): + def test_replace_notification_acknowledgement_required_params(self): """ - test_get_distribution_list_destination_value_error() + test_replace_notification_acknowledgement_required_params() """ # Set up mock - url = preprocess_url( - '/v1/distribution_lists/a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6/destinations/12345678-1234-1234-1234-123456789012' + url = preprocess_url('/v1/notifications/acknowledgement') + mock_response = '{"has_unread": true, "last_acknowledged": 1772804159452}' + responses.add( + responses.PUT, + url, + body=mock_response, + content_type='application/json', + status=200, ) - mock_response = ( - '{"destination_id": "12345678-1234-1234-1234-123456789012", "destination_type": "event_notifications"}' + + # Set up parameter values + last_acknowledged = 1772804159452 + + # Invoke method + response = _service.replace_notification_acknowledgement( + last_acknowledged, + headers={}, ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + # Validate body params + req_body = json.loads(str(responses.calls[0].request.body, 'utf-8')) + assert req_body['last_acknowledged'] == 1772804159452 + + def test_replace_notification_acknowledgement_required_params_with_retries(self): + # Enable retries and run test_replace_notification_acknowledgement_required_params. + _service.enable_retries() + self.test_replace_notification_acknowledgement_required_params() + + # Disable retries and run test_replace_notification_acknowledgement_required_params. + _service.disable_retries() + self.test_replace_notification_acknowledgement_required_params() + + @responses.activate + def test_replace_notification_acknowledgement_value_error(self): + """ + test_replace_notification_acknowledgement_value_error() + """ + # Set up mock + url = preprocess_url('/v1/notifications/acknowledgement') + mock_response = '{"has_unread": true, "last_acknowledged": 1772804159452}' responses.add( - responses.GET, + responses.PUT, url, body=mock_response, content_type='application/json', @@ -340,656 +434,645 @@ def test_get_distribution_list_destination_value_error(self): ) # Set up parameter values - account_id = 'a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6' - destination_id = '12345678-1234-1234-1234-123456789012' + last_acknowledged = 1772804159452 # Pass in all but one required param and check for a ValueError req_param_dict = { - "account_id": account_id, - "destination_id": destination_id, + "last_acknowledged": last_acknowledged, } for param in req_param_dict.keys(): req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} with pytest.raises(ValueError): - _service.get_distribution_list_destination(**req_copy) + _service.replace_notification_acknowledgement(**req_copy) - def test_get_distribution_list_destination_value_error_with_retries(self): - # Enable retries and run test_get_distribution_list_destination_value_error. + def test_replace_notification_acknowledgement_value_error_with_retries(self): + # Enable retries and run test_replace_notification_acknowledgement_value_error. _service.enable_retries() - self.test_get_distribution_list_destination_value_error() + self.test_replace_notification_acknowledgement_value_error() - # Disable retries and run test_get_distribution_list_destination_value_error. + # Disable retries and run test_replace_notification_acknowledgement_value_error. _service.disable_retries() - self.test_get_distribution_list_destination_value_error() + self.test_replace_notification_acknowledgement_value_error() -class TestDeleteDistributionListDestination: +# endregion +############################################################################## +# End of Service: Notifications +############################################################################## + +############################################################################## +# Start of Service: DistributionLists +############################################################################## +# region + + +class TestNewInstance: """ - Test Class for delete_distribution_list_destination + Test Class for new_instance + """ + + def test_new_instance(self): + """ + new_instance() + """ + os.environ['TEST_SERVICE_AUTH_TYPE'] = 'noAuth' + + service = PlatformNotificationsV1.new_instance( + service_name='TEST_SERVICE', + ) + + assert service is not None + assert isinstance(service, PlatformNotificationsV1) + + def test_new_instance_without_authenticator(self): + """ + new_instance_without_authenticator() + """ + with pytest.raises(ValueError, match='authenticator must be provided'): + service = PlatformNotificationsV1.new_instance( + service_name='TEST_SERVICE_NOT_FOUND', + ) + + +class TestListDistributionListDestinations: + """ + Test Class for list_distribution_list_destinations """ @responses.activate - def test_delete_distribution_list_destination_all_params(self): + def test_list_distribution_list_destinations_all_params(self): """ - delete_distribution_list_destination() + list_distribution_list_destinations() """ # Set up mock - url = preprocess_url( - '/v1/distribution_lists/a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6/destinations/12345678-1234-1234-1234-123456789012' - ) + url = preprocess_url('/v1/distribution_lists/a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6/destinations') + mock_response = '{"destinations": [{"destination_id": "12345678-1234-1234-1234-123456789012", "destination_type": "event_notifications"}]}' responses.add( - responses.DELETE, + responses.GET, url, - status=204, + body=mock_response, + content_type='application/json', + status=200, ) # Set up parameter values account_id = 'a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6' - destination_id = '12345678-1234-1234-1234-123456789012' # Invoke method - response = _service.delete_distribution_list_destination( + response = _service.list_distribution_list_destinations( account_id, - destination_id, headers={}, ) # Check for correct operation assert len(responses.calls) == 1 - assert response.status_code == 204 + assert response.status_code == 200 - def test_delete_distribution_list_destination_all_params_with_retries(self): - # Enable retries and run test_delete_distribution_list_destination_all_params. + def test_list_distribution_list_destinations_all_params_with_retries(self): + # Enable retries and run test_list_distribution_list_destinations_all_params. _service.enable_retries() - self.test_delete_distribution_list_destination_all_params() + self.test_list_distribution_list_destinations_all_params() - # Disable retries and run test_delete_distribution_list_destination_all_params. + # Disable retries and run test_list_distribution_list_destinations_all_params. _service.disable_retries() - self.test_delete_distribution_list_destination_all_params() + self.test_list_distribution_list_destinations_all_params() @responses.activate - def test_delete_distribution_list_destination_value_error(self): + def test_list_distribution_list_destinations_value_error(self): """ - test_delete_distribution_list_destination_value_error() + test_list_distribution_list_destinations_value_error() """ # Set up mock - url = preprocess_url( - '/v1/distribution_lists/a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6/destinations/12345678-1234-1234-1234-123456789012' - ) + url = preprocess_url('/v1/distribution_lists/a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6/destinations') + mock_response = '{"destinations": [{"destination_id": "12345678-1234-1234-1234-123456789012", "destination_type": "event_notifications"}]}' responses.add( - responses.DELETE, + responses.GET, url, - status=204, + body=mock_response, + content_type='application/json', + status=200, ) # Set up parameter values account_id = 'a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6' - destination_id = '12345678-1234-1234-1234-123456789012' # Pass in all but one required param and check for a ValueError req_param_dict = { "account_id": account_id, - "destination_id": destination_id, } for param in req_param_dict.keys(): req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} with pytest.raises(ValueError): - _service.delete_distribution_list_destination(**req_copy) + _service.list_distribution_list_destinations(**req_copy) - def test_delete_distribution_list_destination_value_error_with_retries(self): - # Enable retries and run test_delete_distribution_list_destination_value_error. + def test_list_distribution_list_destinations_value_error_with_retries(self): + # Enable retries and run test_list_distribution_list_destinations_value_error. _service.enable_retries() - self.test_delete_distribution_list_destination_value_error() + self.test_list_distribution_list_destinations_value_error() - # Disable retries and run test_delete_distribution_list_destination_value_error. + # Disable retries and run test_list_distribution_list_destinations_value_error. _service.disable_retries() - self.test_delete_distribution_list_destination_value_error() + self.test_list_distribution_list_destinations_value_error() -class TestTestDistributionListDestination: +class TestCreateDistributionListDestination: """ - Test Class for test_distribution_list_destination + Test Class for create_distribution_list_destination """ @responses.activate - def test_test_distribution_list_destination_all_params(self): + def test_create_distribution_list_destination_all_params(self): """ - test_distribution_list_destination() + create_distribution_list_destination() """ # Set up mock - url = preprocess_url( - '/v1/distribution_lists/a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6/destinations/12345678-1234-1234-1234-123456789012/test' + url = preprocess_url('/v1/distribution_lists/a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6/destinations') + mock_response = ( + '{"destination_id": "12345678-1234-1234-1234-123456789012", "destination_type": "event_notifications"}' ) - mock_response = '{"message": "success"}' responses.add( responses.POST, url, body=mock_response, content_type='application/json', - status=200, + status=201, ) - # Construct a dict representation of a TestDestinationRequestBodyPrototypeTestEventNotificationDestinationRequestBodyPrototype model - test_destination_request_body_prototype_model = {} - test_destination_request_body_prototype_model['destination_type'] = 'event_notifications' - test_destination_request_body_prototype_model['notification_type'] = 'incident' + # Construct a dict representation of a AddDestinationPrototypeEventNotificationDestinationPrototype model + add_destination_prototype_model = {} + add_destination_prototype_model['destination_id'] = '12345678-1234-1234-1234-123456789012' + add_destination_prototype_model['destination_type'] = 'event_notifications' # Set up parameter values account_id = 'a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6' - destination_id = '12345678-1234-1234-1234-123456789012' - test_destination_request_body_prototype = test_destination_request_body_prototype_model + add_destination_prototype = add_destination_prototype_model # Invoke method - response = _service.test_distribution_list_destination( + response = _service.create_distribution_list_destination( account_id, - destination_id, - test_destination_request_body_prototype, + add_destination_prototype, headers={}, ) # Check for correct operation assert len(responses.calls) == 1 - assert response.status_code == 200 + assert response.status_code == 201 # Validate body params req_body = json.loads(str(responses.calls[0].request.body, 'utf-8')) - assert req_body == test_destination_request_body_prototype + assert req_body == add_destination_prototype - def test_test_distribution_list_destination_all_params_with_retries(self): - # Enable retries and run test_test_distribution_list_destination_all_params. + def test_create_distribution_list_destination_all_params_with_retries(self): + # Enable retries and run test_create_distribution_list_destination_all_params. _service.enable_retries() - self.test_test_distribution_list_destination_all_params() + self.test_create_distribution_list_destination_all_params() - # Disable retries and run test_test_distribution_list_destination_all_params. + # Disable retries and run test_create_distribution_list_destination_all_params. _service.disable_retries() - self.test_test_distribution_list_destination_all_params() + self.test_create_distribution_list_destination_all_params() @responses.activate - def test_test_distribution_list_destination_value_error(self): + def test_create_distribution_list_destination_value_error(self): """ - test_test_distribution_list_destination_value_error() + test_create_distribution_list_destination_value_error() """ # Set up mock - url = preprocess_url( - '/v1/distribution_lists/a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6/destinations/12345678-1234-1234-1234-123456789012/test' + url = preprocess_url('/v1/distribution_lists/a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6/destinations') + mock_response = ( + '{"destination_id": "12345678-1234-1234-1234-123456789012", "destination_type": "event_notifications"}' ) - mock_response = '{"message": "success"}' responses.add( responses.POST, url, body=mock_response, content_type='application/json', - status=200, + status=201, ) - # Construct a dict representation of a TestDestinationRequestBodyPrototypeTestEventNotificationDestinationRequestBodyPrototype model - test_destination_request_body_prototype_model = {} - test_destination_request_body_prototype_model['destination_type'] = 'event_notifications' - test_destination_request_body_prototype_model['notification_type'] = 'incident' + # Construct a dict representation of a AddDestinationPrototypeEventNotificationDestinationPrototype model + add_destination_prototype_model = {} + add_destination_prototype_model['destination_id'] = '12345678-1234-1234-1234-123456789012' + add_destination_prototype_model['destination_type'] = 'event_notifications' # Set up parameter values account_id = 'a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6' - destination_id = '12345678-1234-1234-1234-123456789012' - test_destination_request_body_prototype = test_destination_request_body_prototype_model + add_destination_prototype = add_destination_prototype_model # Pass in all but one required param and check for a ValueError req_param_dict = { "account_id": account_id, - "destination_id": destination_id, - "test_destination_request_body_prototype": test_destination_request_body_prototype, + "add_destination_prototype": add_destination_prototype, } for param in req_param_dict.keys(): req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} with pytest.raises(ValueError): - _service.test_distribution_list_destination(**req_copy) + _service.create_distribution_list_destination(**req_copy) - def test_test_distribution_list_destination_value_error_with_retries(self): - # Enable retries and run test_test_distribution_list_destination_value_error. + def test_create_distribution_list_destination_value_error_with_retries(self): + # Enable retries and run test_create_distribution_list_destination_value_error. _service.enable_retries() - self.test_test_distribution_list_destination_value_error() + self.test_create_distribution_list_destination_value_error() - # Disable retries and run test_test_distribution_list_destination_value_error. + # Disable retries and run test_create_distribution_list_destination_value_error. _service.disable_retries() - self.test_test_distribution_list_destination_value_error() - - -# endregion -############################################################################## -# End of Service: DistributionLists -############################################################################## - -############################################################################## -# Start of Service: UserPreferences -############################################################################## -# region + self.test_create_distribution_list_destination_value_error() -class TestNewInstance: +class TestGetDistributionListDestination: """ - Test Class for new_instance + Test Class for get_distribution_list_destination """ - def test_new_instance(self): + @responses.activate + def test_get_distribution_list_destination_all_params(self): """ - new_instance() + get_distribution_list_destination() """ - os.environ['TEST_SERVICE_AUTH_TYPE'] = 'noAuth' + # Set up mock + url = preprocess_url( + '/v1/distribution_lists/a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6/destinations/12345678-1234-1234-1234-123456789012' + ) + mock_response = ( + '{"destination_id": "12345678-1234-1234-1234-123456789012", "destination_type": "event_notifications"}' + ) + responses.add( + responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200, + ) - service = PlatformNotificationsV1.new_instance( - service_name='TEST_SERVICE', + # Set up parameter values + account_id = 'a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6' + destination_id = '12345678-1234-1234-1234-123456789012' + + # Invoke method + response = _service.get_distribution_list_destination( + account_id, + destination_id, + headers={}, ) - assert service is not None - assert isinstance(service, PlatformNotificationsV1) + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 - def test_new_instance_without_authenticator(self): + def test_get_distribution_list_destination_all_params_with_retries(self): + # Enable retries and run test_get_distribution_list_destination_all_params. + _service.enable_retries() + self.test_get_distribution_list_destination_all_params() + + # Disable retries and run test_get_distribution_list_destination_all_params. + _service.disable_retries() + self.test_get_distribution_list_destination_all_params() + + @responses.activate + def test_get_distribution_list_destination_value_error(self): """ - new_instance_without_authenticator() + test_get_distribution_list_destination_value_error() """ - with pytest.raises(ValueError, match='authenticator must be provided'): - service = PlatformNotificationsV1.new_instance( - service_name='TEST_SERVICE_NOT_FOUND', - ) + # Set up mock + url = preprocess_url( + '/v1/distribution_lists/a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6/destinations/12345678-1234-1234-1234-123456789012' + ) + mock_response = ( + '{"destination_id": "12345678-1234-1234-1234-123456789012", "destination_type": "event_notifications"}' + ) + responses.add( + responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200, + ) + # Set up parameter values + account_id = 'a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6' + destination_id = '12345678-1234-1234-1234-123456789012' -class TestCreatePreferences: + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "account_id": account_id, + "destination_id": destination_id, + } + for param in req_param_dict.keys(): + req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} + with pytest.raises(ValueError): + _service.get_distribution_list_destination(**req_copy) + + def test_get_distribution_list_destination_value_error_with_retries(self): + # Enable retries and run test_get_distribution_list_destination_value_error. + _service.enable_retries() + self.test_get_distribution_list_destination_value_error() + + # Disable retries and run test_get_distribution_list_destination_value_error. + _service.disable_retries() + self.test_get_distribution_list_destination_value_error() + + +class TestDeleteDistributionListDestination: """ - Test Class for create_preferences + Test Class for delete_distribution_list_destination """ @responses.activate - def test_create_preferences_all_params(self): + def test_delete_distribution_list_destination_all_params(self): """ - create_preferences() + delete_distribution_list_destination() """ # Set up mock - url = preprocess_url('/v1/notifications/IBMid-1234567890/preferences') - mock_response = '{"incident_severity1": {"channels": ["email"], "updates": true}, "incident_severity2": {"channels": ["email"], "updates": true}, "incident_severity3": {"channels": ["email"], "updates": true}, "incident_severity4": {"channels": ["email"], "updates": true}, "maintenance_high": {"channels": ["email"], "updates": true}, "maintenance_medium": {"channels": ["email"], "updates": true}, "maintenance_low": {"channels": ["email"], "updates": true}, "announcements_major": {"channels": ["email"]}, "announcements_minor": {"channels": ["email"]}, "security_normal": {"channels": ["email"]}, "account_normal": {"channels": ["email"]}, "billing_and_usage_order": {"channels": ["email"]}, "billing_and_usage_invoices": {"channels": ["email"]}, "billing_and_usage_payments": {"channels": ["email"]}, "billing_and_usage_subscriptions_and_promo_codes": {"channels": ["email"]}, "billing_and_usage_spending_alerts": {"channels": ["email"]}, "resourceactivity_normal": {"channels": ["email"]}, "ordering_review": {"channels": ["email"]}, "ordering_approved": {"channels": ["email"]}, "ordering_approved_vsi": {"channels": ["email"]}, "ordering_approved_server": {"channels": ["email"]}, "provisioning_reload_complete": {"channels": ["email"]}, "provisioning_complete_vsi": {"channels": ["email"]}, "provisioning_complete_server": {"channels": ["email"]}}' + url = preprocess_url( + '/v1/distribution_lists/a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6/destinations/12345678-1234-1234-1234-123456789012' + ) responses.add( - responses.POST, + responses.DELETE, url, - body=mock_response, - content_type='application/json', - status=201, + status=204, ) - # Construct a dict representation of a PreferenceValueWithUpdates model - preference_value_with_updates_model = {} - preference_value_with_updates_model['channels'] = ['email'] - preference_value_with_updates_model['updates'] = True - - # Construct a dict representation of a PreferenceValueWithoutUpdates model - preference_value_without_updates_model = {} - preference_value_without_updates_model['channels'] = ['email'] - # Set up parameter values - iam_id = 'IBMid-1234567890' - incident_severity1 = preference_value_with_updates_model - incident_severity2 = preference_value_with_updates_model - incident_severity3 = preference_value_with_updates_model - incident_severity4 = preference_value_with_updates_model - maintenance_high = preference_value_with_updates_model - maintenance_medium = preference_value_with_updates_model - maintenance_low = preference_value_with_updates_model - announcements_major = preference_value_without_updates_model - announcements_minor = preference_value_without_updates_model - security_normal = preference_value_without_updates_model - account_normal = preference_value_without_updates_model - billing_and_usage_order = preference_value_without_updates_model - billing_and_usage_invoices = preference_value_without_updates_model - billing_and_usage_payments = preference_value_without_updates_model - billing_and_usage_subscriptions_and_promo_codes = preference_value_without_updates_model - billing_and_usage_spending_alerts = preference_value_without_updates_model - resourceactivity_normal = preference_value_without_updates_model - ordering_review = preference_value_without_updates_model - ordering_approved = preference_value_without_updates_model - ordering_approved_vsi = preference_value_without_updates_model - ordering_approved_server = preference_value_without_updates_model - provisioning_reload_complete = preference_value_without_updates_model - provisioning_complete_vsi = preference_value_without_updates_model - provisioning_complete_server = preference_value_without_updates_model account_id = 'a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6' + destination_id = '12345678-1234-1234-1234-123456789012' # Invoke method - response = _service.create_preferences( - iam_id, - incident_severity1=incident_severity1, - incident_severity2=incident_severity2, - incident_severity3=incident_severity3, - incident_severity4=incident_severity4, - maintenance_high=maintenance_high, - maintenance_medium=maintenance_medium, - maintenance_low=maintenance_low, - announcements_major=announcements_major, - announcements_minor=announcements_minor, - security_normal=security_normal, - account_normal=account_normal, - billing_and_usage_order=billing_and_usage_order, - billing_and_usage_invoices=billing_and_usage_invoices, - billing_and_usage_payments=billing_and_usage_payments, - billing_and_usage_subscriptions_and_promo_codes=billing_and_usage_subscriptions_and_promo_codes, - billing_and_usage_spending_alerts=billing_and_usage_spending_alerts, - resourceactivity_normal=resourceactivity_normal, - ordering_review=ordering_review, - ordering_approved=ordering_approved, - ordering_approved_vsi=ordering_approved_vsi, - ordering_approved_server=ordering_approved_server, - provisioning_reload_complete=provisioning_reload_complete, - provisioning_complete_vsi=provisioning_complete_vsi, - provisioning_complete_server=provisioning_complete_server, - account_id=account_id, + response = _service.delete_distribution_list_destination( + account_id, + destination_id, headers={}, ) # Check for correct operation assert len(responses.calls) == 1 - assert response.status_code == 201 - # Validate query params - query_string = responses.calls[0].request.url.split('?', 1)[1] - query_string = urllib.parse.unquote_plus(query_string) - assert 'account_id={}'.format(account_id) in query_string - # Validate body params - req_body = json.loads(str(responses.calls[0].request.body, 'utf-8')) - assert req_body['incident_severity1'] == preference_value_with_updates_model - assert req_body['incident_severity2'] == preference_value_with_updates_model - assert req_body['incident_severity3'] == preference_value_with_updates_model - assert req_body['incident_severity4'] == preference_value_with_updates_model - assert req_body['maintenance_high'] == preference_value_with_updates_model - assert req_body['maintenance_medium'] == preference_value_with_updates_model - assert req_body['maintenance_low'] == preference_value_with_updates_model - assert req_body['announcements_major'] == preference_value_without_updates_model - assert req_body['announcements_minor'] == preference_value_without_updates_model - assert req_body['security_normal'] == preference_value_without_updates_model - assert req_body['account_normal'] == preference_value_without_updates_model - assert req_body['billing_and_usage_order'] == preference_value_without_updates_model - assert req_body['billing_and_usage_invoices'] == preference_value_without_updates_model - assert req_body['billing_and_usage_payments'] == preference_value_without_updates_model - assert req_body['billing_and_usage_subscriptions_and_promo_codes'] == preference_value_without_updates_model - assert req_body['billing_and_usage_spending_alerts'] == preference_value_without_updates_model - assert req_body['resourceactivity_normal'] == preference_value_without_updates_model - assert req_body['ordering_review'] == preference_value_without_updates_model - assert req_body['ordering_approved'] == preference_value_without_updates_model - assert req_body['ordering_approved_vsi'] == preference_value_without_updates_model - assert req_body['ordering_approved_server'] == preference_value_without_updates_model - assert req_body['provisioning_reload_complete'] == preference_value_without_updates_model - assert req_body['provisioning_complete_vsi'] == preference_value_without_updates_model - assert req_body['provisioning_complete_server'] == preference_value_without_updates_model + assert response.status_code == 204 - def test_create_preferences_all_params_with_retries(self): - # Enable retries and run test_create_preferences_all_params. + def test_delete_distribution_list_destination_all_params_with_retries(self): + # Enable retries and run test_delete_distribution_list_destination_all_params. _service.enable_retries() - self.test_create_preferences_all_params() + self.test_delete_distribution_list_destination_all_params() - # Disable retries and run test_create_preferences_all_params. + # Disable retries and run test_delete_distribution_list_destination_all_params. _service.disable_retries() - self.test_create_preferences_all_params() + self.test_delete_distribution_list_destination_all_params() @responses.activate - def test_create_preferences_required_params(self): + def test_delete_distribution_list_destination_value_error(self): """ - test_create_preferences_required_params() + test_delete_distribution_list_destination_value_error() """ # Set up mock - url = preprocess_url('/v1/notifications/IBMid-1234567890/preferences') - mock_response = '{"incident_severity1": {"channels": ["email"], "updates": true}, "incident_severity2": {"channels": ["email"], "updates": true}, "incident_severity3": {"channels": ["email"], "updates": true}, "incident_severity4": {"channels": ["email"], "updates": true}, "maintenance_high": {"channels": ["email"], "updates": true}, "maintenance_medium": {"channels": ["email"], "updates": true}, "maintenance_low": {"channels": ["email"], "updates": true}, "announcements_major": {"channels": ["email"]}, "announcements_minor": {"channels": ["email"]}, "security_normal": {"channels": ["email"]}, "account_normal": {"channels": ["email"]}, "billing_and_usage_order": {"channels": ["email"]}, "billing_and_usage_invoices": {"channels": ["email"]}, "billing_and_usage_payments": {"channels": ["email"]}, "billing_and_usage_subscriptions_and_promo_codes": {"channels": ["email"]}, "billing_and_usage_spending_alerts": {"channels": ["email"]}, "resourceactivity_normal": {"channels": ["email"]}, "ordering_review": {"channels": ["email"]}, "ordering_approved": {"channels": ["email"]}, "ordering_approved_vsi": {"channels": ["email"]}, "ordering_approved_server": {"channels": ["email"]}, "provisioning_reload_complete": {"channels": ["email"]}, "provisioning_complete_vsi": {"channels": ["email"]}, "provisioning_complete_server": {"channels": ["email"]}}' + url = preprocess_url( + '/v1/distribution_lists/a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6/destinations/12345678-1234-1234-1234-123456789012' + ) responses.add( - responses.POST, + responses.DELETE, url, - body=mock_response, - content_type='application/json', - status=201, + status=204, ) - # Construct a dict representation of a PreferenceValueWithUpdates model - preference_value_with_updates_model = {} - preference_value_with_updates_model['channels'] = ['email'] - preference_value_with_updates_model['updates'] = True - - # Construct a dict representation of a PreferenceValueWithoutUpdates model - preference_value_without_updates_model = {} - preference_value_without_updates_model['channels'] = ['email'] - - # Set up parameter values - iam_id = 'IBMid-1234567890' - incident_severity1 = preference_value_with_updates_model - incident_severity2 = preference_value_with_updates_model - incident_severity3 = preference_value_with_updates_model - incident_severity4 = preference_value_with_updates_model - maintenance_high = preference_value_with_updates_model - maintenance_medium = preference_value_with_updates_model - maintenance_low = preference_value_with_updates_model - announcements_major = preference_value_without_updates_model - announcements_minor = preference_value_without_updates_model - security_normal = preference_value_without_updates_model - account_normal = preference_value_without_updates_model - billing_and_usage_order = preference_value_without_updates_model - billing_and_usage_invoices = preference_value_without_updates_model - billing_and_usage_payments = preference_value_without_updates_model - billing_and_usage_subscriptions_and_promo_codes = preference_value_without_updates_model - billing_and_usage_spending_alerts = preference_value_without_updates_model - resourceactivity_normal = preference_value_without_updates_model - ordering_review = preference_value_without_updates_model - ordering_approved = preference_value_without_updates_model - ordering_approved_vsi = preference_value_without_updates_model - ordering_approved_server = preference_value_without_updates_model - provisioning_reload_complete = preference_value_without_updates_model - provisioning_complete_vsi = preference_value_without_updates_model - provisioning_complete_server = preference_value_without_updates_model - - # Invoke method - response = _service.create_preferences( - iam_id, - incident_severity1=incident_severity1, - incident_severity2=incident_severity2, - incident_severity3=incident_severity3, - incident_severity4=incident_severity4, - maintenance_high=maintenance_high, - maintenance_medium=maintenance_medium, - maintenance_low=maintenance_low, - announcements_major=announcements_major, - announcements_minor=announcements_minor, - security_normal=security_normal, - account_normal=account_normal, - billing_and_usage_order=billing_and_usage_order, - billing_and_usage_invoices=billing_and_usage_invoices, - billing_and_usage_payments=billing_and_usage_payments, - billing_and_usage_subscriptions_and_promo_codes=billing_and_usage_subscriptions_and_promo_codes, - billing_and_usage_spending_alerts=billing_and_usage_spending_alerts, - resourceactivity_normal=resourceactivity_normal, - ordering_review=ordering_review, - ordering_approved=ordering_approved, - ordering_approved_vsi=ordering_approved_vsi, - ordering_approved_server=ordering_approved_server, - provisioning_reload_complete=provisioning_reload_complete, - provisioning_complete_vsi=provisioning_complete_vsi, - provisioning_complete_server=provisioning_complete_server, - headers={}, - ) - - # Check for correct operation - assert len(responses.calls) == 1 - assert response.status_code == 201 - # Validate body params - req_body = json.loads(str(responses.calls[0].request.body, 'utf-8')) - assert req_body['incident_severity1'] == preference_value_with_updates_model - assert req_body['incident_severity2'] == preference_value_with_updates_model - assert req_body['incident_severity3'] == preference_value_with_updates_model - assert req_body['incident_severity4'] == preference_value_with_updates_model - assert req_body['maintenance_high'] == preference_value_with_updates_model - assert req_body['maintenance_medium'] == preference_value_with_updates_model - assert req_body['maintenance_low'] == preference_value_with_updates_model - assert req_body['announcements_major'] == preference_value_without_updates_model - assert req_body['announcements_minor'] == preference_value_without_updates_model - assert req_body['security_normal'] == preference_value_without_updates_model - assert req_body['account_normal'] == preference_value_without_updates_model - assert req_body['billing_and_usage_order'] == preference_value_without_updates_model - assert req_body['billing_and_usage_invoices'] == preference_value_without_updates_model - assert req_body['billing_and_usage_payments'] == preference_value_without_updates_model - assert req_body['billing_and_usage_subscriptions_and_promo_codes'] == preference_value_without_updates_model - assert req_body['billing_and_usage_spending_alerts'] == preference_value_without_updates_model - assert req_body['resourceactivity_normal'] == preference_value_without_updates_model - assert req_body['ordering_review'] == preference_value_without_updates_model - assert req_body['ordering_approved'] == preference_value_without_updates_model - assert req_body['ordering_approved_vsi'] == preference_value_without_updates_model - assert req_body['ordering_approved_server'] == preference_value_without_updates_model - assert req_body['provisioning_reload_complete'] == preference_value_without_updates_model - assert req_body['provisioning_complete_vsi'] == preference_value_without_updates_model - assert req_body['provisioning_complete_server'] == preference_value_without_updates_model - - def test_create_preferences_required_params_with_retries(self): - # Enable retries and run test_create_preferences_required_params. - _service.enable_retries() - self.test_create_preferences_required_params() - - # Disable retries and run test_create_preferences_required_params. - _service.disable_retries() - self.test_create_preferences_required_params() - - @responses.activate - def test_create_preferences_value_error(self): - """ - test_create_preferences_value_error() - """ - # Set up mock - url = preprocess_url('/v1/notifications/IBMid-1234567890/preferences') - mock_response = '{"incident_severity1": {"channels": ["email"], "updates": true}, "incident_severity2": {"channels": ["email"], "updates": true}, "incident_severity3": {"channels": ["email"], "updates": true}, "incident_severity4": {"channels": ["email"], "updates": true}, "maintenance_high": {"channels": ["email"], "updates": true}, "maintenance_medium": {"channels": ["email"], "updates": true}, "maintenance_low": {"channels": ["email"], "updates": true}, "announcements_major": {"channels": ["email"]}, "announcements_minor": {"channels": ["email"]}, "security_normal": {"channels": ["email"]}, "account_normal": {"channels": ["email"]}, "billing_and_usage_order": {"channels": ["email"]}, "billing_and_usage_invoices": {"channels": ["email"]}, "billing_and_usage_payments": {"channels": ["email"]}, "billing_and_usage_subscriptions_and_promo_codes": {"channels": ["email"]}, "billing_and_usage_spending_alerts": {"channels": ["email"]}, "resourceactivity_normal": {"channels": ["email"]}, "ordering_review": {"channels": ["email"]}, "ordering_approved": {"channels": ["email"]}, "ordering_approved_vsi": {"channels": ["email"]}, "ordering_approved_server": {"channels": ["email"]}, "provisioning_reload_complete": {"channels": ["email"]}, "provisioning_complete_vsi": {"channels": ["email"]}, "provisioning_complete_server": {"channels": ["email"]}}' - responses.add( - responses.POST, - url, - body=mock_response, - content_type='application/json', - status=201, - ) - - # Construct a dict representation of a PreferenceValueWithUpdates model - preference_value_with_updates_model = {} - preference_value_with_updates_model['channels'] = ['email'] - preference_value_with_updates_model['updates'] = True - - # Construct a dict representation of a PreferenceValueWithoutUpdates model - preference_value_without_updates_model = {} - preference_value_without_updates_model['channels'] = ['email'] - # Set up parameter values - iam_id = 'IBMid-1234567890' - incident_severity1 = preference_value_with_updates_model - incident_severity2 = preference_value_with_updates_model - incident_severity3 = preference_value_with_updates_model - incident_severity4 = preference_value_with_updates_model - maintenance_high = preference_value_with_updates_model - maintenance_medium = preference_value_with_updates_model - maintenance_low = preference_value_with_updates_model - announcements_major = preference_value_without_updates_model - announcements_minor = preference_value_without_updates_model - security_normal = preference_value_without_updates_model - account_normal = preference_value_without_updates_model - billing_and_usage_order = preference_value_without_updates_model - billing_and_usage_invoices = preference_value_without_updates_model - billing_and_usage_payments = preference_value_without_updates_model - billing_and_usage_subscriptions_and_promo_codes = preference_value_without_updates_model - billing_and_usage_spending_alerts = preference_value_without_updates_model - resourceactivity_normal = preference_value_without_updates_model - ordering_review = preference_value_without_updates_model - ordering_approved = preference_value_without_updates_model - ordering_approved_vsi = preference_value_without_updates_model - ordering_approved_server = preference_value_without_updates_model - provisioning_reload_complete = preference_value_without_updates_model - provisioning_complete_vsi = preference_value_without_updates_model - provisioning_complete_server = preference_value_without_updates_model + account_id = 'a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6' + destination_id = '12345678-1234-1234-1234-123456789012' # Pass in all but one required param and check for a ValueError req_param_dict = { - "iam_id": iam_id, + "account_id": account_id, + "destination_id": destination_id, } for param in req_param_dict.keys(): req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} with pytest.raises(ValueError): - _service.create_preferences(**req_copy) + _service.delete_distribution_list_destination(**req_copy) - def test_create_preferences_value_error_with_retries(self): - # Enable retries and run test_create_preferences_value_error. + def test_delete_distribution_list_destination_value_error_with_retries(self): + # Enable retries and run test_delete_distribution_list_destination_value_error. _service.enable_retries() - self.test_create_preferences_value_error() + self.test_delete_distribution_list_destination_value_error() - # Disable retries and run test_create_preferences_value_error. + # Disable retries and run test_delete_distribution_list_destination_value_error. _service.disable_retries() - self.test_create_preferences_value_error() + self.test_delete_distribution_list_destination_value_error() -class TestGetPreferences: +class TestTestDistributionListDestination: """ - Test Class for get_preferences + Test Class for test_distribution_list_destination """ @responses.activate - def test_get_preferences_all_params(self): + def test_test_distribution_list_destination_all_params(self): """ - get_preferences() + test_distribution_list_destination() """ # Set up mock - url = preprocess_url('/v1/notifications/IBMid-1234567890/preferences') - mock_response = '{"incident_severity1": {"channels": ["email"], "updates": true}, "incident_severity2": {"channels": ["email"], "updates": true}, "incident_severity3": {"channels": ["email"], "updates": true}, "incident_severity4": {"channels": ["email"], "updates": true}, "maintenance_high": {"channels": ["email"], "updates": true}, "maintenance_medium": {"channels": ["email"], "updates": true}, "maintenance_low": {"channels": ["email"], "updates": true}, "announcements_major": {"channels": ["email"]}, "announcements_minor": {"channels": ["email"]}, "security_normal": {"channels": ["email"]}, "account_normal": {"channels": ["email"]}, "billing_and_usage_order": {"channels": ["email"]}, "billing_and_usage_invoices": {"channels": ["email"]}, "billing_and_usage_payments": {"channels": ["email"]}, "billing_and_usage_subscriptions_and_promo_codes": {"channels": ["email"]}, "billing_and_usage_spending_alerts": {"channels": ["email"]}, "resourceactivity_normal": {"channels": ["email"]}, "ordering_review": {"channels": ["email"]}, "ordering_approved": {"channels": ["email"]}, "ordering_approved_vsi": {"channels": ["email"]}, "ordering_approved_server": {"channels": ["email"]}, "provisioning_reload_complete": {"channels": ["email"]}, "provisioning_complete_vsi": {"channels": ["email"]}, "provisioning_complete_server": {"channels": ["email"]}}' + url = preprocess_url( + '/v1/distribution_lists/a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6/destinations/12345678-1234-1234-1234-123456789012/test' + ) + mock_response = '{"message": "success"}' responses.add( - responses.GET, + responses.POST, url, body=mock_response, content_type='application/json', status=200, ) + # Construct a dict representation of a TestDestinationRequestBodyPrototypeTestEventNotificationDestinationRequestBodyPrototype model + test_destination_request_body_prototype_model = {} + test_destination_request_body_prototype_model['destination_type'] = 'event_notifications' + test_destination_request_body_prototype_model['notification_type'] = 'incident' + # Set up parameter values - iam_id = 'IBMid-1234567890' account_id = 'a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6' + destination_id = '12345678-1234-1234-1234-123456789012' + test_destination_request_body_prototype = test_destination_request_body_prototype_model # Invoke method - response = _service.get_preferences( - iam_id, - account_id=account_id, + response = _service.test_distribution_list_destination( + account_id, + destination_id, + test_destination_request_body_prototype, headers={}, ) # Check for correct operation assert len(responses.calls) == 1 assert response.status_code == 200 - # Validate query params - query_string = responses.calls[0].request.url.split('?', 1)[1] - query_string = urllib.parse.unquote_plus(query_string) - assert 'account_id={}'.format(account_id) in query_string + # Validate body params + req_body = json.loads(str(responses.calls[0].request.body, 'utf-8')) + assert req_body == test_destination_request_body_prototype - def test_get_preferences_all_params_with_retries(self): - # Enable retries and run test_get_preferences_all_params. + def test_test_distribution_list_destination_all_params_with_retries(self): + # Enable retries and run test_test_distribution_list_destination_all_params. _service.enable_retries() - self.test_get_preferences_all_params() + self.test_test_distribution_list_destination_all_params() - # Disable retries and run test_get_preferences_all_params. + # Disable retries and run test_test_distribution_list_destination_all_params. _service.disable_retries() - self.test_get_preferences_all_params() + self.test_test_distribution_list_destination_all_params() @responses.activate - def test_get_preferences_required_params(self): + def test_test_distribution_list_destination_value_error(self): """ - test_get_preferences_required_params() + test_test_distribution_list_destination_value_error() """ # Set up mock - url = preprocess_url('/v1/notifications/IBMid-1234567890/preferences') - mock_response = '{"incident_severity1": {"channels": ["email"], "updates": true}, "incident_severity2": {"channels": ["email"], "updates": true}, "incident_severity3": {"channels": ["email"], "updates": true}, "incident_severity4": {"channels": ["email"], "updates": true}, "maintenance_high": {"channels": ["email"], "updates": true}, "maintenance_medium": {"channels": ["email"], "updates": true}, "maintenance_low": {"channels": ["email"], "updates": true}, "announcements_major": {"channels": ["email"]}, "announcements_minor": {"channels": ["email"]}, "security_normal": {"channels": ["email"]}, "account_normal": {"channels": ["email"]}, "billing_and_usage_order": {"channels": ["email"]}, "billing_and_usage_invoices": {"channels": ["email"]}, "billing_and_usage_payments": {"channels": ["email"]}, "billing_and_usage_subscriptions_and_promo_codes": {"channels": ["email"]}, "billing_and_usage_spending_alerts": {"channels": ["email"]}, "resourceactivity_normal": {"channels": ["email"]}, "ordering_review": {"channels": ["email"]}, "ordering_approved": {"channels": ["email"]}, "ordering_approved_vsi": {"channels": ["email"]}, "ordering_approved_server": {"channels": ["email"]}, "provisioning_reload_complete": {"channels": ["email"]}, "provisioning_complete_vsi": {"channels": ["email"]}, "provisioning_complete_server": {"channels": ["email"]}}' + url = preprocess_url( + '/v1/distribution_lists/a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6/destinations/12345678-1234-1234-1234-123456789012/test' + ) + mock_response = '{"message": "success"}' responses.add( - responses.GET, + responses.POST, url, body=mock_response, content_type='application/json', status=200, ) + # Construct a dict representation of a TestDestinationRequestBodyPrototypeTestEventNotificationDestinationRequestBodyPrototype model + test_destination_request_body_prototype_model = {} + test_destination_request_body_prototype_model['destination_type'] = 'event_notifications' + test_destination_request_body_prototype_model['notification_type'] = 'incident' + # Set up parameter values - iam_id = 'IBMid-1234567890' + account_id = 'a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6' + destination_id = '12345678-1234-1234-1234-123456789012' + test_destination_request_body_prototype = test_destination_request_body_prototype_model - # Invoke method - response = _service.get_preferences( - iam_id, - headers={}, - ) + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "account_id": account_id, + "destination_id": destination_id, + "test_destination_request_body_prototype": test_destination_request_body_prototype, + } + for param in req_param_dict.keys(): + req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} + with pytest.raises(ValueError): + _service.test_distribution_list_destination(**req_copy) - # Check for correct operation + def test_test_distribution_list_destination_value_error_with_retries(self): + # Enable retries and run test_test_distribution_list_destination_value_error. + _service.enable_retries() + self.test_test_distribution_list_destination_value_error() + + # Disable retries and run test_test_distribution_list_destination_value_error. + _service.disable_retries() + self.test_test_distribution_list_destination_value_error() + + +# endregion +############################################################################## +# End of Service: DistributionLists +############################################################################## + +############################################################################## +# Start of Service: UserPreferences +############################################################################## +# region + + +class TestNewInstance: + """ + Test Class for new_instance + """ + + def test_new_instance(self): + """ + new_instance() + """ + os.environ['TEST_SERVICE_AUTH_TYPE'] = 'noAuth' + + service = PlatformNotificationsV1.new_instance( + service_name='TEST_SERVICE', + ) + + assert service is not None + assert isinstance(service, PlatformNotificationsV1) + + def test_new_instance_without_authenticator(self): + """ + new_instance_without_authenticator() + """ + with pytest.raises(ValueError, match='authenticator must be provided'): + service = PlatformNotificationsV1.new_instance( + service_name='TEST_SERVICE_NOT_FOUND', + ) + + +class TestGetPreferences: + """ + Test Class for get_preferences + """ + + @responses.activate + def test_get_preferences_all_params(self): + """ + get_preferences() + """ + # Set up mock + url = preprocess_url('/v1/notifications/IBMid-1234567890/preferences') + mock_response = '{"incident_severity1": {"channels": ["email"], "updates": true}, "incident_severity2": {"channels": ["email"], "updates": true}, "incident_severity3": {"channels": ["email"], "updates": true}, "incident_severity4": {"channels": ["email"], "updates": true}, "maintenance_high": {"channels": ["email"], "updates": true}, "maintenance_medium": {"channels": ["email"], "updates": true}, "maintenance_low": {"channels": ["email"], "updates": true}, "announcements_major": {"channels": ["email"]}, "announcements_minor": {"channels": ["email"]}, "security_normal": {"channels": ["email"]}, "account_normal": {"channels": ["email"]}, "billing_and_usage_order": {"channels": ["email"]}, "billing_and_usage_invoices": {"channels": ["email"]}, "billing_and_usage_payments": {"channels": ["email"]}, "billing_and_usage_subscriptions_and_promo_codes": {"channels": ["email"]}, "billing_and_usage_spending_alerts": {"channels": ["email"]}, "resourceactivity_normal": {"channels": ["email"]}, "ordering_review": {"channels": ["email"]}, "ordering_approved": {"channels": ["email"]}, "ordering_approved_vsi": {"channels": ["email"]}, "ordering_approved_server": {"channels": ["email"]}, "provisioning_reload_complete": {"channels": ["email"]}, "provisioning_complete_vsi": {"channels": ["email"]}, "provisioning_complete_server": {"channels": ["email"]}}' + responses.add( + responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200, + ) + + # Set up parameter values + iam_id = 'IBMid-1234567890' + account_id = 'a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6' + + # Invoke method + response = _service.get_preferences( + iam_id, + account_id=account_id, + headers={}, + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + # Validate query params + query_string = responses.calls[0].request.url.split('?', 1)[1] + query_string = urllib.parse.unquote_plus(query_string) + assert 'account_id={}'.format(account_id) in query_string + + def test_get_preferences_all_params_with_retries(self): + # Enable retries and run test_get_preferences_all_params. + _service.enable_retries() + self.test_get_preferences_all_params() + + # Disable retries and run test_get_preferences_all_params. + _service.disable_retries() + self.test_get_preferences_all_params() + + @responses.activate + def test_get_preferences_required_params(self): + """ + test_get_preferences_required_params() + """ + # Set up mock + url = preprocess_url('/v1/notifications/IBMid-1234567890/preferences') + mock_response = '{"incident_severity1": {"channels": ["email"], "updates": true}, "incident_severity2": {"channels": ["email"], "updates": true}, "incident_severity3": {"channels": ["email"], "updates": true}, "incident_severity4": {"channels": ["email"], "updates": true}, "maintenance_high": {"channels": ["email"], "updates": true}, "maintenance_medium": {"channels": ["email"], "updates": true}, "maintenance_low": {"channels": ["email"], "updates": true}, "announcements_major": {"channels": ["email"]}, "announcements_minor": {"channels": ["email"]}, "security_normal": {"channels": ["email"]}, "account_normal": {"channels": ["email"]}, "billing_and_usage_order": {"channels": ["email"]}, "billing_and_usage_invoices": {"channels": ["email"]}, "billing_and_usage_payments": {"channels": ["email"]}, "billing_and_usage_subscriptions_and_promo_codes": {"channels": ["email"]}, "billing_and_usage_spending_alerts": {"channels": ["email"]}, "resourceactivity_normal": {"channels": ["email"]}, "ordering_review": {"channels": ["email"]}, "ordering_approved": {"channels": ["email"]}, "ordering_approved_vsi": {"channels": ["email"]}, "ordering_approved_server": {"channels": ["email"]}, "provisioning_reload_complete": {"channels": ["email"]}, "provisioning_complete_vsi": {"channels": ["email"]}, "provisioning_complete_server": {"channels": ["email"]}}' + responses.add( + responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200, + ) + + # Set up parameter values + iam_id = 'IBMid-1234567890' + + # Invoke method + response = _service.get_preferences( + iam_id, + headers={}, + ) + + # Check for correct operation assert len(responses.calls) == 1 assert response.status_code == 200 @@ -1040,25 +1123,25 @@ def test_get_preferences_value_error_with_retries(self): self.test_get_preferences_value_error() -class TestReplaceNotificationPreferences: +class TestCreatePreferences: """ - Test Class for replace_notification_preferences + Test Class for create_preferences """ @responses.activate - def test_replace_notification_preferences_all_params(self): + def test_create_preferences_all_params(self): """ - replace_notification_preferences() + create_preferences() """ # Set up mock url = preprocess_url('/v1/notifications/IBMid-1234567890/preferences') mock_response = '{"incident_severity1": {"channels": ["email"], "updates": true}, "incident_severity2": {"channels": ["email"], "updates": true}, "incident_severity3": {"channels": ["email"], "updates": true}, "incident_severity4": {"channels": ["email"], "updates": true}, "maintenance_high": {"channels": ["email"], "updates": true}, "maintenance_medium": {"channels": ["email"], "updates": true}, "maintenance_low": {"channels": ["email"], "updates": true}, "announcements_major": {"channels": ["email"]}, "announcements_minor": {"channels": ["email"]}, "security_normal": {"channels": ["email"]}, "account_normal": {"channels": ["email"]}, "billing_and_usage_order": {"channels": ["email"]}, "billing_and_usage_invoices": {"channels": ["email"]}, "billing_and_usage_payments": {"channels": ["email"]}, "billing_and_usage_subscriptions_and_promo_codes": {"channels": ["email"]}, "billing_and_usage_spending_alerts": {"channels": ["email"]}, "resourceactivity_normal": {"channels": ["email"]}, "ordering_review": {"channels": ["email"]}, "ordering_approved": {"channels": ["email"]}, "ordering_approved_vsi": {"channels": ["email"]}, "ordering_approved_server": {"channels": ["email"]}, "provisioning_reload_complete": {"channels": ["email"]}, "provisioning_complete_vsi": {"channels": ["email"]}, "provisioning_complete_server": {"channels": ["email"]}}' responses.add( - responses.PUT, + responses.POST, url, body=mock_response, content_type='application/json', - status=200, + status=201, ) # Construct a dict representation of a PreferenceValueWithUpdates model @@ -1099,7 +1182,7 @@ def test_replace_notification_preferences_all_params(self): account_id = 'a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6' # Invoke method - response = _service.replace_notification_preferences( + response = _service.create_preferences( iam_id, incident_severity1=incident_severity1, incident_severity2=incident_severity2, @@ -1131,7 +1214,7 @@ def test_replace_notification_preferences_all_params(self): # Check for correct operation assert len(responses.calls) == 1 - assert response.status_code == 200 + assert response.status_code == 201 # Validate query params query_string = responses.calls[0].request.url.split('?', 1)[1] query_string = urllib.parse.unquote_plus(query_string) @@ -1163,29 +1246,29 @@ def test_replace_notification_preferences_all_params(self): assert req_body['provisioning_complete_vsi'] == preference_value_without_updates_model assert req_body['provisioning_complete_server'] == preference_value_without_updates_model - def test_replace_notification_preferences_all_params_with_retries(self): - # Enable retries and run test_replace_notification_preferences_all_params. + def test_create_preferences_all_params_with_retries(self): + # Enable retries and run test_create_preferences_all_params. _service.enable_retries() - self.test_replace_notification_preferences_all_params() + self.test_create_preferences_all_params() - # Disable retries and run test_replace_notification_preferences_all_params. + # Disable retries and run test_create_preferences_all_params. _service.disable_retries() - self.test_replace_notification_preferences_all_params() + self.test_create_preferences_all_params() @responses.activate - def test_replace_notification_preferences_required_params(self): + def test_create_preferences_required_params(self): """ - test_replace_notification_preferences_required_params() + test_create_preferences_required_params() """ # Set up mock url = preprocess_url('/v1/notifications/IBMid-1234567890/preferences') mock_response = '{"incident_severity1": {"channels": ["email"], "updates": true}, "incident_severity2": {"channels": ["email"], "updates": true}, "incident_severity3": {"channels": ["email"], "updates": true}, "incident_severity4": {"channels": ["email"], "updates": true}, "maintenance_high": {"channels": ["email"], "updates": true}, "maintenance_medium": {"channels": ["email"], "updates": true}, "maintenance_low": {"channels": ["email"], "updates": true}, "announcements_major": {"channels": ["email"]}, "announcements_minor": {"channels": ["email"]}, "security_normal": {"channels": ["email"]}, "account_normal": {"channels": ["email"]}, "billing_and_usage_order": {"channels": ["email"]}, "billing_and_usage_invoices": {"channels": ["email"]}, "billing_and_usage_payments": {"channels": ["email"]}, "billing_and_usage_subscriptions_and_promo_codes": {"channels": ["email"]}, "billing_and_usage_spending_alerts": {"channels": ["email"]}, "resourceactivity_normal": {"channels": ["email"]}, "ordering_review": {"channels": ["email"]}, "ordering_approved": {"channels": ["email"]}, "ordering_approved_vsi": {"channels": ["email"]}, "ordering_approved_server": {"channels": ["email"]}, "provisioning_reload_complete": {"channels": ["email"]}, "provisioning_complete_vsi": {"channels": ["email"]}, "provisioning_complete_server": {"channels": ["email"]}}' responses.add( - responses.PUT, + responses.POST, url, body=mock_response, content_type='application/json', - status=200, + status=201, ) # Construct a dict representation of a PreferenceValueWithUpdates model @@ -1225,7 +1308,7 @@ def test_replace_notification_preferences_required_params(self): provisioning_complete_server = preference_value_without_updates_model # Invoke method - response = _service.replace_notification_preferences( + response = _service.create_preferences( iam_id, incident_severity1=incident_severity1, incident_severity2=incident_severity2, @@ -1256,7 +1339,7 @@ def test_replace_notification_preferences_required_params(self): # Check for correct operation assert len(responses.calls) == 1 - assert response.status_code == 200 + assert response.status_code == 201 # Validate body params req_body = json.loads(str(responses.calls[0].request.body, 'utf-8')) assert req_body['incident_severity1'] == preference_value_with_updates_model @@ -1284,29 +1367,29 @@ def test_replace_notification_preferences_required_params(self): assert req_body['provisioning_complete_vsi'] == preference_value_without_updates_model assert req_body['provisioning_complete_server'] == preference_value_without_updates_model - def test_replace_notification_preferences_required_params_with_retries(self): - # Enable retries and run test_replace_notification_preferences_required_params. + def test_create_preferences_required_params_with_retries(self): + # Enable retries and run test_create_preferences_required_params. _service.enable_retries() - self.test_replace_notification_preferences_required_params() + self.test_create_preferences_required_params() - # Disable retries and run test_replace_notification_preferences_required_params. + # Disable retries and run test_create_preferences_required_params. _service.disable_retries() - self.test_replace_notification_preferences_required_params() + self.test_create_preferences_required_params() @responses.activate - def test_replace_notification_preferences_value_error(self): + def test_create_preferences_value_error(self): """ - test_replace_notification_preferences_value_error() + test_create_preferences_value_error() """ # Set up mock url = preprocess_url('/v1/notifications/IBMid-1234567890/preferences') mock_response = '{"incident_severity1": {"channels": ["email"], "updates": true}, "incident_severity2": {"channels": ["email"], "updates": true}, "incident_severity3": {"channels": ["email"], "updates": true}, "incident_severity4": {"channels": ["email"], "updates": true}, "maintenance_high": {"channels": ["email"], "updates": true}, "maintenance_medium": {"channels": ["email"], "updates": true}, "maintenance_low": {"channels": ["email"], "updates": true}, "announcements_major": {"channels": ["email"]}, "announcements_minor": {"channels": ["email"]}, "security_normal": {"channels": ["email"]}, "account_normal": {"channels": ["email"]}, "billing_and_usage_order": {"channels": ["email"]}, "billing_and_usage_invoices": {"channels": ["email"]}, "billing_and_usage_payments": {"channels": ["email"]}, "billing_and_usage_subscriptions_and_promo_codes": {"channels": ["email"]}, "billing_and_usage_spending_alerts": {"channels": ["email"]}, "resourceactivity_normal": {"channels": ["email"]}, "ordering_review": {"channels": ["email"]}, "ordering_approved": {"channels": ["email"]}, "ordering_approved_vsi": {"channels": ["email"]}, "ordering_approved_server": {"channels": ["email"]}, "provisioning_reload_complete": {"channels": ["email"]}, "provisioning_complete_vsi": {"channels": ["email"]}, "provisioning_complete_server": {"channels": ["email"]}}' responses.add( - responses.PUT, + responses.POST, url, body=mock_response, content_type='application/json', - status=200, + status=201, ) # Construct a dict representation of a PreferenceValueWithUpdates model @@ -1352,207 +1435,107 @@ def test_replace_notification_preferences_value_error(self): for param in req_param_dict.keys(): req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} with pytest.raises(ValueError): - _service.replace_notification_preferences(**req_copy) + _service.create_preferences(**req_copy) - def test_replace_notification_preferences_value_error_with_retries(self): - # Enable retries and run test_replace_notification_preferences_value_error. + def test_create_preferences_value_error_with_retries(self): + # Enable retries and run test_create_preferences_value_error. _service.enable_retries() - self.test_replace_notification_preferences_value_error() + self.test_create_preferences_value_error() - # Disable retries and run test_replace_notification_preferences_value_error. + # Disable retries and run test_create_preferences_value_error. _service.disable_retries() - self.test_replace_notification_preferences_value_error() + self.test_create_preferences_value_error() -class TestDeleteNotificationPreferences: +class TestReplaceNotificationPreferences: """ - Test Class for delete_notification_preferences + Test Class for replace_notification_preferences """ @responses.activate - def test_delete_notification_preferences_all_params(self): + def test_replace_notification_preferences_all_params(self): """ - delete_notification_preferences() + replace_notification_preferences() """ # Set up mock url = preprocess_url('/v1/notifications/IBMid-1234567890/preferences') + mock_response = '{"incident_severity1": {"channels": ["email"], "updates": true}, "incident_severity2": {"channels": ["email"], "updates": true}, "incident_severity3": {"channels": ["email"], "updates": true}, "incident_severity4": {"channels": ["email"], "updates": true}, "maintenance_high": {"channels": ["email"], "updates": true}, "maintenance_medium": {"channels": ["email"], "updates": true}, "maintenance_low": {"channels": ["email"], "updates": true}, "announcements_major": {"channels": ["email"]}, "announcements_minor": {"channels": ["email"]}, "security_normal": {"channels": ["email"]}, "account_normal": {"channels": ["email"]}, "billing_and_usage_order": {"channels": ["email"]}, "billing_and_usage_invoices": {"channels": ["email"]}, "billing_and_usage_payments": {"channels": ["email"]}, "billing_and_usage_subscriptions_and_promo_codes": {"channels": ["email"]}, "billing_and_usage_spending_alerts": {"channels": ["email"]}, "resourceactivity_normal": {"channels": ["email"]}, "ordering_review": {"channels": ["email"]}, "ordering_approved": {"channels": ["email"]}, "ordering_approved_vsi": {"channels": ["email"]}, "ordering_approved_server": {"channels": ["email"]}, "provisioning_reload_complete": {"channels": ["email"]}, "provisioning_complete_vsi": {"channels": ["email"]}, "provisioning_complete_server": {"channels": ["email"]}}' responses.add( - responses.DELETE, + responses.PUT, url, - status=204, + body=mock_response, + content_type='application/json', + status=200, ) + # Construct a dict representation of a PreferenceValueWithUpdates model + preference_value_with_updates_model = {} + preference_value_with_updates_model['channels'] = ['email'] + preference_value_with_updates_model['updates'] = True + + # Construct a dict representation of a PreferenceValueWithoutUpdates model + preference_value_without_updates_model = {} + preference_value_without_updates_model['channels'] = ['email'] + # Set up parameter values iam_id = 'IBMid-1234567890' + incident_severity1 = preference_value_with_updates_model + incident_severity2 = preference_value_with_updates_model + incident_severity3 = preference_value_with_updates_model + incident_severity4 = preference_value_with_updates_model + maintenance_high = preference_value_with_updates_model + maintenance_medium = preference_value_with_updates_model + maintenance_low = preference_value_with_updates_model + announcements_major = preference_value_without_updates_model + announcements_minor = preference_value_without_updates_model + security_normal = preference_value_without_updates_model + account_normal = preference_value_without_updates_model + billing_and_usage_order = preference_value_without_updates_model + billing_and_usage_invoices = preference_value_without_updates_model + billing_and_usage_payments = preference_value_without_updates_model + billing_and_usage_subscriptions_and_promo_codes = preference_value_without_updates_model + billing_and_usage_spending_alerts = preference_value_without_updates_model + resourceactivity_normal = preference_value_without_updates_model + ordering_review = preference_value_without_updates_model + ordering_approved = preference_value_without_updates_model + ordering_approved_vsi = preference_value_without_updates_model + ordering_approved_server = preference_value_without_updates_model + provisioning_reload_complete = preference_value_without_updates_model + provisioning_complete_vsi = preference_value_without_updates_model + provisioning_complete_server = preference_value_without_updates_model account_id = 'a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6' # Invoke method - response = _service.delete_notification_preferences( + response = _service.replace_notification_preferences( iam_id, + incident_severity1=incident_severity1, + incident_severity2=incident_severity2, + incident_severity3=incident_severity3, + incident_severity4=incident_severity4, + maintenance_high=maintenance_high, + maintenance_medium=maintenance_medium, + maintenance_low=maintenance_low, + announcements_major=announcements_major, + announcements_minor=announcements_minor, + security_normal=security_normal, + account_normal=account_normal, + billing_and_usage_order=billing_and_usage_order, + billing_and_usage_invoices=billing_and_usage_invoices, + billing_and_usage_payments=billing_and_usage_payments, + billing_and_usage_subscriptions_and_promo_codes=billing_and_usage_subscriptions_and_promo_codes, + billing_and_usage_spending_alerts=billing_and_usage_spending_alerts, + resourceactivity_normal=resourceactivity_normal, + ordering_review=ordering_review, + ordering_approved=ordering_approved, + ordering_approved_vsi=ordering_approved_vsi, + ordering_approved_server=ordering_approved_server, + provisioning_reload_complete=provisioning_reload_complete, + provisioning_complete_vsi=provisioning_complete_vsi, + provisioning_complete_server=provisioning_complete_server, account_id=account_id, headers={}, ) - # Check for correct operation - assert len(responses.calls) == 1 - assert response.status_code == 204 - # Validate query params - query_string = responses.calls[0].request.url.split('?', 1)[1] - query_string = urllib.parse.unquote_plus(query_string) - assert 'account_id={}'.format(account_id) in query_string - - def test_delete_notification_preferences_all_params_with_retries(self): - # Enable retries and run test_delete_notification_preferences_all_params. - _service.enable_retries() - self.test_delete_notification_preferences_all_params() - - # Disable retries and run test_delete_notification_preferences_all_params. - _service.disable_retries() - self.test_delete_notification_preferences_all_params() - - @responses.activate - def test_delete_notification_preferences_required_params(self): - """ - test_delete_notification_preferences_required_params() - """ - # Set up mock - url = preprocess_url('/v1/notifications/IBMid-1234567890/preferences') - responses.add( - responses.DELETE, - url, - status=204, - ) - - # Set up parameter values - iam_id = 'IBMid-1234567890' - - # Invoke method - response = _service.delete_notification_preferences( - iam_id, - headers={}, - ) - - # Check for correct operation - assert len(responses.calls) == 1 - assert response.status_code == 204 - - def test_delete_notification_preferences_required_params_with_retries(self): - # Enable retries and run test_delete_notification_preferences_required_params. - _service.enable_retries() - self.test_delete_notification_preferences_required_params() - - # Disable retries and run test_delete_notification_preferences_required_params. - _service.disable_retries() - self.test_delete_notification_preferences_required_params() - - @responses.activate - def test_delete_notification_preferences_value_error(self): - """ - test_delete_notification_preferences_value_error() - """ - # Set up mock - url = preprocess_url('/v1/notifications/IBMid-1234567890/preferences') - responses.add( - responses.DELETE, - url, - status=204, - ) - - # Set up parameter values - iam_id = 'IBMid-1234567890' - - # Pass in all but one required param and check for a ValueError - req_param_dict = { - "iam_id": iam_id, - } - for param in req_param_dict.keys(): - req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} - with pytest.raises(ValueError): - _service.delete_notification_preferences(**req_copy) - - def test_delete_notification_preferences_value_error_with_retries(self): - # Enable retries and run test_delete_notification_preferences_value_error. - _service.enable_retries() - self.test_delete_notification_preferences_value_error() - - # Disable retries and run test_delete_notification_preferences_value_error. - _service.disable_retries() - self.test_delete_notification_preferences_value_error() - - -# endregion -############################################################################## -# End of Service: UserPreferences -############################################################################## - -############################################################################## -# Start of Service: Notifications -############################################################################## -# region - - -class TestNewInstance: - """ - Test Class for new_instance - """ - - def test_new_instance(self): - """ - new_instance() - """ - os.environ['TEST_SERVICE_AUTH_TYPE'] = 'noAuth' - - service = PlatformNotificationsV1.new_instance( - service_name='TEST_SERVICE', - ) - - assert service is not None - assert isinstance(service, PlatformNotificationsV1) - - def test_new_instance_without_authenticator(self): - """ - new_instance_without_authenticator() - """ - with pytest.raises(ValueError, match='authenticator must be provided'): - service = PlatformNotificationsV1.new_instance( - service_name='TEST_SERVICE_NOT_FOUND', - ) - - -class TestListNotifications: - """ - Test Class for list_notifications - """ - - @responses.activate - def test_list_notifications_all_params(self): - """ - list_notifications() - """ - # Set up mock - url = preprocess_url('/v1/notifications') - mock_response = '{"limit": 50, "total_count": 232, "first": {"href": "https://api.example.com/v1/notifications?limit=50"}, "previous": {"href": "https://api.example.com/v1/notifications?start=3fe78a36b9aa7f26&limit=50", "start": "3fe78a36b9aa7f26"}, "next": {"href": "https://api.example.com/v1/notifications?start=3fe78a36b9aa7f26&limit=50", "start": "3fe78a36b9aa7f26"}, "last": {"href": "https://api.example.com/v1/notifications?start=3fe78a36b9aa7f26&limit=50", "start": "3fe78a36b9aa7f26"}, "notifications": [{"title": "System Maintenance Scheduled", "body": "Scheduled maintenance will occur on March 15th from 10:00 AM to 11:00 AM UTC.", "id": "12345", "category": "maintenance", "component_names": ["component_names"], "start_time": 1771791490, "is_global": false, "state": "new", "regions": ["regions"], "crn_masks": ["crn_masks"], "record_id": "rec-67890", "source_id": "src-11111", "completion_code": "successful", "end_time": 1771791490, "update_time": 1771791490, "severity": 2, "lucene_query": "region:us-south AND service_name:event-notifications", "resource_link": "https://cloud.ibm.com/status/incident/12345"}]}' - responses.add( - responses.GET, - url, - body=mock_response, - content_type='application/json', - status=200, - ) - - # Set up parameter values - account_id = 'a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6' - start = '3fe78a36b9aa7f26' - limit = 50 - - # Invoke method - response = _service.list_notifications( - account_id=account_id, - start=start, - limit=limit, - headers={}, - ) - # Check for correct operation assert len(responses.calls) == 1 assert response.status_code == 200 @@ -1560,346 +1543,353 @@ def test_list_notifications_all_params(self): query_string = responses.calls[0].request.url.split('?', 1)[1] query_string = urllib.parse.unquote_plus(query_string) assert 'account_id={}'.format(account_id) in query_string - assert 'start={}'.format(start) in query_string - assert 'limit={}'.format(limit) in query_string + # Validate body params + req_body = json.loads(str(responses.calls[0].request.body, 'utf-8')) + assert req_body['incident_severity1'] == preference_value_with_updates_model + assert req_body['incident_severity2'] == preference_value_with_updates_model + assert req_body['incident_severity3'] == preference_value_with_updates_model + assert req_body['incident_severity4'] == preference_value_with_updates_model + assert req_body['maintenance_high'] == preference_value_with_updates_model + assert req_body['maintenance_medium'] == preference_value_with_updates_model + assert req_body['maintenance_low'] == preference_value_with_updates_model + assert req_body['announcements_major'] == preference_value_without_updates_model + assert req_body['announcements_minor'] == preference_value_without_updates_model + assert req_body['security_normal'] == preference_value_without_updates_model + assert req_body['account_normal'] == preference_value_without_updates_model + assert req_body['billing_and_usage_order'] == preference_value_without_updates_model + assert req_body['billing_and_usage_invoices'] == preference_value_without_updates_model + assert req_body['billing_and_usage_payments'] == preference_value_without_updates_model + assert req_body['billing_and_usage_subscriptions_and_promo_codes'] == preference_value_without_updates_model + assert req_body['billing_and_usage_spending_alerts'] == preference_value_without_updates_model + assert req_body['resourceactivity_normal'] == preference_value_without_updates_model + assert req_body['ordering_review'] == preference_value_without_updates_model + assert req_body['ordering_approved'] == preference_value_without_updates_model + assert req_body['ordering_approved_vsi'] == preference_value_without_updates_model + assert req_body['ordering_approved_server'] == preference_value_without_updates_model + assert req_body['provisioning_reload_complete'] == preference_value_without_updates_model + assert req_body['provisioning_complete_vsi'] == preference_value_without_updates_model + assert req_body['provisioning_complete_server'] == preference_value_without_updates_model - def test_list_notifications_all_params_with_retries(self): - # Enable retries and run test_list_notifications_all_params. + def test_replace_notification_preferences_all_params_with_retries(self): + # Enable retries and run test_replace_notification_preferences_all_params. _service.enable_retries() - self.test_list_notifications_all_params() + self.test_replace_notification_preferences_all_params() - # Disable retries and run test_list_notifications_all_params. + # Disable retries and run test_replace_notification_preferences_all_params. _service.disable_retries() - self.test_list_notifications_all_params() + self.test_replace_notification_preferences_all_params() @responses.activate - def test_list_notifications_required_params(self): + def test_replace_notification_preferences_required_params(self): """ - test_list_notifications_required_params() + test_replace_notification_preferences_required_params() """ # Set up mock - url = preprocess_url('/v1/notifications') - mock_response = '{"limit": 50, "total_count": 232, "first": {"href": "https://api.example.com/v1/notifications?limit=50"}, "previous": {"href": "https://api.example.com/v1/notifications?start=3fe78a36b9aa7f26&limit=50", "start": "3fe78a36b9aa7f26"}, "next": {"href": "https://api.example.com/v1/notifications?start=3fe78a36b9aa7f26&limit=50", "start": "3fe78a36b9aa7f26"}, "last": {"href": "https://api.example.com/v1/notifications?start=3fe78a36b9aa7f26&limit=50", "start": "3fe78a36b9aa7f26"}, "notifications": [{"title": "System Maintenance Scheduled", "body": "Scheduled maintenance will occur on March 15th from 10:00 AM to 11:00 AM UTC.", "id": "12345", "category": "maintenance", "component_names": ["component_names"], "start_time": 1771791490, "is_global": false, "state": "new", "regions": ["regions"], "crn_masks": ["crn_masks"], "record_id": "rec-67890", "source_id": "src-11111", "completion_code": "successful", "end_time": 1771791490, "update_time": 1771791490, "severity": 2, "lucene_query": "region:us-south AND service_name:event-notifications", "resource_link": "https://cloud.ibm.com/status/incident/12345"}]}' + url = preprocess_url('/v1/notifications/IBMid-1234567890/preferences') + mock_response = '{"incident_severity1": {"channels": ["email"], "updates": true}, "incident_severity2": {"channels": ["email"], "updates": true}, "incident_severity3": {"channels": ["email"], "updates": true}, "incident_severity4": {"channels": ["email"], "updates": true}, "maintenance_high": {"channels": ["email"], "updates": true}, "maintenance_medium": {"channels": ["email"], "updates": true}, "maintenance_low": {"channels": ["email"], "updates": true}, "announcements_major": {"channels": ["email"]}, "announcements_minor": {"channels": ["email"]}, "security_normal": {"channels": ["email"]}, "account_normal": {"channels": ["email"]}, "billing_and_usage_order": {"channels": ["email"]}, "billing_and_usage_invoices": {"channels": ["email"]}, "billing_and_usage_payments": {"channels": ["email"]}, "billing_and_usage_subscriptions_and_promo_codes": {"channels": ["email"]}, "billing_and_usage_spending_alerts": {"channels": ["email"]}, "resourceactivity_normal": {"channels": ["email"]}, "ordering_review": {"channels": ["email"]}, "ordering_approved": {"channels": ["email"]}, "ordering_approved_vsi": {"channels": ["email"]}, "ordering_approved_server": {"channels": ["email"]}, "provisioning_reload_complete": {"channels": ["email"]}, "provisioning_complete_vsi": {"channels": ["email"]}, "provisioning_complete_server": {"channels": ["email"]}}' responses.add( - responses.GET, + responses.PUT, url, body=mock_response, content_type='application/json', status=200, ) - # Invoke method - response = _service.list_notifications() - - # Check for correct operation - assert len(responses.calls) == 1 - assert response.status_code == 200 - - def test_list_notifications_required_params_with_retries(self): - # Enable retries and run test_list_notifications_required_params. - _service.enable_retries() - self.test_list_notifications_required_params() - - # Disable retries and run test_list_notifications_required_params. - _service.disable_retries() - self.test_list_notifications_required_params() - - @responses.activate - def test_list_notifications_with_pager_get_next(self): - """ - test_list_notifications_with_pager_get_next() - """ - # Set up a two-page mock response - url = preprocess_url('/v1/notifications') - mock_response1 = '{"next":{"start":"1"},"total_count":2,"limit":1,"notifications":[{"title":"System Maintenance Scheduled","body":"Scheduled maintenance will occur on March 15th from 10:00 AM to 11:00 AM UTC.","id":"12345","category":"maintenance","component_names":["component_names"],"start_time":1771791490,"is_global":false,"state":"new","regions":["regions"],"crn_masks":["crn_masks"],"record_id":"rec-67890","source_id":"src-11111","completion_code":"successful","end_time":1771791490,"update_time":1771791490,"severity":2,"lucene_query":"region:us-south AND service_name:event-notifications","resource_link":"https://cloud.ibm.com/status/incident/12345"}]}' - mock_response2 = '{"total_count":2,"limit":1,"notifications":[{"title":"System Maintenance Scheduled","body":"Scheduled maintenance will occur on March 15th from 10:00 AM to 11:00 AM UTC.","id":"12345","category":"maintenance","component_names":["component_names"],"start_time":1771791490,"is_global":false,"state":"new","regions":["regions"],"crn_masks":["crn_masks"],"record_id":"rec-67890","source_id":"src-11111","completion_code":"successful","end_time":1771791490,"update_time":1771791490,"severity":2,"lucene_query":"region:us-south AND service_name:event-notifications","resource_link":"https://cloud.ibm.com/status/incident/12345"}]}' - responses.add( - responses.GET, - url, - body=mock_response1, - content_type='application/json', - status=200, - ) - responses.add( - responses.GET, - url, - body=mock_response2, - content_type='application/json', - status=200, - ) - - # Exercise the pager class for this operation - all_results = [] - pager = NotificationsPager( - client=_service, - account_id='a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6', - limit=50, - ) - while pager.has_next(): - next_page = pager.get_next() - assert next_page is not None - all_results.extend(next_page) - assert len(all_results) == 2 - - @responses.activate - def test_list_notifications_with_pager_get_all(self): - """ - test_list_notifications_with_pager_get_all() - """ - # Set up a two-page mock response - url = preprocess_url('/v1/notifications') - mock_response1 = '{"next":{"start":"1"},"total_count":2,"limit":1,"notifications":[{"title":"System Maintenance Scheduled","body":"Scheduled maintenance will occur on March 15th from 10:00 AM to 11:00 AM UTC.","id":"12345","category":"maintenance","component_names":["component_names"],"start_time":1771791490,"is_global":false,"state":"new","regions":["regions"],"crn_masks":["crn_masks"],"record_id":"rec-67890","source_id":"src-11111","completion_code":"successful","end_time":1771791490,"update_time":1771791490,"severity":2,"lucene_query":"region:us-south AND service_name:event-notifications","resource_link":"https://cloud.ibm.com/status/incident/12345"}]}' - mock_response2 = '{"total_count":2,"limit":1,"notifications":[{"title":"System Maintenance Scheduled","body":"Scheduled maintenance will occur on March 15th from 10:00 AM to 11:00 AM UTC.","id":"12345","category":"maintenance","component_names":["component_names"],"start_time":1771791490,"is_global":false,"state":"new","regions":["regions"],"crn_masks":["crn_masks"],"record_id":"rec-67890","source_id":"src-11111","completion_code":"successful","end_time":1771791490,"update_time":1771791490,"severity":2,"lucene_query":"region:us-south AND service_name:event-notifications","resource_link":"https://cloud.ibm.com/status/incident/12345"}]}' - responses.add( - responses.GET, - url, - body=mock_response1, - content_type='application/json', - status=200, - ) - responses.add( - responses.GET, - url, - body=mock_response2, - content_type='application/json', - status=200, - ) - - # Exercise the pager class for this operation - pager = NotificationsPager( - client=_service, - account_id='a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6', - limit=50, - ) - all_results = pager.get_all() - assert all_results is not None - assert len(all_results) == 2 - - -class TestGetAcknowledgement: - """ - Test Class for get_acknowledgement - """ + # Construct a dict representation of a PreferenceValueWithUpdates model + preference_value_with_updates_model = {} + preference_value_with_updates_model['channels'] = ['email'] + preference_value_with_updates_model['updates'] = True - @responses.activate - def test_get_acknowledgement_all_params(self): - """ - get_acknowledgement() - """ - # Set up mock - url = preprocess_url('/v1/notifications/acknowledgement') - mock_response = ( - '{"has_unread": true, "latest_notification_id": "1678901234000", "last_acknowledged_id": "1678800000000"}' - ) - responses.add( - responses.GET, - url, - body=mock_response, - content_type='application/json', - status=200, - ) + # Construct a dict representation of a PreferenceValueWithoutUpdates model + preference_value_without_updates_model = {} + preference_value_without_updates_model['channels'] = ['email'] # Set up parameter values - account_id = '1369339417d906e5620b8d861d40cfd7' + iam_id = 'IBMid-1234567890' + incident_severity1 = preference_value_with_updates_model + incident_severity2 = preference_value_with_updates_model + incident_severity3 = preference_value_with_updates_model + incident_severity4 = preference_value_with_updates_model + maintenance_high = preference_value_with_updates_model + maintenance_medium = preference_value_with_updates_model + maintenance_low = preference_value_with_updates_model + announcements_major = preference_value_without_updates_model + announcements_minor = preference_value_without_updates_model + security_normal = preference_value_without_updates_model + account_normal = preference_value_without_updates_model + billing_and_usage_order = preference_value_without_updates_model + billing_and_usage_invoices = preference_value_without_updates_model + billing_and_usage_payments = preference_value_without_updates_model + billing_and_usage_subscriptions_and_promo_codes = preference_value_without_updates_model + billing_and_usage_spending_alerts = preference_value_without_updates_model + resourceactivity_normal = preference_value_without_updates_model + ordering_review = preference_value_without_updates_model + ordering_approved = preference_value_without_updates_model + ordering_approved_vsi = preference_value_without_updates_model + ordering_approved_server = preference_value_without_updates_model + provisioning_reload_complete = preference_value_without_updates_model + provisioning_complete_vsi = preference_value_without_updates_model + provisioning_complete_server = preference_value_without_updates_model # Invoke method - response = _service.get_acknowledgement( - account_id=account_id, + response = _service.replace_notification_preferences( + iam_id, + incident_severity1=incident_severity1, + incident_severity2=incident_severity2, + incident_severity3=incident_severity3, + incident_severity4=incident_severity4, + maintenance_high=maintenance_high, + maintenance_medium=maintenance_medium, + maintenance_low=maintenance_low, + announcements_major=announcements_major, + announcements_minor=announcements_minor, + security_normal=security_normal, + account_normal=account_normal, + billing_and_usage_order=billing_and_usage_order, + billing_and_usage_invoices=billing_and_usage_invoices, + billing_and_usage_payments=billing_and_usage_payments, + billing_and_usage_subscriptions_and_promo_codes=billing_and_usage_subscriptions_and_promo_codes, + billing_and_usage_spending_alerts=billing_and_usage_spending_alerts, + resourceactivity_normal=resourceactivity_normal, + ordering_review=ordering_review, + ordering_approved=ordering_approved, + ordering_approved_vsi=ordering_approved_vsi, + ordering_approved_server=ordering_approved_server, + provisioning_reload_complete=provisioning_reload_complete, + provisioning_complete_vsi=provisioning_complete_vsi, + provisioning_complete_server=provisioning_complete_server, headers={}, ) # Check for correct operation assert len(responses.calls) == 1 assert response.status_code == 200 - # Validate query params - query_string = responses.calls[0].request.url.split('?', 1)[1] - query_string = urllib.parse.unquote_plus(query_string) - assert 'account_id={}'.format(account_id) in query_string + # Validate body params + req_body = json.loads(str(responses.calls[0].request.body, 'utf-8')) + assert req_body['incident_severity1'] == preference_value_with_updates_model + assert req_body['incident_severity2'] == preference_value_with_updates_model + assert req_body['incident_severity3'] == preference_value_with_updates_model + assert req_body['incident_severity4'] == preference_value_with_updates_model + assert req_body['maintenance_high'] == preference_value_with_updates_model + assert req_body['maintenance_medium'] == preference_value_with_updates_model + assert req_body['maintenance_low'] == preference_value_with_updates_model + assert req_body['announcements_major'] == preference_value_without_updates_model + assert req_body['announcements_minor'] == preference_value_without_updates_model + assert req_body['security_normal'] == preference_value_without_updates_model + assert req_body['account_normal'] == preference_value_without_updates_model + assert req_body['billing_and_usage_order'] == preference_value_without_updates_model + assert req_body['billing_and_usage_invoices'] == preference_value_without_updates_model + assert req_body['billing_and_usage_payments'] == preference_value_without_updates_model + assert req_body['billing_and_usage_subscriptions_and_promo_codes'] == preference_value_without_updates_model + assert req_body['billing_and_usage_spending_alerts'] == preference_value_without_updates_model + assert req_body['resourceactivity_normal'] == preference_value_without_updates_model + assert req_body['ordering_review'] == preference_value_without_updates_model + assert req_body['ordering_approved'] == preference_value_without_updates_model + assert req_body['ordering_approved_vsi'] == preference_value_without_updates_model + assert req_body['ordering_approved_server'] == preference_value_without_updates_model + assert req_body['provisioning_reload_complete'] == preference_value_without_updates_model + assert req_body['provisioning_complete_vsi'] == preference_value_without_updates_model + assert req_body['provisioning_complete_server'] == preference_value_without_updates_model - def test_get_acknowledgement_all_params_with_retries(self): - # Enable retries and run test_get_acknowledgement_all_params. + def test_replace_notification_preferences_required_params_with_retries(self): + # Enable retries and run test_replace_notification_preferences_required_params. _service.enable_retries() - self.test_get_acknowledgement_all_params() + self.test_replace_notification_preferences_required_params() - # Disable retries and run test_get_acknowledgement_all_params. + # Disable retries and run test_replace_notification_preferences_required_params. _service.disable_retries() - self.test_get_acknowledgement_all_params() + self.test_replace_notification_preferences_required_params() @responses.activate - def test_get_acknowledgement_required_params(self): + def test_replace_notification_preferences_value_error(self): """ - test_get_acknowledgement_required_params() + test_replace_notification_preferences_value_error() """ # Set up mock - url = preprocess_url('/v1/notifications/acknowledgement') - mock_response = ( - '{"has_unread": true, "latest_notification_id": "1678901234000", "last_acknowledged_id": "1678800000000"}' - ) + url = preprocess_url('/v1/notifications/IBMid-1234567890/preferences') + mock_response = '{"incident_severity1": {"channels": ["email"], "updates": true}, "incident_severity2": {"channels": ["email"], "updates": true}, "incident_severity3": {"channels": ["email"], "updates": true}, "incident_severity4": {"channels": ["email"], "updates": true}, "maintenance_high": {"channels": ["email"], "updates": true}, "maintenance_medium": {"channels": ["email"], "updates": true}, "maintenance_low": {"channels": ["email"], "updates": true}, "announcements_major": {"channels": ["email"]}, "announcements_minor": {"channels": ["email"]}, "security_normal": {"channels": ["email"]}, "account_normal": {"channels": ["email"]}, "billing_and_usage_order": {"channels": ["email"]}, "billing_and_usage_invoices": {"channels": ["email"]}, "billing_and_usage_payments": {"channels": ["email"]}, "billing_and_usage_subscriptions_and_promo_codes": {"channels": ["email"]}, "billing_and_usage_spending_alerts": {"channels": ["email"]}, "resourceactivity_normal": {"channels": ["email"]}, "ordering_review": {"channels": ["email"]}, "ordering_approved": {"channels": ["email"]}, "ordering_approved_vsi": {"channels": ["email"]}, "ordering_approved_server": {"channels": ["email"]}, "provisioning_reload_complete": {"channels": ["email"]}, "provisioning_complete_vsi": {"channels": ["email"]}, "provisioning_complete_server": {"channels": ["email"]}}' responses.add( - responses.GET, + responses.PUT, url, body=mock_response, content_type='application/json', status=200, ) - # Invoke method - response = _service.get_acknowledgement() + # Construct a dict representation of a PreferenceValueWithUpdates model + preference_value_with_updates_model = {} + preference_value_with_updates_model['channels'] = ['email'] + preference_value_with_updates_model['updates'] = True - # Check for correct operation - assert len(responses.calls) == 1 - assert response.status_code == 200 + # Construct a dict representation of a PreferenceValueWithoutUpdates model + preference_value_without_updates_model = {} + preference_value_without_updates_model['channels'] = ['email'] - def test_get_acknowledgement_required_params_with_retries(self): - # Enable retries and run test_get_acknowledgement_required_params. + # Set up parameter values + iam_id = 'IBMid-1234567890' + incident_severity1 = preference_value_with_updates_model + incident_severity2 = preference_value_with_updates_model + incident_severity3 = preference_value_with_updates_model + incident_severity4 = preference_value_with_updates_model + maintenance_high = preference_value_with_updates_model + maintenance_medium = preference_value_with_updates_model + maintenance_low = preference_value_with_updates_model + announcements_major = preference_value_without_updates_model + announcements_minor = preference_value_without_updates_model + security_normal = preference_value_without_updates_model + account_normal = preference_value_without_updates_model + billing_and_usage_order = preference_value_without_updates_model + billing_and_usage_invoices = preference_value_without_updates_model + billing_and_usage_payments = preference_value_without_updates_model + billing_and_usage_subscriptions_and_promo_codes = preference_value_without_updates_model + billing_and_usage_spending_alerts = preference_value_without_updates_model + resourceactivity_normal = preference_value_without_updates_model + ordering_review = preference_value_without_updates_model + ordering_approved = preference_value_without_updates_model + ordering_approved_vsi = preference_value_without_updates_model + ordering_approved_server = preference_value_without_updates_model + provisioning_reload_complete = preference_value_without_updates_model + provisioning_complete_vsi = preference_value_without_updates_model + provisioning_complete_server = preference_value_without_updates_model + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "iam_id": iam_id, + } + for param in req_param_dict.keys(): + req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} + with pytest.raises(ValueError): + _service.replace_notification_preferences(**req_copy) + + def test_replace_notification_preferences_value_error_with_retries(self): + # Enable retries and run test_replace_notification_preferences_value_error. _service.enable_retries() - self.test_get_acknowledgement_required_params() + self.test_replace_notification_preferences_value_error() - # Disable retries and run test_get_acknowledgement_required_params. + # Disable retries and run test_replace_notification_preferences_value_error. _service.disable_retries() - self.test_get_acknowledgement_required_params() + self.test_replace_notification_preferences_value_error() -class TestReplaceNotificationAcknowledgement: +class TestDeleteNotificationPreferences: """ - Test Class for replace_notification_acknowledgement + Test Class for delete_notification_preferences """ @responses.activate - def test_replace_notification_acknowledgement_all_params(self): + def test_delete_notification_preferences_all_params(self): """ - replace_notification_acknowledgement() + delete_notification_preferences() """ # Set up mock - url = preprocess_url('/v1/notifications/acknowledgement') - mock_response = ( - '{"has_unread": true, "latest_notification_id": "1678901234000", "last_acknowledged_id": "1678800000000"}' - ) + url = preprocess_url('/v1/notifications/IBMid-1234567890/preferences') responses.add( - responses.PUT, + responses.DELETE, url, - body=mock_response, - content_type='application/json', - status=200, + status=204, ) # Set up parameter values - last_acknowledged_id = '1772804159452' - account_id = '1369339417d906e5620b8d861d40cfd7' + iam_id = 'IBMid-1234567890' + account_id = 'a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6' # Invoke method - response = _service.replace_notification_acknowledgement( - last_acknowledged_id, + response = _service.delete_notification_preferences( + iam_id, account_id=account_id, headers={}, ) # Check for correct operation assert len(responses.calls) == 1 - assert response.status_code == 200 + assert response.status_code == 204 # Validate query params query_string = responses.calls[0].request.url.split('?', 1)[1] query_string = urllib.parse.unquote_plus(query_string) assert 'account_id={}'.format(account_id) in query_string - # Validate body params - req_body = json.loads(str(responses.calls[0].request.body, 'utf-8')) - assert req_body['last_acknowledged_id'] == '1772804159452' - def test_replace_notification_acknowledgement_all_params_with_retries(self): - # Enable retries and run test_replace_notification_acknowledgement_all_params. + def test_delete_notification_preferences_all_params_with_retries(self): + # Enable retries and run test_delete_notification_preferences_all_params. _service.enable_retries() - self.test_replace_notification_acknowledgement_all_params() + self.test_delete_notification_preferences_all_params() - # Disable retries and run test_replace_notification_acknowledgement_all_params. + # Disable retries and run test_delete_notification_preferences_all_params. _service.disable_retries() - self.test_replace_notification_acknowledgement_all_params() + self.test_delete_notification_preferences_all_params() @responses.activate - def test_replace_notification_acknowledgement_required_params(self): + def test_delete_notification_preferences_required_params(self): """ - test_replace_notification_acknowledgement_required_params() + test_delete_notification_preferences_required_params() """ # Set up mock - url = preprocess_url('/v1/notifications/acknowledgement') - mock_response = ( - '{"has_unread": true, "latest_notification_id": "1678901234000", "last_acknowledged_id": "1678800000000"}' - ) + url = preprocess_url('/v1/notifications/IBMid-1234567890/preferences') responses.add( - responses.PUT, + responses.DELETE, url, - body=mock_response, - content_type='application/json', - status=200, + status=204, ) # Set up parameter values - last_acknowledged_id = '1772804159452' + iam_id = 'IBMid-1234567890' # Invoke method - response = _service.replace_notification_acknowledgement( - last_acknowledged_id, + response = _service.delete_notification_preferences( + iam_id, headers={}, ) # Check for correct operation assert len(responses.calls) == 1 - assert response.status_code == 200 - # Validate body params - req_body = json.loads(str(responses.calls[0].request.body, 'utf-8')) - assert req_body['last_acknowledged_id'] == '1772804159452' + assert response.status_code == 204 - def test_replace_notification_acknowledgement_required_params_with_retries(self): - # Enable retries and run test_replace_notification_acknowledgement_required_params. + def test_delete_notification_preferences_required_params_with_retries(self): + # Enable retries and run test_delete_notification_preferences_required_params. _service.enable_retries() - self.test_replace_notification_acknowledgement_required_params() + self.test_delete_notification_preferences_required_params() - # Disable retries and run test_replace_notification_acknowledgement_required_params. + # Disable retries and run test_delete_notification_preferences_required_params. _service.disable_retries() - self.test_replace_notification_acknowledgement_required_params() + self.test_delete_notification_preferences_required_params() @responses.activate - def test_replace_notification_acknowledgement_value_error(self): + def test_delete_notification_preferences_value_error(self): """ - test_replace_notification_acknowledgement_value_error() + test_delete_notification_preferences_value_error() """ # Set up mock - url = preprocess_url('/v1/notifications/acknowledgement') - mock_response = ( - '{"has_unread": true, "latest_notification_id": "1678901234000", "last_acknowledged_id": "1678800000000"}' - ) + url = preprocess_url('/v1/notifications/IBMid-1234567890/preferences') responses.add( - responses.PUT, + responses.DELETE, url, - body=mock_response, - content_type='application/json', - status=200, + status=204, ) # Set up parameter values - last_acknowledged_id = '1772804159452' + iam_id = 'IBMid-1234567890' # Pass in all but one required param and check for a ValueError req_param_dict = { - "last_acknowledged_id": last_acknowledged_id, + "iam_id": iam_id, } for param in req_param_dict.keys(): req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} with pytest.raises(ValueError): - _service.replace_notification_acknowledgement(**req_copy) + _service.delete_notification_preferences(**req_copy) - def test_replace_notification_acknowledgement_value_error_with_retries(self): - # Enable retries and run test_replace_notification_acknowledgement_value_error. + def test_delete_notification_preferences_value_error_with_retries(self): + # Enable retries and run test_delete_notification_preferences_value_error. _service.enable_retries() - self.test_replace_notification_acknowledgement_value_error() + self.test_delete_notification_preferences_value_error() - # Disable retries and run test_replace_notification_acknowledgement_value_error. + # Disable retries and run test_delete_notification_preferences_value_error. _service.disable_retries() - self.test_replace_notification_acknowledgement_value_error() + self.test_delete_notification_preferences_value_error() # endregion ############################################################################## -# End of Service: Notifications +# End of Service: UserPreferences ############################################################################## @@ -1909,6 +1899,37 @@ def test_replace_notification_acknowledgement_value_error_with_retries(self): # region +class TestModel_Acknowledgement: + """ + Test Class for Acknowledgement + """ + + def test_acknowledgement_serialization(self): + """ + Test serialization/deserialization for Acknowledgement + """ + + # Construct a json representation of a Acknowledgement model + acknowledgement_model_json = {} + acknowledgement_model_json['has_unread'] = True + acknowledgement_model_json['last_acknowledged'] = 1772804159452 + + # Construct a model instance of Acknowledgement by calling from_dict on the json representation + acknowledgement_model = Acknowledgement.from_dict(acknowledgement_model_json) + assert acknowledgement_model != False + + # Construct a model instance of Acknowledgement by calling from_dict on the json representation + acknowledgement_model_dict = Acknowledgement.from_dict(acknowledgement_model_json).__dict__ + acknowledgement_model2 = Acknowledgement(**acknowledgement_model_dict) + + # Verify the model instances are equivalent + assert acknowledgement_model == acknowledgement_model2 + + # Convert model instance back to dict and verify no loss of data + acknowledgement_model_json2 = acknowledgement_model.to_dict() + assert acknowledgement_model_json2 == acknowledgement_model_json + + class TestModel_AddDestinationCollection: """ Test Class for AddDestinationCollection @@ -1979,6 +2000,7 @@ def test_notification_serialization(self): notification_model_json['severity'] = 2 notification_model_json['lucene_query'] = 'region:us-south AND service_name:event-notifications' notification_model_json['resource_link'] = 'https://cloud.ibm.com/status/incident/12345' + notification_model_json['creation_timestamp'] = 1772804159452 # Construct a model instance of Notification by calling from_dict on the json representation notification_model = Notification.from_dict(notification_model_json) @@ -2009,11 +2031,11 @@ def test_notification_collection_serialization(self): # Construct dict forms of any model objects needed in order to build this model. pagination_link_model = {} # PaginationLink - pagination_link_model['href'] = 'https://api.example.com/v1/notifications?limit=50' + pagination_link_model['href'] = 'https://notifications.cloud.ibm.com/api/v1/notifications?limit=50' pagination_link_with_token_model = {} # PaginationLinkWithToken pagination_link_with_token_model['href'] = ( - 'https://api.example.com/v1/notifications?start=3fe78a36b9aa7f26&limit=50' + 'https://notifications.cloud.ibm.com/api/v1/notifications?start=3fe78a36b9aa7f26&limit=50' ) pagination_link_with_token_model['start'] = '3fe78a36b9aa7f26' @@ -2036,6 +2058,7 @@ def test_notification_collection_serialization(self): notification_model['severity'] = 2 notification_model['lucene_query'] = 'region:us-south AND service_name:event-notifications' notification_model['resource_link'] = 'https://cloud.ibm.com/status/incident/12345' + notification_model['creation_timestamp'] = 1772804159452 # Construct a json representation of a NotificationCollection model notification_collection_model_json = {} @@ -2077,7 +2100,7 @@ def test_pagination_link_serialization(self): # Construct a json representation of a PaginationLink model pagination_link_model_json = {} - pagination_link_model_json['href'] = 'https://api.example.com/v1/notifications?limit=50' + pagination_link_model_json['href'] = 'https://notifications.cloud.ibm.com/api/v1/notifications?limit=50' # Construct a model instance of PaginationLink by calling from_dict on the json representation pagination_link_model = PaginationLink.from_dict(pagination_link_model_json) @@ -2108,7 +2131,7 @@ def test_pagination_link_with_token_serialization(self): # Construct a json representation of a PaginationLinkWithToken model pagination_link_with_token_model_json = {} pagination_link_with_token_model_json['href'] = ( - 'https://api.example.com/v1/notifications?start=3fe78a36b9aa7f26&limit=50' + 'https://notifications.cloud.ibm.com/api/v1/notifications?start=3fe78a36b9aa7f26&limit=50' ) pagination_link_with_token_model_json['start'] = '3fe78a36b9aa7f26' @@ -2299,38 +2322,6 @@ def test_test_destination_response_body_serialization(self): assert test_destination_response_body_model_json2 == test_destination_response_body_model_json -class TestModel_Acknowledgement: - """ - Test Class for Acknowledgement - """ - - def test_acknowledgement_serialization(self): - """ - Test serialization/deserialization for Acknowledgement - """ - - # Construct a json representation of a Acknowledgement model - acknowledgement_model_json = {} - acknowledgement_model_json['has_unread'] = True - acknowledgement_model_json['latest_notification_id'] = '1678901234000' - acknowledgement_model_json['last_acknowledged_id'] = '1678800000000' - - # Construct a model instance of Acknowledgement by calling from_dict on the json representation - acknowledgement_model = Acknowledgement.from_dict(acknowledgement_model_json) - assert acknowledgement_model != False - - # Construct a model instance of Acknowledgement by calling from_dict on the json representation - acknowledgement_model_dict = Acknowledgement.from_dict(acknowledgement_model_json).__dict__ - acknowledgement_model2 = Acknowledgement(**acknowledgement_model_dict) - - # Verify the model instances are equivalent - assert acknowledgement_model == acknowledgement_model2 - - # Convert model instance back to dict and verify no loss of data - acknowledgement_model_json2 = acknowledgement_model.to_dict() - assert acknowledgement_model_json2 == acknowledgement_model_json - - class TestModel_AddDestinationPrototypeEventNotificationDestinationPrototype: """ Test Class for AddDestinationPrototypeEventNotificationDestinationPrototype From 4508fc03a95030ce1c49b56753cff2830bda80df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81kos=20Sztremi?= Date: Thu, 25 Jun 2026 12:46:32 +0200 Subject: [PATCH 8/8] fix: update required vars MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ákos Sztremi --- examples/test_platform_notifications_v1_examples.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/examples/test_platform_notifications_v1_examples.py b/examples/test_platform_notifications_v1_examples.py index 19d0d69a..088c350a 100644 --- a/examples/test_platform_notifications_v1_examples.py +++ b/examples/test_platform_notifications_v1_examples.py @@ -26,10 +26,14 @@ # This file provides an example of how to use the Platform Notifications service. # # The following configuration properties are assumed to be defined: -# PLATFORM_NOTIFICATIONS_URL= +# PLATFORM_NOTIFICATIONS_IAM_PROFILE_ID= # PLATFORM_NOTIFICATIONS_AUTH_TYPE=iam -# PLATFORM_NOTIFICATIONS_APIKEY= +# PLATFORM_NOTIFICATIONS_APIKEY= # PLATFORM_NOTIFICATIONS_AUTH_URL= +# PLATFORM_NOTIFICATIONS_ACCOUNT_ID= +# PLATFORM_NOTIFICATIONS_DESTINATION_ID= +# PLATFORM_NOTIFICATIONS_IAM_ID= +# PLATFORM_NOTIFICATIONS_SERVICE_URL= # # These configuration properties can be exported as environment variables, or stored # in a configuration file and then: