diff --git a/examples/test_context_based_restrictions_v1_examples.py b/examples/test_context_based_restrictions_v1_examples.py index a94e804a..1b2ffc2a 100644 --- a/examples/test_context_based_restrictions_v1_examples.py +++ b/examples/test_context_based_restrictions_v1_examples.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# (C) Copyright IBM Corp. 2022. +# (C) Copyright IBM Corp. 2023. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -34,6 +34,7 @@ # CONTEXT_BASED_RESTRICTIONS_TEST_SERVICE_NAME= # CONTEXT_BASED_RESTRICTIONS_TEST_VPC_CRN= # +# # These configuration properties can be exported as environment variables, or stored # in a configuration file and then: # export IBM_CREDENTIALS_FILE= @@ -52,7 +53,6 @@ rule_id = None rule_rev = None - ############################################################################## # Start of Examples for Service: ContextBasedRestrictionsV1 ############################################################################## @@ -131,7 +131,7 @@ def test_create_zone_example(self): 'value': '169.23.22.127', } - zone = context_based_restrictions_service.create_zone( + response = context_based_restrictions_service.create_zone( name='an example of zone', account_id=account_id, addresses=[ @@ -141,9 +141,10 @@ def test_create_zone_example(self): vpc_address_model, service_ref_address_model, ], - excluded=[excluded_ip_address_model], description='this is an example of zone', - ).get_result() + excluded=[excluded_ip_address_model], + ) + zone = response.get_result() print(json.dumps(zone, indent=2)) @@ -163,7 +164,10 @@ def test_list_zones_example(self): print('\nlist_zones() result:') # begin-list_zones - zone_list = context_based_restrictions_service.list_zones(account_id=account_id).get_result() + response = context_based_restrictions_service.list_zones( + account_id=account_id, + ) + zone_list = response.get_result() print(json.dumps(zone_list, indent=2)) @@ -181,14 +185,16 @@ def test_get_zone_example(self): print('\nget_zone() result:') # begin-get_zone - get_zone_response = context_based_restrictions_service.get_zone(zone_id=zone_id) - zone = get_zone_response.get_result() + response = context_based_restrictions_service.get_zone( + zone_id=zone_id, + ) + zone = response.get_result() print(json.dumps(zone, indent=2)) # end-get_zone global zone_rev - zone_rev = get_zone_response.headers.get("ETag") + zone_rev = response.headers.get("ETag") except ApiException as e: pytest.fail(str(e)) @@ -207,14 +213,15 @@ def test_replace_zone_example(self): 'value': '169.23.56.234', } - zone = context_based_restrictions_service.replace_zone( + response = context_based_restrictions_service.replace_zone( zone_id=zone_id, if_match=zone_rev, - name='an example of updated zone', + name='an example of zone', account_id=account_id, addresses=[address_model], - description='this is an example of updated zone', - ).get_result() + description='this is an example of zone', + ) + zone = response.get_result() print(json.dumps(zone, indent=2)) @@ -232,9 +239,8 @@ def test_list_available_serviceref_targets_example(self): print('\nlist_available_serviceref_targets() result:') # begin-list_available_serviceref_targets - service_ref_target_list = ( - context_based_restrictions_service.list_available_serviceref_targets().get_result() - ) + response = context_based_restrictions_service.list_available_serviceref_targets() + service_ref_target_list = response.get_result() print(json.dumps(service_ref_target_list, indent=2)) @@ -261,7 +267,7 @@ def test_create_rule_example(self): 'attributes': [rule_context_attribute_model], } - resource_attribute_account_id_model = { + resource_attribute_model = { 'name': 'accountId', 'value': account_id, } @@ -272,15 +278,16 @@ def test_create_rule_example(self): } resource_model = { - 'attributes': [resource_attribute_account_id_model, resource_attribute_service_name_model], + 'attributes': [resource_attribute_model, resource_attribute_service_name_model], } - rule = context_based_restrictions_service.create_rule( + response = context_based_restrictions_service.create_rule( contexts=[rule_context_model], resources=[resource_model], description='this is an example of rule', enforcement_mode='enabled', - ).get_result() + ) + rule = response.get_result() print(json.dumps(rule, indent=2)) @@ -300,7 +307,10 @@ def test_list_rules_example(self): print('\nlist_rules() result:') # begin-list_rules - rule_list = context_based_restrictions_service.list_rules(account_id=account_id).get_result() + response = context_based_restrictions_service.list_rules( + account_id=account_id, + ) + rule_list = response.get_result() print(json.dumps(rule_list, indent=2)) @@ -318,14 +328,16 @@ def test_get_rule_example(self): print('\nget_rule() result:') # begin-get_rule - get_rule_response = context_based_restrictions_service.get_rule(rule_id=rule_id) - rule = get_rule_response.get_result() + response = context_based_restrictions_service.get_rule( + rule_id=rule_id, + ) + rule = response.get_result() print(json.dumps(rule, indent=2)) # end-get_rule global rule_rev - rule_rev = get_rule_response.headers.get("ETag") + rule_rev = response.headers.get("ETag") except ApiException as e: pytest.fail(str(e)) @@ -348,7 +360,7 @@ def test_replace_rule_example(self): 'attributes': [rule_context_attribute_model], } - resource_attribute_account_id_model = { + resource_attribute_model = { 'name': 'accountId', 'value': account_id, } @@ -364,18 +376,19 @@ def test_replace_rule_example(self): } resource_model = { - 'attributes': [resource_attribute_account_id_model, resource_attribute_service_name_model], + 'attributes': [resource_attribute_model, resource_attribute_service_name_model], 'tags': [resource_tag_attribute_model], } - rule = context_based_restrictions_service.replace_rule( + response = context_based_restrictions_service.replace_rule( rule_id=rule_id, if_match=rule_rev, contexts=[rule_context_model], resources=[resource_model], description='this is an example of updated rule', enforcement_mode='disabled', - ).get_result() + ) + rule = response.get_result() print(json.dumps(rule, indent=2)) @@ -393,9 +406,10 @@ def test_get_account_settings_example(self): print('\nget_account_settings() result:') # begin-get_account_settings - account_settings = context_based_restrictions_service.get_account_settings( - account_id=account_id - ).get_result() + response = context_based_restrictions_service.get_account_settings( + account_id=account_id, + ) + account_settings = response.get_result() print(json.dumps(account_settings, indent=2)) @@ -432,7 +446,9 @@ def test_delete_rule_example(self): try: # begin-delete_rule - response = context_based_restrictions_service.delete_rule(rule_id=rule_id) + response = context_based_restrictions_service.delete_rule( + rule_id=rule_id, + ) # end-delete_rule print('\ndelete_rule() response status code: ', response.get_status_code()) @@ -448,7 +464,9 @@ def test_delete_zone_example(self): try: # begin-delete_zone - response = context_based_restrictions_service.delete_zone(zone_id=zone_id) + response = context_based_restrictions_service.delete_zone( + zone_id=zone_id, + ) # end-delete_zone print('\ndelete_zone() response status code: ', response.get_status_code()) diff --git a/ibm_platform_services/context_based_restrictions_v1.py b/ibm_platform_services/context_based_restrictions_v1.py index f9a110d5..4ca2c4d7 100644 --- a/ibm_platform_services/context_based_restrictions_v1.py +++ b/ibm_platform_services/context_based_restrictions_v1.py @@ -1,6 +1,6 @@ # coding: utf-8 -# (C) Copyright IBM Corp. 2022. +# (C) Copyright IBM Corp. 2023. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,7 +14,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -# IBM OpenAPI SDK Code Generator Version: 3.57.1-4c556507-20220928-143422 +# IBM OpenAPI SDK Code Generator Version: 3.79.0-2eb6af3d-20230905-174838 """ With the Context Based Restrictions API, you can: @@ -90,7 +90,7 @@ def create_zone( excluded: List['Address'] = None, x_correlation_id: str = None, transaction_id: str = None, - **kwargs + **kwargs, ) -> DetailedResponse: """ Create a network zone. @@ -110,9 +110,9 @@ def create_zone( the corresponding response. The same value is used for downstream requests and retries of those requests. If a value of this headers is not supplied in a request, the service generates a random (version 4) UUID. - :param str transaction_id: (optional) The `Transaction-Id` header behaves - as the `X-Correlation-Id` header. It is supported for backward - compatibility with other IBM platform services that support the + :param str transaction_id: (optional) Deprecated: The `Transaction-Id` + header behaves as the `X-Correlation-Id` header. It is supported for + backward compatibility with other IBM platform services that support the `Transaction-Id` header only. If both `X-Correlation-Id` and `Transaction-Id` are provided, `X-Correlation-Id` has the precedence over `Transaction-Id`. @@ -125,9 +125,14 @@ def create_zone( addresses = [convert_model(x) for x in addresses] if excluded is not None: excluded = [convert_model(x) for x in excluded] - headers = {'X-Correlation-Id': x_correlation_id, 'Transaction-Id': transaction_id} + headers = { + 'X-Correlation-Id': x_correlation_id, + 'Transaction-Id': transaction_id, + } sdk_headers = get_sdk_headers( - service_name=self.DEFAULT_SERVICE_NAME, service_version='V1', operation_id='create_zone' + service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='create_zone', ) headers.update(sdk_headers) @@ -148,7 +153,12 @@ def create_zone( headers['Accept'] = 'application/json' url = '/v1/zones' - request = self.prepare_request(method='POST', url=url, headers=headers, data=data) + request = self.prepare_request( + method='POST', + url=url, + headers=headers, + data=data, + ) response = self.send(request, **kwargs) return response @@ -161,7 +171,7 @@ def list_zones( transaction_id: str = None, name: str = None, sort: str = None, - **kwargs + **kwargs, ) -> DetailedResponse: """ List network zones. @@ -174,9 +184,9 @@ def list_zones( the corresponding response. The same value is used for downstream requests and retries of those requests. If a value of this headers is not supplied in a request, the service generates a random (version 4) UUID. - :param str transaction_id: (optional) The `Transaction-Id` header behaves - as the `X-Correlation-Id` header. It is supported for backward - compatibility with other IBM platform services that support the + :param str transaction_id: (optional) Deprecated: The `Transaction-Id` + header behaves as the `X-Correlation-Id` header. It is supported for + backward compatibility with other IBM platform services that support the `Transaction-Id` header only. If both `X-Correlation-Id` and `Transaction-Id` are provided, `X-Correlation-Id` has the precedence over `Transaction-Id`. @@ -189,15 +199,24 @@ def list_zones( :rtype: DetailedResponse with `dict` result representing a `ZoneList` object """ - if account_id is None: + if not account_id: raise ValueError('account_id must be provided') - headers = {'X-Correlation-Id': x_correlation_id, 'Transaction-Id': transaction_id} + headers = { + 'X-Correlation-Id': x_correlation_id, + 'Transaction-Id': transaction_id, + } sdk_headers = get_sdk_headers( - service_name=self.DEFAULT_SERVICE_NAME, service_version='V1', operation_id='list_zones' + service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='list_zones', ) headers.update(sdk_headers) - params = {'account_id': account_id, 'name': name, 'sort': sort} + params = { + 'account_id': account_id, + 'name': name, + 'sort': sort, + } if 'headers' in kwargs: headers.update(kwargs.get('headers')) @@ -205,13 +224,23 @@ def list_zones( headers['Accept'] = 'application/json' url = '/v1/zones' - request = self.prepare_request(method='GET', url=url, headers=headers, params=params) + request = self.prepare_request( + method='GET', + url=url, + headers=headers, + params=params, + ) response = self.send(request, **kwargs) return response def get_zone( - self, zone_id: str, *, x_correlation_id: str = None, transaction_id: str = None, **kwargs + self, + zone_id: str, + *, + x_correlation_id: str = None, + transaction_id: str = None, + **kwargs, ) -> DetailedResponse: """ Get a network zone. @@ -224,9 +253,9 @@ def get_zone( the corresponding response. The same value is used for downstream requests and retries of those requests. If a value of this headers is not supplied in a request, the service generates a random (version 4) UUID. - :param str transaction_id: (optional) The `Transaction-Id` header behaves - as the `X-Correlation-Id` header. It is supported for backward - compatibility with other IBM platform services that support the + :param str transaction_id: (optional) Deprecated: The `Transaction-Id` + header behaves as the `X-Correlation-Id` header. It is supported for + backward compatibility with other IBM platform services that support the `Transaction-Id` header only. If both `X-Correlation-Id` and `Transaction-Id` are provided, `X-Correlation-Id` has the precedence over `Transaction-Id`. @@ -235,11 +264,16 @@ def get_zone( :rtype: DetailedResponse with `dict` result representing a `Zone` object """ - if zone_id is None: + if not zone_id: raise ValueError('zone_id must be provided') - headers = {'X-Correlation-Id': x_correlation_id, 'Transaction-Id': transaction_id} + headers = { + 'X-Correlation-Id': x_correlation_id, + 'Transaction-Id': transaction_id, + } sdk_headers = get_sdk_headers( - service_name=self.DEFAULT_SERVICE_NAME, service_version='V1', operation_id='get_zone' + service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='get_zone', ) headers.update(sdk_headers) @@ -252,7 +286,11 @@ def get_zone( path_param_values = self.encode_path_vars(zone_id) path_param_dict = dict(zip(path_param_keys, path_param_values)) url = '/v1/zones/{zone_id}'.format(**path_param_dict) - request = self.prepare_request(method='GET', url=url, headers=headers) + request = self.prepare_request( + method='GET', + url=url, + headers=headers, + ) response = self.send(request, **kwargs) return response @@ -269,7 +307,7 @@ def replace_zone( excluded: List['Address'] = None, x_correlation_id: str = None, transaction_id: str = None, - **kwargs + **kwargs, ) -> DetailedResponse: """ Replace a network zone. @@ -294,9 +332,9 @@ def replace_zone( the corresponding response. The same value is used for downstream requests and retries of those requests. If a value of this headers is not supplied in a request, the service generates a random (version 4) UUID. - :param str transaction_id: (optional) The `Transaction-Id` header behaves - as the `X-Correlation-Id` header. It is supported for backward - compatibility with other IBM platform services that support the + :param str transaction_id: (optional) Deprecated: The `Transaction-Id` + header behaves as the `X-Correlation-Id` header. It is supported for + backward compatibility with other IBM platform services that support the `Transaction-Id` header only. If both `X-Correlation-Id` and `Transaction-Id` are provided, `X-Correlation-Id` has the precedence over `Transaction-Id`. @@ -305,17 +343,23 @@ def replace_zone( :rtype: DetailedResponse with `dict` result representing a `Zone` object """ - if zone_id is None: + if not zone_id: raise ValueError('zone_id must be provided') - if if_match is None: + if not if_match: raise ValueError('if_match must be provided') if addresses is not None: addresses = [convert_model(x) for x in addresses] if excluded is not None: excluded = [convert_model(x) for x in excluded] - headers = {'If-Match': if_match, 'X-Correlation-Id': x_correlation_id, 'Transaction-Id': transaction_id} + headers = { + 'If-Match': if_match, + 'X-Correlation-Id': x_correlation_id, + 'Transaction-Id': transaction_id, + } sdk_headers = get_sdk_headers( - service_name=self.DEFAULT_SERVICE_NAME, service_version='V1', operation_id='replace_zone' + service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='replace_zone', ) headers.update(sdk_headers) @@ -339,13 +383,23 @@ def replace_zone( path_param_values = self.encode_path_vars(zone_id) path_param_dict = dict(zip(path_param_keys, path_param_values)) url = '/v1/zones/{zone_id}'.format(**path_param_dict) - request = self.prepare_request(method='PUT', url=url, headers=headers, data=data) + request = self.prepare_request( + method='PUT', + url=url, + headers=headers, + data=data, + ) response = self.send(request, **kwargs) return response def delete_zone( - self, zone_id: str, *, x_correlation_id: str = None, transaction_id: str = None, **kwargs + self, + zone_id: str, + *, + x_correlation_id: str = None, + transaction_id: str = None, + **kwargs, ) -> DetailedResponse: """ Delete a network zone. @@ -358,9 +412,9 @@ def delete_zone( the corresponding response. The same value is used for downstream requests and retries of those requests. If a value of this headers is not supplied in a request, the service generates a random (version 4) UUID. - :param str transaction_id: (optional) The `Transaction-Id` header behaves - as the `X-Correlation-Id` header. It is supported for backward - compatibility with other IBM platform services that support the + :param str transaction_id: (optional) Deprecated: The `Transaction-Id` + header behaves as the `X-Correlation-Id` header. It is supported for + backward compatibility with other IBM platform services that support the `Transaction-Id` header only. If both `X-Correlation-Id` and `Transaction-Id` are provided, `X-Correlation-Id` has the precedence over `Transaction-Id`. @@ -369,11 +423,16 @@ def delete_zone( :rtype: DetailedResponse """ - if zone_id is None: + if not zone_id: raise ValueError('zone_id must be provided') - headers = {'X-Correlation-Id': x_correlation_id, 'Transaction-Id': transaction_id} + headers = { + 'X-Correlation-Id': x_correlation_id, + 'Transaction-Id': transaction_id, + } sdk_headers = get_sdk_headers( - service_name=self.DEFAULT_SERVICE_NAME, service_version='V1', operation_id='delete_zone' + service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='delete_zone', ) headers.update(sdk_headers) @@ -385,13 +444,22 @@ def delete_zone( path_param_values = self.encode_path_vars(zone_id) path_param_dict = dict(zip(path_param_keys, path_param_values)) url = '/v1/zones/{zone_id}'.format(**path_param_dict) - request = self.prepare_request(method='DELETE', url=url, headers=headers) + request = self.prepare_request( + method='DELETE', + url=url, + headers=headers, + ) response = self.send(request, **kwargs) return response def list_available_serviceref_targets( - self, *, x_correlation_id: str = None, transaction_id: str = None, type: str = None, **kwargs + self, + *, + x_correlation_id: str = None, + transaction_id: str = None, + type: str = None, + **kwargs, ) -> DetailedResponse: """ List available service reference targets. @@ -403,9 +471,9 @@ def list_available_serviceref_targets( the corresponding response. The same value is used for downstream requests and retries of those requests. If a value of this headers is not supplied in a request, the service generates a random (version 4) UUID. - :param str transaction_id: (optional) The `Transaction-Id` header behaves - as the `X-Correlation-Id` header. It is supported for backward - compatibility with other IBM platform services that support the + :param str transaction_id: (optional) Deprecated: The `Transaction-Id` + header behaves as the `X-Correlation-Id` header. It is supported for + backward compatibility with other IBM platform services that support the `Transaction-Id` header only. If both `X-Correlation-Id` and `Transaction-Id` are provided, `X-Correlation-Id` has the precedence over `Transaction-Id`. @@ -415,7 +483,10 @@ def list_available_serviceref_targets( :rtype: DetailedResponse with `dict` result representing a `ServiceRefTargetList` object """ - headers = {'X-Correlation-Id': x_correlation_id, 'Transaction-Id': transaction_id} + headers = { + 'X-Correlation-Id': x_correlation_id, + 'Transaction-Id': transaction_id, + } sdk_headers = get_sdk_headers( service_name=self.DEFAULT_SERVICE_NAME, service_version='V1', @@ -423,7 +494,9 @@ def list_available_serviceref_targets( ) headers.update(sdk_headers) - params = {'type': type} + params = { + 'type': type, + } if 'headers' in kwargs: headers.update(kwargs.get('headers')) @@ -431,7 +504,12 @@ def list_available_serviceref_targets( headers['Accept'] = 'application/json' url = '/v1/zones/serviceref_targets' - request = self.prepare_request(method='GET', url=url, headers=headers, params=params) + request = self.prepare_request( + method='GET', + url=url, + headers=headers, + params=params, + ) response = self.send(request, **kwargs) return response @@ -450,7 +528,7 @@ def create_rule( enforcement_mode: str = None, x_correlation_id: str = None, transaction_id: str = None, - **kwargs + **kwargs, ) -> DetailedResponse: """ Create a rule. @@ -476,9 +554,9 @@ def create_rule( the corresponding response. The same value is used for downstream requests and retries of those requests. If a value of this headers is not supplied in a request, the service generates a random (version 4) UUID. - :param str transaction_id: (optional) The `Transaction-Id` header behaves - as the `X-Correlation-Id` header. It is supported for backward - compatibility with other IBM platform services that support the + :param str transaction_id: (optional) Deprecated: The `Transaction-Id` + header behaves as the `X-Correlation-Id` header. It is supported for + backward compatibility with other IBM platform services that support the `Transaction-Id` header only. If both `X-Correlation-Id` and `Transaction-Id` are provided, `X-Correlation-Id` has the precedence over `Transaction-Id`. @@ -493,9 +571,14 @@ def create_rule( resources = [convert_model(x) for x in resources] if operations is not None: operations = convert_model(operations) - headers = {'X-Correlation-Id': x_correlation_id, 'Transaction-Id': transaction_id} + headers = { + 'X-Correlation-Id': x_correlation_id, + 'Transaction-Id': transaction_id, + } sdk_headers = get_sdk_headers( - service_name=self.DEFAULT_SERVICE_NAME, service_version='V1', operation_id='create_rule' + service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='create_rule', ) headers.update(sdk_headers) @@ -516,7 +599,12 @@ def create_rule( headers['Accept'] = 'application/json' url = '/v1/rules' - request = self.prepare_request(method='POST', url=url, headers=headers, data=data) + request = self.prepare_request( + method='POST', + url=url, + headers=headers, + data=data, + ) response = self.send(request, **kwargs) return response @@ -537,7 +625,7 @@ def list_rules( zone_id: str = None, sort: str = None, enforcement_mode: str = None, - **kwargs + **kwargs, ) -> DetailedResponse: """ List rules. @@ -550,9 +638,9 @@ def list_rules( the corresponding response. The same value is used for downstream requests and retries of those requests. If a value of this headers is not supplied in a request, the service generates a random (version 4) UUID. - :param str transaction_id: (optional) The `Transaction-Id` header behaves - as the `X-Correlation-Id` header. It is supported for backward - compatibility with other IBM platform services that support the + :param str transaction_id: (optional) Deprecated: The `Transaction-Id` + header behaves as the `X-Correlation-Id` header. It is supported for + backward compatibility with other IBM platform services that support the `Transaction-Id` header only. If both `X-Correlation-Id` and `Transaction-Id` are provided, `X-Correlation-Id` has the precedence over `Transaction-Id`. @@ -577,11 +665,16 @@ def list_rules( :rtype: DetailedResponse with `dict` result representing a `RuleList` object """ - if account_id is None: + if not account_id: raise ValueError('account_id must be provided') - headers = {'X-Correlation-Id': x_correlation_id, 'Transaction-Id': transaction_id} + headers = { + 'X-Correlation-Id': x_correlation_id, + 'Transaction-Id': transaction_id, + } sdk_headers = get_sdk_headers( - service_name=self.DEFAULT_SERVICE_NAME, service_version='V1', operation_id='list_rules' + service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='list_rules', ) headers.update(sdk_headers) @@ -605,13 +698,23 @@ def list_rules( headers['Accept'] = 'application/json' url = '/v1/rules' - request = self.prepare_request(method='GET', url=url, headers=headers, params=params) + request = self.prepare_request( + method='GET', + url=url, + headers=headers, + params=params, + ) response = self.send(request, **kwargs) return response def get_rule( - self, rule_id: str, *, x_correlation_id: str = None, transaction_id: str = None, **kwargs + self, + rule_id: str, + *, + x_correlation_id: str = None, + transaction_id: str = None, + **kwargs, ) -> DetailedResponse: """ Get a rule. @@ -624,9 +727,9 @@ def get_rule( the corresponding response. The same value is used for downstream requests and retries of those requests. If a value of this headers is not supplied in a request, the service generates a random (version 4) UUID. - :param str transaction_id: (optional) The `Transaction-Id` header behaves - as the `X-Correlation-Id` header. It is supported for backward - compatibility with other IBM platform services that support the + :param str transaction_id: (optional) Deprecated: The `Transaction-Id` + header behaves as the `X-Correlation-Id` header. It is supported for + backward compatibility with other IBM platform services that support the `Transaction-Id` header only. If both `X-Correlation-Id` and `Transaction-Id` are provided, `X-Correlation-Id` has the precedence over `Transaction-Id`. @@ -635,11 +738,16 @@ def get_rule( :rtype: DetailedResponse with `dict` result representing a `Rule` object """ - if rule_id is None: + if not rule_id: raise ValueError('rule_id must be provided') - headers = {'X-Correlation-Id': x_correlation_id, 'Transaction-Id': transaction_id} + headers = { + 'X-Correlation-Id': x_correlation_id, + 'Transaction-Id': transaction_id, + } sdk_headers = get_sdk_headers( - service_name=self.DEFAULT_SERVICE_NAME, service_version='V1', operation_id='get_rule' + service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='get_rule', ) headers.update(sdk_headers) @@ -652,7 +760,11 @@ def get_rule( path_param_values = self.encode_path_vars(rule_id) path_param_dict = dict(zip(path_param_keys, path_param_values)) url = '/v1/rules/{rule_id}'.format(**path_param_dict) - request = self.prepare_request(method='GET', url=url, headers=headers) + request = self.prepare_request( + method='GET', + url=url, + headers=headers, + ) response = self.send(request, **kwargs) return response @@ -669,7 +781,7 @@ def replace_rule( enforcement_mode: str = None, x_correlation_id: str = None, transaction_id: str = None, - **kwargs + **kwargs, ) -> DetailedResponse: """ Replace a rule. @@ -699,9 +811,9 @@ def replace_rule( the corresponding response. The same value is used for downstream requests and retries of those requests. If a value of this headers is not supplied in a request, the service generates a random (version 4) UUID. - :param str transaction_id: (optional) The `Transaction-Id` header behaves - as the `X-Correlation-Id` header. It is supported for backward - compatibility with other IBM platform services that support the + :param str transaction_id: (optional) Deprecated: The `Transaction-Id` + header behaves as the `X-Correlation-Id` header. It is supported for + backward compatibility with other IBM platform services that support the `Transaction-Id` header only. If both `X-Correlation-Id` and `Transaction-Id` are provided, `X-Correlation-Id` has the precedence over `Transaction-Id`. @@ -710,9 +822,9 @@ def replace_rule( :rtype: DetailedResponse with `dict` result representing a `Rule` object """ - if rule_id is None: + if not rule_id: raise ValueError('rule_id must be provided') - if if_match is None: + if not if_match: raise ValueError('if_match must be provided') if contexts is not None: contexts = [convert_model(x) for x in contexts] @@ -720,9 +832,15 @@ def replace_rule( resources = [convert_model(x) for x in resources] if operations is not None: operations = convert_model(operations) - headers = {'If-Match': if_match, 'X-Correlation-Id': x_correlation_id, 'Transaction-Id': transaction_id} + headers = { + 'If-Match': if_match, + 'X-Correlation-Id': x_correlation_id, + 'Transaction-Id': transaction_id, + } sdk_headers = get_sdk_headers( - service_name=self.DEFAULT_SERVICE_NAME, service_version='V1', operation_id='replace_rule' + service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='replace_rule', ) headers.update(sdk_headers) @@ -746,13 +864,23 @@ def replace_rule( path_param_values = self.encode_path_vars(rule_id) path_param_dict = dict(zip(path_param_keys, path_param_values)) url = '/v1/rules/{rule_id}'.format(**path_param_dict) - request = self.prepare_request(method='PUT', url=url, headers=headers, data=data) + request = self.prepare_request( + method='PUT', + url=url, + headers=headers, + data=data, + ) response = self.send(request, **kwargs) return response def delete_rule( - self, rule_id: str, *, x_correlation_id: str = None, transaction_id: str = None, **kwargs + self, + rule_id: str, + *, + x_correlation_id: str = None, + transaction_id: str = None, + **kwargs, ) -> DetailedResponse: """ Delete a rule. @@ -765,9 +893,9 @@ def delete_rule( the corresponding response. The same value is used for downstream requests and retries of those requests. If a value of this headers is not supplied in a request, the service generates a random (version 4) UUID. - :param str transaction_id: (optional) The `Transaction-Id` header behaves - as the `X-Correlation-Id` header. It is supported for backward - compatibility with other IBM platform services that support the + :param str transaction_id: (optional) Deprecated: The `Transaction-Id` + header behaves as the `X-Correlation-Id` header. It is supported for + backward compatibility with other IBM platform services that support the `Transaction-Id` header only. If both `X-Correlation-Id` and `Transaction-Id` are provided, `X-Correlation-Id` has the precedence over `Transaction-Id`. @@ -776,11 +904,16 @@ def delete_rule( :rtype: DetailedResponse """ - if rule_id is None: + if not rule_id: raise ValueError('rule_id must be provided') - headers = {'X-Correlation-Id': x_correlation_id, 'Transaction-Id': transaction_id} + headers = { + 'X-Correlation-Id': x_correlation_id, + 'Transaction-Id': transaction_id, + } sdk_headers = get_sdk_headers( - service_name=self.DEFAULT_SERVICE_NAME, service_version='V1', operation_id='delete_rule' + service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='delete_rule', ) headers.update(sdk_headers) @@ -792,7 +925,11 @@ def delete_rule( path_param_values = self.encode_path_vars(rule_id) path_param_dict = dict(zip(path_param_keys, path_param_values)) url = '/v1/rules/{rule_id}'.format(**path_param_dict) - request = self.prepare_request(method='DELETE', url=url, headers=headers) + request = self.prepare_request( + method='DELETE', + url=url, + headers=headers, + ) response = self.send(request, **kwargs) return response @@ -802,7 +939,12 @@ def delete_rule( ######################### def get_account_settings( - self, account_id: str, *, x_correlation_id: str = None, transaction_id: str = None, **kwargs + self, + account_id: str, + *, + x_correlation_id: str = None, + transaction_id: str = None, + **kwargs, ) -> DetailedResponse: """ Get account settings. @@ -815,9 +957,9 @@ def get_account_settings( the corresponding response. The same value is used for downstream requests and retries of those requests. If a value of this headers is not supplied in a request, the service generates a random (version 4) UUID. - :param str transaction_id: (optional) The `Transaction-Id` header behaves - as the `X-Correlation-Id` header. It is supported for backward - compatibility with other IBM platform services that support the + :param str transaction_id: (optional) Deprecated: The `Transaction-Id` + header behaves as the `X-Correlation-Id` header. It is supported for + backward compatibility with other IBM platform services that support the `Transaction-Id` header only. If both `X-Correlation-Id` and `Transaction-Id` are provided, `X-Correlation-Id` has the precedence over `Transaction-Id`. @@ -826,11 +968,16 @@ def get_account_settings( :rtype: DetailedResponse with `dict` result representing a `AccountSettings` object """ - if account_id is None: + if not account_id: raise ValueError('account_id must be provided') - headers = {'X-Correlation-Id': x_correlation_id, 'Transaction-Id': transaction_id} + headers = { + 'X-Correlation-Id': x_correlation_id, + 'Transaction-Id': transaction_id, + } sdk_headers = get_sdk_headers( - service_name=self.DEFAULT_SERVICE_NAME, service_version='V1', operation_id='get_account_settings' + service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='get_account_settings', ) headers.update(sdk_headers) @@ -843,7 +990,11 @@ def get_account_settings( path_param_values = self.encode_path_vars(account_id) path_param_dict = dict(zip(path_param_keys, path_param_values)) url = '/v1/account_settings/{account_id}'.format(**path_param_dict) - request = self.prepare_request(method='GET', url=url, headers=headers) + request = self.prepare_request( + method='GET', + url=url, + headers=headers, + ) response = self.send(request, **kwargs) return response @@ -853,33 +1004,43 @@ def get_account_settings( ######################### def list_available_service_operations( - self, service_name: str, *, x_correlation_id: str = None, transaction_id: str = None, **kwargs + self, + *, + x_correlation_id: str = None, + transaction_id: str = None, + service_name: str = None, + service_group_id: str = None, + resource_type: str = None, + **kwargs, ) -> DetailedResponse: """ List available service operations. This operation lists all available service operations. - :param str service_name: The name of the service. :param str x_correlation_id: (optional) The supplied or generated value of this header is logged for a request and repeated in a response header for the corresponding response. The same value is used for downstream requests and retries of those requests. If a value of this headers is not supplied in a request, the service generates a random (version 4) UUID. - :param str transaction_id: (optional) The `Transaction-Id` header behaves - as the `X-Correlation-Id` header. It is supported for backward - compatibility with other IBM platform services that support the + :param str transaction_id: (optional) Deprecated: The `Transaction-Id` + header behaves as the `X-Correlation-Id` header. It is supported for + backward compatibility with other IBM platform services that support the `Transaction-Id` header only. If both `X-Correlation-Id` and `Transaction-Id` are provided, `X-Correlation-Id` has the precedence over `Transaction-Id`. + :param str service_name: (optional) The name of the service. + :param str service_group_id: (optional) The id of the service group. + :param str resource_type: (optional) The type of resource. :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 `OperationsList` object """ - if service_name is None: - raise ValueError('service_name must be provided') - headers = {'X-Correlation-Id': x_correlation_id, 'Transaction-Id': transaction_id} + headers = { + 'X-Correlation-Id': x_correlation_id, + 'Transaction-Id': transaction_id, + } sdk_headers = get_sdk_headers( service_name=self.DEFAULT_SERVICE_NAME, service_version='V1', @@ -887,7 +1048,11 @@ def list_available_service_operations( ) headers.update(sdk_headers) - params = {'service_name': service_name} + params = { + 'service_name': service_name, + 'service_group_id': service_group_id, + 'resource_type': resource_type, + } if 'headers' in kwargs: headers.update(kwargs.get('headers')) @@ -895,7 +1060,12 @@ def list_available_service_operations( headers['Accept'] = 'application/json' url = '/v1/operations' - request = self.prepare_request(method='GET', url=url, headers=headers, params=params) + request = self.prepare_request( + method='GET', + url=url, + headers=headers, + params=params, + ) response = self.send(request, **kwargs) return response @@ -942,21 +1112,31 @@ class APIType: :attr str api_type_id: The id of the API type. :attr str display_name: The displayed name of the API type. :attr str description: The description of the API type. + :attr str type: The type of the API type. :attr List[Action] actions: The actions available for the API type. """ - def __init__(self, api_type_id: str, display_name: str, description: str, actions: List['Action']) -> None: + def __init__( + self, + api_type_id: str, + display_name: str, + description: str, + type: str, + actions: List['Action'], + ) -> None: """ Initialize a APIType object. :param str api_type_id: The id of the API type. :param str display_name: The displayed name of the API type. :param str description: The description of the API type. + :param str type: The type of the API type. :param List[Action] actions: The actions available for the API type. """ self.api_type_id = api_type_id self.display_name = display_name self.description = description + self.type = type self.actions = actions @classmethod @@ -975,8 +1155,12 @@ def from_dict(cls, _dict: Dict) -> 'APIType': args['description'] = _dict.get('description') else: raise ValueError('Required property \'description\' not present in APIType JSON') + if 'type' in _dict: + args['type'] = _dict.get('type') + else: + raise ValueError('Required property \'type\' not present in APIType JSON') if 'actions' in _dict: - args['actions'] = [Action.from_dict(x) for x in _dict.get('actions')] + args['actions'] = [Action.from_dict(v) for v in _dict.get('actions')] else: raise ValueError('Required property \'actions\' not present in APIType JSON') return cls(**args) @@ -995,8 +1179,16 @@ def to_dict(self) -> Dict: _dict['display_name'] = self.display_name if hasattr(self, 'description') and self.description is not None: _dict['description'] = self.description + if hasattr(self, 'type') and self.type is not None: + _dict['type'] = self.type if hasattr(self, 'actions') and self.actions is not None: - _dict['actions'] = [x.to_dict() for x in self.actions] + actions_list = [] + for v in self.actions: + if isinstance(v, dict): + actions_list.append(v) + else: + actions_list.append(v.to_dict()) + _dict['actions'] = actions_list return _dict def _to_dict(self): @@ -1193,7 +1385,11 @@ class Action: :attr str description: The description of the action. """ - def __init__(self, action_id: str, description: str) -> None: + def __init__( + self, + action_id: str, + description: str, + ) -> None: """ Initialize a Action object. @@ -1257,7 +1453,11 @@ class Address: :attr str type: (optional) The type of address. """ - def __init__(self, *, type: str = None) -> None: + def __init__( + self, + *, + type: str = None, + ) -> None: """ Initialize a Address object. @@ -1274,10 +1474,7 @@ def from_dict(cls, _dict: Dict) -> 'Address': 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 'Address'. " - + "The discriminator value should map to a valid subclass: {1}" - ).format( + msg = "Cannot convert dictionary into an instance of base class 'Address'. The discriminator value should map to a valid subclass: {1}".format( ", ".join(['AddressIPAddress', 'AddressIPAddressRange', 'AddressSubnet', 'AddressVPC', 'AddressServiceRef']) ) raise Exception(msg) @@ -1327,7 +1524,10 @@ class NewRuleOperations: applies to. """ - def __init__(self, api_types: List['NewRuleOperationsApiTypesItem']) -> None: + def __init__( + self, + api_types: List['NewRuleOperationsApiTypesItem'], + ) -> None: """ Initialize a NewRuleOperations object. @@ -1341,7 +1541,7 @@ def from_dict(cls, _dict: Dict) -> 'NewRuleOperations': """Initialize a NewRuleOperations object from a json dictionary.""" args = {} if 'api_types' in _dict: - args['api_types'] = [NewRuleOperationsApiTypesItem.from_dict(x) for x in _dict.get('api_types')] + args['api_types'] = [NewRuleOperationsApiTypesItem.from_dict(v) for v in _dict.get('api_types')] else: raise ValueError('Required property \'api_types\' not present in NewRuleOperations JSON') return cls(**args) @@ -1355,7 +1555,13 @@ def to_dict(self) -> Dict: """Return a json dictionary representing this model.""" _dict = {} if hasattr(self, 'api_types') and self.api_types is not None: - _dict['api_types'] = [x.to_dict() for x in self.api_types] + api_types_list = [] + for v in self.api_types: + if isinstance(v, dict): + api_types_list.append(v) + else: + api_types_list.append(v.to_dict()) + _dict['api_types'] = api_types_list return _dict def _to_dict(self): @@ -1384,7 +1590,10 @@ class NewRuleOperationsApiTypesItem: :attr str api_type_id: """ - def __init__(self, api_type_id: str) -> None: + def __init__( + self, + api_type_id: str, + ) -> None: """ Initialize a NewRuleOperationsApiTypesItem object. @@ -1440,7 +1649,10 @@ class OperationsList: :attr List[APIType] api_types: The returned API types. """ - def __init__(self, api_types: List['APIType']) -> None: + def __init__( + self, + api_types: List['APIType'], + ) -> None: """ Initialize a OperationsList object. @@ -1453,7 +1665,7 @@ def from_dict(cls, _dict: Dict) -> 'OperationsList': """Initialize a OperationsList object from a json dictionary.""" args = {} if 'api_types' in _dict: - args['api_types'] = [APIType.from_dict(x) for x in _dict.get('api_types')] + args['api_types'] = [APIType.from_dict(v) for v in _dict.get('api_types')] else: raise ValueError('Required property \'api_types\' not present in OperationsList JSON') return cls(**args) @@ -1467,7 +1679,13 @@ def to_dict(self) -> Dict: """Return a json dictionary representing this model.""" _dict = {} if hasattr(self, 'api_types') and self.api_types is not None: - _dict['api_types'] = [x.to_dict() for x in self.api_types] + api_types_list = [] + for v in self.api_types: + if isinstance(v, dict): + api_types_list.append(v) + else: + api_types_list.append(v.to_dict()) + _dict['api_types'] = api_types_list return _dict def _to_dict(self): @@ -1497,7 +1715,12 @@ class Resource: :attr List[ResourceTagAttribute] tags: (optional) The optional resource tags. """ - def __init__(self, attributes: List['ResourceAttribute'], *, tags: List['ResourceTagAttribute'] = None) -> None: + def __init__( + self, + attributes: List['ResourceAttribute'], + *, + tags: List['ResourceTagAttribute'] = None, + ) -> None: """ Initialize a Resource object. @@ -1513,11 +1736,11 @@ def from_dict(cls, _dict: Dict) -> 'Resource': """Initialize a Resource object from a json dictionary.""" args = {} if 'attributes' in _dict: - args['attributes'] = [ResourceAttribute.from_dict(x) for x in _dict.get('attributes')] + args['attributes'] = [ResourceAttribute.from_dict(v) for v in _dict.get('attributes')] else: raise ValueError('Required property \'attributes\' not present in Resource JSON') if 'tags' in _dict: - args['tags'] = [ResourceTagAttribute.from_dict(x) for x in _dict.get('tags')] + args['tags'] = [ResourceTagAttribute.from_dict(v) for v in _dict.get('tags')] return cls(**args) @classmethod @@ -1529,9 +1752,21 @@ def to_dict(self) -> Dict: """Return a json dictionary representing this model.""" _dict = {} if hasattr(self, 'attributes') and self.attributes is not None: - _dict['attributes'] = [x.to_dict() for x in self.attributes] + attributes_list = [] + for v in self.attributes: + if isinstance(v, dict): + attributes_list.append(v) + else: + attributes_list.append(v.to_dict()) + _dict['attributes'] = attributes_list if hasattr(self, 'tags') and self.tags is not None: - _dict['tags'] = [x.to_dict() for x in self.tags] + tags_list = [] + for v in self.tags: + if isinstance(v, dict): + tags_list.append(v) + else: + tags_list.append(v.to_dict()) + _dict['tags'] = tags_list return _dict def _to_dict(self): @@ -1562,7 +1797,13 @@ class ResourceAttribute: :attr str operator: (optional) The attribute operator. """ - def __init__(self, name: str, value: str, *, operator: str = None) -> None: + def __init__( + self, + name: str, + value: str, + *, + operator: str = None, + ) -> None: """ Initialize a ResourceAttribute object. @@ -1634,7 +1875,13 @@ class ResourceTagAttribute: :attr str operator: (optional) The attribute operator. """ - def __init__(self, name: str, value: str, *, operator: str = None) -> None: + def __init__( + self, + name: str, + value: str, + *, + operator: str = None, + ) -> None: """ Initialize a ResourceTagAttribute object. @@ -1735,7 +1982,7 @@ def __init__( last_modified_by_id: str, *, operations: 'NewRuleOperations' = None, - enforcement_mode: str = None + enforcement_mode: str = None, ) -> None: """ Initialize a Rule object. @@ -1792,11 +2039,11 @@ def from_dict(cls, _dict: Dict) -> 'Rule': else: raise ValueError('Required property \'description\' not present in Rule JSON') if 'contexts' in _dict: - args['contexts'] = [RuleContext.from_dict(x) for x in _dict.get('contexts')] + args['contexts'] = [RuleContext.from_dict(v) for v in _dict.get('contexts')] else: raise ValueError('Required property \'contexts\' not present in Rule JSON') if 'resources' in _dict: - args['resources'] = [Resource.from_dict(x) for x in _dict.get('resources')] + args['resources'] = [Resource.from_dict(v) for v in _dict.get('resources')] else: raise ValueError('Required property \'resources\' not present in Rule JSON') if 'operations' in _dict: @@ -1840,11 +2087,26 @@ def to_dict(self) -> Dict: if hasattr(self, 'description') and self.description is not None: _dict['description'] = self.description if hasattr(self, 'contexts') and self.contexts is not None: - _dict['contexts'] = [x.to_dict() for x in self.contexts] + contexts_list = [] + for v in self.contexts: + if isinstance(v, dict): + contexts_list.append(v) + else: + contexts_list.append(v.to_dict()) + _dict['contexts'] = contexts_list if hasattr(self, 'resources') and self.resources is not None: - _dict['resources'] = [x.to_dict() for x in self.resources] + resources_list = [] + for v in self.resources: + if isinstance(v, dict): + resources_list.append(v) + else: + resources_list.append(v.to_dict()) + _dict['resources'] = resources_list if hasattr(self, 'operations') and self.operations is not None: - _dict['operations'] = self.operations.to_dict() + if isinstance(self.operations, dict): + _dict['operations'] = self.operations + else: + _dict['operations'] = self.operations.to_dict() if hasattr(self, 'enforcement_mode') and self.enforcement_mode is not None: _dict['enforcement_mode'] = self.enforcement_mode if hasattr(self, 'href') and self.href is not None: @@ -1897,7 +2159,10 @@ class RuleContext: :attr List[RuleContextAttribute] attributes: The attributes. """ - def __init__(self, attributes: List['RuleContextAttribute']) -> None: + def __init__( + self, + attributes: List['RuleContextAttribute'], + ) -> None: """ Initialize a RuleContext object. @@ -1910,7 +2175,7 @@ def from_dict(cls, _dict: Dict) -> 'RuleContext': """Initialize a RuleContext object from a json dictionary.""" args = {} if 'attributes' in _dict: - args['attributes'] = [RuleContextAttribute.from_dict(x) for x in _dict.get('attributes')] + args['attributes'] = [RuleContextAttribute.from_dict(v) for v in _dict.get('attributes')] else: raise ValueError('Required property \'attributes\' not present in RuleContext JSON') return cls(**args) @@ -1924,7 +2189,13 @@ def to_dict(self) -> Dict: """Return a json dictionary representing this model.""" _dict = {} if hasattr(self, 'attributes') and self.attributes is not None: - _dict['attributes'] = [x.to_dict() for x in self.attributes] + attributes_list = [] + for v in self.attributes: + if isinstance(v, dict): + attributes_list.append(v) + else: + attributes_list.append(v.to_dict()) + _dict['attributes'] = attributes_list return _dict def _to_dict(self): @@ -1954,7 +2225,11 @@ class RuleContextAttribute: :attr str value: The attribute value. """ - def __init__(self, name: str, value: str) -> None: + def __init__( + self, + name: str, + value: str, + ) -> None: """ Initialize a RuleContextAttribute object. @@ -2019,7 +2294,11 @@ class RuleList: :attr List[Rule] rules: The returned rules. """ - def __init__(self, count: int, rules: List['Rule']) -> None: + def __init__( + self, + count: int, + rules: List['Rule'], + ) -> None: """ Initialize a RuleList object. @@ -2038,7 +2317,7 @@ def from_dict(cls, _dict: Dict) -> 'RuleList': else: raise ValueError('Required property \'count\' not present in RuleList JSON') if 'rules' in _dict: - args['rules'] = [Rule.from_dict(x) for x in _dict.get('rules')] + args['rules'] = [Rule.from_dict(v) for v in _dict.get('rules')] else: raise ValueError('Required property \'rules\' not present in RuleList JSON') return cls(**args) @@ -2054,7 +2333,13 @@ def to_dict(self) -> Dict: if hasattr(self, 'count') and self.count is not None: _dict['count'] = self.count if hasattr(self, 'rules') and self.rules is not None: - _dict['rules'] = [x.to_dict() for x in self.rules] + rules_list = [] + for v in self.rules: + if isinstance(v, dict): + rules_list.append(v) + else: + rules_list.append(v.to_dict()) + _dict['rules'] = rules_list return _dict def _to_dict(self): @@ -2087,7 +2372,11 @@ class ServiceRefTarget: """ def __init__( - self, service_name: str, *, service_type: str = None, locations: List['ServiceRefTargetLocationsItem'] = None + self, + service_name: str, + *, + service_type: str = None, + locations: List['ServiceRefTargetLocationsItem'] = None, ) -> None: """ Initialize a ServiceRefTarget object. @@ -2112,7 +2401,7 @@ def from_dict(cls, _dict: Dict) -> 'ServiceRefTarget': if 'service_type' in _dict: args['service_type'] = _dict.get('service_type') if 'locations' in _dict: - args['locations'] = [ServiceRefTargetLocationsItem.from_dict(x) for x in _dict.get('locations')] + args['locations'] = [ServiceRefTargetLocationsItem.from_dict(v) for v in _dict.get('locations')] return cls(**args) @classmethod @@ -2128,7 +2417,13 @@ def to_dict(self) -> Dict: if hasattr(self, 'service_type') and self.service_type is not None: _dict['service_type'] = self.service_type if hasattr(self, 'locations') and self.locations is not None: - _dict['locations'] = [x.to_dict() for x in self.locations] + locations_list = [] + for v in self.locations: + if isinstance(v, dict): + locations_list.append(v) + else: + locations_list.append(v.to_dict()) + _dict['locations'] = locations_list return _dict def _to_dict(self): @@ -2158,7 +2453,11 @@ class ServiceRefTargetList: :attr List[ServiceRefTarget] targets: The list of service reference targets. """ - def __init__(self, count: int, targets: List['ServiceRefTarget']) -> None: + def __init__( + self, + count: int, + targets: List['ServiceRefTarget'], + ) -> None: """ Initialize a ServiceRefTargetList object. @@ -2178,7 +2477,7 @@ def from_dict(cls, _dict: Dict) -> 'ServiceRefTargetList': else: raise ValueError('Required property \'count\' not present in ServiceRefTargetList JSON') if 'targets' in _dict: - args['targets'] = [ServiceRefTarget.from_dict(x) for x in _dict.get('targets')] + args['targets'] = [ServiceRefTarget.from_dict(v) for v in _dict.get('targets')] else: raise ValueError('Required property \'targets\' not present in ServiceRefTargetList JSON') return cls(**args) @@ -2194,7 +2493,13 @@ def to_dict(self) -> Dict: if hasattr(self, 'count') and self.count is not None: _dict['count'] = self.count if hasattr(self, 'targets') and self.targets is not None: - _dict['targets'] = [x.to_dict() for x in self.targets] + targets_list = [] + for v in self.targets: + if isinstance(v, dict): + targets_list.append(v) + else: + targets_list.append(v.to_dict()) + _dict['targets'] = targets_list return _dict def _to_dict(self): @@ -2223,7 +2528,10 @@ class ServiceRefTargetLocationsItem: :attr str name: The location name. """ - def __init__(self, name: str) -> None: + def __init__( + self, + name: str, + ) -> None: """ Initialize a ServiceRefTargetLocationsItem object. @@ -2290,7 +2598,7 @@ def __init__( service_type: str = None, service_name: str = None, service_instance: str = None, - location: str = None + location: str = None, ) -> None: """ Initialize a ServiceRefValue object. @@ -2474,11 +2782,11 @@ def from_dict(cls, _dict: Dict) -> 'Zone': else: raise ValueError('Required property \'description\' not present in Zone JSON') if 'addresses' in _dict: - args['addresses'] = [Address.from_dict(x) for x in _dict.get('addresses')] + args['addresses'] = [Address.from_dict(v) for v in _dict.get('addresses')] else: raise ValueError('Required property \'addresses\' not present in Zone JSON') if 'excluded' in _dict: - args['excluded'] = [Address.from_dict(x) for x in _dict.get('excluded')] + args['excluded'] = [Address.from_dict(v) for v in _dict.get('excluded')] else: raise ValueError('Required property \'excluded\' not present in Zone JSON') if 'href' in _dict: @@ -2526,9 +2834,21 @@ def to_dict(self) -> Dict: if hasattr(self, 'description') and self.description is not None: _dict['description'] = self.description if hasattr(self, 'addresses') and self.addresses is not None: - _dict['addresses'] = [x.to_dict() for x in self.addresses] + addresses_list = [] + for v in self.addresses: + if isinstance(v, dict): + addresses_list.append(v) + else: + addresses_list.append(v.to_dict()) + _dict['addresses'] = addresses_list if hasattr(self, 'excluded') and self.excluded is not None: - _dict['excluded'] = [x.to_dict() for x in self.excluded] + excluded_list = [] + for v in self.excluded: + if isinstance(v, dict): + excluded_list.append(v) + else: + excluded_list.append(v.to_dict()) + _dict['excluded'] = excluded_list if hasattr(self, 'href') and self.href is not None: _dict['href'] = self.href if hasattr(self, 'created_at') and self.created_at is not None: @@ -2568,7 +2888,11 @@ class ZoneList: :attr List[ZoneSummary] zones: The returned zones. """ - def __init__(self, count: int, zones: List['ZoneSummary']) -> None: + def __init__( + self, + count: int, + zones: List['ZoneSummary'], + ) -> None: """ Initialize a ZoneList object. @@ -2587,7 +2911,7 @@ def from_dict(cls, _dict: Dict) -> 'ZoneList': else: raise ValueError('Required property \'count\' not present in ZoneList JSON') if 'zones' in _dict: - args['zones'] = [ZoneSummary.from_dict(x) for x in _dict.get('zones')] + args['zones'] = [ZoneSummary.from_dict(v) for v in _dict.get('zones')] else: raise ValueError('Required property \'zones\' not present in ZoneList JSON') return cls(**args) @@ -2603,7 +2927,13 @@ def to_dict(self) -> Dict: if hasattr(self, 'count') and self.count is not None: _dict['count'] = self.count if hasattr(self, 'zones') and self.zones is not None: - _dict['zones'] = [x.to_dict() for x in self.zones] + zones_list = [] + for v in self.zones: + if isinstance(v, dict): + zones_list.append(v) + else: + zones_list.append(v.to_dict()) + _dict['zones'] = zones_list return _dict def _to_dict(self): @@ -2660,7 +2990,7 @@ def __init__( last_modified_at: datetime, last_modified_by_id: str, *, - description: str = None + description: str = None, ) -> None: """ Initialize a ZoneSummary object. @@ -2713,7 +3043,7 @@ def from_dict(cls, _dict: Dict) -> 'ZoneSummary': if 'description' in _dict: args['description'] = _dict.get('description') if 'addresses_preview' in _dict: - args['addresses_preview'] = [Address.from_dict(x) for x in _dict.get('addresses_preview')] + args['addresses_preview'] = [Address.from_dict(v) for v in _dict.get('addresses_preview')] else: raise ValueError('Required property \'addresses_preview\' not present in ZoneSummary JSON') if 'address_count' in _dict: @@ -2763,7 +3093,13 @@ def to_dict(self) -> Dict: if hasattr(self, 'description') and self.description is not None: _dict['description'] = self.description if hasattr(self, 'addresses_preview') and self.addresses_preview is not None: - _dict['addresses_preview'] = [x.to_dict() for x in self.addresses_preview] + addresses_preview_list = [] + for v in self.addresses_preview: + if isinstance(v, dict): + addresses_preview_list.append(v) + else: + addresses_preview_list.append(v.to_dict()) + _dict['addresses_preview'] = addresses_preview_list if hasattr(self, 'address_count') and self.address_count is not None: _dict['address_count'] = self.address_count if hasattr(self, 'excluded_count') and self.excluded_count is not None: @@ -2801,13 +3137,17 @@ def __ne__(self, other: 'ZoneSummary') -> bool: class AddressIPAddress(Address): """ - A single IP address. + A single IP address. IPv4 and IPv6 are supported. :attr str type: The type of address. :attr str value: The IP address. """ - def __init__(self, type: str, value: str) -> None: + def __init__( + self, + type: str, + value: str, + ) -> None: """ Initialize a AddressIPAddress object. @@ -2874,13 +3214,17 @@ class TypeEnum(str, Enum): class AddressIPAddressRange(Address): """ - An IP address range. + An IP address range. IPv4 and IPv6 are supported. :attr str type: The type of address. :attr str value: The ip range in - format. """ - def __init__(self, type: str, value: str) -> None: + def __init__( + self, + type: str, + value: str, + ) -> None: """ Initialize a AddressIPAddressRange object. @@ -2953,7 +3297,11 @@ class AddressServiceRef(Address): :attr ServiceRefValue ref: A service reference value. """ - def __init__(self, type: str, ref: 'ServiceRefValue') -> None: + def __init__( + self, + type: str, + ref: 'ServiceRefValue', + ) -> None: """ Initialize a AddressServiceRef object. @@ -2989,7 +3337,10 @@ def to_dict(self) -> Dict: if hasattr(self, 'type') and self.type is not None: _dict['type'] = self.type if hasattr(self, 'ref') and self.ref is not None: - _dict['ref'] = self.ref.to_dict() + if isinstance(self.ref, dict): + _dict['ref'] = self.ref + else: + _dict['ref'] = self.ref.to_dict() return _dict def _to_dict(self): @@ -3026,7 +3377,11 @@ class AddressSubnet(Address): :attr str value: The subnet in CIDR format. """ - def __init__(self, type: str, value: str) -> None: + def __init__( + self, + type: str, + value: str, + ) -> None: """ Initialize a AddressSubnet object. @@ -3099,7 +3454,11 @@ class AddressVPC(Address): :attr str value: The VPC CRN. """ - def __init__(self, type: str, value: str) -> None: + def __init__( + self, + type: str, + value: str, + ) -> None: """ Initialize a AddressVPC object. diff --git a/test/integration/test_context_based_restrictions_v1.py b/test/integration/test_context_based_restrictions_v1.py index d23c5dda..df5505ea 100644 --- a/test/integration/test_context_based_restrictions_v1.py +++ b/test/integration/test_context_based_restrictions_v1.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# (C) Copyright IBM Corp. 2022. +# (C) Copyright IBM Corp. 2023. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -645,16 +645,53 @@ def test_get_account_settings_with_invalid_account_id_parameter(self): ) @needscredentials - def test_list_available_service_operations(self): - list_available_service_operations_response = ( - self.context_based_restrictions_service.list_available_service_operations( - service_name='containers-kubernetes', transaction_id=self.getTransactionID() - ) + def test_list_available_service_operations_with_service_name(self): + response = self.context_based_restrictions_service.list_available_service_operations( + transaction_id=self.getTransactionID(), + service_name='containers-kubernetes', + ) + + assert response.get_status_code() == 200 + operations_list = response.get_result() + assert operations_list is not None + for api_type in operations_list['api_types']: + assert api_type is not "" + + @needscredentials + def test_list_available_service_operations_with_service_group(self): + response = self.context_based_restrictions_service.list_available_service_operations( + transaction_id=self.getTransactionID(), + service_group_id='IAM', + ) + + assert response.get_status_code() == 200 + operations_list = response.get_result() + assert operations_list is not None + for api_type in operations_list['api_types']: + assert api_type is not "" + + @needscredentials + def test_list_available_service_operations_with_resource_type(self): + response = self.context_based_restrictions_service.list_available_service_operations( + transaction_id=self.getTransactionID(), + service_name='iam-access-management', + resource_type='customRole', ) - assert list_available_service_operations_response.get_status_code() == 200 - operations_list = list_available_service_operations_response.get_result() + assert response.get_status_code() == 200 + operations_list = response.get_result() assert operations_list is not None + for api_type in operations_list['api_types']: + assert api_type is not "" + + @needscredentials + def test_list_available_service_operations_with_mutual_exclusion_error(self): + with pytest.raises(ApiException, match="400"): + self.context_based_restrictions_service.list_available_service_operations( + transaction_id=self.getTransactionID(), + service_name='iam-access-management', + service_group_id='IAM', + ) @needscredentials def test_delete_rule(self): diff --git a/test/unit/test_context_based_restrictions_v1.py b/test/unit/test_context_based_restrictions_v1.py index cb9729fd..4aef2872 100644 --- a/test/unit/test_context_based_restrictions_v1.py +++ b/test/unit/test_context_based_restrictions_v1.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# (C) Copyright IBM Corp. 2022. +# (C) Copyright IBM Corp. 2023. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -59,7 +59,8 @@ def preprocess_url(operation_path: str): # Otherwise, return a regular expression that matches one or more trailing /. if re.fullmatch('.*/+', request_url) is None: return request_url - return re.compile(request_url.rstrip('/') + '/+') + else: + return re.compile(request_url.rstrip('/') + '/+') ############################################################################## @@ -109,12 +110,18 @@ def test_create_zone_all_params(self): # Set up mock url = preprocess_url('/v1/zones') mock_response = '{"id": "id", "crn": "crn", "address_count": 13, "excluded_count": 14, "name": "name", "account_id": "account_id", "description": "description", "addresses": [{"type": "ipAddress", "value": "value"}], "excluded": [{"type": "ipAddress", "value": "value"}], "href": "href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id"}' - responses.add(responses.POST, url, body=mock_response, content_type='application/json', status=201) + responses.add( + responses.POST, + url, + body=mock_response, + content_type='application/json', + status=201, + ) # Construct a dict representation of a AddressIPAddress model address_model = {} address_model['type'] = 'ipAddress' - address_model['value'] = '169.23.56.234' + address_model['value'] = '169.23.56.234, 3ffe:1900:fe21:4545::' # Set up parameter values name = 'an example of zone' @@ -165,7 +172,13 @@ def test_create_zone_required_params(self): # Set up mock url = preprocess_url('/v1/zones') mock_response = '{"id": "id", "crn": "crn", "address_count": 13, "excluded_count": 14, "name": "name", "account_id": "account_id", "description": "description", "addresses": [{"type": "ipAddress", "value": "value"}], "excluded": [{"type": "ipAddress", "value": "value"}], "href": "href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id"}' - responses.add(responses.POST, url, body=mock_response, content_type='application/json', status=201) + responses.add( + responses.POST, + url, + body=mock_response, + content_type='application/json', + status=201, + ) # Invoke method response = _service.create_zone() @@ -197,7 +210,13 @@ def test_list_zones_all_params(self): # Set up mock url = preprocess_url('/v1/zones') mock_response = '{"count": 5, "zones": [{"id": "id", "crn": "crn", "name": "name", "description": "description", "addresses_preview": [{"type": "ipAddress", "value": "value"}], "address_count": 13, "excluded_count": 14, "href": "href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id"}]}' - responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + responses.add( + responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200, + ) # Set up parameter values account_id = 'testString' @@ -243,13 +262,22 @@ def test_list_zones_required_params(self): # Set up mock url = preprocess_url('/v1/zones') mock_response = '{"count": 5, "zones": [{"id": "id", "crn": "crn", "name": "name", "description": "description", "addresses_preview": [{"type": "ipAddress", "value": "value"}], "address_count": 13, "excluded_count": 14, "href": "href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id"}]}' - responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + responses.add( + responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200, + ) # Set up parameter values account_id = 'testString' # Invoke method - response = _service.list_zones(account_id, headers={}) + response = _service.list_zones( + account_id, + headers={}, + ) # Check for correct operation assert len(responses.calls) == 1 @@ -276,7 +304,13 @@ def test_list_zones_value_error(self): # Set up mock url = preprocess_url('/v1/zones') mock_response = '{"count": 5, "zones": [{"id": "id", "crn": "crn", "name": "name", "description": "description", "addresses_preview": [{"type": "ipAddress", "value": "value"}], "address_count": 13, "excluded_count": 14, "href": "href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id"}]}' - responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + responses.add( + responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200, + ) # Set up parameter values account_id = 'testString' @@ -313,7 +347,13 @@ def test_get_zone_all_params(self): # Set up mock url = preprocess_url('/v1/zones/testString') mock_response = '{"id": "id", "crn": "crn", "address_count": 13, "excluded_count": 14, "name": "name", "account_id": "account_id", "description": "description", "addresses": [{"type": "ipAddress", "value": "value"}], "excluded": [{"type": "ipAddress", "value": "value"}], "href": "href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id"}' - responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + responses.add( + responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200, + ) # Set up parameter values zone_id = 'testString' @@ -322,7 +362,10 @@ def test_get_zone_all_params(self): # Invoke method response = _service.get_zone( - zone_id, x_correlation_id=x_correlation_id, transaction_id=transaction_id, headers={} + zone_id, + x_correlation_id=x_correlation_id, + transaction_id=transaction_id, + headers={}, ) # Check for correct operation @@ -346,13 +389,22 @@ def test_get_zone_required_params(self): # Set up mock url = preprocess_url('/v1/zones/testString') mock_response = '{"id": "id", "crn": "crn", "address_count": 13, "excluded_count": 14, "name": "name", "account_id": "account_id", "description": "description", "addresses": [{"type": "ipAddress", "value": "value"}], "excluded": [{"type": "ipAddress", "value": "value"}], "href": "href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id"}' - responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + responses.add( + responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200, + ) # Set up parameter values zone_id = 'testString' # Invoke method - response = _service.get_zone(zone_id, headers={}) + response = _service.get_zone( + zone_id, + headers={}, + ) # Check for correct operation assert len(responses.calls) == 1 @@ -375,7 +427,13 @@ def test_get_zone_value_error(self): # Set up mock url = preprocess_url('/v1/zones/testString') mock_response = '{"id": "id", "crn": "crn", "address_count": 13, "excluded_count": 14, "name": "name", "account_id": "account_id", "description": "description", "addresses": [{"type": "ipAddress", "value": "value"}], "excluded": [{"type": "ipAddress", "value": "value"}], "href": "href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id"}' - responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + responses.add( + responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200, + ) # Set up parameter values zone_id = 'testString' @@ -412,12 +470,18 @@ def test_replace_zone_all_params(self): # Set up mock url = preprocess_url('/v1/zones/testString') mock_response = '{"id": "id", "crn": "crn", "address_count": 13, "excluded_count": 14, "name": "name", "account_id": "account_id", "description": "description", "addresses": [{"type": "ipAddress", "value": "value"}], "excluded": [{"type": "ipAddress", "value": "value"}], "href": "href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id"}' - responses.add(responses.PUT, url, body=mock_response, content_type='application/json', status=200) + responses.add( + responses.PUT, + url, + body=mock_response, + content_type='application/json', + status=200, + ) # Construct a dict representation of a AddressIPAddress model address_model = {} address_model['type'] = 'ipAddress' - address_model['value'] = '169.23.56.234' + address_model['value'] = '169.23.56.234, 3ffe:1900:fe21:4545::' # Set up parameter values zone_id = 'testString' @@ -472,14 +536,24 @@ def test_replace_zone_required_params(self): # Set up mock url = preprocess_url('/v1/zones/testString') mock_response = '{"id": "id", "crn": "crn", "address_count": 13, "excluded_count": 14, "name": "name", "account_id": "account_id", "description": "description", "addresses": [{"type": "ipAddress", "value": "value"}], "excluded": [{"type": "ipAddress", "value": "value"}], "href": "href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id"}' - responses.add(responses.PUT, url, body=mock_response, content_type='application/json', status=200) + responses.add( + responses.PUT, + url, + body=mock_response, + content_type='application/json', + status=200, + ) # Set up parameter values zone_id = 'testString' if_match = 'testString' # Invoke method - response = _service.replace_zone(zone_id, if_match, headers={}) + response = _service.replace_zone( + zone_id, + if_match, + headers={}, + ) # Check for correct operation assert len(responses.calls) == 1 @@ -502,7 +576,13 @@ def test_replace_zone_value_error(self): # Set up mock url = preprocess_url('/v1/zones/testString') mock_response = '{"id": "id", "crn": "crn", "address_count": 13, "excluded_count": 14, "name": "name", "account_id": "account_id", "description": "description", "addresses": [{"type": "ipAddress", "value": "value"}], "excluded": [{"type": "ipAddress", "value": "value"}], "href": "href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id"}' - responses.add(responses.PUT, url, body=mock_response, content_type='application/json', status=200) + responses.add( + responses.PUT, + url, + body=mock_response, + content_type='application/json', + status=200, + ) # Set up parameter values zone_id = 'testString' @@ -540,7 +620,11 @@ def test_delete_zone_all_params(self): """ # Set up mock url = preprocess_url('/v1/zones/testString') - responses.add(responses.DELETE, url, status=204) + responses.add( + responses.DELETE, + url, + status=204, + ) # Set up parameter values zone_id = 'testString' @@ -549,7 +633,10 @@ def test_delete_zone_all_params(self): # Invoke method response = _service.delete_zone( - zone_id, x_correlation_id=x_correlation_id, transaction_id=transaction_id, headers={} + zone_id, + x_correlation_id=x_correlation_id, + transaction_id=transaction_id, + headers={}, ) # Check for correct operation @@ -572,13 +659,20 @@ def test_delete_zone_required_params(self): """ # Set up mock url = preprocess_url('/v1/zones/testString') - responses.add(responses.DELETE, url, status=204) + responses.add( + responses.DELETE, + url, + status=204, + ) # Set up parameter values zone_id = 'testString' # Invoke method - response = _service.delete_zone(zone_id, headers={}) + response = _service.delete_zone( + zone_id, + headers={}, + ) # Check for correct operation assert len(responses.calls) == 1 @@ -600,7 +694,11 @@ def test_delete_zone_value_error(self): """ # Set up mock url = preprocess_url('/v1/zones/testString') - responses.add(responses.DELETE, url, status=204) + responses.add( + responses.DELETE, + url, + status=204, + ) # Set up parameter values zone_id = 'testString' @@ -637,7 +735,13 @@ def test_list_available_serviceref_targets_all_params(self): # Set up mock url = preprocess_url('/v1/zones/serviceref_targets') mock_response = '{"count": 5, "targets": [{"service_name": "service_name", "service_type": "service_type", "locations": [{"name": "name"}]}]}' - responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + responses.add( + responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200, + ) # Set up parameter values x_correlation_id = 'testString' @@ -646,7 +750,10 @@ def test_list_available_serviceref_targets_all_params(self): # Invoke method response = _service.list_available_serviceref_targets( - x_correlation_id=x_correlation_id, transaction_id=transaction_id, type=type, headers={} + x_correlation_id=x_correlation_id, + transaction_id=transaction_id, + type=type, + headers={}, ) # Check for correct operation @@ -674,7 +781,13 @@ def test_list_available_serviceref_targets_required_params(self): # Set up mock url = preprocess_url('/v1/zones/serviceref_targets') mock_response = '{"count": 5, "targets": [{"service_name": "service_name", "service_type": "service_type", "locations": [{"name": "name"}]}]}' - responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + responses.add( + responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200, + ) # Invoke method response = _service.list_available_serviceref_targets() @@ -745,7 +858,13 @@ def test_create_rule_all_params(self): # Set up mock url = preprocess_url('/v1/rules') mock_response = '{"id": "id", "crn": "crn", "description": "description", "contexts": [{"attributes": [{"name": "name", "value": "value"}]}], "resources": [{"attributes": [{"name": "name", "value": "value", "operator": "operator"}], "tags": [{"name": "name", "value": "value", "operator": "operator"}]}], "operations": {"api_types": [{"api_type_id": "api_type_id"}]}, "enforcement_mode": "enabled", "href": "href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id"}' - responses.add(responses.POST, url, body=mock_response, content_type='application/json', status=201) + responses.add( + responses.POST, + url, + body=mock_response, + content_type='application/json', + status=201, + ) # Construct a dict representation of a RuleContextAttribute model rule_context_attribute_model = {} @@ -830,7 +949,13 @@ def test_create_rule_required_params(self): # Set up mock url = preprocess_url('/v1/rules') mock_response = '{"id": "id", "crn": "crn", "description": "description", "contexts": [{"attributes": [{"name": "name", "value": "value"}]}], "resources": [{"attributes": [{"name": "name", "value": "value", "operator": "operator"}], "tags": [{"name": "name", "value": "value", "operator": "operator"}]}], "operations": {"api_types": [{"api_type_id": "api_type_id"}]}, "enforcement_mode": "enabled", "href": "href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id"}' - responses.add(responses.POST, url, body=mock_response, content_type='application/json', status=201) + responses.add( + responses.POST, + url, + body=mock_response, + content_type='application/json', + status=201, + ) # Invoke method response = _service.create_rule() @@ -862,7 +987,13 @@ def test_list_rules_all_params(self): # Set up mock url = preprocess_url('/v1/rules') mock_response = '{"count": 5, "rules": [{"id": "id", "crn": "crn", "description": "description", "contexts": [{"attributes": [{"name": "name", "value": "value"}]}], "resources": [{"attributes": [{"name": "name", "value": "value", "operator": "operator"}], "tags": [{"name": "name", "value": "value", "operator": "operator"}]}], "operations": {"api_types": [{"api_type_id": "api_type_id"}]}, "enforcement_mode": "enabled", "href": "href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id"}]}' - responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + responses.add( + responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200, + ) # Set up parameter values account_id = 'testString' @@ -932,13 +1063,22 @@ def test_list_rules_required_params(self): # Set up mock url = preprocess_url('/v1/rules') mock_response = '{"count": 5, "rules": [{"id": "id", "crn": "crn", "description": "description", "contexts": [{"attributes": [{"name": "name", "value": "value"}]}], "resources": [{"attributes": [{"name": "name", "value": "value", "operator": "operator"}], "tags": [{"name": "name", "value": "value", "operator": "operator"}]}], "operations": {"api_types": [{"api_type_id": "api_type_id"}]}, "enforcement_mode": "enabled", "href": "href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id"}]}' - responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + responses.add( + responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200, + ) # Set up parameter values account_id = 'testString' # Invoke method - response = _service.list_rules(account_id, headers={}) + response = _service.list_rules( + account_id, + headers={}, + ) # Check for correct operation assert len(responses.calls) == 1 @@ -965,7 +1105,13 @@ def test_list_rules_value_error(self): # Set up mock url = preprocess_url('/v1/rules') mock_response = '{"count": 5, "rules": [{"id": "id", "crn": "crn", "description": "description", "contexts": [{"attributes": [{"name": "name", "value": "value"}]}], "resources": [{"attributes": [{"name": "name", "value": "value", "operator": "operator"}], "tags": [{"name": "name", "value": "value", "operator": "operator"}]}], "operations": {"api_types": [{"api_type_id": "api_type_id"}]}, "enforcement_mode": "enabled", "href": "href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id"}]}' - responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + responses.add( + responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200, + ) # Set up parameter values account_id = 'testString' @@ -1002,7 +1148,13 @@ def test_get_rule_all_params(self): # Set up mock url = preprocess_url('/v1/rules/testString') mock_response = '{"id": "id", "crn": "crn", "description": "description", "contexts": [{"attributes": [{"name": "name", "value": "value"}]}], "resources": [{"attributes": [{"name": "name", "value": "value", "operator": "operator"}], "tags": [{"name": "name", "value": "value", "operator": "operator"}]}], "operations": {"api_types": [{"api_type_id": "api_type_id"}]}, "enforcement_mode": "enabled", "href": "href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id"}' - responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + responses.add( + responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200, + ) # Set up parameter values rule_id = 'testString' @@ -1011,7 +1163,10 @@ def test_get_rule_all_params(self): # Invoke method response = _service.get_rule( - rule_id, x_correlation_id=x_correlation_id, transaction_id=transaction_id, headers={} + rule_id, + x_correlation_id=x_correlation_id, + transaction_id=transaction_id, + headers={}, ) # Check for correct operation @@ -1035,13 +1190,22 @@ def test_get_rule_required_params(self): # Set up mock url = preprocess_url('/v1/rules/testString') mock_response = '{"id": "id", "crn": "crn", "description": "description", "contexts": [{"attributes": [{"name": "name", "value": "value"}]}], "resources": [{"attributes": [{"name": "name", "value": "value", "operator": "operator"}], "tags": [{"name": "name", "value": "value", "operator": "operator"}]}], "operations": {"api_types": [{"api_type_id": "api_type_id"}]}, "enforcement_mode": "enabled", "href": "href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id"}' - responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + responses.add( + responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200, + ) # Set up parameter values rule_id = 'testString' # Invoke method - response = _service.get_rule(rule_id, headers={}) + response = _service.get_rule( + rule_id, + headers={}, + ) # Check for correct operation assert len(responses.calls) == 1 @@ -1064,7 +1228,13 @@ def test_get_rule_value_error(self): # Set up mock url = preprocess_url('/v1/rules/testString') mock_response = '{"id": "id", "crn": "crn", "description": "description", "contexts": [{"attributes": [{"name": "name", "value": "value"}]}], "resources": [{"attributes": [{"name": "name", "value": "value", "operator": "operator"}], "tags": [{"name": "name", "value": "value", "operator": "operator"}]}], "operations": {"api_types": [{"api_type_id": "api_type_id"}]}, "enforcement_mode": "enabled", "href": "href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id"}' - responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + responses.add( + responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200, + ) # Set up parameter values rule_id = 'testString' @@ -1101,7 +1271,13 @@ def test_replace_rule_all_params(self): # Set up mock url = preprocess_url('/v1/rules/testString') mock_response = '{"id": "id", "crn": "crn", "description": "description", "contexts": [{"attributes": [{"name": "name", "value": "value"}]}], "resources": [{"attributes": [{"name": "name", "value": "value", "operator": "operator"}], "tags": [{"name": "name", "value": "value", "operator": "operator"}]}], "operations": {"api_types": [{"api_type_id": "api_type_id"}]}, "enforcement_mode": "enabled", "href": "href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id"}' - responses.add(responses.PUT, url, body=mock_response, content_type='application/json', status=200) + responses.add( + responses.PUT, + url, + body=mock_response, + content_type='application/json', + status=200, + ) # Construct a dict representation of a RuleContextAttribute model rule_context_attribute_model = {} @@ -1190,14 +1366,24 @@ def test_replace_rule_required_params(self): # Set up mock url = preprocess_url('/v1/rules/testString') mock_response = '{"id": "id", "crn": "crn", "description": "description", "contexts": [{"attributes": [{"name": "name", "value": "value"}]}], "resources": [{"attributes": [{"name": "name", "value": "value", "operator": "operator"}], "tags": [{"name": "name", "value": "value", "operator": "operator"}]}], "operations": {"api_types": [{"api_type_id": "api_type_id"}]}, "enforcement_mode": "enabled", "href": "href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id"}' - responses.add(responses.PUT, url, body=mock_response, content_type='application/json', status=200) + responses.add( + responses.PUT, + url, + body=mock_response, + content_type='application/json', + status=200, + ) # Set up parameter values rule_id = 'testString' if_match = 'testString' # Invoke method - response = _service.replace_rule(rule_id, if_match, headers={}) + response = _service.replace_rule( + rule_id, + if_match, + headers={}, + ) # Check for correct operation assert len(responses.calls) == 1 @@ -1220,7 +1406,13 @@ def test_replace_rule_value_error(self): # Set up mock url = preprocess_url('/v1/rules/testString') mock_response = '{"id": "id", "crn": "crn", "description": "description", "contexts": [{"attributes": [{"name": "name", "value": "value"}]}], "resources": [{"attributes": [{"name": "name", "value": "value", "operator": "operator"}], "tags": [{"name": "name", "value": "value", "operator": "operator"}]}], "operations": {"api_types": [{"api_type_id": "api_type_id"}]}, "enforcement_mode": "enabled", "href": "href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id"}' - responses.add(responses.PUT, url, body=mock_response, content_type='application/json', status=200) + responses.add( + responses.PUT, + url, + body=mock_response, + content_type='application/json', + status=200, + ) # Set up parameter values rule_id = 'testString' @@ -1258,7 +1450,11 @@ def test_delete_rule_all_params(self): """ # Set up mock url = preprocess_url('/v1/rules/testString') - responses.add(responses.DELETE, url, status=204) + responses.add( + responses.DELETE, + url, + status=204, + ) # Set up parameter values rule_id = 'testString' @@ -1267,7 +1463,10 @@ def test_delete_rule_all_params(self): # Invoke method response = _service.delete_rule( - rule_id, x_correlation_id=x_correlation_id, transaction_id=transaction_id, headers={} + rule_id, + x_correlation_id=x_correlation_id, + transaction_id=transaction_id, + headers={}, ) # Check for correct operation @@ -1290,13 +1489,20 @@ def test_delete_rule_required_params(self): """ # Set up mock url = preprocess_url('/v1/rules/testString') - responses.add(responses.DELETE, url, status=204) + responses.add( + responses.DELETE, + url, + status=204, + ) # Set up parameter values rule_id = 'testString' # Invoke method - response = _service.delete_rule(rule_id, headers={}) + response = _service.delete_rule( + rule_id, + headers={}, + ) # Check for correct operation assert len(responses.calls) == 1 @@ -1318,7 +1524,11 @@ def test_delete_rule_value_error(self): """ # Set up mock url = preprocess_url('/v1/rules/testString') - responses.add(responses.DELETE, url, status=204) + responses.add( + responses.DELETE, + url, + status=204, + ) # Set up parameter values rule_id = 'testString' @@ -1394,7 +1604,13 @@ def test_get_account_settings_all_params(self): # Set up mock url = preprocess_url('/v1/account_settings/testString') mock_response = '{"id": "id", "crn": "crn", "rule_count_limit": 16, "zone_count_limit": 16, "current_rule_count": 18, "current_zone_count": 18, "href": "href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id"}' - responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + responses.add( + responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200, + ) # Set up parameter values account_id = 'testString' @@ -1403,7 +1619,10 @@ def test_get_account_settings_all_params(self): # Invoke method response = _service.get_account_settings( - account_id, x_correlation_id=x_correlation_id, transaction_id=transaction_id, headers={} + account_id, + x_correlation_id=x_correlation_id, + transaction_id=transaction_id, + headers={}, ) # Check for correct operation @@ -1427,13 +1646,22 @@ def test_get_account_settings_required_params(self): # Set up mock url = preprocess_url('/v1/account_settings/testString') mock_response = '{"id": "id", "crn": "crn", "rule_count_limit": 16, "zone_count_limit": 16, "current_rule_count": 18, "current_zone_count": 18, "href": "href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id"}' - responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + responses.add( + responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200, + ) # Set up parameter values account_id = 'testString' # Invoke method - response = _service.get_account_settings(account_id, headers={}) + response = _service.get_account_settings( + account_id, + headers={}, + ) # Check for correct operation assert len(responses.calls) == 1 @@ -1456,7 +1684,13 @@ def test_get_account_settings_value_error(self): # Set up mock url = preprocess_url('/v1/account_settings/testString') mock_response = '{"id": "id", "crn": "crn", "rule_count_limit": 16, "zone_count_limit": 16, "current_rule_count": 18, "current_zone_count": 18, "href": "href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "created_by_id", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "last_modified_by_id"}' - responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + responses.add( + responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200, + ) # Set up parameter values account_id = 'testString' @@ -1531,17 +1765,30 @@ def test_list_available_service_operations_all_params(self): """ # Set up mock url = preprocess_url('/v1/operations') - mock_response = '{"api_types": [{"api_type_id": "api_type_id", "display_name": "display_name", "description": "description", "actions": [{"action_id": "action_id", "description": "description"}]}]}' - responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) + mock_response = '{"api_types": [{"api_type_id": "api_type_id", "display_name": "display_name", "description": "description", "type": "type", "actions": [{"action_id": "action_id", "description": "description"}]}]}' + responses.add( + responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200, + ) # Set up parameter values - service_name = 'testString' x_correlation_id = 'testString' transaction_id = 'testString' + service_name = 'testString' + service_group_id = 'testString' + resource_type = 'testString' # Invoke method response = _service.list_available_service_operations( - service_name, x_correlation_id=x_correlation_id, transaction_id=transaction_id, headers={} + x_correlation_id=x_correlation_id, + transaction_id=transaction_id, + service_name=service_name, + service_group_id=service_group_id, + resource_type=resource_type, + headers={}, ) # Check for correct operation @@ -1551,6 +1798,8 @@ def test_list_available_service_operations_all_params(self): query_string = responses.calls[0].request.url.split('?', 1)[1] query_string = urllib.parse.unquote_plus(query_string) assert 'service_name={}'.format(service_name) in query_string + assert 'service_group_id={}'.format(service_group_id) in query_string + assert 'resource_type={}'.format(resource_type) in query_string def test_list_available_service_operations_all_params_with_retries(self): # Enable retries and run test_list_available_service_operations_all_params. @@ -1568,22 +1817,21 @@ def test_list_available_service_operations_required_params(self): """ # Set up mock url = preprocess_url('/v1/operations') - mock_response = '{"api_types": [{"api_type_id": "api_type_id", "display_name": "display_name", "description": "description", "actions": [{"action_id": "action_id", "description": "description"}]}]}' - responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) - - # Set up parameter values - service_name = 'testString' + mock_response = '{"api_types": [{"api_type_id": "api_type_id", "display_name": "display_name", "description": "description", "type": "type", "actions": [{"action_id": "action_id", "description": "description"}]}]}' + responses.add( + responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200, + ) # Invoke method - response = _service.list_available_service_operations(service_name, headers={}) + response = _service.list_available_service_operations() # 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 'service_name={}'.format(service_name) in query_string def test_list_available_service_operations_required_params_with_retries(self): # Enable retries and run test_list_available_service_operations_required_params. @@ -1594,37 +1842,6 @@ def test_list_available_service_operations_required_params_with_retries(self): _service.disable_retries() self.test_list_available_service_operations_required_params() - @responses.activate - def test_list_available_service_operations_value_error(self): - """ - test_list_available_service_operations_value_error() - """ - # Set up mock - url = preprocess_url('/v1/operations') - mock_response = '{"api_types": [{"api_type_id": "api_type_id", "display_name": "display_name", "description": "description", "actions": [{"action_id": "action_id", "description": "description"}]}]}' - responses.add(responses.GET, url, body=mock_response, content_type='application/json', status=200) - - # Set up parameter values - service_name = 'testString' - - # Pass in all but one required param and check for a ValueError - req_param_dict = { - "service_name": service_name, - } - 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_available_service_operations(**req_copy) - - def test_list_available_service_operations_value_error_with_retries(self): - # Enable retries and run test_list_available_service_operations_value_error. - _service.enable_retries() - self.test_list_available_service_operations_value_error() - - # Disable retries and run test_list_available_service_operations_value_error. - _service.disable_retries() - self.test_list_available_service_operations_value_error() - # endregion ############################################################################## @@ -1636,6 +1853,8 @@ def test_list_available_service_operations_value_error_with_retries(self): # Start of Model Tests ############################################################################## # region + + class TestModel_APIType: """ Test Class for APIType @@ -1657,6 +1876,7 @@ def test_api_type_serialization(self): api_type_model_json['api_type_id'] = 'testString' api_type_model_json['display_name'] = 'testString' api_type_model_json['description'] = 'testString' + api_type_model_json['type'] = 'testString' api_type_model_json['actions'] = [action_model] # Construct a model instance of APIType by calling from_dict on the json representation @@ -1837,6 +2057,7 @@ def test_operations_list_serialization(self): api_type_model['api_type_id'] = 'testString' api_type_model['display_name'] = 'testString' api_type_model['description'] = 'testString' + api_type_model['type'] = 'testString' api_type_model['actions'] = [action_model] # Construct a json representation of a OperationsList model