Skip to content

feat(Enterprise Management): re-gen after trait schema change #199

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 82 additions & 9 deletions ibm_platform_services/enterprise_management_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from ibm_cloud_sdk_core import BaseService, DetailedResponse, get_query_param
from ibm_cloud_sdk_core.authenticators.authenticator import Authenticator
from ibm_cloud_sdk_core.get_authenticator import get_authenticator_from_environment
from ibm_cloud_sdk_core.utils import datetime_to_string, string_to_datetime
from ibm_cloud_sdk_core.utils import convert_model, datetime_to_string, string_to_datetime

from .common import get_sdk_headers

Expand Down Expand Up @@ -270,7 +270,11 @@ def update_enterprise(
)
headers.update(sdk_headers)

data = {'name': name, 'domain': domain, 'primary_contact_iam_id': primary_contact_iam_id}
data = {
'name': name,
'domain': domain,
'primary_contact_iam_id': primary_contact_iam_id,
}
data = {k: v for (k, v) in data.items() if v is not None}
data = json.dumps(data)
headers['content-type'] = 'application/json'
Expand Down Expand Up @@ -334,7 +338,10 @@ def import_account_to_enterprise(
)
headers.update(sdk_headers)

data = {'parent': parent, 'billing_unit_id': billing_unit_id}
data = {
'parent': parent,
'billing_unit_id': billing_unit_id,
}
data = {k: v for (k, v) in data.items() if v is not None}
data = json.dumps(data)
headers['content-type'] = 'application/json'
Expand All @@ -353,7 +360,7 @@ def import_account_to_enterprise(
return response

def create_account(
self, parent: str, name: str, owner_iam_id: str, *, traits: dict = None, **kwargs
self, parent: str, name: str, owner_iam_id: str, *, traits: 'CreateAccountRequestTraits' = None, **kwargs
) -> DetailedResponse:
"""
Create a new account in an enterprise.
Expand All @@ -371,9 +378,9 @@ def create_account(
characters.
:param str owner_iam_id: The IAM ID of the account owner, such as
`IBMid-0123ABC`. The IAM ID must already exist.
:param dict traits: (optional) The traits object can be used to opt-out of
Multi-Factor Authentication setting when creating a child account in the
enterprise. This is an optional field.
:param CreateAccountRequestTraits traits: (optional) The traits object can
be used to opt-out of Multi-Factor Authentication setting when creating a
child account in the enterprise. This is an optional field.
: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 `CreateAccountResponse` object
Expand All @@ -385,6 +392,8 @@ def create_account(
raise ValueError('name must be provided')
if owner_iam_id is None:
raise ValueError('owner_iam_id must be provided')
if traits is not None:
traits = convert_model(traits)
headers = {}
sdk_headers = get_sdk_headers(
service_name=self.DEFAULT_SERVICE_NAME, service_version='V1', operation_id='create_account'
Expand Down Expand Up @@ -636,7 +645,11 @@ def create_account_group(self, parent: str, name: str, primary_contact_iam_id: s
)
headers.update(sdk_headers)

data = {'parent': parent, 'name': name, 'primary_contact_iam_id': primary_contact_iam_id}
data = {
'parent': parent,
'name': name,
'primary_contact_iam_id': primary_contact_iam_id,
}
data = {k: v for (k, v) in data.items() if v is not None}
data = json.dumps(data)
headers['content-type'] = 'application/json'
Expand Down Expand Up @@ -791,7 +804,10 @@ def update_account_group(
)
headers.update(sdk_headers)

data = {'name': name, 'primary_contact_iam_id': primary_contact_iam_id}
data = {
'name': name,
'primary_contact_iam_id': primary_contact_iam_id,
}
data = {k: v for (k, v) in data.items() if v is not None}
data = json.dumps(data)
headers['content-type'] = 'application/json'
Expand Down Expand Up @@ -1296,6 +1312,63 @@ def __ne__(self, other: 'CreateAccountGroupResponse') -> bool:
return not self == other


class CreateAccountRequestTraits:
"""
The traits object can be used to opt-out of Multi-Factor Authentication setting when
creating a child account in the enterprise. This is an optional field.

:attr str mfa: (optional) By default MFA will be set on the account. To opt out,
pass the traits object with the mfa field set to empty string.
"""

def __init__(self, *, mfa: str = None) -> None:
"""
Initialize a CreateAccountRequestTraits object.

:param str mfa: (optional) By default MFA will be set on the account. To
opt out, pass the traits object with the mfa field set to empty string.
"""
self.mfa = mfa

@classmethod
def from_dict(cls, _dict: Dict) -> 'CreateAccountRequestTraits':
"""Initialize a CreateAccountRequestTraits object from a json dictionary."""
args = {}
if 'mfa' in _dict:
args['mfa'] = _dict.get('mfa')
return cls(**args)

@classmethod
def _from_dict(cls, _dict):
"""Initialize a CreateAccountRequestTraits 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, 'mfa') and self.mfa is not None:
_dict['mfa'] = self.mfa
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 CreateAccountRequestTraits object."""
return json.dumps(self.to_dict(), indent=2)

def __eq__(self, other: 'CreateAccountRequestTraits') -> 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: 'CreateAccountRequestTraits') -> bool:
"""Return `true` when self and other are not equal, false otherwise."""
return not self == other


class CreateAccountResponse:
"""
A newly-created account.
Expand Down
51 changes: 47 additions & 4 deletions test/unit/test_enterprise_management_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ def preprocess_url(operation_path: str):
# Otherwise, return a regular expression that matches one or more trailing /.
if re.fullmatch('.*/+', request_url) is None:
return request_url
return re.compile(request_url.rstrip('/') + '/+')
else:
return re.compile(request_url.rstrip('/') + '/+')


