diff --git a/examples/test_iam_identity_v1_examples.py b/examples/test_iam_identity_v1_examples.py index 273fb5d7..24e76462 100644 --- a/examples/test_iam_identity_v1_examples.py +++ b/examples/test_iam_identity_v1_examples.py @@ -192,7 +192,8 @@ def test_get_api_key_example(self): # begin-get_api_key response = iam_identity_service.get_api_key( - id=apikey_id + id=apikey_id, + include_activity=True, ) apikey_etag = response.get_headers()['Etag'] @@ -322,7 +323,8 @@ def test_get_service_id_example(self): # begin-get_service_id response = iam_identity_service.get_service_id( - id=svc_id + id=svc_id, + include_history=True, ) svc_id_etag = response.get_headers()['Etag'] @@ -475,7 +477,8 @@ def test_get_profile_example(self): # begin-get_profile response = iam_identity_service.get_profile( - profile_id=profile_id + profile_id=profile_id, + include_history=True, ) profile_etag = response.get_headers()['Etag'] @@ -831,6 +834,47 @@ def test_update_account_settings_example(self): except ApiException as e: pytest.fail(str(e)) + @needscredentials + def test_create_report(self): + """ + create_report request example + """ + try: + print('\ncreate_report() result:') + # begin-createReport + + create_report_response = iam_identity_service.create_report( + account_id=account_id, + type="inactive", + duration="120", + ).get_result() + + print(json.dumps(create_report_response, indent=2)) + + # end-createReport + + except ApiException as e: + pytest.fail(str(e)) + @needscredentials + def test_get_report(self): + """ + get_report request example + """ + try: + print('\nget_report() result:') + # begin-getReport + + get_report_response = iam_identity_service.get_report( + account_id=account_id, + type="latest", + ).get_result() + + print(json.dumps(get_report_response, indent=2)) + + # end-getReport + + except ApiException as e: + pytest.fail(str(e)) # endregion ############################################################################## diff --git a/ibm_platform_services/iam_identity_v1.py b/ibm_platform_services/iam_identity_v1.py index e5cc01a8..93408e25 100644 --- a/ibm_platform_services/iam_identity_v1.py +++ b/ibm_platform_services/iam_identity_v1.py @@ -1,6 +1,6 @@ # coding: utf-8 -# (C) Copyright IBM Corp. 2021. +# (C) Copyright IBM Corp. 2022. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,11 +14,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -# IBM OpenAPI SDK Code Generator Version: 3.37.0-a85661cd-20210802-190136 +# IBM OpenAPI SDK Code Generator Version: 3.47.0-60650593-20220330-200002 """ The IAM Identity Service API allows for the management of Account Settings and Identities (Service IDs, ApiKeys). + +API Version: 1.0.0 """ from datetime import datetime @@ -65,7 +67,7 @@ def __init__(self, Construct a new client for the iam_identity service. :param Authenticator authenticator: The authenticator specifies the authentication mechanism. - Get up to date information from https://github.com/IBM/python-sdk-core/blob/master/README.md + Get up to date information from https://github.com/IBM/python-sdk-core/blob/main/README.md about initializing the authenticator of your choice. """ BaseService.__init__(self, @@ -101,21 +103,21 @@ def list_api_keys(self, manager or IBM Cloud space developer in order to manage service IDs of the entity. - :param str account_id: (optional) Account ID of the API keys(s) to query. - If a service IAM ID is specified in iam_id then account_id must match the + :param str account_id: (optional) Account ID of the API keys to query. If a + service IAM ID is specified in iam_id then account_id must match the account of the IAM ID. If a user IAM ID is specified in iam_id then then account_id must match the account of the Authorization token. - :param str iam_id: (optional) IAM ID of the API key(s) to be queried. The - IAM ID may be that of a user or a service. For a user IAM ID iam_id must - match the Authorization token. + :param str iam_id: (optional) IAM ID of the API keys to be queried. The IAM + ID may be that of a user or a service. For a user IAM ID iam_id must match + the Authorization token. :param int pagesize: (optional) Optional size of a single page. Default is 20 items per page. Valid range is 1 to 100. :param str pagetoken: (optional) Optional Prev or Next page token returned from a previous query execution. Default is start with first page. :param str scope: (optional) Optional parameter to define the scope of the - queried API Keys. Can be 'entity' (default) or 'account'. + queried API keys. Can be 'entity' (default) or 'account'. :param str type: (optional) Optional parameter to filter the type of the - queried API Keys. Can be 'user' or 'serviceid'. + queried API keys. Can be 'user' or 'serviceid'. :param str sort: (optional) Optional sort property, valid values are name, description, created_at and created_by. If specified, the items are sorted by the value of this property. @@ -292,6 +294,7 @@ def get_api_key(self, id: str, *, include_history: bool = None, + include_activity: bool = None, **kwargs ) -> DetailedResponse: """ @@ -306,6 +309,9 @@ def get_api_key(self, :param str id: Unique ID of the API key. :param bool include_history: (optional) Defines if the entity history is included in the response. + :param bool include_activity: (optional) Defines if the entity's activity + is included in the response. Retrieving activity data is an expensive + operation, so please only request this when needed. :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 `ApiKey` object @@ -320,7 +326,8 @@ def get_api_key(self, headers.update(sdk_headers) params = { - 'include_history': include_history + 'include_history': include_history, + 'include_activity': include_activity } if 'headers' in kwargs: @@ -686,6 +693,7 @@ def get_service_id(self, id: str, *, include_history: bool = None, + include_activity: bool = None, **kwargs ) -> DetailedResponse: """ @@ -699,6 +707,9 @@ def get_service_id(self, :param str id: Unique ID of the service ID. :param bool include_history: (optional) Defines if the entity history is included in the response. + :param bool include_activity: (optional) Defines if the entity's activity + is included in the response. Retrieving activity data is an expensive + operation, so please only request this when needed. :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 `ServiceId` object @@ -713,7 +724,8 @@ def get_service_id(self, headers.update(sdk_headers) params = { - 'include_history': include_history + 'include_history': include_history, + 'include_activity': include_activity } if 'headers' in kwargs: @@ -1069,6 +1081,8 @@ def list_profiles(self, def get_profile(self, profile_id: str, + *, + include_activity: bool = None, **kwargs ) -> DetailedResponse: """ @@ -1079,6 +1093,9 @@ def get_profile(self, compute resources that qualify to apply the trusted profile. :param str profile_id: ID of the trusted profile to get. + :param bool include_activity: (optional) Defines if the entity's activity + is included in the response. Retrieving activity data is an expensive + operation, so please only request this when needed. :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 `TrustedProfile` object @@ -1092,6 +1109,10 @@ def get_profile(self, operation_id='get_profile') headers.update(sdk_headers) + params = { + 'include_activity': include_activity + } + if 'headers' in kwargs: headers.update(kwargs.get('headers')) headers['Accept'] = 'application/json' @@ -1102,7 +1123,8 @@ def get_profile(self, url = '/v1/profiles/{profile-id}'.format(**path_param_dict) request = self.prepare_request(method='GET', url=url, - headers=headers) + headers=headers, + params=params) response = self.send(request, **kwargs) return response @@ -1870,6 +1892,107 @@ def update_account_settings(self, response = self.send(request, **kwargs) return response + ######################### + # activityOperations + ######################### + + + def create_report(self, + account_id: str, + *, + type: str = None, + duration: str = None, + **kwargs + ) -> DetailedResponse: + """ + Trigger activity report across on account scope. + + Trigger activity report across on account scope for a given accountid. + + :param str account_id: ID of the account. + :param str type: (optional) Optional report type, supported value is + 'inactive' - List all identities that have not authenticated within the + time indicated by duration. + :param str duration: (optional) Optional duration of the report, supported + unit of duration is hours. + :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 `ReportReference` object + """ + + if account_id is None: + raise ValueError('account_id must be provided') + headers = {} + sdk_headers = get_sdk_headers(service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='create_report') + headers.update(sdk_headers) + + params = { + 'type': type, + 'duration': duration + } + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + headers['Accept'] = 'application/json' + + path_param_keys = ['account_id'] + path_param_values = self.encode_path_vars(account_id) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/v1/activity/accounts/{account_id}/report'.format(**path_param_dict) + request = self.prepare_request(method='POST', + url=url, + headers=headers, + params=params) + + response = self.send(request, **kwargs) + return response + + + def get_report(self, + account_id: str, + reference: str, + **kwargs + ) -> DetailedResponse: + """ + Get activity report across on account scope. + + Get activity report across on account scope for a given accountid. + + :param str account_id: ID of the account. + :param str reference: Reference for the report to be generated, You can use + 'latest' to get the latest report for the given account. + :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 `Report` object + """ + + if account_id is None: + raise ValueError('account_id must be provided') + if reference is None: + raise ValueError('reference must be provided') + headers = {} + sdk_headers = get_sdk_headers(service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='get_report') + headers.update(sdk_headers) + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + headers['Accept'] = 'application/json' + + path_param_keys = ['account_id', 'reference'] + path_param_values = self.encode_path_vars(account_id, reference) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/v1/activity/accounts/{account_id}/report/{reference}'.format(**path_param_dict) + request = self.prepare_request(method='GET', + url=url, + headers=headers) + + response = self.send(request, **kwargs) + return response + class ListApiKeysEnums: """ @@ -1878,14 +2001,14 @@ class ListApiKeysEnums: class Scope(str, Enum): """ - Optional parameter to define the scope of the queried API Keys. Can be 'entity' + Optional parameter to define the scope of the queried API keys. Can be 'entity' (default) or 'account'. """ ENTITY = 'entity' ACCOUNT = 'account' class Type(str, Enum): """ - Optional parameter to filter the type of the queried API Keys. Can be 'user' or + Optional parameter to filter the type of the queried API keys. Can be 'user' or 'serviceid'. """ USER = 'user' @@ -2178,6 +2301,74 @@ class MfaEnum(str, Enum): LEVEL3 = 'LEVEL3' +class Activity(): + """ + Activity. + + :attr str last_authn: (optional) Time when the entity was last authenticated. + :attr int authn_count: Authentication count, number of times the entity was + authenticated. + """ + + def __init__(self, + authn_count: int, + *, + last_authn: str = None) -> None: + """ + Initialize a Activity object. + + :param int authn_count: Authentication count, number of times the entity + was authenticated. + :param str last_authn: (optional) Time when the entity was last + authenticated. + """ + self.last_authn = last_authn + self.authn_count = authn_count + + @classmethod + def from_dict(cls, _dict: Dict) -> 'Activity': + """Initialize a Activity object from a json dictionary.""" + args = {} + if 'last_authn' in _dict: + args['last_authn'] = _dict.get('last_authn') + if 'authn_count' in _dict: + args['authn_count'] = _dict.get('authn_count') + else: + raise ValueError('Required property \'authn_count\' not present in Activity JSON') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a Activity object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'last_authn') and self.last_authn is not None: + _dict['last_authn'] = self.last_authn + if hasattr(self, 'authn_count') and self.authn_count is not None: + _dict['authn_count'] = self.authn_count + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this Activity object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'Activity') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'Activity') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + class ApiKey(): """ Response body format for API key V1 REST requests. @@ -2210,6 +2401,7 @@ class ApiKey(): API key value, for example all user API key related operations, except for create, don't contain the API key value. :attr List[EnityHistoryRecord] history: (optional) History of the API key. + :attr Activity activity: (optional) """ def __init__(self, @@ -2227,7 +2419,8 @@ def __init__(self, created_at: datetime = None, modified_at: datetime = None, description: str = None, - history: List['EnityHistoryRecord'] = None) -> None: + history: List['EnityHistoryRecord'] = None, + activity: 'Activity' = None) -> None: """ Initialize a ApiKey object. @@ -2263,6 +2456,7 @@ def __init__(self, The 'description' property is only available if a description was provided during a create of an API key. :param List[EnityHistoryRecord] history: (optional) History of the API key. + :param Activity activity: (optional) """ self.context = context self.id = id @@ -2278,6 +2472,7 @@ def __init__(self, self.account_id = account_id self.apikey = apikey self.history = history + self.activity = activity @classmethod def from_dict(cls, _dict: Dict) -> 'ApiKey': @@ -2327,6 +2522,8 @@ def from_dict(cls, _dict: Dict) -> 'ApiKey': raise ValueError('Required property \'apikey\' not present in ApiKey JSON') if 'history' in _dict: args['history'] = [EnityHistoryRecord.from_dict(x) for x in _dict.get('history')] + if 'activity' in _dict: + args['activity'] = Activity.from_dict(_dict.get('activity')) return cls(**args) @classmethod @@ -2365,6 +2562,8 @@ def to_dict(self) -> Dict: _dict['apikey'] = self.apikey if hasattr(self, 'history') and self.history is not None: _dict['history'] = [x.to_dict() for x in self.history] + if hasattr(self, 'activity') and self.activity is not None: + _dict['activity'] = self.activity.to_dict() return _dict def _to_dict(self): @@ -2793,6 +2992,80 @@ def __ne__(self, other: 'EnityHistoryRecord') -> bool: """Return `true` when self and other are not equal, false otherwise.""" return not self == other +class EntityActivity(): + """ + EntityActivity. + + :attr str id: Unique id of the entity. + :attr str name: (optional) Name provided during creation of the entity. + :attr str last_authn: (optional) Time when the entity was last authenticated. + """ + + def __init__(self, + id: str, + *, + name: str = None, + last_authn: str = None) -> None: + """ + Initialize a EntityActivity object. + + :param str id: Unique id of the entity. + :param str name: (optional) Name provided during creation of the entity. + :param str last_authn: (optional) Time when the entity was last + authenticated. + """ + self.id = id + self.name = name + self.last_authn = last_authn + + @classmethod + def from_dict(cls, _dict: Dict) -> 'EntityActivity': + """Initialize a EntityActivity object from a json dictionary.""" + args = {} + if 'id' in _dict: + args['id'] = _dict.get('id') + else: + raise ValueError('Required property \'id\' not present in EntityActivity JSON') + if 'name' in _dict: + args['name'] = _dict.get('name') + if 'last_authn' in _dict: + args['last_authn'] = _dict.get('last_authn') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a EntityActivity object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'id') and self.id is not None: + _dict['id'] = self.id + if hasattr(self, 'name') and self.name is not None: + _dict['name'] = self.name + if hasattr(self, 'last_authn') and self.last_authn is not None: + _dict['last_authn'] = self.last_authn + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this EntityActivity object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'EntityActivity') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'EntityActivity') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + class ProfileClaimRule(): """ ProfileClaimRule. @@ -3343,6 +3616,192 @@ def __ne__(self, other: 'ProfileLinkList') -> bool: """Return `true` when self and other are not equal, false otherwise.""" return not self == other +class Report(): + """ + Report. + + :attr str created_by: IAMid of the user who triggered the report. + :attr str reference: Unique reference used to generate the report. + :attr str report_duration: Duration in hours for which the report is generated. + :attr str report_start_time: Start time of the report. + :attr str report_end_time: End time of the report. + :attr List[UserActivity] users: (optional) List of users. + :attr List[EntityActivity] apikeys: (optional) List of apikeys. + :attr List[EntityActivity] serviceids: (optional) List of serviceids. + :attr List[EntityActivity] profiles: (optional) List of profiles. + """ + + def __init__(self, + created_by: str, + reference: str, + report_duration: str, + report_start_time: str, + report_end_time: str, + *, + users: List['UserActivity'] = None, + apikeys: List['EntityActivity'] = None, + serviceids: List['EntityActivity'] = None, + profiles: List['EntityActivity'] = None) -> None: + """ + Initialize a Report object. + + :param str created_by: IAMid of the user who triggered the report. + :param str reference: Unique reference used to generate the report. + :param str report_duration: Duration in hours for which the report is + generated. + :param str report_start_time: Start time of the report. + :param str report_end_time: End time of the report. + :param List[UserActivity] users: (optional) List of users. + :param List[EntityActivity] apikeys: (optional) List of apikeys. + :param List[EntityActivity] serviceids: (optional) List of serviceids. + :param List[EntityActivity] profiles: (optional) List of profiles. + """ + self.created_by = created_by + self.reference = reference + self.report_duration = report_duration + self.report_start_time = report_start_time + self.report_end_time = report_end_time + self.users = users + self.apikeys = apikeys + self.serviceids = serviceids + self.profiles = profiles + + @classmethod + def from_dict(cls, _dict: Dict) -> 'Report': + """Initialize a Report object from a json dictionary.""" + args = {} + if 'created_by' in _dict: + args['created_by'] = _dict.get('created_by') + else: + raise ValueError('Required property \'created_by\' not present in Report JSON') + if 'reference' in _dict: + args['reference'] = _dict.get('reference') + else: + raise ValueError('Required property \'reference\' not present in Report JSON') + if 'report_duration' in _dict: + args['report_duration'] = _dict.get('report_duration') + else: + raise ValueError('Required property \'report_duration\' not present in Report JSON') + if 'report_start_time' in _dict: + args['report_start_time'] = _dict.get('report_start_time') + else: + raise ValueError('Required property \'report_start_time\' not present in Report JSON') + if 'report_end_time' in _dict: + args['report_end_time'] = _dict.get('report_end_time') + else: + raise ValueError('Required property \'report_end_time\' not present in Report JSON') + if 'users' in _dict: + args['users'] = [UserActivity.from_dict(x) for x in _dict.get('users')] + if 'apikeys' in _dict: + args['apikeys'] = [EntityActivity.from_dict(x) for x in _dict.get('apikeys')] + if 'serviceids' in _dict: + args['serviceids'] = [EntityActivity.from_dict(x) for x in _dict.get('serviceids')] + if 'profiles' in _dict: + args['profiles'] = [EntityActivity.from_dict(x) for x in _dict.get('profiles')] + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a Report object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'created_by') and self.created_by is not None: + _dict['created_by'] = self.created_by + if hasattr(self, 'reference') and self.reference is not None: + _dict['reference'] = self.reference + if hasattr(self, 'report_duration') and self.report_duration is not None: + _dict['report_duration'] = self.report_duration + if hasattr(self, 'report_start_time') and self.report_start_time is not None: + _dict['report_start_time'] = self.report_start_time + if hasattr(self, 'report_end_time') and self.report_end_time is not None: + _dict['report_end_time'] = self.report_end_time + if hasattr(self, 'users') and self.users is not None: + _dict['users'] = [x.to_dict() for x in self.users] + if hasattr(self, 'apikeys') and self.apikeys is not None: + _dict['apikeys'] = [x.to_dict() for x in self.apikeys] + if hasattr(self, 'serviceids') and self.serviceids is not None: + _dict['serviceids'] = [x.to_dict() for x in self.serviceids] + if hasattr(self, 'profiles') and self.profiles is not None: + _dict['profiles'] = [x.to_dict() for x in self.profiles] + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this Report object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'Report') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'Report') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + +class ReportReference(): + """ + ReportReference. + + :attr str reference: Reference for the report to be generated. + """ + + def __init__(self, + reference: str) -> None: + """ + Initialize a ReportReference object. + + :param str reference: Reference for the report to be generated. + """ + self.reference = reference + + @classmethod + def from_dict(cls, _dict: Dict) -> 'ReportReference': + """Initialize a ReportReference object from a json dictionary.""" + args = {} + if 'reference' in _dict: + args['reference'] = _dict.get('reference') + else: + raise ValueError('Required property \'reference\' not present in ReportReference JSON') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a ReportReference object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'reference') and self.reference is not None: + _dict['reference'] = self.reference + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this ReportReference object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'ReportReference') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'ReportReference') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + class ResponseContext(): """ Context with key properties for problem determination. @@ -3516,6 +3975,7 @@ class ServiceId(): :attr List[EnityHistoryRecord] history: (optional) History of the Service ID. :attr ApiKey apikey: (optional) Response body format for API key V1 REST requests. + :attr Activity activity: (optional) """ def __init__(self, @@ -3533,7 +3993,8 @@ def __init__(self, description: str = None, unique_instance_crns: List[str] = None, history: List['EnityHistoryRecord'] = None, - apikey: 'ApiKey' = None) -> None: + apikey: 'ApiKey' = None, + activity: 'Activity' = None) -> None: """ Initialize a ServiceId object. @@ -3564,6 +4025,7 @@ def __init__(self, ID. :param ApiKey apikey: (optional) Response body format for API key V1 REST requests. + :param Activity activity: (optional) """ self.context = context self.id = id @@ -3579,6 +4041,7 @@ def __init__(self, self.unique_instance_crns = unique_instance_crns self.history = history self.apikey = apikey + self.activity = activity @classmethod def from_dict(cls, _dict: Dict) -> 'ServiceId': @@ -3630,6 +4093,8 @@ def from_dict(cls, _dict: Dict) -> 'ServiceId': args['history'] = [EnityHistoryRecord.from_dict(x) for x in _dict.get('history')] if 'apikey' in _dict: args['apikey'] = ApiKey.from_dict(_dict.get('apikey')) + if 'activity' in _dict: + args['activity'] = Activity.from_dict(_dict.get('activity')) return cls(**args) @classmethod @@ -3668,6 +4133,8 @@ def to_dict(self) -> Dict: _dict['history'] = [x.to_dict() for x in self.history] if hasattr(self, 'apikey') and self.apikey is not None: _dict['apikey'] = self.apikey.to_dict() + if hasattr(self, 'activity') and self.activity is not None: + _dict['activity'] = self.activity.to_dict() return _dict def _to_dict(self): @@ -3835,6 +4302,7 @@ class TrustedProfile(): :attr int ims_user_id: (optional) IMS user ID of the trusted profile. :attr List[EnityHistoryRecord] history: (optional) History of the trusted profile. + :attr Activity activity: (optional) """ def __init__(self, @@ -3851,7 +4319,8 @@ def __init__(self, modified_at: datetime = None, ims_account_id: int = None, ims_user_id: int = None, - history: List['EnityHistoryRecord'] = None) -> None: + history: List['EnityHistoryRecord'] = None, + activity: 'Activity' = None) -> None: """ Initialize a TrustedProfile object. @@ -3882,6 +4351,7 @@ def __init__(self, :param int ims_user_id: (optional) IMS user ID of the trusted profile. :param List[EnityHistoryRecord] history: (optional) History of the trusted profile. + :param Activity activity: (optional) """ self.context = context self.id = id @@ -3896,6 +4366,7 @@ def __init__(self, self.ims_account_id = ims_account_id self.ims_user_id = ims_user_id self.history = history + self.activity = activity @classmethod def from_dict(cls, _dict: Dict) -> 'TrustedProfile': @@ -3939,6 +4410,8 @@ def from_dict(cls, _dict: Dict) -> 'TrustedProfile': args['ims_user_id'] = _dict.get('ims_user_id') if 'history' in _dict: args['history'] = [EnityHistoryRecord.from_dict(x) for x in _dict.get('history')] + if 'activity' in _dict: + args['activity'] = Activity.from_dict(_dict.get('activity')) return cls(**args) @classmethod @@ -3975,6 +4448,8 @@ def to_dict(self) -> Dict: _dict['ims_user_id'] = self.ims_user_id if hasattr(self, 'history') and self.history is not None: _dict['history'] = [x.to_dict() for x in self.history] + if hasattr(self, 'activity') and self.activity is not None: + _dict['activity'] = self.activity.to_dict() return _dict def _to_dict(self): @@ -4108,3 +4583,79 @@ def __eq__(self, other: 'TrustedProfilesList') -> bool: def __ne__(self, other: 'TrustedProfilesList') -> bool: """Return `true` when self and other are not equal, false otherwise.""" return not self == other + +class UserActivity(): + """ + UserActivity. + + :attr str iam_id: IAMid of the user. + :attr str username: Username of the user. + :attr str last_authn: (optional) Time when the user was last authenticated. + """ + + def __init__(self, + iam_id: str, + username: str, + *, + last_authn: str = None) -> None: + """ + Initialize a UserActivity object. + + :param str iam_id: IAMid of the user. + :param str username: Username of the user. + :param str last_authn: (optional) Time when the user was last + authenticated. + """ + self.iam_id = iam_id + self.username = username + self.last_authn = last_authn + + @classmethod + def from_dict(cls, _dict: Dict) -> 'UserActivity': + """Initialize a UserActivity object from a json dictionary.""" + args = {} + if 'iam_id' in _dict: + args['iam_id'] = _dict.get('iam_id') + else: + raise ValueError('Required property \'iam_id\' not present in UserActivity JSON') + if 'username' in _dict: + args['username'] = _dict.get('username') + else: + raise ValueError('Required property \'username\' not present in UserActivity JSON') + if 'last_authn' in _dict: + args['last_authn'] = _dict.get('last_authn') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a UserActivity object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'iam_id') and self.iam_id is not None: + _dict['iam_id'] = self.iam_id + if hasattr(self, 'username') and self.username is not None: + _dict['username'] = self.username + if hasattr(self, 'last_authn') and self.last_authn is not None: + _dict['last_authn'] = self.last_authn + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this UserActivity object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'UserActivity') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'UserActivity') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other diff --git a/test/integration/test_iam_identity_v1.py b/test/integration/test_iam_identity_v1.py index 74a34106..b3aa13ee 100644 --- a/test/integration/test_iam_identity_v1.py +++ b/test/integration/test_iam_identity_v1.py @@ -21,6 +21,7 @@ import json import pytest import urllib.parse as urlparse +import time from urllib.parse import parse_qs from ibm_cloud_sdk_core import * from ibm_platform_services.iam_identity_v1 import * @@ -49,6 +50,8 @@ account_setting_etag = None +report_reference = None + class TestIamIdentityV1(): """ Integration Test Class for IamIdentityV1 @@ -239,7 +242,8 @@ def test_get_api_key(self): get_api_key_response = self.iam_identity_service.get_api_key( id=apikey_id1, - include_history=True + include_history=True, + include_activity=True, ) assert get_api_key_response.get_status_code() == 200 @@ -276,7 +280,7 @@ def test_get_api_keys_details(self): assert api_key['account_id'] == self.account_id assert api_key['created_by'] == self.iam_id assert api_key['created_at'] is not None - assert api_key['locked'] == False + assert api_key['locked'] == True @needscredentials def test_list_api_keys(self): @@ -417,7 +421,8 @@ def test_get_service_id(self): get_service_id_response = self.iam_identity_service.get_service_id( id=serviceid_id1, - include_history=True + include_history=True, + include_activity=True, ) assert get_service_id_response.get_status_code() == 200 @@ -563,7 +568,8 @@ def test_get_profile(self): assert profile_id1 is not None get_profile_response = self.iam_identity_service.get_profile( - profile_id=profile_id1 + profile_id=profile_id1, + include_activity=True, ) assert get_profile_response.get_status_code() == 200 @@ -798,7 +804,7 @@ def test_delete_claimRule2(self): @needscredentials def test_create_link(self): CreateProfileLinkRequestLink = {} - CreateProfileLinkRequestLink['crn'] = 'crn:v1:staging:public:iam-identity::a/18e3020749ce4744b0b472466d61fdb4::computeresource:Fake-Compute-Resource' + CreateProfileLinkRequestLink['crn'] = 'crn:v1:staging:public:iam-identity::a/'+ self.account_id +'::computeresource:Fake-Compute-Resource' CreateProfileLinkRequestLink['namespace'] = 'default' CreateProfileLinkRequestLink['name'] = 'nice name' @@ -969,7 +975,7 @@ def test_delete_claimRule_not_found(self): def test_create_link_bad_request(self): CreateProfileLinkRequestLink = {} - CreateProfileLinkRequestLink['crn'] = 'crn:v1:staging:public:iam-identity::a/18e3020749ce4744b0b472466d61fdb4::computeresource:Fake-Compute-Resource' + CreateProfileLinkRequestLink['crn'] = 'crn:v1:staging:public:iam-identity::a/' + self.account_id + '::computeresource:Fake-Compute-Resource' CreateProfileLinkRequestLink['namespace'] = 'default' CreateProfileLinkRequestLink['name'] = 'nice name' with pytest.raises(ApiException) as e: @@ -1054,3 +1060,66 @@ def test_update_account_settings(self): assert settings["history"] is not None assert settings["session_expiration_in_seconds"] == "86400" assert settings["session_invalidation_in_seconds"] == "7200" + + @needscredentials + def test_create_report(self): + global report_reference + assert report_reference is None + + create_report_response = self.iam_identity_service.create_report( + account_id=self.account_id, + type="inactive", + duration="120", + ) + + assert create_report_response.get_status_code() == 202 + reportReference = create_report_response.get_result() + assert reportReference is not None + print('\ncreate_report() response: ', json.dumps(reportReference, indent=2)) + + + report_reference = reportReference['reference'] + assert report_reference is not None + + @needscredentials + def test_get_inactivity_report_incomplete(self): + get_report_response = self.iam_identity_service.get_report( + account_id=self.account_id, + reference=report_reference, + ) + + assert get_report_response.get_status_code() == 204 + report = get_report_response.get_result() + + @needscredentials + def test_get_inactivity_report_complete(self): + get_report_response = self.iam_identity_service.get_report( + account_id=self.account_id, + reference=report_reference, + ) + + for x in range(30): + get_report_response = self.iam_identity_service.get_report( + account_id=self.account_id, + reference=report_reference, + ) + + if(get_report_response.get_status_code()!=204): + report = get_report_response.get_result() + assert report is not None + assert report['created_by'] is not None + assert report['reference'] is not None + assert report['report_duration'] is not None + assert report['report_start_time'] is not None + assert report['report_end_time'] is not None + break + time.sleep(1) + @needscredentials + def test_get_inactivity_report_notfound(self): + with pytest.raises(ApiException) as e: + self.iam_identity_service.get_report( + account_id=self.account_id, + reference='test123', + ) + assert e.value.code == 404 + diff --git a/test/unit/test_iam_identity_v1.py b/test/unit/test_iam_identity_v1.py index 200985dd..31aa6d11 100644 --- a/test/unit/test_iam_identity_v1.py +++ b/test/unit/test_iam_identity_v1.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# (C) Copyright IBM Corp. 2021. +# (C) Copyright IBM Corp. 2022. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -33,11 +33,38 @@ _service = IamIdentityV1( authenticator=NoAuthAuthenticator() - ) +) _base_url = 'https://iam.cloud.ibm.com' _service.set_service_url(_base_url) + +def preprocess_url(operation_path: str): + """ + Returns the request url associated with the specified operation path. + This will be base_url concatenated with a quoted version of operation_path. + The returned request URL is used to register the mock response so it needs + to match the request URL that is formed by the requests library. + """ + # First, unquote the path since it might have some quoted/escaped characters in it + # due to how the generator inserts the operation paths into the unit test code. + operation_path = urllib.parse.unquote(operation_path) + + # Next, quote the path using urllib so that we approximate what will + # happen during request processing. + operation_path = urllib.parse.quote(operation_path, safe='/') + + # Finally, form the request URL from the base URL and operation path. + request_url = _base_url + operation_path + + # If the request url does NOT end with a /, then just return it as-is. + # Otherwise, return a regular expression that matches one or more trailing /. + if re.fullmatch('.*/+', request_url) is None: + return request_url + else: + return re.compile(request_url.rstrip('/') + '/+') + + ############################################################################## # Start of Service: APIKeyOperations ############################################################################## @@ -67,6 +94,7 @@ def test_new_instance_without_authenticator(self): """ with pytest.raises(ValueError, match='authenticator must be provided'): service = IamIdentityV1.new_instance( + service_name='TEST_SERVICE_NOT_FOUND', ) class TestListApiKeys(): @@ -74,25 +102,14 @@ class TestListApiKeys(): Test Class for list_api_keys """ - def preprocess_url(self, request_url: str): - """ - Preprocess the request URL to ensure the mock response will be found. - """ - request_url = urllib.parse.unquote(request_url) # don't double-encode if already encoded - request_url = urllib.parse.quote(request_url, safe=':/') - if re.fullmatch('.*/+', request_url) is None: - return request_url - else: - return re.compile(request_url.rstrip('/') + '/+') - @responses.activate def test_list_api_keys_all_params(self): """ list_api_keys() """ # Set up mock - url = self.preprocess_url(_base_url + '/v1/apikeys') - mock_response = '{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "offset": 6, "limit": 5, "first": "first", "previous": "previous", "next": "next", "apikeys": [{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "entity_tag": "entity_tag", "crn": "crn", "locked": true, "created_at": "2019-01-01T12:00:00.000Z", "created_by": "created_by", "modified_at": "2019-01-01T12:00:00.000Z", "name": "name", "description": "description", "iam_id": "iam_id", "account_id": "account_id", "apikey": "apikey", "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}]}]}' + url = preprocess_url('/v1/apikeys') + mock_response = '{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "offset": 6, "limit": 5, "first": "first", "previous": "previous", "next": "next", "apikeys": [{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "entity_tag": "entity_tag", "crn": "crn", "locked": true, "created_at": "2019-01-01T12:00:00.000Z", "created_by": "created_by", "modified_at": "2019-01-01T12:00:00.000Z", "name": "name", "description": "description", "iam_id": "iam_id", "account_id": "account_id", "apikey": "apikey", "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}], "activity": {"last_authn": "last_authn", "authn_count": 11}}]}' responses.add(responses.GET, url, body=mock_response, @@ -140,6 +157,14 @@ def test_list_api_keys_all_params(self): assert 'order={}'.format(order) in query_string assert 'include_history={}'.format('true' if include_history else 'false') in query_string + def test_list_api_keys_all_params_with_retries(self): + # Enable retries and run test_list_api_keys_all_params. + _service.enable_retries() + self.test_list_api_keys_all_params() + + # Disable retries and run test_list_api_keys_all_params. + _service.disable_retries() + self.test_list_api_keys_all_params() @responses.activate def test_list_api_keys_required_params(self): @@ -147,8 +172,8 @@ def test_list_api_keys_required_params(self): test_list_api_keys_required_params() """ # Set up mock - url = self.preprocess_url(_base_url + '/v1/apikeys') - mock_response = '{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "offset": 6, "limit": 5, "first": "first", "previous": "previous", "next": "next", "apikeys": [{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "entity_tag": "entity_tag", "crn": "crn", "locked": true, "created_at": "2019-01-01T12:00:00.000Z", "created_by": "created_by", "modified_at": "2019-01-01T12:00:00.000Z", "name": "name", "description": "description", "iam_id": "iam_id", "account_id": "account_id", "apikey": "apikey", "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}]}]}' + url = preprocess_url('/v1/apikeys') + mock_response = '{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "offset": 6, "limit": 5, "first": "first", "previous": "previous", "next": "next", "apikeys": [{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "entity_tag": "entity_tag", "crn": "crn", "locked": true, "created_at": "2019-01-01T12:00:00.000Z", "created_by": "created_by", "modified_at": "2019-01-01T12:00:00.000Z", "name": "name", "description": "description", "iam_id": "iam_id", "account_id": "account_id", "apikey": "apikey", "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}], "activity": {"last_authn": "last_authn", "authn_count": 11}}]}' responses.add(responses.GET, url, body=mock_response, @@ -163,31 +188,28 @@ def test_list_api_keys_required_params(self): assert len(responses.calls) == 1 assert response.status_code == 200 + def test_list_api_keys_required_params_with_retries(self): + # Enable retries and run test_list_api_keys_required_params. + _service.enable_retries() + self.test_list_api_keys_required_params() + + # Disable retries and run test_list_api_keys_required_params. + _service.disable_retries() + self.test_list_api_keys_required_params() class TestCreateApiKey(): """ Test Class for create_api_key """ - def preprocess_url(self, request_url: str): - """ - Preprocess the request URL to ensure the mock response will be found. - """ - request_url = urllib.parse.unquote(request_url) # don't double-encode if already encoded - request_url = urllib.parse.quote(request_url, safe=':/') - if re.fullmatch('.*/+', request_url) is None: - return request_url - else: - return re.compile(request_url.rstrip('/') + '/+') - @responses.activate def test_create_api_key_all_params(self): """ create_api_key() """ # Set up mock - url = self.preprocess_url(_base_url + '/v1/apikeys') - mock_response = '{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "entity_tag": "entity_tag", "crn": "crn", "locked": true, "created_at": "2019-01-01T12:00:00.000Z", "created_by": "created_by", "modified_at": "2019-01-01T12:00:00.000Z", "name": "name", "description": "description", "iam_id": "iam_id", "account_id": "account_id", "apikey": "apikey", "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}]}' + url = preprocess_url('/v1/apikeys') + mock_response = '{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "entity_tag": "entity_tag", "crn": "crn", "locked": true, "created_at": "2019-01-01T12:00:00.000Z", "created_by": "created_by", "modified_at": "2019-01-01T12:00:00.000Z", "name": "name", "description": "description", "iam_id": "iam_id", "account_id": "account_id", "apikey": "apikey", "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}], "activity": {"last_authn": "last_authn", "authn_count": 11}}' responses.add(responses.POST, url, body=mock_response, @@ -227,6 +249,14 @@ def test_create_api_key_all_params(self): assert req_body['apikey'] == 'testString' assert req_body['store_value'] == True + def test_create_api_key_all_params_with_retries(self): + # Enable retries and run test_create_api_key_all_params. + _service.enable_retries() + self.test_create_api_key_all_params() + + # Disable retries and run test_create_api_key_all_params. + _service.disable_retries() + self.test_create_api_key_all_params() @responses.activate def test_create_api_key_required_params(self): @@ -234,8 +264,8 @@ def test_create_api_key_required_params(self): test_create_api_key_required_params() """ # Set up mock - url = self.preprocess_url(_base_url + '/v1/apikeys') - mock_response = '{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "entity_tag": "entity_tag", "crn": "crn", "locked": true, "created_at": "2019-01-01T12:00:00.000Z", "created_by": "created_by", "modified_at": "2019-01-01T12:00:00.000Z", "name": "name", "description": "description", "iam_id": "iam_id", "account_id": "account_id", "apikey": "apikey", "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}]}' + url = preprocess_url('/v1/apikeys') + mock_response = '{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "entity_tag": "entity_tag", "crn": "crn", "locked": true, "created_at": "2019-01-01T12:00:00.000Z", "created_by": "created_by", "modified_at": "2019-01-01T12:00:00.000Z", "name": "name", "description": "description", "iam_id": "iam_id", "account_id": "account_id", "apikey": "apikey", "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}], "activity": {"last_authn": "last_authn", "authn_count": 11}}' responses.add(responses.POST, url, body=mock_response, @@ -273,6 +303,14 @@ def test_create_api_key_required_params(self): assert req_body['apikey'] == 'testString' assert req_body['store_value'] == True + def test_create_api_key_required_params_with_retries(self): + # Enable retries and run test_create_api_key_required_params. + _service.enable_retries() + self.test_create_api_key_required_params() + + # Disable retries and run test_create_api_key_required_params. + _service.disable_retries() + self.test_create_api_key_required_params() @responses.activate def test_create_api_key_value_error(self): @@ -280,8 +318,8 @@ def test_create_api_key_value_error(self): test_create_api_key_value_error() """ # Set up mock - url = self.preprocess_url(_base_url + '/v1/apikeys') - mock_response = '{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "entity_tag": "entity_tag", "crn": "crn", "locked": true, "created_at": "2019-01-01T12:00:00.000Z", "created_by": "created_by", "modified_at": "2019-01-01T12:00:00.000Z", "name": "name", "description": "description", "iam_id": "iam_id", "account_id": "account_id", "apikey": "apikey", "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}]}' + url = preprocess_url('/v1/apikeys') + mock_response = '{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "entity_tag": "entity_tag", "crn": "crn", "locked": true, "created_at": "2019-01-01T12:00:00.000Z", "created_by": "created_by", "modified_at": "2019-01-01T12:00:00.000Z", "name": "name", "description": "description", "iam_id": "iam_id", "account_id": "account_id", "apikey": "apikey", "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}], "activity": {"last_authn": "last_authn", "authn_count": 11}}' responses.add(responses.POST, url, body=mock_response, @@ -307,31 +345,28 @@ def test_create_api_key_value_error(self): _service.create_api_key(**req_copy) + def test_create_api_key_value_error_with_retries(self): + # Enable retries and run test_create_api_key_value_error. + _service.enable_retries() + self.test_create_api_key_value_error() + + # Disable retries and run test_create_api_key_value_error. + _service.disable_retries() + self.test_create_api_key_value_error() class TestGetApiKeysDetails(): """ Test Class for get_api_keys_details """ - def preprocess_url(self, request_url: str): - """ - Preprocess the request URL to ensure the mock response will be found. - """ - request_url = urllib.parse.unquote(request_url) # don't double-encode if already encoded - request_url = urllib.parse.quote(request_url, safe=':/') - if re.fullmatch('.*/+', request_url) is None: - return request_url - else: - return re.compile(request_url.rstrip('/') + '/+') - @responses.activate def test_get_api_keys_details_all_params(self): """ get_api_keys_details() """ # Set up mock - url = self.preprocess_url(_base_url + '/v1/apikeys/details') - mock_response = '{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "entity_tag": "entity_tag", "crn": "crn", "locked": true, "created_at": "2019-01-01T12:00:00.000Z", "created_by": "created_by", "modified_at": "2019-01-01T12:00:00.000Z", "name": "name", "description": "description", "iam_id": "iam_id", "account_id": "account_id", "apikey": "apikey", "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}]}' + url = preprocess_url('/v1/apikeys/details') + mock_response = '{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "entity_tag": "entity_tag", "crn": "crn", "locked": true, "created_at": "2019-01-01T12:00:00.000Z", "created_by": "created_by", "modified_at": "2019-01-01T12:00:00.000Z", "name": "name", "description": "description", "iam_id": "iam_id", "account_id": "account_id", "apikey": "apikey", "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}], "activity": {"last_authn": "last_authn", "authn_count": 11}}' responses.add(responses.GET, url, body=mock_response, @@ -357,6 +392,14 @@ def test_get_api_keys_details_all_params(self): query_string = urllib.parse.unquote_plus(query_string) assert 'include_history={}'.format('true' if include_history else 'false') in query_string + def test_get_api_keys_details_all_params_with_retries(self): + # Enable retries and run test_get_api_keys_details_all_params. + _service.enable_retries() + self.test_get_api_keys_details_all_params() + + # Disable retries and run test_get_api_keys_details_all_params. + _service.disable_retries() + self.test_get_api_keys_details_all_params() @responses.activate def test_get_api_keys_details_required_params(self): @@ -364,8 +407,8 @@ def test_get_api_keys_details_required_params(self): test_get_api_keys_details_required_params() """ # Set up mock - url = self.preprocess_url(_base_url + '/v1/apikeys/details') - mock_response = '{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "entity_tag": "entity_tag", "crn": "crn", "locked": true, "created_at": "2019-01-01T12:00:00.000Z", "created_by": "created_by", "modified_at": "2019-01-01T12:00:00.000Z", "name": "name", "description": "description", "iam_id": "iam_id", "account_id": "account_id", "apikey": "apikey", "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}]}' + url = preprocess_url('/v1/apikeys/details') + mock_response = '{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "entity_tag": "entity_tag", "crn": "crn", "locked": true, "created_at": "2019-01-01T12:00:00.000Z", "created_by": "created_by", "modified_at": "2019-01-01T12:00:00.000Z", "name": "name", "description": "description", "iam_id": "iam_id", "account_id": "account_id", "apikey": "apikey", "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}], "activity": {"last_authn": "last_authn", "authn_count": 11}}' responses.add(responses.GET, url, body=mock_response, @@ -380,31 +423,28 @@ def test_get_api_keys_details_required_params(self): assert len(responses.calls) == 1 assert response.status_code == 200 + def test_get_api_keys_details_required_params_with_retries(self): + # Enable retries and run test_get_api_keys_details_required_params. + _service.enable_retries() + self.test_get_api_keys_details_required_params() + + # Disable retries and run test_get_api_keys_details_required_params. + _service.disable_retries() + self.test_get_api_keys_details_required_params() class TestGetApiKey(): """ Test Class for get_api_key """ - def preprocess_url(self, request_url: str): - """ - Preprocess the request URL to ensure the mock response will be found. - """ - request_url = urllib.parse.unquote(request_url) # don't double-encode if already encoded - request_url = urllib.parse.quote(request_url, safe=':/') - if re.fullmatch('.*/+', request_url) is None: - return request_url - else: - return re.compile(request_url.rstrip('/') + '/+') - @responses.activate def test_get_api_key_all_params(self): """ get_api_key() """ # Set up mock - url = self.preprocess_url(_base_url + '/v1/apikeys/testString') - mock_response = '{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "entity_tag": "entity_tag", "crn": "crn", "locked": true, "created_at": "2019-01-01T12:00:00.000Z", "created_by": "created_by", "modified_at": "2019-01-01T12:00:00.000Z", "name": "name", "description": "description", "iam_id": "iam_id", "account_id": "account_id", "apikey": "apikey", "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}]}' + url = preprocess_url('/v1/apikeys/testString') + mock_response = '{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "entity_tag": "entity_tag", "crn": "crn", "locked": true, "created_at": "2019-01-01T12:00:00.000Z", "created_by": "created_by", "modified_at": "2019-01-01T12:00:00.000Z", "name": "name", "description": "description", "iam_id": "iam_id", "account_id": "account_id", "apikey": "apikey", "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}], "activity": {"last_authn": "last_authn", "authn_count": 11}}' responses.add(responses.GET, url, body=mock_response, @@ -414,11 +454,13 @@ def test_get_api_key_all_params(self): # Set up parameter values id = 'testString' include_history = False + include_activity = False # Invoke method response = _service.get_api_key( id, include_history=include_history, + include_activity=include_activity, headers={} ) @@ -429,7 +471,16 @@ def test_get_api_key_all_params(self): query_string = responses.calls[0].request.url.split('?',1)[1] query_string = urllib.parse.unquote_plus(query_string) assert 'include_history={}'.format('true' if include_history else 'false') in query_string + assert 'include_activity={}'.format('true' if include_activity else 'false') in query_string + def test_get_api_key_all_params_with_retries(self): + # Enable retries and run test_get_api_key_all_params. + _service.enable_retries() + self.test_get_api_key_all_params() + + # Disable retries and run test_get_api_key_all_params. + _service.disable_retries() + self.test_get_api_key_all_params() @responses.activate def test_get_api_key_required_params(self): @@ -437,8 +488,8 @@ def test_get_api_key_required_params(self): test_get_api_key_required_params() """ # Set up mock - url = self.preprocess_url(_base_url + '/v1/apikeys/testString') - mock_response = '{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "entity_tag": "entity_tag", "crn": "crn", "locked": true, "created_at": "2019-01-01T12:00:00.000Z", "created_by": "created_by", "modified_at": "2019-01-01T12:00:00.000Z", "name": "name", "description": "description", "iam_id": "iam_id", "account_id": "account_id", "apikey": "apikey", "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}]}' + url = preprocess_url('/v1/apikeys/testString') + mock_response = '{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "entity_tag": "entity_tag", "crn": "crn", "locked": true, "created_at": "2019-01-01T12:00:00.000Z", "created_by": "created_by", "modified_at": "2019-01-01T12:00:00.000Z", "name": "name", "description": "description", "iam_id": "iam_id", "account_id": "account_id", "apikey": "apikey", "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}], "activity": {"last_authn": "last_authn", "authn_count": 11}}' responses.add(responses.GET, url, body=mock_response, @@ -458,6 +509,14 @@ def test_get_api_key_required_params(self): assert len(responses.calls) == 1 assert response.status_code == 200 + def test_get_api_key_required_params_with_retries(self): + # Enable retries and run test_get_api_key_required_params. + _service.enable_retries() + self.test_get_api_key_required_params() + + # Disable retries and run test_get_api_key_required_params. + _service.disable_retries() + self.test_get_api_key_required_params() @responses.activate def test_get_api_key_value_error(self): @@ -465,8 +524,8 @@ def test_get_api_key_value_error(self): test_get_api_key_value_error() """ # Set up mock - url = self.preprocess_url(_base_url + '/v1/apikeys/testString') - mock_response = '{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "entity_tag": "entity_tag", "crn": "crn", "locked": true, "created_at": "2019-01-01T12:00:00.000Z", "created_by": "created_by", "modified_at": "2019-01-01T12:00:00.000Z", "name": "name", "description": "description", "iam_id": "iam_id", "account_id": "account_id", "apikey": "apikey", "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}]}' + url = preprocess_url('/v1/apikeys/testString') + mock_response = '{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "entity_tag": "entity_tag", "crn": "crn", "locked": true, "created_at": "2019-01-01T12:00:00.000Z", "created_by": "created_by", "modified_at": "2019-01-01T12:00:00.000Z", "name": "name", "description": "description", "iam_id": "iam_id", "account_id": "account_id", "apikey": "apikey", "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}], "activity": {"last_authn": "last_authn", "authn_count": 11}}' responses.add(responses.GET, url, body=mock_response, @@ -486,31 +545,28 @@ def test_get_api_key_value_error(self): _service.get_api_key(**req_copy) + def test_get_api_key_value_error_with_retries(self): + # Enable retries and run test_get_api_key_value_error. + _service.enable_retries() + self.test_get_api_key_value_error() + + # Disable retries and run test_get_api_key_value_error. + _service.disable_retries() + self.test_get_api_key_value_error() class TestUpdateApiKey(): """ Test Class for update_api_key """ - def preprocess_url(self, request_url: str): - """ - Preprocess the request URL to ensure the mock response will be found. - """ - request_url = urllib.parse.unquote(request_url) # don't double-encode if already encoded - request_url = urllib.parse.quote(request_url, safe=':/') - if re.fullmatch('.*/+', request_url) is None: - return request_url - else: - return re.compile(request_url.rstrip('/') + '/+') - @responses.activate def test_update_api_key_all_params(self): """ update_api_key() """ # Set up mock - url = self.preprocess_url(_base_url + '/v1/apikeys/testString') - mock_response = '{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "entity_tag": "entity_tag", "crn": "crn", "locked": true, "created_at": "2019-01-01T12:00:00.000Z", "created_by": "created_by", "modified_at": "2019-01-01T12:00:00.000Z", "name": "name", "description": "description", "iam_id": "iam_id", "account_id": "account_id", "apikey": "apikey", "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}]}' + url = preprocess_url('/v1/apikeys/testString') + mock_response = '{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "entity_tag": "entity_tag", "crn": "crn", "locked": true, "created_at": "2019-01-01T12:00:00.000Z", "created_by": "created_by", "modified_at": "2019-01-01T12:00:00.000Z", "name": "name", "description": "description", "iam_id": "iam_id", "account_id": "account_id", "apikey": "apikey", "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}], "activity": {"last_authn": "last_authn", "authn_count": 11}}' responses.add(responses.PUT, url, body=mock_response, @@ -540,6 +596,14 @@ def test_update_api_key_all_params(self): assert req_body['name'] == 'testString' assert req_body['description'] == 'testString' + def test_update_api_key_all_params_with_retries(self): + # Enable retries and run test_update_api_key_all_params. + _service.enable_retries() + self.test_update_api_key_all_params() + + # Disable retries and run test_update_api_key_all_params. + _service.disable_retries() + self.test_update_api_key_all_params() @responses.activate def test_update_api_key_value_error(self): @@ -547,8 +611,8 @@ def test_update_api_key_value_error(self): test_update_api_key_value_error() """ # Set up mock - url = self.preprocess_url(_base_url + '/v1/apikeys/testString') - mock_response = '{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "entity_tag": "entity_tag", "crn": "crn", "locked": true, "created_at": "2019-01-01T12:00:00.000Z", "created_by": "created_by", "modified_at": "2019-01-01T12:00:00.000Z", "name": "name", "description": "description", "iam_id": "iam_id", "account_id": "account_id", "apikey": "apikey", "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}]}' + url = preprocess_url('/v1/apikeys/testString') + mock_response = '{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "entity_tag": "entity_tag", "crn": "crn", "locked": true, "created_at": "2019-01-01T12:00:00.000Z", "created_by": "created_by", "modified_at": "2019-01-01T12:00:00.000Z", "name": "name", "description": "description", "iam_id": "iam_id", "account_id": "account_id", "apikey": "apikey", "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}], "activity": {"last_authn": "last_authn", "authn_count": 11}}' responses.add(responses.PUT, url, body=mock_response, @@ -572,30 +636,27 @@ def test_update_api_key_value_error(self): _service.update_api_key(**req_copy) + def test_update_api_key_value_error_with_retries(self): + # Enable retries and run test_update_api_key_value_error. + _service.enable_retries() + self.test_update_api_key_value_error() + + # Disable retries and run test_update_api_key_value_error. + _service.disable_retries() + self.test_update_api_key_value_error() class TestDeleteApiKey(): """ Test Class for delete_api_key """ - def preprocess_url(self, request_url: str): - """ - Preprocess the request URL to ensure the mock response will be found. - """ - request_url = urllib.parse.unquote(request_url) # don't double-encode if already encoded - request_url = urllib.parse.quote(request_url, safe=':/') - if re.fullmatch('.*/+', request_url) is None: - return request_url - else: - return re.compile(request_url.rstrip('/') + '/+') - @responses.activate def test_delete_api_key_all_params(self): """ delete_api_key() """ # Set up mock - url = self.preprocess_url(_base_url + '/v1/apikeys/testString') + url = preprocess_url('/v1/apikeys/testString') responses.add(responses.DELETE, url, status=204) @@ -613,6 +674,14 @@ def test_delete_api_key_all_params(self): assert len(responses.calls) == 1 assert response.status_code == 204 + def test_delete_api_key_all_params_with_retries(self): + # Enable retries and run test_delete_api_key_all_params. + _service.enable_retries() + self.test_delete_api_key_all_params() + + # Disable retries and run test_delete_api_key_all_params. + _service.disable_retries() + self.test_delete_api_key_all_params() @responses.activate def test_delete_api_key_value_error(self): @@ -620,7 +689,7 @@ def test_delete_api_key_value_error(self): test_delete_api_key_value_error() """ # Set up mock - url = self.preprocess_url(_base_url + '/v1/apikeys/testString') + url = preprocess_url('/v1/apikeys/testString') responses.add(responses.DELETE, url, status=204) @@ -638,30 +707,27 @@ def test_delete_api_key_value_error(self): _service.delete_api_key(**req_copy) + def test_delete_api_key_value_error_with_retries(self): + # Enable retries and run test_delete_api_key_value_error. + _service.enable_retries() + self.test_delete_api_key_value_error() + + # Disable retries and run test_delete_api_key_value_error. + _service.disable_retries() + self.test_delete_api_key_value_error() class TestLockApiKey(): """ Test Class for lock_api_key """ - def preprocess_url(self, request_url: str): - """ - Preprocess the request URL to ensure the mock response will be found. - """ - request_url = urllib.parse.unquote(request_url) # don't double-encode if already encoded - request_url = urllib.parse.quote(request_url, safe=':/') - if re.fullmatch('.*/+', request_url) is None: - return request_url - else: - return re.compile(request_url.rstrip('/') + '/+') - @responses.activate def test_lock_api_key_all_params(self): """ lock_api_key() """ # Set up mock - url = self.preprocess_url(_base_url + '/v1/apikeys/testString/lock') + url = preprocess_url('/v1/apikeys/testString/lock') responses.add(responses.POST, url, status=204) @@ -679,6 +745,14 @@ def test_lock_api_key_all_params(self): assert len(responses.calls) == 1 assert response.status_code == 204 + def test_lock_api_key_all_params_with_retries(self): + # Enable retries and run test_lock_api_key_all_params. + _service.enable_retries() + self.test_lock_api_key_all_params() + + # Disable retries and run test_lock_api_key_all_params. + _service.disable_retries() + self.test_lock_api_key_all_params() @responses.activate def test_lock_api_key_value_error(self): @@ -686,7 +760,7 @@ def test_lock_api_key_value_error(self): test_lock_api_key_value_error() """ # Set up mock - url = self.preprocess_url(_base_url + '/v1/apikeys/testString/lock') + url = preprocess_url('/v1/apikeys/testString/lock') responses.add(responses.POST, url, status=204) @@ -704,30 +778,27 @@ def test_lock_api_key_value_error(self): _service.lock_api_key(**req_copy) + def test_lock_api_key_value_error_with_retries(self): + # Enable retries and run test_lock_api_key_value_error. + _service.enable_retries() + self.test_lock_api_key_value_error() + + # Disable retries and run test_lock_api_key_value_error. + _service.disable_retries() + self.test_lock_api_key_value_error() class TestUnlockApiKey(): """ Test Class for unlock_api_key """ - def preprocess_url(self, request_url: str): - """ - Preprocess the request URL to ensure the mock response will be found. - """ - request_url = urllib.parse.unquote(request_url) # don't double-encode if already encoded - request_url = urllib.parse.quote(request_url, safe=':/') - if re.fullmatch('.*/+', request_url) is None: - return request_url - else: - return re.compile(request_url.rstrip('/') + '/+') - @responses.activate def test_unlock_api_key_all_params(self): """ unlock_api_key() """ # Set up mock - url = self.preprocess_url(_base_url + '/v1/apikeys/testString/lock') + url = preprocess_url('/v1/apikeys/testString/lock') responses.add(responses.DELETE, url, status=204) @@ -745,6 +816,14 @@ def test_unlock_api_key_all_params(self): assert len(responses.calls) == 1 assert response.status_code == 204 + def test_unlock_api_key_all_params_with_retries(self): + # Enable retries and run test_unlock_api_key_all_params. + _service.enable_retries() + self.test_unlock_api_key_all_params() + + # Disable retries and run test_unlock_api_key_all_params. + _service.disable_retries() + self.test_unlock_api_key_all_params() @responses.activate def test_unlock_api_key_value_error(self): @@ -752,7 +831,7 @@ def test_unlock_api_key_value_error(self): test_unlock_api_key_value_error() """ # Set up mock - url = self.preprocess_url(_base_url + '/v1/apikeys/testString/lock') + url = preprocess_url('/v1/apikeys/testString/lock') responses.add(responses.DELETE, url, status=204) @@ -770,6 +849,14 @@ def test_unlock_api_key_value_error(self): _service.unlock_api_key(**req_copy) + def test_unlock_api_key_value_error_with_retries(self): + # Enable retries and run test_unlock_api_key_value_error. + _service.enable_retries() + self.test_unlock_api_key_value_error() + + # Disable retries and run test_unlock_api_key_value_error. + _service.disable_retries() + self.test_unlock_api_key_value_error() # endregion ############################################################################## @@ -805,6 +892,7 @@ def test_new_instance_without_authenticator(self): """ with pytest.raises(ValueError, match='authenticator must be provided'): service = IamIdentityV1.new_instance( + service_name='TEST_SERVICE_NOT_FOUND', ) class TestListServiceIds(): @@ -812,25 +900,14 @@ class TestListServiceIds(): Test Class for list_service_ids """ - def preprocess_url(self, request_url: str): - """ - Preprocess the request URL to ensure the mock response will be found. - """ - request_url = urllib.parse.unquote(request_url) # don't double-encode if already encoded - request_url = urllib.parse.quote(request_url, safe=':/') - if re.fullmatch('.*/+', request_url) is None: - return request_url - else: - return re.compile(request_url.rstrip('/') + '/+') - @responses.activate def test_list_service_ids_all_params(self): """ list_service_ids() """ # Set up mock - url = self.preprocess_url(_base_url + '/v1/serviceids/') - mock_response = '{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "offset": 6, "limit": 5, "first": "first", "previous": "previous", "next": "next", "serviceids": [{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "iam_id": "iam_id", "entity_tag": "entity_tag", "crn": "crn", "locked": true, "created_at": "2019-01-01T12:00:00.000Z", "modified_at": "2019-01-01T12:00:00.000Z", "account_id": "account_id", "name": "name", "description": "description", "unique_instance_crns": ["unique_instance_crns"], "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}], "apikey": {"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "entity_tag": "entity_tag", "crn": "crn", "locked": true, "created_at": "2019-01-01T12:00:00.000Z", "created_by": "created_by", "modified_at": "2019-01-01T12:00:00.000Z", "name": "name", "description": "description", "iam_id": "iam_id", "account_id": "account_id", "apikey": "apikey", "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}]}}]}' + url = preprocess_url('/v1/serviceids/') + mock_response = '{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "offset": 6, "limit": 5, "first": "first", "previous": "previous", "next": "next", "serviceids": [{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "iam_id": "iam_id", "entity_tag": "entity_tag", "crn": "crn", "locked": true, "created_at": "2019-01-01T12:00:00.000Z", "modified_at": "2019-01-01T12:00:00.000Z", "account_id": "account_id", "name": "name", "description": "description", "unique_instance_crns": ["unique_instance_crns"], "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}], "apikey": {"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "entity_tag": "entity_tag", "crn": "crn", "locked": true, "created_at": "2019-01-01T12:00:00.000Z", "created_by": "created_by", "modified_at": "2019-01-01T12:00:00.000Z", "name": "name", "description": "description", "iam_id": "iam_id", "account_id": "account_id", "apikey": "apikey", "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}], "activity": {"last_authn": "last_authn", "authn_count": 11}}, "activity": {"last_authn": "last_authn", "authn_count": 11}}]}' responses.add(responses.GET, url, body=mock_response, @@ -872,6 +949,14 @@ def test_list_service_ids_all_params(self): assert 'order={}'.format(order) in query_string assert 'include_history={}'.format('true' if include_history else 'false') in query_string + def test_list_service_ids_all_params_with_retries(self): + # Enable retries and run test_list_service_ids_all_params. + _service.enable_retries() + self.test_list_service_ids_all_params() + + # Disable retries and run test_list_service_ids_all_params. + _service.disable_retries() + self.test_list_service_ids_all_params() @responses.activate def test_list_service_ids_required_params(self): @@ -879,8 +964,8 @@ def test_list_service_ids_required_params(self): test_list_service_ids_required_params() """ # Set up mock - url = self.preprocess_url(_base_url + '/v1/serviceids/') - mock_response = '{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "offset": 6, "limit": 5, "first": "first", "previous": "previous", "next": "next", "serviceids": [{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "iam_id": "iam_id", "entity_tag": "entity_tag", "crn": "crn", "locked": true, "created_at": "2019-01-01T12:00:00.000Z", "modified_at": "2019-01-01T12:00:00.000Z", "account_id": "account_id", "name": "name", "description": "description", "unique_instance_crns": ["unique_instance_crns"], "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}], "apikey": {"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "entity_tag": "entity_tag", "crn": "crn", "locked": true, "created_at": "2019-01-01T12:00:00.000Z", "created_by": "created_by", "modified_at": "2019-01-01T12:00:00.000Z", "name": "name", "description": "description", "iam_id": "iam_id", "account_id": "account_id", "apikey": "apikey", "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}]}}]}' + url = preprocess_url('/v1/serviceids/') + mock_response = '{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "offset": 6, "limit": 5, "first": "first", "previous": "previous", "next": "next", "serviceids": [{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "iam_id": "iam_id", "entity_tag": "entity_tag", "crn": "crn", "locked": true, "created_at": "2019-01-01T12:00:00.000Z", "modified_at": "2019-01-01T12:00:00.000Z", "account_id": "account_id", "name": "name", "description": "description", "unique_instance_crns": ["unique_instance_crns"], "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}], "apikey": {"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "entity_tag": "entity_tag", "crn": "crn", "locked": true, "created_at": "2019-01-01T12:00:00.000Z", "created_by": "created_by", "modified_at": "2019-01-01T12:00:00.000Z", "name": "name", "description": "description", "iam_id": "iam_id", "account_id": "account_id", "apikey": "apikey", "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}], "activity": {"last_authn": "last_authn", "authn_count": 11}}, "activity": {"last_authn": "last_authn", "authn_count": 11}}]}' responses.add(responses.GET, url, body=mock_response, @@ -895,31 +980,28 @@ def test_list_service_ids_required_params(self): assert len(responses.calls) == 1 assert response.status_code == 200 + def test_list_service_ids_required_params_with_retries(self): + # Enable retries and run test_list_service_ids_required_params. + _service.enable_retries() + self.test_list_service_ids_required_params() + + # Disable retries and run test_list_service_ids_required_params. + _service.disable_retries() + self.test_list_service_ids_required_params() class TestCreateServiceId(): """ Test Class for create_service_id """ - def preprocess_url(self, request_url: str): - """ - Preprocess the request URL to ensure the mock response will be found. - """ - request_url = urllib.parse.unquote(request_url) # don't double-encode if already encoded - request_url = urllib.parse.quote(request_url, safe=':/') - if re.fullmatch('.*/+', request_url) is None: - return request_url - else: - return re.compile(request_url.rstrip('/') + '/+') - @responses.activate def test_create_service_id_all_params(self): """ create_service_id() """ # Set up mock - url = self.preprocess_url(_base_url + '/v1/serviceids/') - mock_response = '{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "iam_id": "iam_id", "entity_tag": "entity_tag", "crn": "crn", "locked": true, "created_at": "2019-01-01T12:00:00.000Z", "modified_at": "2019-01-01T12:00:00.000Z", "account_id": "account_id", "name": "name", "description": "description", "unique_instance_crns": ["unique_instance_crns"], "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}], "apikey": {"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "entity_tag": "entity_tag", "crn": "crn", "locked": true, "created_at": "2019-01-01T12:00:00.000Z", "created_by": "created_by", "modified_at": "2019-01-01T12:00:00.000Z", "name": "name", "description": "description", "iam_id": "iam_id", "account_id": "account_id", "apikey": "apikey", "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}]}}' + url = preprocess_url('/v1/serviceids/') + mock_response = '{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "iam_id": "iam_id", "entity_tag": "entity_tag", "crn": "crn", "locked": true, "created_at": "2019-01-01T12:00:00.000Z", "modified_at": "2019-01-01T12:00:00.000Z", "account_id": "account_id", "name": "name", "description": "description", "unique_instance_crns": ["unique_instance_crns"], "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}], "apikey": {"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "entity_tag": "entity_tag", "crn": "crn", "locked": true, "created_at": "2019-01-01T12:00:00.000Z", "created_by": "created_by", "modified_at": "2019-01-01T12:00:00.000Z", "name": "name", "description": "description", "iam_id": "iam_id", "account_id": "account_id", "apikey": "apikey", "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}], "activity": {"last_authn": "last_authn", "authn_count": 11}}, "activity": {"last_authn": "last_authn", "authn_count": 11}}' responses.add(responses.POST, url, body=mock_response, @@ -963,6 +1045,14 @@ def test_create_service_id_all_params(self): assert req_body['unique_instance_crns'] == ['testString'] assert req_body['apikey'] == api_key_inside_create_service_id_request_model + def test_create_service_id_all_params_with_retries(self): + # Enable retries and run test_create_service_id_all_params. + _service.enable_retries() + self.test_create_service_id_all_params() + + # Disable retries and run test_create_service_id_all_params. + _service.disable_retries() + self.test_create_service_id_all_params() @responses.activate def test_create_service_id_required_params(self): @@ -970,8 +1060,8 @@ def test_create_service_id_required_params(self): test_create_service_id_required_params() """ # Set up mock - url = self.preprocess_url(_base_url + '/v1/serviceids/') - mock_response = '{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "iam_id": "iam_id", "entity_tag": "entity_tag", "crn": "crn", "locked": true, "created_at": "2019-01-01T12:00:00.000Z", "modified_at": "2019-01-01T12:00:00.000Z", "account_id": "account_id", "name": "name", "description": "description", "unique_instance_crns": ["unique_instance_crns"], "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}], "apikey": {"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "entity_tag": "entity_tag", "crn": "crn", "locked": true, "created_at": "2019-01-01T12:00:00.000Z", "created_by": "created_by", "modified_at": "2019-01-01T12:00:00.000Z", "name": "name", "description": "description", "iam_id": "iam_id", "account_id": "account_id", "apikey": "apikey", "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}]}}' + url = preprocess_url('/v1/serviceids/') + mock_response = '{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "iam_id": "iam_id", "entity_tag": "entity_tag", "crn": "crn", "locked": true, "created_at": "2019-01-01T12:00:00.000Z", "modified_at": "2019-01-01T12:00:00.000Z", "account_id": "account_id", "name": "name", "description": "description", "unique_instance_crns": ["unique_instance_crns"], "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}], "apikey": {"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "entity_tag": "entity_tag", "crn": "crn", "locked": true, "created_at": "2019-01-01T12:00:00.000Z", "created_by": "created_by", "modified_at": "2019-01-01T12:00:00.000Z", "name": "name", "description": "description", "iam_id": "iam_id", "account_id": "account_id", "apikey": "apikey", "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}], "activity": {"last_authn": "last_authn", "authn_count": 11}}, "activity": {"last_authn": "last_authn", "authn_count": 11}}' responses.add(responses.POST, url, body=mock_response, @@ -1013,6 +1103,14 @@ def test_create_service_id_required_params(self): assert req_body['unique_instance_crns'] == ['testString'] assert req_body['apikey'] == api_key_inside_create_service_id_request_model + def test_create_service_id_required_params_with_retries(self): + # Enable retries and run test_create_service_id_required_params. + _service.enable_retries() + self.test_create_service_id_required_params() + + # Disable retries and run test_create_service_id_required_params. + _service.disable_retries() + self.test_create_service_id_required_params() @responses.activate def test_create_service_id_value_error(self): @@ -1020,8 +1118,8 @@ def test_create_service_id_value_error(self): test_create_service_id_value_error() """ # Set up mock - url = self.preprocess_url(_base_url + '/v1/serviceids/') - mock_response = '{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "iam_id": "iam_id", "entity_tag": "entity_tag", "crn": "crn", "locked": true, "created_at": "2019-01-01T12:00:00.000Z", "modified_at": "2019-01-01T12:00:00.000Z", "account_id": "account_id", "name": "name", "description": "description", "unique_instance_crns": ["unique_instance_crns"], "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}], "apikey": {"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "entity_tag": "entity_tag", "crn": "crn", "locked": true, "created_at": "2019-01-01T12:00:00.000Z", "created_by": "created_by", "modified_at": "2019-01-01T12:00:00.000Z", "name": "name", "description": "description", "iam_id": "iam_id", "account_id": "account_id", "apikey": "apikey", "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}]}}' + url = preprocess_url('/v1/serviceids/') + mock_response = '{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "iam_id": "iam_id", "entity_tag": "entity_tag", "crn": "crn", "locked": true, "created_at": "2019-01-01T12:00:00.000Z", "modified_at": "2019-01-01T12:00:00.000Z", "account_id": "account_id", "name": "name", "description": "description", "unique_instance_crns": ["unique_instance_crns"], "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}], "apikey": {"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "entity_tag": "entity_tag", "crn": "crn", "locked": true, "created_at": "2019-01-01T12:00:00.000Z", "created_by": "created_by", "modified_at": "2019-01-01T12:00:00.000Z", "name": "name", "description": "description", "iam_id": "iam_id", "account_id": "account_id", "apikey": "apikey", "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}], "activity": {"last_authn": "last_authn", "authn_count": 11}}, "activity": {"last_authn": "last_authn", "authn_count": 11}}' responses.add(responses.POST, url, body=mock_response, @@ -1053,31 +1151,28 @@ def test_create_service_id_value_error(self): _service.create_service_id(**req_copy) + def test_create_service_id_value_error_with_retries(self): + # Enable retries and run test_create_service_id_value_error. + _service.enable_retries() + self.test_create_service_id_value_error() + + # Disable retries and run test_create_service_id_value_error. + _service.disable_retries() + self.test_create_service_id_value_error() class TestGetServiceId(): """ Test Class for get_service_id """ - def preprocess_url(self, request_url: str): - """ - Preprocess the request URL to ensure the mock response will be found. - """ - request_url = urllib.parse.unquote(request_url) # don't double-encode if already encoded - request_url = urllib.parse.quote(request_url, safe=':/') - if re.fullmatch('.*/+', request_url) is None: - return request_url - else: - return re.compile(request_url.rstrip('/') + '/+') - @responses.activate def test_get_service_id_all_params(self): """ get_service_id() """ # Set up mock - url = self.preprocess_url(_base_url + '/v1/serviceids/testString') - mock_response = '{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "iam_id": "iam_id", "entity_tag": "entity_tag", "crn": "crn", "locked": true, "created_at": "2019-01-01T12:00:00.000Z", "modified_at": "2019-01-01T12:00:00.000Z", "account_id": "account_id", "name": "name", "description": "description", "unique_instance_crns": ["unique_instance_crns"], "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}], "apikey": {"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "entity_tag": "entity_tag", "crn": "crn", "locked": true, "created_at": "2019-01-01T12:00:00.000Z", "created_by": "created_by", "modified_at": "2019-01-01T12:00:00.000Z", "name": "name", "description": "description", "iam_id": "iam_id", "account_id": "account_id", "apikey": "apikey", "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}]}}' + url = preprocess_url('/v1/serviceids/testString') + mock_response = '{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "iam_id": "iam_id", "entity_tag": "entity_tag", "crn": "crn", "locked": true, "created_at": "2019-01-01T12:00:00.000Z", "modified_at": "2019-01-01T12:00:00.000Z", "account_id": "account_id", "name": "name", "description": "description", "unique_instance_crns": ["unique_instance_crns"], "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}], "apikey": {"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "entity_tag": "entity_tag", "crn": "crn", "locked": true, "created_at": "2019-01-01T12:00:00.000Z", "created_by": "created_by", "modified_at": "2019-01-01T12:00:00.000Z", "name": "name", "description": "description", "iam_id": "iam_id", "account_id": "account_id", "apikey": "apikey", "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}], "activity": {"last_authn": "last_authn", "authn_count": 11}}, "activity": {"last_authn": "last_authn", "authn_count": 11}}' responses.add(responses.GET, url, body=mock_response, @@ -1087,11 +1182,13 @@ def test_get_service_id_all_params(self): # Set up parameter values id = 'testString' include_history = False + include_activity = False # Invoke method response = _service.get_service_id( id, include_history=include_history, + include_activity=include_activity, headers={} ) @@ -1102,7 +1199,16 @@ def test_get_service_id_all_params(self): query_string = responses.calls[0].request.url.split('?',1)[1] query_string = urllib.parse.unquote_plus(query_string) assert 'include_history={}'.format('true' if include_history else 'false') in query_string + assert 'include_activity={}'.format('true' if include_activity else 'false') in query_string + + def test_get_service_id_all_params_with_retries(self): + # Enable retries and run test_get_service_id_all_params. + _service.enable_retries() + self.test_get_service_id_all_params() + # Disable retries and run test_get_service_id_all_params. + _service.disable_retries() + self.test_get_service_id_all_params() @responses.activate def test_get_service_id_required_params(self): @@ -1110,8 +1216,8 @@ def test_get_service_id_required_params(self): test_get_service_id_required_params() """ # Set up mock - url = self.preprocess_url(_base_url + '/v1/serviceids/testString') - mock_response = '{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "iam_id": "iam_id", "entity_tag": "entity_tag", "crn": "crn", "locked": true, "created_at": "2019-01-01T12:00:00.000Z", "modified_at": "2019-01-01T12:00:00.000Z", "account_id": "account_id", "name": "name", "description": "description", "unique_instance_crns": ["unique_instance_crns"], "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}], "apikey": {"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "entity_tag": "entity_tag", "crn": "crn", "locked": true, "created_at": "2019-01-01T12:00:00.000Z", "created_by": "created_by", "modified_at": "2019-01-01T12:00:00.000Z", "name": "name", "description": "description", "iam_id": "iam_id", "account_id": "account_id", "apikey": "apikey", "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}]}}' + url = preprocess_url('/v1/serviceids/testString') + mock_response = '{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "iam_id": "iam_id", "entity_tag": "entity_tag", "crn": "crn", "locked": true, "created_at": "2019-01-01T12:00:00.000Z", "modified_at": "2019-01-01T12:00:00.000Z", "account_id": "account_id", "name": "name", "description": "description", "unique_instance_crns": ["unique_instance_crns"], "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}], "apikey": {"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "entity_tag": "entity_tag", "crn": "crn", "locked": true, "created_at": "2019-01-01T12:00:00.000Z", "created_by": "created_by", "modified_at": "2019-01-01T12:00:00.000Z", "name": "name", "description": "description", "iam_id": "iam_id", "account_id": "account_id", "apikey": "apikey", "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}], "activity": {"last_authn": "last_authn", "authn_count": 11}}, "activity": {"last_authn": "last_authn", "authn_count": 11}}' responses.add(responses.GET, url, body=mock_response, @@ -1131,6 +1237,14 @@ def test_get_service_id_required_params(self): assert len(responses.calls) == 1 assert response.status_code == 200 + def test_get_service_id_required_params_with_retries(self): + # Enable retries and run test_get_service_id_required_params. + _service.enable_retries() + self.test_get_service_id_required_params() + + # Disable retries and run test_get_service_id_required_params. + _service.disable_retries() + self.test_get_service_id_required_params() @responses.activate def test_get_service_id_value_error(self): @@ -1138,8 +1252,8 @@ def test_get_service_id_value_error(self): test_get_service_id_value_error() """ # Set up mock - url = self.preprocess_url(_base_url + '/v1/serviceids/testString') - mock_response = '{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "iam_id": "iam_id", "entity_tag": "entity_tag", "crn": "crn", "locked": true, "created_at": "2019-01-01T12:00:00.000Z", "modified_at": "2019-01-01T12:00:00.000Z", "account_id": "account_id", "name": "name", "description": "description", "unique_instance_crns": ["unique_instance_crns"], "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}], "apikey": {"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "entity_tag": "entity_tag", "crn": "crn", "locked": true, "created_at": "2019-01-01T12:00:00.000Z", "created_by": "created_by", "modified_at": "2019-01-01T12:00:00.000Z", "name": "name", "description": "description", "iam_id": "iam_id", "account_id": "account_id", "apikey": "apikey", "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}]}}' + url = preprocess_url('/v1/serviceids/testString') + mock_response = '{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "iam_id": "iam_id", "entity_tag": "entity_tag", "crn": "crn", "locked": true, "created_at": "2019-01-01T12:00:00.000Z", "modified_at": "2019-01-01T12:00:00.000Z", "account_id": "account_id", "name": "name", "description": "description", "unique_instance_crns": ["unique_instance_crns"], "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}], "apikey": {"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "entity_tag": "entity_tag", "crn": "crn", "locked": true, "created_at": "2019-01-01T12:00:00.000Z", "created_by": "created_by", "modified_at": "2019-01-01T12:00:00.000Z", "name": "name", "description": "description", "iam_id": "iam_id", "account_id": "account_id", "apikey": "apikey", "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}], "activity": {"last_authn": "last_authn", "authn_count": 11}}, "activity": {"last_authn": "last_authn", "authn_count": 11}}' responses.add(responses.GET, url, body=mock_response, @@ -1159,31 +1273,28 @@ def test_get_service_id_value_error(self): _service.get_service_id(**req_copy) + def test_get_service_id_value_error_with_retries(self): + # Enable retries and run test_get_service_id_value_error. + _service.enable_retries() + self.test_get_service_id_value_error() + + # Disable retries and run test_get_service_id_value_error. + _service.disable_retries() + self.test_get_service_id_value_error() class TestUpdateServiceId(): """ Test Class for update_service_id """ - def preprocess_url(self, request_url: str): - """ - Preprocess the request URL to ensure the mock response will be found. - """ - request_url = urllib.parse.unquote(request_url) # don't double-encode if already encoded - request_url = urllib.parse.quote(request_url, safe=':/') - if re.fullmatch('.*/+', request_url) is None: - return request_url - else: - return re.compile(request_url.rstrip('/') + '/+') - @responses.activate def test_update_service_id_all_params(self): """ update_service_id() """ # Set up mock - url = self.preprocess_url(_base_url + '/v1/serviceids/testString') - mock_response = '{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "iam_id": "iam_id", "entity_tag": "entity_tag", "crn": "crn", "locked": true, "created_at": "2019-01-01T12:00:00.000Z", "modified_at": "2019-01-01T12:00:00.000Z", "account_id": "account_id", "name": "name", "description": "description", "unique_instance_crns": ["unique_instance_crns"], "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}], "apikey": {"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "entity_tag": "entity_tag", "crn": "crn", "locked": true, "created_at": "2019-01-01T12:00:00.000Z", "created_by": "created_by", "modified_at": "2019-01-01T12:00:00.000Z", "name": "name", "description": "description", "iam_id": "iam_id", "account_id": "account_id", "apikey": "apikey", "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}]}}' + url = preprocess_url('/v1/serviceids/testString') + mock_response = '{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "iam_id": "iam_id", "entity_tag": "entity_tag", "crn": "crn", "locked": true, "created_at": "2019-01-01T12:00:00.000Z", "modified_at": "2019-01-01T12:00:00.000Z", "account_id": "account_id", "name": "name", "description": "description", "unique_instance_crns": ["unique_instance_crns"], "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}], "apikey": {"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "entity_tag": "entity_tag", "crn": "crn", "locked": true, "created_at": "2019-01-01T12:00:00.000Z", "created_by": "created_by", "modified_at": "2019-01-01T12:00:00.000Z", "name": "name", "description": "description", "iam_id": "iam_id", "account_id": "account_id", "apikey": "apikey", "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}], "activity": {"last_authn": "last_authn", "authn_count": 11}}, "activity": {"last_authn": "last_authn", "authn_count": 11}}' responses.add(responses.PUT, url, body=mock_response, @@ -1216,6 +1327,14 @@ def test_update_service_id_all_params(self): assert req_body['description'] == 'testString' assert req_body['unique_instance_crns'] == ['testString'] + def test_update_service_id_all_params_with_retries(self): + # Enable retries and run test_update_service_id_all_params. + _service.enable_retries() + self.test_update_service_id_all_params() + + # Disable retries and run test_update_service_id_all_params. + _service.disable_retries() + self.test_update_service_id_all_params() @responses.activate def test_update_service_id_value_error(self): @@ -1223,8 +1342,8 @@ def test_update_service_id_value_error(self): test_update_service_id_value_error() """ # Set up mock - url = self.preprocess_url(_base_url + '/v1/serviceids/testString') - mock_response = '{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "iam_id": "iam_id", "entity_tag": "entity_tag", "crn": "crn", "locked": true, "created_at": "2019-01-01T12:00:00.000Z", "modified_at": "2019-01-01T12:00:00.000Z", "account_id": "account_id", "name": "name", "description": "description", "unique_instance_crns": ["unique_instance_crns"], "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}], "apikey": {"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "entity_tag": "entity_tag", "crn": "crn", "locked": true, "created_at": "2019-01-01T12:00:00.000Z", "created_by": "created_by", "modified_at": "2019-01-01T12:00:00.000Z", "name": "name", "description": "description", "iam_id": "iam_id", "account_id": "account_id", "apikey": "apikey", "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}]}}' + url = preprocess_url('/v1/serviceids/testString') + mock_response = '{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "iam_id": "iam_id", "entity_tag": "entity_tag", "crn": "crn", "locked": true, "created_at": "2019-01-01T12:00:00.000Z", "modified_at": "2019-01-01T12:00:00.000Z", "account_id": "account_id", "name": "name", "description": "description", "unique_instance_crns": ["unique_instance_crns"], "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}], "apikey": {"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "entity_tag": "entity_tag", "crn": "crn", "locked": true, "created_at": "2019-01-01T12:00:00.000Z", "created_by": "created_by", "modified_at": "2019-01-01T12:00:00.000Z", "name": "name", "description": "description", "iam_id": "iam_id", "account_id": "account_id", "apikey": "apikey", "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}], "activity": {"last_authn": "last_authn", "authn_count": 11}}, "activity": {"last_authn": "last_authn", "authn_count": 11}}' responses.add(responses.PUT, url, body=mock_response, @@ -1249,30 +1368,27 @@ def test_update_service_id_value_error(self): _service.update_service_id(**req_copy) + def test_update_service_id_value_error_with_retries(self): + # Enable retries and run test_update_service_id_value_error. + _service.enable_retries() + self.test_update_service_id_value_error() + + # Disable retries and run test_update_service_id_value_error. + _service.disable_retries() + self.test_update_service_id_value_error() class TestDeleteServiceId(): """ Test Class for delete_service_id """ - def preprocess_url(self, request_url: str): - """ - Preprocess the request URL to ensure the mock response will be found. - """ - request_url = urllib.parse.unquote(request_url) # don't double-encode if already encoded - request_url = urllib.parse.quote(request_url, safe=':/') - if re.fullmatch('.*/+', request_url) is None: - return request_url - else: - return re.compile(request_url.rstrip('/') + '/+') - @responses.activate def test_delete_service_id_all_params(self): """ delete_service_id() """ # Set up mock - url = self.preprocess_url(_base_url + '/v1/serviceids/testString') + url = preprocess_url('/v1/serviceids/testString') responses.add(responses.DELETE, url, status=204) @@ -1290,6 +1406,14 @@ def test_delete_service_id_all_params(self): assert len(responses.calls) == 1 assert response.status_code == 204 + def test_delete_service_id_all_params_with_retries(self): + # Enable retries and run test_delete_service_id_all_params. + _service.enable_retries() + self.test_delete_service_id_all_params() + + # Disable retries and run test_delete_service_id_all_params. + _service.disable_retries() + self.test_delete_service_id_all_params() @responses.activate def test_delete_service_id_value_error(self): @@ -1297,7 +1421,7 @@ def test_delete_service_id_value_error(self): test_delete_service_id_value_error() """ # Set up mock - url = self.preprocess_url(_base_url + '/v1/serviceids/testString') + url = preprocess_url('/v1/serviceids/testString') responses.add(responses.DELETE, url, status=204) @@ -1315,30 +1439,27 @@ def test_delete_service_id_value_error(self): _service.delete_service_id(**req_copy) + def test_delete_service_id_value_error_with_retries(self): + # Enable retries and run test_delete_service_id_value_error. + _service.enable_retries() + self.test_delete_service_id_value_error() + + # Disable retries and run test_delete_service_id_value_error. + _service.disable_retries() + self.test_delete_service_id_value_error() class TestLockServiceId(): """ Test Class for lock_service_id """ - def preprocess_url(self, request_url: str): - """ - Preprocess the request URL to ensure the mock response will be found. - """ - request_url = urllib.parse.unquote(request_url) # don't double-encode if already encoded - request_url = urllib.parse.quote(request_url, safe=':/') - if re.fullmatch('.*/+', request_url) is None: - return request_url - else: - return re.compile(request_url.rstrip('/') + '/+') - @responses.activate def test_lock_service_id_all_params(self): """ lock_service_id() """ # Set up mock - url = self.preprocess_url(_base_url + '/v1/serviceids/testString/lock') + url = preprocess_url('/v1/serviceids/testString/lock') responses.add(responses.POST, url, status=204) @@ -1356,6 +1477,14 @@ def test_lock_service_id_all_params(self): assert len(responses.calls) == 1 assert response.status_code == 204 + def test_lock_service_id_all_params_with_retries(self): + # Enable retries and run test_lock_service_id_all_params. + _service.enable_retries() + self.test_lock_service_id_all_params() + + # Disable retries and run test_lock_service_id_all_params. + _service.disable_retries() + self.test_lock_service_id_all_params() @responses.activate def test_lock_service_id_value_error(self): @@ -1363,7 +1492,7 @@ def test_lock_service_id_value_error(self): test_lock_service_id_value_error() """ # Set up mock - url = self.preprocess_url(_base_url + '/v1/serviceids/testString/lock') + url = preprocess_url('/v1/serviceids/testString/lock') responses.add(responses.POST, url, status=204) @@ -1381,30 +1510,27 @@ def test_lock_service_id_value_error(self): _service.lock_service_id(**req_copy) + def test_lock_service_id_value_error_with_retries(self): + # Enable retries and run test_lock_service_id_value_error. + _service.enable_retries() + self.test_lock_service_id_value_error() + + # Disable retries and run test_lock_service_id_value_error. + _service.disable_retries() + self.test_lock_service_id_value_error() class TestUnlockServiceId(): """ Test Class for unlock_service_id """ - def preprocess_url(self, request_url: str): - """ - Preprocess the request URL to ensure the mock response will be found. - """ - request_url = urllib.parse.unquote(request_url) # don't double-encode if already encoded - request_url = urllib.parse.quote(request_url, safe=':/') - if re.fullmatch('.*/+', request_url) is None: - return request_url - else: - return re.compile(request_url.rstrip('/') + '/+') - @responses.activate def test_unlock_service_id_all_params(self): """ unlock_service_id() """ # Set up mock - url = self.preprocess_url(_base_url + '/v1/serviceids/testString/lock') + url = preprocess_url('/v1/serviceids/testString/lock') responses.add(responses.DELETE, url, status=204) @@ -1422,6 +1548,14 @@ def test_unlock_service_id_all_params(self): assert len(responses.calls) == 1 assert response.status_code == 204 + def test_unlock_service_id_all_params_with_retries(self): + # Enable retries and run test_unlock_service_id_all_params. + _service.enable_retries() + self.test_unlock_service_id_all_params() + + # Disable retries and run test_unlock_service_id_all_params. + _service.disable_retries() + self.test_unlock_service_id_all_params() @responses.activate def test_unlock_service_id_value_error(self): @@ -1429,7 +1563,7 @@ def test_unlock_service_id_value_error(self): test_unlock_service_id_value_error() """ # Set up mock - url = self.preprocess_url(_base_url + '/v1/serviceids/testString/lock') + url = preprocess_url('/v1/serviceids/testString/lock') responses.add(responses.DELETE, url, status=204) @@ -1447,6 +1581,14 @@ def test_unlock_service_id_value_error(self): _service.unlock_service_id(**req_copy) + def test_unlock_service_id_value_error_with_retries(self): + # Enable retries and run test_unlock_service_id_value_error. + _service.enable_retries() + self.test_unlock_service_id_value_error() + + # Disable retries and run test_unlock_service_id_value_error. + _service.disable_retries() + self.test_unlock_service_id_value_error() # endregion ############################################################################## @@ -1482,6 +1624,7 @@ def test_new_instance_without_authenticator(self): """ with pytest.raises(ValueError, match='authenticator must be provided'): service = IamIdentityV1.new_instance( + service_name='TEST_SERVICE_NOT_FOUND', ) class TestCreateProfile(): @@ -1489,25 +1632,14 @@ class TestCreateProfile(): Test Class for create_profile """ - def preprocess_url(self, request_url: str): - """ - Preprocess the request URL to ensure the mock response will be found. - """ - request_url = urllib.parse.unquote(request_url) # don't double-encode if already encoded - request_url = urllib.parse.quote(request_url, safe=':/') - if re.fullmatch('.*/+', request_url) is None: - return request_url - else: - return re.compile(request_url.rstrip('/') + '/+') - @responses.activate def test_create_profile_all_params(self): """ create_profile() """ # Set up mock - url = self.preprocess_url(_base_url + '/v1/profiles') - mock_response = '{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "entity_tag": "entity_tag", "crn": "crn", "name": "name", "description": "description", "created_at": "2019-01-01T12:00:00.000Z", "modified_at": "2019-01-01T12:00:00.000Z", "iam_id": "iam_id", "account_id": "account_id", "ims_account_id": 14, "ims_user_id": 11, "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}]}' + url = preprocess_url('/v1/profiles') + mock_response = '{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "entity_tag": "entity_tag", "crn": "crn", "name": "name", "description": "description", "created_at": "2019-01-01T12:00:00.000Z", "modified_at": "2019-01-01T12:00:00.000Z", "iam_id": "iam_id", "account_id": "account_id", "ims_account_id": 14, "ims_user_id": 11, "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}], "activity": {"last_authn": "last_authn", "authn_count": 11}}' responses.add(responses.POST, url, body=mock_response, @@ -1536,6 +1668,14 @@ def test_create_profile_all_params(self): assert req_body['account_id'] == 'testString' assert req_body['description'] == 'testString' + def test_create_profile_all_params_with_retries(self): + # Enable retries and run test_create_profile_all_params. + _service.enable_retries() + self.test_create_profile_all_params() + + # Disable retries and run test_create_profile_all_params. + _service.disable_retries() + self.test_create_profile_all_params() @responses.activate def test_create_profile_value_error(self): @@ -1543,8 +1683,8 @@ def test_create_profile_value_error(self): test_create_profile_value_error() """ # Set up mock - url = self.preprocess_url(_base_url + '/v1/profiles') - mock_response = '{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "entity_tag": "entity_tag", "crn": "crn", "name": "name", "description": "description", "created_at": "2019-01-01T12:00:00.000Z", "modified_at": "2019-01-01T12:00:00.000Z", "iam_id": "iam_id", "account_id": "account_id", "ims_account_id": 14, "ims_user_id": 11, "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}]}' + url = preprocess_url('/v1/profiles') + mock_response = '{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "entity_tag": "entity_tag", "crn": "crn", "name": "name", "description": "description", "created_at": "2019-01-01T12:00:00.000Z", "modified_at": "2019-01-01T12:00:00.000Z", "iam_id": "iam_id", "account_id": "account_id", "ims_account_id": 14, "ims_user_id": 11, "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}], "activity": {"last_authn": "last_authn", "authn_count": 11}}' responses.add(responses.POST, url, body=mock_response, @@ -1567,31 +1707,28 @@ def test_create_profile_value_error(self): _service.create_profile(**req_copy) + def test_create_profile_value_error_with_retries(self): + # Enable retries and run test_create_profile_value_error. + _service.enable_retries() + self.test_create_profile_value_error() + + # Disable retries and run test_create_profile_value_error. + _service.disable_retries() + self.test_create_profile_value_error() class TestListProfiles(): """ Test Class for list_profiles """ - def preprocess_url(self, request_url: str): - """ - Preprocess the request URL to ensure the mock response will be found. - """ - request_url = urllib.parse.unquote(request_url) # don't double-encode if already encoded - request_url = urllib.parse.quote(request_url, safe=':/') - if re.fullmatch('.*/+', request_url) is None: - return request_url - else: - return re.compile(request_url.rstrip('/') + '/+') - @responses.activate def test_list_profiles_all_params(self): """ list_profiles() """ # Set up mock - url = self.preprocess_url(_base_url + '/v1/profiles') - mock_response = '{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "offset": 6, "limit": 5, "first": "first", "previous": "previous", "next": "next", "profiles": [{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "entity_tag": "entity_tag", "crn": "crn", "name": "name", "description": "description", "created_at": "2019-01-01T12:00:00.000Z", "modified_at": "2019-01-01T12:00:00.000Z", "iam_id": "iam_id", "account_id": "account_id", "ims_account_id": 14, "ims_user_id": 11, "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}]}]}' + url = preprocess_url('/v1/profiles') + mock_response = '{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "offset": 6, "limit": 5, "first": "first", "previous": "previous", "next": "next", "profiles": [{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "entity_tag": "entity_tag", "crn": "crn", "name": "name", "description": "description", "created_at": "2019-01-01T12:00:00.000Z", "modified_at": "2019-01-01T12:00:00.000Z", "iam_id": "iam_id", "account_id": "account_id", "ims_account_id": 14, "ims_user_id": 11, "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}], "activity": {"last_authn": "last_authn", "authn_count": 11}}]}' responses.add(responses.GET, url, body=mock_response, @@ -1633,6 +1770,14 @@ def test_list_profiles_all_params(self): assert 'include_history={}'.format('true' if include_history else 'false') in query_string assert 'pagetoken={}'.format(pagetoken) in query_string + def test_list_profiles_all_params_with_retries(self): + # Enable retries and run test_list_profiles_all_params. + _service.enable_retries() + self.test_list_profiles_all_params() + + # Disable retries and run test_list_profiles_all_params. + _service.disable_retries() + self.test_list_profiles_all_params() @responses.activate def test_list_profiles_required_params(self): @@ -1640,8 +1785,8 @@ def test_list_profiles_required_params(self): test_list_profiles_required_params() """ # Set up mock - url = self.preprocess_url(_base_url + '/v1/profiles') - mock_response = '{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "offset": 6, "limit": 5, "first": "first", "previous": "previous", "next": "next", "profiles": [{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "entity_tag": "entity_tag", "crn": "crn", "name": "name", "description": "description", "created_at": "2019-01-01T12:00:00.000Z", "modified_at": "2019-01-01T12:00:00.000Z", "iam_id": "iam_id", "account_id": "account_id", "ims_account_id": 14, "ims_user_id": 11, "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}]}]}' + url = preprocess_url('/v1/profiles') + mock_response = '{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "offset": 6, "limit": 5, "first": "first", "previous": "previous", "next": "next", "profiles": [{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "entity_tag": "entity_tag", "crn": "crn", "name": "name", "description": "description", "created_at": "2019-01-01T12:00:00.000Z", "modified_at": "2019-01-01T12:00:00.000Z", "iam_id": "iam_id", "account_id": "account_id", "ims_account_id": 14, "ims_user_id": 11, "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}], "activity": {"last_authn": "last_authn", "authn_count": 11}}]}' responses.add(responses.GET, url, body=mock_response, @@ -1665,6 +1810,14 @@ def test_list_profiles_required_params(self): query_string = urllib.parse.unquote_plus(query_string) assert 'account_id={}'.format(account_id) in query_string + def test_list_profiles_required_params_with_retries(self): + # Enable retries and run test_list_profiles_required_params. + _service.enable_retries() + self.test_list_profiles_required_params() + + # Disable retries and run test_list_profiles_required_params. + _service.disable_retries() + self.test_list_profiles_required_params() @responses.activate def test_list_profiles_value_error(self): @@ -1672,8 +1825,8 @@ def test_list_profiles_value_error(self): test_list_profiles_value_error() """ # Set up mock - url = self.preprocess_url(_base_url + '/v1/profiles') - mock_response = '{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "offset": 6, "limit": 5, "first": "first", "previous": "previous", "next": "next", "profiles": [{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "entity_tag": "entity_tag", "crn": "crn", "name": "name", "description": "description", "created_at": "2019-01-01T12:00:00.000Z", "modified_at": "2019-01-01T12:00:00.000Z", "iam_id": "iam_id", "account_id": "account_id", "ims_account_id": 14, "ims_user_id": 11, "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}]}]}' + url = preprocess_url('/v1/profiles') + mock_response = '{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "offset": 6, "limit": 5, "first": "first", "previous": "previous", "next": "next", "profiles": [{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "entity_tag": "entity_tag", "crn": "crn", "name": "name", "description": "description", "created_at": "2019-01-01T12:00:00.000Z", "modified_at": "2019-01-01T12:00:00.000Z", "iam_id": "iam_id", "account_id": "account_id", "ims_account_id": 14, "ims_user_id": 11, "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}], "activity": {"last_authn": "last_authn", "authn_count": 11}}]}' responses.add(responses.GET, url, body=mock_response, @@ -1693,31 +1846,70 @@ def test_list_profiles_value_error(self): _service.list_profiles(**req_copy) + def test_list_profiles_value_error_with_retries(self): + # Enable retries and run test_list_profiles_value_error. + _service.enable_retries() + self.test_list_profiles_value_error() + + # Disable retries and run test_list_profiles_value_error. + _service.disable_retries() + self.test_list_profiles_value_error() class TestGetProfile(): """ Test Class for get_profile """ - def preprocess_url(self, request_url: str): + @responses.activate + def test_get_profile_all_params(self): """ - Preprocess the request URL to ensure the mock response will be found. + get_profile() """ - request_url = urllib.parse.unquote(request_url) # don't double-encode if already encoded - request_url = urllib.parse.quote(request_url, safe=':/') - if re.fullmatch('.*/+', request_url) is None: - return request_url - else: - return re.compile(request_url.rstrip('/') + '/+') + # Set up mock + url = preprocess_url('/v1/profiles/testString') + mock_response = '{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "entity_tag": "entity_tag", "crn": "crn", "name": "name", "description": "description", "created_at": "2019-01-01T12:00:00.000Z", "modified_at": "2019-01-01T12:00:00.000Z", "iam_id": "iam_id", "account_id": "account_id", "ims_account_id": 14, "ims_user_id": 11, "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}], "activity": {"last_authn": "last_authn", "authn_count": 11}}' + responses.add(responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200) + + # Set up parameter values + profile_id = 'testString' + include_activity = False + + # Invoke method + response = _service.get_profile( + profile_id, + include_activity=include_activity, + headers={} + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + # Validate query params + query_string = responses.calls[0].request.url.split('?',1)[1] + query_string = urllib.parse.unquote_plus(query_string) + assert 'include_activity={}'.format('true' if include_activity else 'false') in query_string + + def test_get_profile_all_params_with_retries(self): + # Enable retries and run test_get_profile_all_params. + _service.enable_retries() + self.test_get_profile_all_params() + + # Disable retries and run test_get_profile_all_params. + _service.disable_retries() + self.test_get_profile_all_params() @responses.activate - def test_get_profile_all_params(self): + def test_get_profile_required_params(self): """ - get_profile() + test_get_profile_required_params() """ # Set up mock - url = self.preprocess_url(_base_url + '/v1/profiles/testString') - mock_response = '{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "entity_tag": "entity_tag", "crn": "crn", "name": "name", "description": "description", "created_at": "2019-01-01T12:00:00.000Z", "modified_at": "2019-01-01T12:00:00.000Z", "iam_id": "iam_id", "account_id": "account_id", "ims_account_id": 14, "ims_user_id": 11, "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}]}' + url = preprocess_url('/v1/profiles/testString') + mock_response = '{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "entity_tag": "entity_tag", "crn": "crn", "name": "name", "description": "description", "created_at": "2019-01-01T12:00:00.000Z", "modified_at": "2019-01-01T12:00:00.000Z", "iam_id": "iam_id", "account_id": "account_id", "ims_account_id": 14, "ims_user_id": 11, "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}], "activity": {"last_authn": "last_authn", "authn_count": 11}}' responses.add(responses.GET, url, body=mock_response, @@ -1737,6 +1929,14 @@ def test_get_profile_all_params(self): assert len(responses.calls) == 1 assert response.status_code == 200 + def test_get_profile_required_params_with_retries(self): + # Enable retries and run test_get_profile_required_params. + _service.enable_retries() + self.test_get_profile_required_params() + + # Disable retries and run test_get_profile_required_params. + _service.disable_retries() + self.test_get_profile_required_params() @responses.activate def test_get_profile_value_error(self): @@ -1744,8 +1944,8 @@ def test_get_profile_value_error(self): test_get_profile_value_error() """ # Set up mock - url = self.preprocess_url(_base_url + '/v1/profiles/testString') - mock_response = '{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "entity_tag": "entity_tag", "crn": "crn", "name": "name", "description": "description", "created_at": "2019-01-01T12:00:00.000Z", "modified_at": "2019-01-01T12:00:00.000Z", "iam_id": "iam_id", "account_id": "account_id", "ims_account_id": 14, "ims_user_id": 11, "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}]}' + url = preprocess_url('/v1/profiles/testString') + mock_response = '{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "entity_tag": "entity_tag", "crn": "crn", "name": "name", "description": "description", "created_at": "2019-01-01T12:00:00.000Z", "modified_at": "2019-01-01T12:00:00.000Z", "iam_id": "iam_id", "account_id": "account_id", "ims_account_id": 14, "ims_user_id": 11, "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}], "activity": {"last_authn": "last_authn", "authn_count": 11}}' responses.add(responses.GET, url, body=mock_response, @@ -1765,31 +1965,28 @@ def test_get_profile_value_error(self): _service.get_profile(**req_copy) + def test_get_profile_value_error_with_retries(self): + # Enable retries and run test_get_profile_value_error. + _service.enable_retries() + self.test_get_profile_value_error() + + # Disable retries and run test_get_profile_value_error. + _service.disable_retries() + self.test_get_profile_value_error() class TestUpdateProfile(): """ Test Class for update_profile """ - def preprocess_url(self, request_url: str): - """ - Preprocess the request URL to ensure the mock response will be found. - """ - request_url = urllib.parse.unquote(request_url) # don't double-encode if already encoded - request_url = urllib.parse.quote(request_url, safe=':/') - if re.fullmatch('.*/+', request_url) is None: - return request_url - else: - return re.compile(request_url.rstrip('/') + '/+') - @responses.activate def test_update_profile_all_params(self): """ update_profile() """ # Set up mock - url = self.preprocess_url(_base_url + '/v1/profiles/testString') - mock_response = '{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "entity_tag": "entity_tag", "crn": "crn", "name": "name", "description": "description", "created_at": "2019-01-01T12:00:00.000Z", "modified_at": "2019-01-01T12:00:00.000Z", "iam_id": "iam_id", "account_id": "account_id", "ims_account_id": 14, "ims_user_id": 11, "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}]}' + url = preprocess_url('/v1/profiles/testString') + mock_response = '{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "entity_tag": "entity_tag", "crn": "crn", "name": "name", "description": "description", "created_at": "2019-01-01T12:00:00.000Z", "modified_at": "2019-01-01T12:00:00.000Z", "iam_id": "iam_id", "account_id": "account_id", "ims_account_id": 14, "ims_user_id": 11, "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}], "activity": {"last_authn": "last_authn", "authn_count": 11}}' responses.add(responses.PUT, url, body=mock_response, @@ -1819,6 +2016,14 @@ def test_update_profile_all_params(self): assert req_body['name'] == 'testString' assert req_body['description'] == 'testString' + def test_update_profile_all_params_with_retries(self): + # Enable retries and run test_update_profile_all_params. + _service.enable_retries() + self.test_update_profile_all_params() + + # Disable retries and run test_update_profile_all_params. + _service.disable_retries() + self.test_update_profile_all_params() @responses.activate def test_update_profile_value_error(self): @@ -1826,8 +2031,8 @@ def test_update_profile_value_error(self): test_update_profile_value_error() """ # Set up mock - url = self.preprocess_url(_base_url + '/v1/profiles/testString') - mock_response = '{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "entity_tag": "entity_tag", "crn": "crn", "name": "name", "description": "description", "created_at": "2019-01-01T12:00:00.000Z", "modified_at": "2019-01-01T12:00:00.000Z", "iam_id": "iam_id", "account_id": "account_id", "ims_account_id": 14, "ims_user_id": 11, "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}]}' + url = preprocess_url('/v1/profiles/testString') + mock_response = '{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "id": "id", "entity_tag": "entity_tag", "crn": "crn", "name": "name", "description": "description", "created_at": "2019-01-01T12:00:00.000Z", "modified_at": "2019-01-01T12:00:00.000Z", "iam_id": "iam_id", "account_id": "account_id", "ims_account_id": 14, "ims_user_id": 11, "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}], "activity": {"last_authn": "last_authn", "authn_count": 11}}' responses.add(responses.PUT, url, body=mock_response, @@ -1851,30 +2056,27 @@ def test_update_profile_value_error(self): _service.update_profile(**req_copy) + def test_update_profile_value_error_with_retries(self): + # Enable retries and run test_update_profile_value_error. + _service.enable_retries() + self.test_update_profile_value_error() + + # Disable retries and run test_update_profile_value_error. + _service.disable_retries() + self.test_update_profile_value_error() class TestDeleteProfile(): """ Test Class for delete_profile """ - def preprocess_url(self, request_url: str): - """ - Preprocess the request URL to ensure the mock response will be found. - """ - request_url = urllib.parse.unquote(request_url) # don't double-encode if already encoded - request_url = urllib.parse.quote(request_url, safe=':/') - if re.fullmatch('.*/+', request_url) is None: - return request_url - else: - return re.compile(request_url.rstrip('/') + '/+') - @responses.activate def test_delete_profile_all_params(self): """ delete_profile() """ # Set up mock - url = self.preprocess_url(_base_url + '/v1/profiles/testString') + url = preprocess_url('/v1/profiles/testString') responses.add(responses.DELETE, url, status=204) @@ -1892,6 +2094,14 @@ def test_delete_profile_all_params(self): assert len(responses.calls) == 1 assert response.status_code == 204 + def test_delete_profile_all_params_with_retries(self): + # Enable retries and run test_delete_profile_all_params. + _service.enable_retries() + self.test_delete_profile_all_params() + + # Disable retries and run test_delete_profile_all_params. + _service.disable_retries() + self.test_delete_profile_all_params() @responses.activate def test_delete_profile_value_error(self): @@ -1899,7 +2109,7 @@ def test_delete_profile_value_error(self): test_delete_profile_value_error() """ # Set up mock - url = self.preprocess_url(_base_url + '/v1/profiles/testString') + url = preprocess_url('/v1/profiles/testString') responses.add(responses.DELETE, url, status=204) @@ -1917,30 +2127,27 @@ def test_delete_profile_value_error(self): _service.delete_profile(**req_copy) + def test_delete_profile_value_error_with_retries(self): + # Enable retries and run test_delete_profile_value_error. + _service.enable_retries() + self.test_delete_profile_value_error() + + # Disable retries and run test_delete_profile_value_error. + _service.disable_retries() + self.test_delete_profile_value_error() class TestCreateClaimRule(): """ Test Class for create_claim_rule """ - def preprocess_url(self, request_url: str): - """ - Preprocess the request URL to ensure the mock response will be found. - """ - request_url = urllib.parse.unquote(request_url) # don't double-encode if already encoded - request_url = urllib.parse.quote(request_url, safe=':/') - if re.fullmatch('.*/+', request_url) is None: - return request_url - else: - return re.compile(request_url.rstrip('/') + '/+') - @responses.activate def test_create_claim_rule_all_params(self): """ create_claim_rule() """ # Set up mock - url = self.preprocess_url(_base_url + '/v1/profiles/testString/rules') + url = preprocess_url('/v1/profiles/testString/rules') mock_response = '{"id": "id", "entity_tag": "entity_tag", "created_at": "2019-01-01T12:00:00.000Z", "modified_at": "2019-01-01T12:00:00.000Z", "name": "name", "type": "type", "realm_name": "realm_name", "expiration": 10, "cr_type": "cr_type", "conditions": [{"claim": "claim", "operator": "operator", "value": "value"}]}' responses.add(responses.POST, url, @@ -2004,6 +2211,14 @@ def test_create_claim_rule_all_params(self): assert req_body['cr_type'] == 'testString' assert req_body['expiration'] == 38 + def test_create_claim_rule_all_params_with_retries(self): + # Enable retries and run test_create_claim_rule_all_params. + _service.enable_retries() + self.test_create_claim_rule_all_params() + + # Disable retries and run test_create_claim_rule_all_params. + _service.disable_retries() + self.test_create_claim_rule_all_params() @responses.activate def test_create_claim_rule_value_error(self): @@ -2011,7 +2226,7 @@ def test_create_claim_rule_value_error(self): test_create_claim_rule_value_error() """ # Set up mock - url = self.preprocess_url(_base_url + '/v1/profiles/testString/rules') + url = preprocess_url('/v1/profiles/testString/rules') mock_response = '{"id": "id", "entity_tag": "entity_tag", "created_at": "2019-01-01T12:00:00.000Z", "modified_at": "2019-01-01T12:00:00.000Z", "name": "name", "type": "type", "realm_name": "realm_name", "expiration": 10, "cr_type": "cr_type", "conditions": [{"claim": "claim", "operator": "operator", "value": "value"}]}' responses.add(responses.POST, url, @@ -2061,30 +2276,27 @@ def test_create_claim_rule_value_error(self): _service.create_claim_rule(**req_copy) + def test_create_claim_rule_value_error_with_retries(self): + # Enable retries and run test_create_claim_rule_value_error. + _service.enable_retries() + self.test_create_claim_rule_value_error() + + # Disable retries and run test_create_claim_rule_value_error. + _service.disable_retries() + self.test_create_claim_rule_value_error() class TestListClaimRules(): """ Test Class for list_claim_rules """ - def preprocess_url(self, request_url: str): - """ - Preprocess the request URL to ensure the mock response will be found. - """ - request_url = urllib.parse.unquote(request_url) # don't double-encode if already encoded - request_url = urllib.parse.quote(request_url, safe=':/') - if re.fullmatch('.*/+', request_url) is None: - return request_url - else: - return re.compile(request_url.rstrip('/') + '/+') - @responses.activate def test_list_claim_rules_all_params(self): """ list_claim_rules() """ # Set up mock - url = self.preprocess_url(_base_url + '/v1/profiles/testString/rules') + url = preprocess_url('/v1/profiles/testString/rules') mock_response = '{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "rules": [{"id": "id", "entity_tag": "entity_tag", "created_at": "2019-01-01T12:00:00.000Z", "modified_at": "2019-01-01T12:00:00.000Z", "name": "name", "type": "type", "realm_name": "realm_name", "expiration": 10, "cr_type": "cr_type", "conditions": [{"claim": "claim", "operator": "operator", "value": "value"}]}]}' responses.add(responses.GET, url, @@ -2105,6 +2317,14 @@ def test_list_claim_rules_all_params(self): assert len(responses.calls) == 1 assert response.status_code == 200 + def test_list_claim_rules_all_params_with_retries(self): + # Enable retries and run test_list_claim_rules_all_params. + _service.enable_retries() + self.test_list_claim_rules_all_params() + + # Disable retries and run test_list_claim_rules_all_params. + _service.disable_retries() + self.test_list_claim_rules_all_params() @responses.activate def test_list_claim_rules_value_error(self): @@ -2112,7 +2332,7 @@ def test_list_claim_rules_value_error(self): test_list_claim_rules_value_error() """ # Set up mock - url = self.preprocess_url(_base_url + '/v1/profiles/testString/rules') + url = preprocess_url('/v1/profiles/testString/rules') mock_response = '{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "rules": [{"id": "id", "entity_tag": "entity_tag", "created_at": "2019-01-01T12:00:00.000Z", "modified_at": "2019-01-01T12:00:00.000Z", "name": "name", "type": "type", "realm_name": "realm_name", "expiration": 10, "cr_type": "cr_type", "conditions": [{"claim": "claim", "operator": "operator", "value": "value"}]}]}' responses.add(responses.GET, url, @@ -2133,30 +2353,27 @@ def test_list_claim_rules_value_error(self): _service.list_claim_rules(**req_copy) + def test_list_claim_rules_value_error_with_retries(self): + # Enable retries and run test_list_claim_rules_value_error. + _service.enable_retries() + self.test_list_claim_rules_value_error() + + # Disable retries and run test_list_claim_rules_value_error. + _service.disable_retries() + self.test_list_claim_rules_value_error() class TestGetClaimRule(): """ Test Class for get_claim_rule """ - def preprocess_url(self, request_url: str): - """ - Preprocess the request URL to ensure the mock response will be found. - """ - request_url = urllib.parse.unquote(request_url) # don't double-encode if already encoded - request_url = urllib.parse.quote(request_url, safe=':/') - if re.fullmatch('.*/+', request_url) is None: - return request_url - else: - return re.compile(request_url.rstrip('/') + '/+') - @responses.activate def test_get_claim_rule_all_params(self): """ get_claim_rule() """ # Set up mock - url = self.preprocess_url(_base_url + '/v1/profiles/testString/rules/testString') + url = preprocess_url('/v1/profiles/testString/rules/testString') mock_response = '{"id": "id", "entity_tag": "entity_tag", "created_at": "2019-01-01T12:00:00.000Z", "modified_at": "2019-01-01T12:00:00.000Z", "name": "name", "type": "type", "realm_name": "realm_name", "expiration": 10, "cr_type": "cr_type", "conditions": [{"claim": "claim", "operator": "operator", "value": "value"}]}' responses.add(responses.GET, url, @@ -2179,6 +2396,14 @@ def test_get_claim_rule_all_params(self): assert len(responses.calls) == 1 assert response.status_code == 200 + def test_get_claim_rule_all_params_with_retries(self): + # Enable retries and run test_get_claim_rule_all_params. + _service.enable_retries() + self.test_get_claim_rule_all_params() + + # Disable retries and run test_get_claim_rule_all_params. + _service.disable_retries() + self.test_get_claim_rule_all_params() @responses.activate def test_get_claim_rule_value_error(self): @@ -2186,7 +2411,7 @@ def test_get_claim_rule_value_error(self): test_get_claim_rule_value_error() """ # Set up mock - url = self.preprocess_url(_base_url + '/v1/profiles/testString/rules/testString') + url = preprocess_url('/v1/profiles/testString/rules/testString') mock_response = '{"id": "id", "entity_tag": "entity_tag", "created_at": "2019-01-01T12:00:00.000Z", "modified_at": "2019-01-01T12:00:00.000Z", "name": "name", "type": "type", "realm_name": "realm_name", "expiration": 10, "cr_type": "cr_type", "conditions": [{"claim": "claim", "operator": "operator", "value": "value"}]}' responses.add(responses.GET, url, @@ -2209,30 +2434,27 @@ def test_get_claim_rule_value_error(self): _service.get_claim_rule(**req_copy) + def test_get_claim_rule_value_error_with_retries(self): + # Enable retries and run test_get_claim_rule_value_error. + _service.enable_retries() + self.test_get_claim_rule_value_error() + + # Disable retries and run test_get_claim_rule_value_error. + _service.disable_retries() + self.test_get_claim_rule_value_error() class TestUpdateClaimRule(): """ Test Class for update_claim_rule """ - def preprocess_url(self, request_url: str): - """ - Preprocess the request URL to ensure the mock response will be found. - """ - request_url = urllib.parse.unquote(request_url) # don't double-encode if already encoded - request_url = urllib.parse.quote(request_url, safe=':/') - if re.fullmatch('.*/+', request_url) is None: - return request_url - else: - return re.compile(request_url.rstrip('/') + '/+') - @responses.activate def test_update_claim_rule_all_params(self): """ update_claim_rule() """ # Set up mock - url = self.preprocess_url(_base_url + '/v1/profiles/testString/rules/testString') + url = preprocess_url('/v1/profiles/testString/rules/testString') mock_response = '{"id": "id", "entity_tag": "entity_tag", "created_at": "2019-01-01T12:00:00.000Z", "modified_at": "2019-01-01T12:00:00.000Z", "name": "name", "type": "type", "realm_name": "realm_name", "expiration": 10, "cr_type": "cr_type", "conditions": [{"claim": "claim", "operator": "operator", "value": "value"}]}' responses.add(responses.PUT, url, @@ -2300,6 +2522,14 @@ def test_update_claim_rule_all_params(self): assert req_body['cr_type'] == 'testString' assert req_body['expiration'] == 38 + def test_update_claim_rule_all_params_with_retries(self): + # Enable retries and run test_update_claim_rule_all_params. + _service.enable_retries() + self.test_update_claim_rule_all_params() + + # Disable retries and run test_update_claim_rule_all_params. + _service.disable_retries() + self.test_update_claim_rule_all_params() @responses.activate def test_update_claim_rule_value_error(self): @@ -2307,7 +2537,7 @@ def test_update_claim_rule_value_error(self): test_update_claim_rule_value_error() """ # Set up mock - url = self.preprocess_url(_base_url + '/v1/profiles/testString/rules/testString') + url = preprocess_url('/v1/profiles/testString/rules/testString') mock_response = '{"id": "id", "entity_tag": "entity_tag", "created_at": "2019-01-01T12:00:00.000Z", "modified_at": "2019-01-01T12:00:00.000Z", "name": "name", "type": "type", "realm_name": "realm_name", "expiration": 10, "cr_type": "cr_type", "conditions": [{"claim": "claim", "operator": "operator", "value": "value"}]}' responses.add(responses.PUT, url, @@ -2361,30 +2591,27 @@ def test_update_claim_rule_value_error(self): _service.update_claim_rule(**req_copy) + def test_update_claim_rule_value_error_with_retries(self): + # Enable retries and run test_update_claim_rule_value_error. + _service.enable_retries() + self.test_update_claim_rule_value_error() + + # Disable retries and run test_update_claim_rule_value_error. + _service.disable_retries() + self.test_update_claim_rule_value_error() class TestDeleteClaimRule(): """ Test Class for delete_claim_rule """ - def preprocess_url(self, request_url: str): - """ - Preprocess the request URL to ensure the mock response will be found. - """ - request_url = urllib.parse.unquote(request_url) # don't double-encode if already encoded - request_url = urllib.parse.quote(request_url, safe=':/') - if re.fullmatch('.*/+', request_url) is None: - return request_url - else: - return re.compile(request_url.rstrip('/') + '/+') - @responses.activate def test_delete_claim_rule_all_params(self): """ delete_claim_rule() """ # Set up mock - url = self.preprocess_url(_base_url + '/v1/profiles/testString/rules/testString') + url = preprocess_url('/v1/profiles/testString/rules/testString') responses.add(responses.DELETE, url, status=204) @@ -2404,6 +2631,14 @@ def test_delete_claim_rule_all_params(self): assert len(responses.calls) == 1 assert response.status_code == 204 + def test_delete_claim_rule_all_params_with_retries(self): + # Enable retries and run test_delete_claim_rule_all_params. + _service.enable_retries() + self.test_delete_claim_rule_all_params() + + # Disable retries and run test_delete_claim_rule_all_params. + _service.disable_retries() + self.test_delete_claim_rule_all_params() @responses.activate def test_delete_claim_rule_value_error(self): @@ -2411,7 +2646,7 @@ def test_delete_claim_rule_value_error(self): test_delete_claim_rule_value_error() """ # Set up mock - url = self.preprocess_url(_base_url + '/v1/profiles/testString/rules/testString') + url = preprocess_url('/v1/profiles/testString/rules/testString') responses.add(responses.DELETE, url, status=204) @@ -2431,30 +2666,27 @@ def test_delete_claim_rule_value_error(self): _service.delete_claim_rule(**req_copy) + def test_delete_claim_rule_value_error_with_retries(self): + # Enable retries and run test_delete_claim_rule_value_error. + _service.enable_retries() + self.test_delete_claim_rule_value_error() + + # Disable retries and run test_delete_claim_rule_value_error. + _service.disable_retries() + self.test_delete_claim_rule_value_error() class TestCreateLink(): """ Test Class for create_link """ - def preprocess_url(self, request_url: str): - """ - Preprocess the request URL to ensure the mock response will be found. - """ - request_url = urllib.parse.unquote(request_url) # don't double-encode if already encoded - request_url = urllib.parse.quote(request_url, safe=':/') - if re.fullmatch('.*/+', request_url) is None: - return request_url - else: - return re.compile(request_url.rstrip('/') + '/+') - @responses.activate def test_create_link_all_params(self): """ create_link() """ # Set up mock - url = self.preprocess_url(_base_url + '/v1/profiles/testString/links') + url = preprocess_url('/v1/profiles/testString/links') mock_response = '{"id": "id", "entity_tag": "entity_tag", "created_at": "2019-01-01T12:00:00.000Z", "modified_at": "2019-01-01T12:00:00.000Z", "name": "name", "cr_type": "cr_type", "link": {"crn": "crn", "namespace": "namespace", "name": "name"}}' responses.add(responses.POST, url, @@ -2492,6 +2724,14 @@ def test_create_link_all_params(self): assert req_body['link'] == create_profile_link_request_link_model assert req_body['name'] == 'testString' + def test_create_link_all_params_with_retries(self): + # Enable retries and run test_create_link_all_params. + _service.enable_retries() + self.test_create_link_all_params() + + # Disable retries and run test_create_link_all_params. + _service.disable_retries() + self.test_create_link_all_params() @responses.activate def test_create_link_value_error(self): @@ -2499,7 +2739,7 @@ def test_create_link_value_error(self): test_create_link_value_error() """ # Set up mock - url = self.preprocess_url(_base_url + '/v1/profiles/testString/links') + url = preprocess_url('/v1/profiles/testString/links') mock_response = '{"id": "id", "entity_tag": "entity_tag", "created_at": "2019-01-01T12:00:00.000Z", "modified_at": "2019-01-01T12:00:00.000Z", "name": "name", "cr_type": "cr_type", "link": {"crn": "crn", "namespace": "namespace", "name": "name"}}' responses.add(responses.POST, url, @@ -2531,30 +2771,27 @@ def test_create_link_value_error(self): _service.create_link(**req_copy) + def test_create_link_value_error_with_retries(self): + # Enable retries and run test_create_link_value_error. + _service.enable_retries() + self.test_create_link_value_error() + + # Disable retries and run test_create_link_value_error. + _service.disable_retries() + self.test_create_link_value_error() class TestListLinks(): """ Test Class for list_links """ - def preprocess_url(self, request_url: str): - """ - Preprocess the request URL to ensure the mock response will be found. - """ - request_url = urllib.parse.unquote(request_url) # don't double-encode if already encoded - request_url = urllib.parse.quote(request_url, safe=':/') - if re.fullmatch('.*/+', request_url) is None: - return request_url - else: - return re.compile(request_url.rstrip('/') + '/+') - @responses.activate def test_list_links_all_params(self): """ list_links() """ # Set up mock - url = self.preprocess_url(_base_url + '/v1/profiles/testString/links') + url = preprocess_url('/v1/profiles/testString/links') mock_response = '{"links": [{"id": "id", "entity_tag": "entity_tag", "created_at": "2019-01-01T12:00:00.000Z", "modified_at": "2019-01-01T12:00:00.000Z", "name": "name", "cr_type": "cr_type", "link": {"crn": "crn", "namespace": "namespace", "name": "name"}}]}' responses.add(responses.GET, url, @@ -2575,6 +2812,14 @@ def test_list_links_all_params(self): assert len(responses.calls) == 1 assert response.status_code == 200 + def test_list_links_all_params_with_retries(self): + # Enable retries and run test_list_links_all_params. + _service.enable_retries() + self.test_list_links_all_params() + + # Disable retries and run test_list_links_all_params. + _service.disable_retries() + self.test_list_links_all_params() @responses.activate def test_list_links_value_error(self): @@ -2582,7 +2827,7 @@ def test_list_links_value_error(self): test_list_links_value_error() """ # Set up mock - url = self.preprocess_url(_base_url + '/v1/profiles/testString/links') + url = preprocess_url('/v1/profiles/testString/links') mock_response = '{"links": [{"id": "id", "entity_tag": "entity_tag", "created_at": "2019-01-01T12:00:00.000Z", "modified_at": "2019-01-01T12:00:00.000Z", "name": "name", "cr_type": "cr_type", "link": {"crn": "crn", "namespace": "namespace", "name": "name"}}]}' responses.add(responses.GET, url, @@ -2603,30 +2848,27 @@ def test_list_links_value_error(self): _service.list_links(**req_copy) + def test_list_links_value_error_with_retries(self): + # Enable retries and run test_list_links_value_error. + _service.enable_retries() + self.test_list_links_value_error() + + # Disable retries and run test_list_links_value_error. + _service.disable_retries() + self.test_list_links_value_error() class TestGetLink(): """ Test Class for get_link """ - def preprocess_url(self, request_url: str): - """ - Preprocess the request URL to ensure the mock response will be found. - """ - request_url = urllib.parse.unquote(request_url) # don't double-encode if already encoded - request_url = urllib.parse.quote(request_url, safe=':/') - if re.fullmatch('.*/+', request_url) is None: - return request_url - else: - return re.compile(request_url.rstrip('/') + '/+') - @responses.activate def test_get_link_all_params(self): """ get_link() """ # Set up mock - url = self.preprocess_url(_base_url + '/v1/profiles/testString/links/testString') + url = preprocess_url('/v1/profiles/testString/links/testString') mock_response = '{"id": "id", "entity_tag": "entity_tag", "created_at": "2019-01-01T12:00:00.000Z", "modified_at": "2019-01-01T12:00:00.000Z", "name": "name", "cr_type": "cr_type", "link": {"crn": "crn", "namespace": "namespace", "name": "name"}}' responses.add(responses.GET, url, @@ -2649,6 +2891,14 @@ def test_get_link_all_params(self): assert len(responses.calls) == 1 assert response.status_code == 200 + def test_get_link_all_params_with_retries(self): + # Enable retries and run test_get_link_all_params. + _service.enable_retries() + self.test_get_link_all_params() + + # Disable retries and run test_get_link_all_params. + _service.disable_retries() + self.test_get_link_all_params() @responses.activate def test_get_link_value_error(self): @@ -2656,7 +2906,7 @@ def test_get_link_value_error(self): test_get_link_value_error() """ # Set up mock - url = self.preprocess_url(_base_url + '/v1/profiles/testString/links/testString') + url = preprocess_url('/v1/profiles/testString/links/testString') mock_response = '{"id": "id", "entity_tag": "entity_tag", "created_at": "2019-01-01T12:00:00.000Z", "modified_at": "2019-01-01T12:00:00.000Z", "name": "name", "cr_type": "cr_type", "link": {"crn": "crn", "namespace": "namespace", "name": "name"}}' responses.add(responses.GET, url, @@ -2679,30 +2929,27 @@ def test_get_link_value_error(self): _service.get_link(**req_copy) + def test_get_link_value_error_with_retries(self): + # Enable retries and run test_get_link_value_error. + _service.enable_retries() + self.test_get_link_value_error() + + # Disable retries and run test_get_link_value_error. + _service.disable_retries() + self.test_get_link_value_error() class TestDeleteLink(): """ Test Class for delete_link """ - def preprocess_url(self, request_url: str): - """ - Preprocess the request URL to ensure the mock response will be found. - """ - request_url = urllib.parse.unquote(request_url) # don't double-encode if already encoded - request_url = urllib.parse.quote(request_url, safe=':/') - if re.fullmatch('.*/+', request_url) is None: - return request_url - else: - return re.compile(request_url.rstrip('/') + '/+') - @responses.activate def test_delete_link_all_params(self): """ delete_link() """ # Set up mock - url = self.preprocess_url(_base_url + '/v1/profiles/testString/links/testString') + url = preprocess_url('/v1/profiles/testString/links/testString') responses.add(responses.DELETE, url, status=204) @@ -2722,6 +2969,14 @@ def test_delete_link_all_params(self): assert len(responses.calls) == 1 assert response.status_code == 204 + def test_delete_link_all_params_with_retries(self): + # Enable retries and run test_delete_link_all_params. + _service.enable_retries() + self.test_delete_link_all_params() + + # Disable retries and run test_delete_link_all_params. + _service.disable_retries() + self.test_delete_link_all_params() @responses.activate def test_delete_link_value_error(self): @@ -2729,7 +2984,7 @@ def test_delete_link_value_error(self): test_delete_link_value_error() """ # Set up mock - url = self.preprocess_url(_base_url + '/v1/profiles/testString/links/testString') + url = preprocess_url('/v1/profiles/testString/links/testString') responses.add(responses.DELETE, url, status=204) @@ -2749,6 +3004,14 @@ def test_delete_link_value_error(self): _service.delete_link(**req_copy) + def test_delete_link_value_error_with_retries(self): + # Enable retries and run test_delete_link_value_error. + _service.enable_retries() + self.test_delete_link_value_error() + + # Disable retries and run test_delete_link_value_error. + _service.disable_retries() + self.test_delete_link_value_error() # endregion ############################################################################## @@ -2784,6 +3047,7 @@ def test_new_instance_without_authenticator(self): """ with pytest.raises(ValueError, match='authenticator must be provided'): service = IamIdentityV1.new_instance( + service_name='TEST_SERVICE_NOT_FOUND', ) class TestGetAccountSettings(): @@ -2791,24 +3055,13 @@ class TestGetAccountSettings(): Test Class for get_account_settings """ - def preprocess_url(self, request_url: str): - """ - Preprocess the request URL to ensure the mock response will be found. - """ - request_url = urllib.parse.unquote(request_url) # don't double-encode if already encoded - request_url = urllib.parse.quote(request_url, safe=':/') - if re.fullmatch('.*/+', request_url) is None: - return request_url - else: - return re.compile(request_url.rstrip('/') + '/+') - @responses.activate def test_get_account_settings_all_params(self): """ get_account_settings() """ # Set up mock - url = self.preprocess_url(_base_url + '/v1/accounts/testString/settings/identity') + url = preprocess_url('/v1/accounts/testString/settings/identity') mock_response = '{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "account_id": "account_id", "restrict_create_service_id": "NOT_SET", "restrict_create_platform_apikey": "NOT_SET", "allowed_ip_addresses": "allowed_ip_addresses", "entity_tag": "entity_tag", "mfa": "NONE", "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}], "session_expiration_in_seconds": "86400", "session_invalidation_in_seconds": "7200", "max_sessions_per_identity": "max_sessions_per_identity"}' responses.add(responses.GET, url, @@ -2835,6 +3088,14 @@ def test_get_account_settings_all_params(self): query_string = urllib.parse.unquote_plus(query_string) assert 'include_history={}'.format('true' if include_history else 'false') in query_string + def test_get_account_settings_all_params_with_retries(self): + # Enable retries and run test_get_account_settings_all_params. + _service.enable_retries() + self.test_get_account_settings_all_params() + + # Disable retries and run test_get_account_settings_all_params. + _service.disable_retries() + self.test_get_account_settings_all_params() @responses.activate def test_get_account_settings_required_params(self): @@ -2842,7 +3103,7 @@ def test_get_account_settings_required_params(self): test_get_account_settings_required_params() """ # Set up mock - url = self.preprocess_url(_base_url + '/v1/accounts/testString/settings/identity') + url = preprocess_url('/v1/accounts/testString/settings/identity') mock_response = '{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "account_id": "account_id", "restrict_create_service_id": "NOT_SET", "restrict_create_platform_apikey": "NOT_SET", "allowed_ip_addresses": "allowed_ip_addresses", "entity_tag": "entity_tag", "mfa": "NONE", "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}], "session_expiration_in_seconds": "86400", "session_invalidation_in_seconds": "7200", "max_sessions_per_identity": "max_sessions_per_identity"}' responses.add(responses.GET, url, @@ -2863,6 +3124,14 @@ def test_get_account_settings_required_params(self): assert len(responses.calls) == 1 assert response.status_code == 200 + def test_get_account_settings_required_params_with_retries(self): + # Enable retries and run test_get_account_settings_required_params. + _service.enable_retries() + self.test_get_account_settings_required_params() + + # Disable retries and run test_get_account_settings_required_params. + _service.disable_retries() + self.test_get_account_settings_required_params() @responses.activate def test_get_account_settings_value_error(self): @@ -2870,7 +3139,7 @@ def test_get_account_settings_value_error(self): test_get_account_settings_value_error() """ # Set up mock - url = self.preprocess_url(_base_url + '/v1/accounts/testString/settings/identity') + url = preprocess_url('/v1/accounts/testString/settings/identity') mock_response = '{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "account_id": "account_id", "restrict_create_service_id": "NOT_SET", "restrict_create_platform_apikey": "NOT_SET", "allowed_ip_addresses": "allowed_ip_addresses", "entity_tag": "entity_tag", "mfa": "NONE", "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}], "session_expiration_in_seconds": "86400", "session_invalidation_in_seconds": "7200", "max_sessions_per_identity": "max_sessions_per_identity"}' responses.add(responses.GET, url, @@ -2891,30 +3160,27 @@ def test_get_account_settings_value_error(self): _service.get_account_settings(**req_copy) + def test_get_account_settings_value_error_with_retries(self): + # Enable retries and run test_get_account_settings_value_error. + _service.enable_retries() + self.test_get_account_settings_value_error() + + # Disable retries and run test_get_account_settings_value_error. + _service.disable_retries() + self.test_get_account_settings_value_error() class TestUpdateAccountSettings(): """ Test Class for update_account_settings """ - def preprocess_url(self, request_url: str): - """ - Preprocess the request URL to ensure the mock response will be found. - """ - request_url = urllib.parse.unquote(request_url) # don't double-encode if already encoded - request_url = urllib.parse.quote(request_url, safe=':/') - if re.fullmatch('.*/+', request_url) is None: - return request_url - else: - return re.compile(request_url.rstrip('/') + '/+') - @responses.activate def test_update_account_settings_all_params(self): """ update_account_settings() """ # Set up mock - url = self.preprocess_url(_base_url + '/v1/accounts/testString/settings/identity') + url = preprocess_url('/v1/accounts/testString/settings/identity') mock_response = '{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "account_id": "account_id", "restrict_create_service_id": "NOT_SET", "restrict_create_platform_apikey": "NOT_SET", "allowed_ip_addresses": "allowed_ip_addresses", "entity_tag": "entity_tag", "mfa": "NONE", "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}], "session_expiration_in_seconds": "86400", "session_invalidation_in_seconds": "7200", "max_sessions_per_identity": "max_sessions_per_identity"}' responses.add(responses.PUT, url, @@ -2960,6 +3226,14 @@ def test_update_account_settings_all_params(self): assert req_body['session_invalidation_in_seconds'] == '7200' assert req_body['max_sessions_per_identity'] == 'testString' + def test_update_account_settings_all_params_with_retries(self): + # Enable retries and run test_update_account_settings_all_params. + _service.enable_retries() + self.test_update_account_settings_all_params() + + # Disable retries and run test_update_account_settings_all_params. + _service.disable_retries() + self.test_update_account_settings_all_params() @responses.activate def test_update_account_settings_value_error(self): @@ -2967,7 +3241,7 @@ def test_update_account_settings_value_error(self): test_update_account_settings_value_error() """ # Set up mock - url = self.preprocess_url(_base_url + '/v1/accounts/testString/settings/identity') + url = preprocess_url('/v1/accounts/testString/settings/identity') mock_response = '{"context": {"transaction_id": "transaction_id", "operation": "operation", "user_agent": "user_agent", "url": "url", "instance_id": "instance_id", "thread_id": "thread_id", "host": "host", "start_time": "start_time", "end_time": "end_time", "elapsed_time": "elapsed_time", "cluster_name": "cluster_name"}, "account_id": "account_id", "restrict_create_service_id": "NOT_SET", "restrict_create_platform_apikey": "NOT_SET", "allowed_ip_addresses": "allowed_ip_addresses", "entity_tag": "entity_tag", "mfa": "NONE", "history": [{"timestamp": "timestamp", "iam_id": "iam_id", "iam_id_account": "iam_id_account", "action": "action", "params": ["params"], "message": "message"}], "session_expiration_in_seconds": "86400", "session_invalidation_in_seconds": "7200", "max_sessions_per_identity": "max_sessions_per_identity"}' responses.add(responses.PUT, url, @@ -2997,12 +3271,260 @@ def test_update_account_settings_value_error(self): _service.update_account_settings(**req_copy) + def test_update_account_settings_value_error_with_retries(self): + # Enable retries and run test_update_account_settings_value_error. + _service.enable_retries() + self.test_update_account_settings_value_error() + + # Disable retries and run test_update_account_settings_value_error. + _service.disable_retries() + self.test_update_account_settings_value_error() # endregion ############################################################################## # End of Service: AccountSettings ############################################################################## +############################################################################## +# Start of Service: ActivityOperations +############################################################################## +# region + +class TestNewInstance(): + """ + Test Class for new_instance + """ + + def test_new_instance(self): + """ + new_instance() + """ + os.environ['TEST_SERVICE_AUTH_TYPE'] = 'noAuth' + + service = IamIdentityV1.new_instance( + service_name='TEST_SERVICE', + ) + + assert service is not None + assert isinstance(service, IamIdentityV1) + + def test_new_instance_without_authenticator(self): + """ + new_instance_without_authenticator() + """ + with pytest.raises(ValueError, match='authenticator must be provided'): + service = IamIdentityV1.new_instance( + service_name='TEST_SERVICE_NOT_FOUND', + ) + +class TestCreateReport(): + """ + Test Class for create_report + """ + + @responses.activate + def test_create_report_all_params(self): + """ + create_report() + """ + # Set up mock + url = preprocess_url('/v1/activity/accounts/testString/report') + mock_response = '{"reference": "reference"}' + responses.add(responses.POST, + url, + body=mock_response, + content_type='application/json', + status=202) + + # Set up parameter values + account_id = 'testString' + type = 'inactive' + duration = '720' + + # Invoke method + response = _service.create_report( + account_id, + type=type, + duration=duration, + headers={} + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 202 + # Validate query params + query_string = responses.calls[0].request.url.split('?',1)[1] + query_string = urllib.parse.unquote_plus(query_string) + assert 'type={}'.format(type) in query_string + assert 'duration={}'.format(duration) in query_string + + def test_create_report_all_params_with_retries(self): + # Enable retries and run test_create_report_all_params. + _service.enable_retries() + self.test_create_report_all_params() + + # Disable retries and run test_create_report_all_params. + _service.disable_retries() + self.test_create_report_all_params() + + @responses.activate + def test_create_report_required_params(self): + """ + test_create_report_required_params() + """ + # Set up mock + url = preprocess_url('/v1/activity/accounts/testString/report') + mock_response = '{"reference": "reference"}' + responses.add(responses.POST, + url, + body=mock_response, + content_type='application/json', + status=202) + + # Set up parameter values + account_id = 'testString' + + # Invoke method + response = _service.create_report( + account_id, + headers={} + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 202 + + def test_create_report_required_params_with_retries(self): + # Enable retries and run test_create_report_required_params. + _service.enable_retries() + self.test_create_report_required_params() + + # Disable retries and run test_create_report_required_params. + _service.disable_retries() + self.test_create_report_required_params() + + @responses.activate + def test_create_report_value_error(self): + """ + test_create_report_value_error() + """ + # Set up mock + url = preprocess_url('/v1/activity/accounts/testString/report') + mock_response = '{"reference": "reference"}' + responses.add(responses.POST, + url, + body=mock_response, + content_type='application/json', + status=202) + + # Set up parameter values + account_id = 'testString' + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "account_id": account_id, + } + for param in req_param_dict.keys(): + req_copy = {key:val if key is not param else None for (key,val) in req_param_dict.items()} + with pytest.raises(ValueError): + _service.create_report(**req_copy) + + + def test_create_report_value_error_with_retries(self): + # Enable retries and run test_create_report_value_error. + _service.enable_retries() + self.test_create_report_value_error() + + # Disable retries and run test_create_report_value_error. + _service.disable_retries() + self.test_create_report_value_error() + +class TestGetReport(): + """ + Test Class for get_report + """ + + @responses.activate + def test_get_report_all_params(self): + """ + get_report() + """ + # Set up mock + url = preprocess_url('/v1/activity/accounts/testString/report/testString') + mock_response = '{"created_by": "created_by", "reference": "reference", "report_duration": "report_duration", "report_start_time": "report_start_time", "report_end_time": "report_end_time", "users": [{"iam_id": "iam_id", "username": "username", "last_authn": "last_authn"}], "apikeys": [{"id": "id", "name": "name", "last_authn": "last_authn"}], "serviceids": [{"id": "id", "name": "name", "last_authn": "last_authn"}], "profiles": [{"id": "id", "name": "name", "last_authn": "last_authn"}]}' + responses.add(responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200) + + # Set up parameter values + account_id = 'testString' + reference = 'testString' + + # Invoke method + response = _service.get_report( + account_id, + reference, + headers={} + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + + def test_get_report_all_params_with_retries(self): + # Enable retries and run test_get_report_all_params. + _service.enable_retries() + self.test_get_report_all_params() + + # Disable retries and run test_get_report_all_params. + _service.disable_retries() + self.test_get_report_all_params() + + @responses.activate + def test_get_report_value_error(self): + """ + test_get_report_value_error() + """ + # Set up mock + url = preprocess_url('/v1/activity/accounts/testString/report/testString') + mock_response = '{"created_by": "created_by", "reference": "reference", "report_duration": "report_duration", "report_start_time": "report_start_time", "report_end_time": "report_end_time", "users": [{"iam_id": "iam_id", "username": "username", "last_authn": "last_authn"}], "apikeys": [{"id": "id", "name": "name", "last_authn": "last_authn"}], "serviceids": [{"id": "id", "name": "name", "last_authn": "last_authn"}], "profiles": [{"id": "id", "name": "name", "last_authn": "last_authn"}]}' + responses.add(responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200) + + # Set up parameter values + account_id = 'testString' + reference = 'testString' + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "account_id": account_id, + "reference": reference, + } + for param in req_param_dict.keys(): + req_copy = {key:val if key is not param else None for (key,val) in req_param_dict.items()} + with pytest.raises(ValueError): + _service.get_report(**req_copy) + + + def test_get_report_value_error_with_retries(self): + # Enable retries and run test_get_report_value_error. + _service.enable_retries() + self.test_get_report_value_error() + + # Disable retries and run test_get_report_value_error. + _service.disable_retries() + self.test_get_report_value_error() + +# endregion +############################################################################## +# End of Service: ActivityOperations +############################################################################## + ############################################################################## # Start of Model Tests @@ -3070,6 +3592,36 @@ def test_account_settings_response_serialization(self): account_settings_response_model_json2 = account_settings_response_model.to_dict() assert account_settings_response_model_json2 == account_settings_response_model_json +class TestModel_Activity(): + """ + Test Class for Activity + """ + + def test_activity_serialization(self): + """ + Test serialization/deserialization for Activity + """ + + # Construct a json representation of a Activity model + activity_model_json = {} + activity_model_json['last_authn'] = 'testString' + activity_model_json['authn_count'] = 26 + + # Construct a model instance of Activity by calling from_dict on the json representation + activity_model = Activity.from_dict(activity_model_json) + assert activity_model != False + + # Construct a model instance of Activity by calling from_dict on the json representation + activity_model_dict = Activity.from_dict(activity_model_json).__dict__ + activity_model2 = Activity(**activity_model_dict) + + # Verify the model instances are equivalent + assert activity_model == activity_model2 + + # Convert model instance back to dict and verify no loss of data + activity_model_json2 = activity_model.to_dict() + assert activity_model_json2 == activity_model_json + class TestModel_ApiKey(): """ Test Class for ApiKey @@ -3103,6 +3655,10 @@ def test_api_key_serialization(self): enity_history_record_model['params'] = ['testString'] enity_history_record_model['message'] = 'testString' + activity_model = {} # Activity + activity_model['last_authn'] = 'testString' + activity_model['authn_count'] = 26 + # Construct a json representation of a ApiKey model api_key_model_json = {} api_key_model_json['context'] = response_context_model @@ -3110,15 +3666,16 @@ def test_api_key_serialization(self): api_key_model_json['entity_tag'] = 'testString' api_key_model_json['crn'] = 'testString' api_key_model_json['locked'] = True - api_key_model_json['created_at'] = "2019-01-01T12:00:00Z" + api_key_model_json['created_at'] = '2019-01-01T12:00:00Z' api_key_model_json['created_by'] = 'testString' - api_key_model_json['modified_at'] = "2019-01-01T12:00:00Z" + api_key_model_json['modified_at'] = '2019-01-01T12:00:00Z' api_key_model_json['name'] = 'testString' api_key_model_json['description'] = 'testString' api_key_model_json['iam_id'] = 'testString' api_key_model_json['account_id'] = 'testString' api_key_model_json['apikey'] = 'testString' api_key_model_json['history'] = [enity_history_record_model] + api_key_model_json['activity'] = activity_model # Construct a model instance of ApiKey by calling from_dict on the json representation api_key_model = ApiKey.from_dict(api_key_model_json) @@ -3200,21 +3757,26 @@ def test_api_key_list_serialization(self): enity_history_record_model['params'] = ['testString'] enity_history_record_model['message'] = 'testString' + activity_model = {} # Activity + activity_model['last_authn'] = 'testString' + activity_model['authn_count'] = 26 + api_key_model = {} # ApiKey api_key_model['context'] = response_context_model api_key_model['id'] = 'testString' api_key_model['entity_tag'] = 'testString' api_key_model['crn'] = 'testString' api_key_model['locked'] = True - api_key_model['created_at'] = "2019-01-01T12:00:00Z" + api_key_model['created_at'] = '2019-01-01T12:00:00Z' api_key_model['created_by'] = 'testString' - api_key_model['modified_at'] = "2019-01-01T12:00:00Z" + api_key_model['modified_at'] = '2019-01-01T12:00:00Z' api_key_model['name'] = 'testString' api_key_model['description'] = 'testString' api_key_model['iam_id'] = 'testString' api_key_model['account_id'] = 'testString' api_key_model['apikey'] = 'testString' api_key_model['history'] = [enity_history_record_model] + api_key_model['activity'] = activity_model # Construct a json representation of a ApiKeyList model api_key_list_model_json = {} @@ -3306,6 +3868,37 @@ def test_enity_history_record_serialization(self): enity_history_record_model_json2 = enity_history_record_model.to_dict() assert enity_history_record_model_json2 == enity_history_record_model_json +class TestModel_EntityActivity(): + """ + Test Class for EntityActivity + """ + + def test_entity_activity_serialization(self): + """ + Test serialization/deserialization for EntityActivity + """ + + # Construct a json representation of a EntityActivity model + entity_activity_model_json = {} + entity_activity_model_json['id'] = 'testString' + entity_activity_model_json['name'] = 'testString' + entity_activity_model_json['last_authn'] = 'testString' + + # Construct a model instance of EntityActivity by calling from_dict on the json representation + entity_activity_model = EntityActivity.from_dict(entity_activity_model_json) + assert entity_activity_model != False + + # Construct a model instance of EntityActivity by calling from_dict on the json representation + entity_activity_model_dict = EntityActivity.from_dict(entity_activity_model_json).__dict__ + entity_activity_model2 = EntityActivity(**entity_activity_model_dict) + + # Verify the model instances are equivalent + assert entity_activity_model == entity_activity_model2 + + # Convert model instance back to dict and verify no loss of data + entity_activity_model_json2 = entity_activity_model.to_dict() + assert entity_activity_model_json2 == entity_activity_model_json + class TestModel_ProfileClaimRule(): """ Test Class for ProfileClaimRule @@ -3327,8 +3920,8 @@ def test_profile_claim_rule_serialization(self): profile_claim_rule_model_json = {} profile_claim_rule_model_json['id'] = 'testString' profile_claim_rule_model_json['entity_tag'] = 'testString' - profile_claim_rule_model_json['created_at'] = "2019-01-01T12:00:00Z" - profile_claim_rule_model_json['modified_at'] = "2019-01-01T12:00:00Z" + profile_claim_rule_model_json['created_at'] = '2019-01-01T12:00:00Z' + profile_claim_rule_model_json['modified_at'] = '2019-01-01T12:00:00Z' profile_claim_rule_model_json['name'] = 'testString' profile_claim_rule_model_json['type'] = 'testString' profile_claim_rule_model_json['realm_name'] = 'testString' @@ -3415,8 +4008,8 @@ def test_profile_claim_rule_list_serialization(self): profile_claim_rule_model = {} # ProfileClaimRule profile_claim_rule_model['id'] = 'testString' profile_claim_rule_model['entity_tag'] = 'testString' - profile_claim_rule_model['created_at'] = "2019-01-01T12:00:00Z" - profile_claim_rule_model['modified_at'] = "2019-01-01T12:00:00Z" + profile_claim_rule_model['created_at'] = '2019-01-01T12:00:00Z' + profile_claim_rule_model['modified_at'] = '2019-01-01T12:00:00Z' profile_claim_rule_model['name'] = 'testString' profile_claim_rule_model['type'] = 'testString' profile_claim_rule_model['realm_name'] = 'testString' @@ -3465,8 +4058,8 @@ def test_profile_link_serialization(self): profile_link_model_json = {} profile_link_model_json['id'] = 'testString' profile_link_model_json['entity_tag'] = 'testString' - profile_link_model_json['created_at'] = "2019-01-01T12:00:00Z" - profile_link_model_json['modified_at'] = "2019-01-01T12:00:00Z" + profile_link_model_json['created_at'] = '2019-01-01T12:00:00Z' + profile_link_model_json['modified_at'] = '2019-01-01T12:00:00Z' profile_link_model_json['name'] = 'testString' profile_link_model_json['cr_type'] = 'testString' profile_link_model_json['link'] = profile_link_link_model @@ -3537,8 +4130,8 @@ def test_profile_link_list_serialization(self): profile_link_model = {} # ProfileLink profile_link_model['id'] = 'testString' profile_link_model['entity_tag'] = 'testString' - profile_link_model['created_at'] = "2019-01-01T12:00:00Z" - profile_link_model['modified_at'] = "2019-01-01T12:00:00Z" + profile_link_model['created_at'] = '2019-01-01T12:00:00Z' + profile_link_model['modified_at'] = '2019-01-01T12:00:00Z' profile_link_model['name'] = 'testString' profile_link_model['cr_type'] = 'testString' profile_link_model['link'] = profile_link_link_model @@ -3562,6 +4155,84 @@ def test_profile_link_list_serialization(self): profile_link_list_model_json2 = profile_link_list_model.to_dict() assert profile_link_list_model_json2 == profile_link_list_model_json +class TestModel_Report(): + """ + Test Class for Report + """ + + def test_report_serialization(self): + """ + Test serialization/deserialization for Report + """ + + # Construct dict forms of any model objects needed in order to build this model. + + user_activity_model = {} # UserActivity + user_activity_model['iam_id'] = 'testString' + user_activity_model['username'] = 'testString' + user_activity_model['last_authn'] = 'testString' + + entity_activity_model = {} # EntityActivity + entity_activity_model['id'] = 'testString' + entity_activity_model['name'] = 'testString' + entity_activity_model['last_authn'] = 'testString' + + # Construct a json representation of a Report model + report_model_json = {} + report_model_json['created_by'] = 'testString' + report_model_json['reference'] = 'testString' + report_model_json['report_duration'] = 'testString' + report_model_json['report_start_time'] = 'testString' + report_model_json['report_end_time'] = 'testString' + report_model_json['users'] = [user_activity_model] + report_model_json['apikeys'] = [entity_activity_model] + report_model_json['serviceids'] = [entity_activity_model] + report_model_json['profiles'] = [entity_activity_model] + + # Construct a model instance of Report by calling from_dict on the json representation + report_model = Report.from_dict(report_model_json) + assert report_model != False + + # Construct a model instance of Report by calling from_dict on the json representation + report_model_dict = Report.from_dict(report_model_json).__dict__ + report_model2 = Report(**report_model_dict) + + # Verify the model instances are equivalent + assert report_model == report_model2 + + # Convert model instance back to dict and verify no loss of data + report_model_json2 = report_model.to_dict() + assert report_model_json2 == report_model_json + +class TestModel_ReportReference(): + """ + Test Class for ReportReference + """ + + def test_report_reference_serialization(self): + """ + Test serialization/deserialization for ReportReference + """ + + # Construct a json representation of a ReportReference model + report_reference_model_json = {} + report_reference_model_json['reference'] = 'testString' + + # Construct a model instance of ReportReference by calling from_dict on the json representation + report_reference_model = ReportReference.from_dict(report_reference_model_json) + assert report_reference_model != False + + # Construct a model instance of ReportReference by calling from_dict on the json representation + report_reference_model_dict = ReportReference.from_dict(report_reference_model_json).__dict__ + report_reference_model2 = ReportReference(**report_reference_model_dict) + + # Verify the model instances are equivalent + assert report_reference_model == report_reference_model2 + + # Convert model instance back to dict and verify no loss of data + report_reference_model_json2 = report_reference_model.to_dict() + assert report_reference_model_json2 == report_reference_model_json + class TestModel_ResponseContext(): """ Test Class for ResponseContext @@ -3634,21 +4305,26 @@ def test_service_id_serialization(self): enity_history_record_model['params'] = ['testString'] enity_history_record_model['message'] = 'testString' + activity_model = {} # Activity + activity_model['last_authn'] = 'testString' + activity_model['authn_count'] = 26 + api_key_model = {} # ApiKey api_key_model['context'] = response_context_model api_key_model['id'] = 'testString' api_key_model['entity_tag'] = 'testString' api_key_model['crn'] = 'testString' api_key_model['locked'] = True - api_key_model['created_at'] = "2019-01-01T12:00:00Z" + api_key_model['created_at'] = '2019-01-01T12:00:00Z' api_key_model['created_by'] = 'testString' - api_key_model['modified_at'] = "2019-01-01T12:00:00Z" + api_key_model['modified_at'] = '2019-01-01T12:00:00Z' api_key_model['name'] = 'testString' api_key_model['description'] = 'testString' api_key_model['iam_id'] = 'testString' api_key_model['account_id'] = 'testString' api_key_model['apikey'] = 'testString' api_key_model['history'] = [enity_history_record_model] + api_key_model['activity'] = activity_model # Construct a json representation of a ServiceId model service_id_model_json = {} @@ -3658,14 +4334,15 @@ def test_service_id_serialization(self): service_id_model_json['entity_tag'] = 'testString' service_id_model_json['crn'] = 'testString' service_id_model_json['locked'] = True - service_id_model_json['created_at'] = "2019-01-01T12:00:00Z" - service_id_model_json['modified_at'] = "2019-01-01T12:00:00Z" + service_id_model_json['created_at'] = '2019-01-01T12:00:00Z' + service_id_model_json['modified_at'] = '2019-01-01T12:00:00Z' service_id_model_json['account_id'] = 'testString' service_id_model_json['name'] = 'testString' service_id_model_json['description'] = 'testString' service_id_model_json['unique_instance_crns'] = ['testString'] service_id_model_json['history'] = [enity_history_record_model] service_id_model_json['apikey'] = api_key_model + service_id_model_json['activity'] = activity_model # Construct a model instance of ServiceId by calling from_dict on the json representation service_id_model = ServiceId.from_dict(service_id_model_json) @@ -3715,21 +4392,26 @@ def test_service_id_list_serialization(self): enity_history_record_model['params'] = ['testString'] enity_history_record_model['message'] = 'testString' + activity_model = {} # Activity + activity_model['last_authn'] = 'testString' + activity_model['authn_count'] = 26 + api_key_model = {} # ApiKey api_key_model['context'] = response_context_model api_key_model['id'] = 'testString' api_key_model['entity_tag'] = 'testString' api_key_model['crn'] = 'testString' api_key_model['locked'] = True - api_key_model['created_at'] = "2019-01-01T12:00:00Z" + api_key_model['created_at'] = '2019-01-01T12:00:00Z' api_key_model['created_by'] = 'testString' - api_key_model['modified_at'] = "2019-01-01T12:00:00Z" + api_key_model['modified_at'] = '2019-01-01T12:00:00Z' api_key_model['name'] = 'testString' api_key_model['description'] = 'testString' api_key_model['iam_id'] = 'testString' api_key_model['account_id'] = 'testString' api_key_model['apikey'] = 'testString' api_key_model['history'] = [enity_history_record_model] + api_key_model['activity'] = activity_model service_id_model = {} # ServiceId service_id_model['context'] = response_context_model @@ -3738,14 +4420,15 @@ def test_service_id_list_serialization(self): service_id_model['entity_tag'] = 'testString' service_id_model['crn'] = 'testString' service_id_model['locked'] = True - service_id_model['created_at'] = "2019-01-01T12:00:00Z" - service_id_model['modified_at'] = "2019-01-01T12:00:00Z" + service_id_model['created_at'] = '2019-01-01T12:00:00Z' + service_id_model['modified_at'] = '2019-01-01T12:00:00Z' service_id_model['account_id'] = 'testString' service_id_model['name'] = 'testString' service_id_model['description'] = 'testString' service_id_model['unique_instance_crns'] = ['testString'] service_id_model['history'] = [enity_history_record_model] service_id_model['apikey'] = api_key_model + service_id_model['activity'] = activity_model # Construct a json representation of a ServiceIdList model service_id_list_model_json = {} @@ -3805,6 +4488,10 @@ def test_trusted_profile_serialization(self): enity_history_record_model['params'] = ['testString'] enity_history_record_model['message'] = 'testString' + activity_model = {} # Activity + activity_model['last_authn'] = 'testString' + activity_model['authn_count'] = 26 + # Construct a json representation of a TrustedProfile model trusted_profile_model_json = {} trusted_profile_model_json['context'] = response_context_model @@ -3813,13 +4500,14 @@ def test_trusted_profile_serialization(self): trusted_profile_model_json['crn'] = 'testString' trusted_profile_model_json['name'] = 'testString' trusted_profile_model_json['description'] = 'testString' - trusted_profile_model_json['created_at'] = "2019-01-01T12:00:00Z" - trusted_profile_model_json['modified_at'] = "2019-01-01T12:00:00Z" + trusted_profile_model_json['created_at'] = '2019-01-01T12:00:00Z' + trusted_profile_model_json['modified_at'] = '2019-01-01T12:00:00Z' trusted_profile_model_json['iam_id'] = 'testString' trusted_profile_model_json['account_id'] = 'testString' trusted_profile_model_json['ims_account_id'] = 26 trusted_profile_model_json['ims_user_id'] = 26 trusted_profile_model_json['history'] = [enity_history_record_model] + trusted_profile_model_json['activity'] = activity_model # Construct a model instance of TrustedProfile by calling from_dict on the json representation trusted_profile_model = TrustedProfile.from_dict(trusted_profile_model_json) @@ -3869,6 +4557,10 @@ def test_trusted_profiles_list_serialization(self): enity_history_record_model['params'] = ['testString'] enity_history_record_model['message'] = 'testString' + activity_model = {} # Activity + activity_model['last_authn'] = 'testString' + activity_model['authn_count'] = 26 + trusted_profile_model = {} # TrustedProfile trusted_profile_model['context'] = response_context_model trusted_profile_model['id'] = 'testString' @@ -3876,13 +4568,14 @@ def test_trusted_profiles_list_serialization(self): trusted_profile_model['crn'] = 'testString' trusted_profile_model['name'] = 'testString' trusted_profile_model['description'] = 'testString' - trusted_profile_model['created_at'] = "2019-01-01T12:00:00Z" - trusted_profile_model['modified_at'] = "2019-01-01T12:00:00Z" + trusted_profile_model['created_at'] = '2019-01-01T12:00:00Z' + trusted_profile_model['modified_at'] = '2019-01-01T12:00:00Z' trusted_profile_model['iam_id'] = 'testString' trusted_profile_model['account_id'] = 'testString' trusted_profile_model['ims_account_id'] = 26 trusted_profile_model['ims_user_id'] = 26 trusted_profile_model['history'] = [enity_history_record_model] + trusted_profile_model['activity'] = activity_model # Construct a json representation of a TrustedProfilesList model trusted_profiles_list_model_json = {} @@ -3909,6 +4602,37 @@ def test_trusted_profiles_list_serialization(self): trusted_profiles_list_model_json2 = trusted_profiles_list_model.to_dict() assert trusted_profiles_list_model_json2 == trusted_profiles_list_model_json +class TestModel_UserActivity(): + """ + Test Class for UserActivity + """ + + def test_user_activity_serialization(self): + """ + Test serialization/deserialization for UserActivity + """ + + # Construct a json representation of a UserActivity model + user_activity_model_json = {} + user_activity_model_json['iam_id'] = 'testString' + user_activity_model_json['username'] = 'testString' + user_activity_model_json['last_authn'] = 'testString' + + # Construct a model instance of UserActivity by calling from_dict on the json representation + user_activity_model = UserActivity.from_dict(user_activity_model_json) + assert user_activity_model != False + + # Construct a model instance of UserActivity by calling from_dict on the json representation + user_activity_model_dict = UserActivity.from_dict(user_activity_model_json).__dict__ + user_activity_model2 = UserActivity(**user_activity_model_dict) + + # Verify the model instances are equivalent + assert user_activity_model == user_activity_model2 + + # Convert model instance back to dict and verify no loss of data + user_activity_model_json2 = user_activity_model.to_dict() + assert user_activity_model_json2 == user_activity_model_json + # endregion ##############################################################################