Skip to content

Commit 919b571

Browse files
fix(Enterprise Management): re-gen after trait schema change (#199)
Signed-off-by: namratabhadauriya <[email protected]>
1 parent 22e1f19 commit 919b571

File tree

2 files changed

+129
-13
lines changed

2 files changed

+129
-13
lines changed

ibm_platform_services/enterprise_management_v1.py

Lines changed: 82 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
from ibm_cloud_sdk_core import BaseService, DetailedResponse, get_query_param
3131
from ibm_cloud_sdk_core.authenticators.authenticator import Authenticator
3232
from ibm_cloud_sdk_core.get_authenticator import get_authenticator_from_environment
33-
from ibm_cloud_sdk_core.utils import datetime_to_string, string_to_datetime
33+
from ibm_cloud_sdk_core.utils import convert_model, datetime_to_string, string_to_datetime
3434

3535
from .common import get_sdk_headers
3636

@@ -270,7 +270,11 @@ def update_enterprise(
270270
)
271271
headers.update(sdk_headers)
272272

273-
data = {'name': name, 'domain': domain, 'primary_contact_iam_id': primary_contact_iam_id}
273+
data = {
274+
'name': name,
275+
'domain': domain,
276+
'primary_contact_iam_id': primary_contact_iam_id,
277+
}
274278
data = {k: v for (k, v) in data.items() if v is not None}
275279
data = json.dumps(data)
276280
headers['content-type'] = 'application/json'
@@ -334,7 +338,10 @@ def import_account_to_enterprise(
334338
)
335339
headers.update(sdk_headers)
336340

337-
data = {'parent': parent, 'billing_unit_id': billing_unit_id}
341+
data = {
342+
'parent': parent,
343+
'billing_unit_id': billing_unit_id,
344+
}
338345
data = {k: v for (k, v) in data.items() if v is not None}
339346
data = json.dumps(data)
340347
headers['content-type'] = 'application/json'
@@ -353,7 +360,7 @@ def import_account_to_enterprise(
353360
return response
354361

355362
def create_account(
356-
self, parent: str, name: str, owner_iam_id: str, *, traits: dict = None, **kwargs
363+
self, parent: str, name: str, owner_iam_id: str, *, traits: 'CreateAccountRequestTraits' = None, **kwargs
357364
) -> DetailedResponse:
358365
"""
359366
Create a new account in an enterprise.
@@ -371,9 +378,9 @@ def create_account(
371378
characters.
372379
:param str owner_iam_id: The IAM ID of the account owner, such as
373380
`IBMid-0123ABC`. The IAM ID must already exist.
374-
:param dict traits: (optional) The traits object can be used to opt-out of
375-
Multi-Factor Authentication setting when creating a child account in the
376-
enterprise. This is an optional field.
381+
:param CreateAccountRequestTraits traits: (optional) The traits object can
382+
be used to opt-out of Multi-Factor Authentication setting when creating a
383+
child account in the enterprise. This is an optional field.
377384
:param dict headers: A `dict` containing the request headers
378385
:return: A `DetailedResponse` containing the result, headers and HTTP status code.
379386
:rtype: DetailedResponse with `dict` result representing a `CreateAccountResponse` object
@@ -385,6 +392,8 @@ def create_account(
385392
raise ValueError('name must be provided')
386393
if owner_iam_id is None:
387394
raise ValueError('owner_iam_id must be provided')
395+
if traits is not None:
396+
traits = convert_model(traits)
388397
headers = {}
389398
sdk_headers = get_sdk_headers(
390399
service_name=self.DEFAULT_SERVICE_NAME, service_version='V1', operation_id='create_account'
@@ -636,7 +645,11 @@ def create_account_group(self, parent: str, name: str, primary_contact_iam_id: s
636645
)
637646
headers.update(sdk_headers)
638647

639-
data = {'parent': parent, 'name': name, 'primary_contact_iam_id': primary_contact_iam_id}
648+
data = {
649+
'parent': parent,
650+
'name': name,
651+
'primary_contact_iam_id': primary_contact_iam_id,
652+
}
640653
data = {k: v for (k, v) in data.items() if v is not None}
641654
data = json.dumps(data)
642655
headers['content-type'] = 'application/json'
@@ -791,7 +804,10 @@ def update_account_group(
791804
)
792805
headers.update(sdk_headers)
793806

794-
data = {'name': name, 'primary_contact_iam_id': primary_contact_iam_id}
807+
data = {
808+
'name': name,
809+
'primary_contact_iam_id': primary_contact_iam_id,
810+
}
795811
data = {k: v for (k, v) in data.items() if v is not None}
796812
data = json.dumps(data)
797813
headers['content-type'] = 'application/json'
@@ -1296,6 +1312,63 @@ def __ne__(self, other: 'CreateAccountGroupResponse') -> bool:
12961312
return not self == other
12971313

12981314

1315+
class CreateAccountRequestTraits:
1316+
"""
1317+
The traits object can be used to opt-out of Multi-Factor Authentication setting when
1318+
creating a child account in the enterprise. This is an optional field.
1319+
1320+
:attr str mfa: (optional) By default MFA will be set on the account. To opt out,
1321+
pass the traits object with the mfa field set to empty string.
1322+
"""
1323+
1324+
def __init__(self, *, mfa: str = None) -> None:
1325+
"""
1326+
Initialize a CreateAccountRequestTraits object.
1327+
1328+
:param str mfa: (optional) By default MFA will be set on the account. To
1329+
opt out, pass the traits object with the mfa field set to empty string.
1330+
"""
1331+
self.mfa = mfa
1332+
1333+
@classmethod
1334+
def from_dict(cls, _dict: Dict) -> 'CreateAccountRequestTraits':
1335+
"""Initialize a CreateAccountRequestTraits object from a json dictionary."""
1336+
args = {}
1337+
if 'mfa' in _dict:
1338+
args['mfa'] = _dict.get('mfa')
1339+
return cls(**args)
1340+
1341+
@classmethod
1342+
def _from_dict(cls, _dict):
1343+
"""Initialize a CreateAccountRequestTraits object from a json dictionary."""
1344+
return cls.from_dict(_dict)
1345+
1346+
def to_dict(self) -> Dict:
1347+
"""Return a json dictionary representing this model."""
1348+
_dict = {}
1349+
if hasattr(self, 'mfa') and self.mfa is not None:
1350+
_dict['mfa'] = self.mfa
1351+
return _dict
1352+
1353+
def _to_dict(self):
1354+
"""Return a json dictionary representing this model."""
1355+
return self.to_dict()
1356+
1357+
def __str__(self) -> str:
1358+
"""Return a `str` version of this CreateAccountRequestTraits object."""
1359+
return json.dumps(self.to_dict(), indent=2)
1360+
1361+
def __eq__(self, other: 'CreateAccountRequestTraits') -> bool:
1362+
"""Return `true` when self and other are equal, false otherwise."""
1363+
if not isinstance(other, self.__class__):
1364+
return False
1365+
return self.__dict__ == other.__dict__
1366+
1367+
def __ne__(self, other: 'CreateAccountRequestTraits') -> bool:
1368+
"""Return `true` when self and other are not equal, false otherwise."""
1369+
return not self == other
1370+
1371+
12991372
class CreateAccountResponse:
13001373
"""
13011374
A newly-created account.

test/unit/test_enterprise_management_v1.py

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ def preprocess_url(operation_path: str):
5959
# Otherwise, return a regular expression that matches one or more trailing /.
6060
if re.fullmatch('.*/+', request_url) is None:
6161
return request_url
62-
return re.compile(request_url.rstrip('/') + '/+')
62+
else:
63+
return re.compile(request_url.rstrip('/') + '/+')
6364

6465

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

614+
# Construct a dict representation of a CreateAccountRequestTraits model
615+
create_account_request_traits_model = {}
616+
create_account_request_traits_model['mfa'] = 'testString'
617+
613618
# Set up parameter values
614619
parent = 'testString'
615620
name = 'testString'
616621
owner_iam_id = 'testString'
617-
traits = {'foo': 'bar'}
622+
traits = create_account_request_traits_model
618623

619624
# Invoke method
620625
response = _service.create_account(parent, name, owner_iam_id, traits=traits, headers={})
@@ -627,7 +632,7 @@ def test_create_account_all_params(self):
627632
assert req_body['parent'] == 'testString'
628633
assert req_body['name'] == 'testString'
629634
assert req_body['owner_iam_id'] == 'testString'
630-
assert req_body['traits'] == {'foo': 'bar'}
635+
assert req_body['traits'] == create_account_request_traits_model
631636

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

656+
# Construct a dict representation of a CreateAccountRequestTraits model
657+
create_account_request_traits_model = {}
658+
create_account_request_traits_model['mfa'] = 'testString'
659+
651660
# Set up parameter values
652661
parent = 'testString'
653662
name = 'testString'
654663
owner_iam_id = 'testString'
655-
traits = {'foo': 'bar'}
664+
traits = create_account_request_traits_model
656665

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

16031612

1613+
class TestModel_CreateAccountRequestTraits:
1614+
"""
1615+
Test Class for CreateAccountRequestTraits
1616+
"""
1617+
1618+
def test_create_account_request_traits_serialization(self):
1619+
"""
1620+
Test serialization/deserialization for CreateAccountRequestTraits
1621+
"""
1622+
1623+
# Construct a json representation of a CreateAccountRequestTraits model
1624+
create_account_request_traits_model_json = {}
1625+
create_account_request_traits_model_json['mfa'] = 'testString'
1626+
1627+
# Construct a model instance of CreateAccountRequestTraits by calling from_dict on the json representation
1628+
create_account_request_traits_model = CreateAccountRequestTraits.from_dict(
1629+
create_account_request_traits_model_json
1630+
)
1631+
assert create_account_request_traits_model != False
1632+
1633+
# Construct a model instance of CreateAccountRequestTraits by calling from_dict on the json representation
1634+
create_account_request_traits_model_dict = CreateAccountRequestTraits.from_dict(
1635+
create_account_request_traits_model_json
1636+
).__dict__
1637+
create_account_request_traits_model2 = CreateAccountRequestTraits(**create_account_request_traits_model_dict)
1638+
1639+
# Verify the model instances are equivalent
1640+
assert create_account_request_traits_model == create_account_request_traits_model2
1641+
1642+
# Convert model instance back to dict and verify no loss of data
1643+
create_account_request_traits_model_json2 = create_account_request_traits_model.to_dict()
1644+
assert create_account_request_traits_model_json2 == create_account_request_traits_model_json
1645+
1646+
16041647
class TestModel_CreateAccountResponse:
16051648
"""
16061649
Test Class for CreateAccountResponse

0 commit comments

Comments
 (0)