##############################################################################
Expand Down Expand Up @@ -610,11 +611,15 @@ def test_create_account_all_params(self):
mock_response = '{"account_id": "account_id"}'
responses.add(responses.POST, url, body=mock_response, content_type='application/json', status=201)

# Construct a dict representation of a CreateAccountRequestTraits model
create_account_request_traits_model = {}
create_account_request_traits_model['mfa'] = 'testString'

# Set up parameter values
parent = 'testString'
name = 'testString'
owner_iam_id = 'testString'
traits = {'foo': 'bar'}
traits = create_account_request_traits_model

# Invoke method
response = _service.create_account(parent, name, owner_iam_id, traits=traits, headers={})
Expand All @@ -627,7 +632,7 @@ def test_create_account_all_params(self):
assert req_body['parent'] == 'testString'
assert req_body['name'] == 'testString'
assert req_body['owner_iam_id'] == 'testString'
assert req_body['traits'] == {'foo': 'bar'}
assert req_body['traits'] == create_account_request_traits_model

def test_create_account_all_params_with_retries(self):
# Enable retries and run test_create_account_all_params.
Expand All @@ -648,11 +653,15 @@ def test_create_account_value_error(self):
mock_response = '{"account_id": "account_id"}'
responses.add(responses.POST, url, body=mock_response, content_type='application/json', status=201)

# Construct a dict representation of a CreateAccountRequestTraits model
create_account_request_traits_model = {}
create_account_request_traits_model['mfa'] = 'testString'

# Set up parameter values
parent = 'testString'
name = 'testString'
owner_iam_id = 'testString'
traits = {'foo': 'bar'}
traits = create_account_request_traits_model

# Pass in all but one required param and check for a ValueError
req_param_dict = {
Expand Down Expand Up @@ -1601,6 +1610,40 @@ def test_create_account_group_response_serialization(self):
assert create_account_group_response_model_json2 == create_account_group_response_model_json


class TestModel_CreateAccountRequestTraits:
"""
Test Class for CreateAccountRequestTraits
"""

def test_create_account_request_traits_serialization(self):
"""
Test serialization/deserialization for CreateAccountRequestTraits
"""

# Construct a json representation of a CreateAccountRequestTraits model
create_account_request_traits_model_json = {}
create_account_request_traits_model_json['mfa'] = 'testString'

# Construct a model instance of CreateAccountRequestTraits by calling from_dict on the json representation
create_account_request_traits_model = CreateAccountRequestTraits.from_dict(
create_account_request_traits_model_json
)
assert create_account_request_traits_model != False

# Construct a model instance of CreateAccountRequestTraits by calling from_dict on the json representation
create_account_request_traits_model_dict = CreateAccountRequestTraits.from_dict(
create_account_request_traits_model_json
).__dict__
create_account_request_traits_model2 = CreateAccountRequestTraits(**create_account_request_traits_model_dict)

# Verify the model instances are equivalent
assert create_account_request_traits_model == create_account_request_traits_model2

# Convert model instance back to dict and verify no loss of data
create_account_request_traits_model_json2 = create_account_request_traits_model.to_dict()
assert create_account_request_traits_model_json2 == create_account_request_traits_model_json


class TestModel_CreateAccountResponse:
"""
Test Class for CreateAccountResponse
Expand Down