Skip to content

Commit 6b75af5

Browse files
Bhavana BellamgariBhavana Bellamgari
authored andcommitted
Updated role template references changes and test cases
1 parent fe2358e commit 6b75af5

File tree

4 files changed

+870
-237
lines changed

4 files changed

+870
-237
lines changed

examples/test_iam_policy_management_v1_examples.py

Lines changed: 76 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
example_role_template_etag = None
7373
example_role_template_assignment_id = None
7474
example_role_template_assignment_etag = None
75+
example_role_policy_template_id = None
7576

7677

7778
##############################################################################
@@ -1443,10 +1444,17 @@ def test_create_role_template_example(self):
14431444
print('\ncreate_role_template() result:')
14441445

14451446
# begin-create_role_template
1446-
1447+
template_role_model = {
1448+
'name': 'SDKCustomRoleName',
1449+
'display_name': 'SDK Test Custom Role',
1450+
'service_name': 'am-test-service',
1451+
'description': 'SDK Test Custom Role',
1452+
'actions': ['am-test-service.test.create'],
1453+
}
14471454
response = iam_policy_management_service.create_role_template(
14481455
name='SDKRoleTemplateExample',
14491456
account_id=example_account_id,
1457+
role=template_role_model,
14501458
)
14511459
role_template = response.get_result()
14521460

@@ -1462,6 +1470,55 @@ def test_create_role_template_example(self):
14621470
except ApiException as e:
14631471
pytest.fail(str(e))
14641472

1473+
@needscredentials
1474+
def test_create_role_policy_template_example(self):
1475+
"""
1476+
create_role_policy_template request example
1477+
"""
1478+
try:
1479+
print('\ncreate_role_policy_template() result:')
1480+
# begin-create_role_policy_template
1481+
1482+
policy_resource_model = {
1483+
'attributes': [{
1484+
'key': 'serviceName',
1485+
'operator': 'stringEquals',
1486+
'value': 'am-test-service',
1487+
}],
1488+
}
1489+
1490+
control_model = TemplateControl(grant=TemplateGrant(
1491+
roles=[{
1492+
'role_id': 'crn:v1:bluemix:public:iam::::role:Viewer',
1493+
}],
1494+
role_template_references=[{
1495+
'id': example_role_template_id, 'version': example_role_template_version
1496+
}]
1497+
))
1498+
1499+
template_policy_model = {
1500+
'type': 'access',
1501+
'resource': policy_resource_model,
1502+
'control': control_model.to_dict(),
1503+
}
1504+
1505+
response = iam_policy_management_service.create_policy_template(
1506+
name='SDKExamplesTest',
1507+
account_id=example_account_id,
1508+
policy=template_policy_model,
1509+
)
1510+
policy_template = response.get_result()
1511+
1512+
global example_role_policy_template_id
1513+
example_role_policy_template_id = policy_template['id']
1514+
1515+
print(json.dumps(policy_template, indent=2))
1516+
1517+
# end-create_policy_template
1518+
1519+
except ApiException as e:
1520+
pytest.fail(str(e))
1521+
14651522
# @needscredentials
14661523
def test_get_role_template_example(self):
14671524
"""
@@ -1498,7 +1555,6 @@ def test_replace_role_template_example(self):
14981555
# begin-replace_role_template
14991556

15001557
template_role_model = {
1501-
'name': 'SDKRoleTemplateExampleRe',
15021558
'display_name': 'am-test-service',
15031559
'service_name': 'am-test-service',
15041560
'actions': ['am-test-service.test.delete'],
@@ -1558,9 +1614,7 @@ def test_create_role_template_version_example(self):
15581614
# begin-create_role_template_version
15591615

15601616
template_role_model = {
1561-
'name': 'SDKRoleTemplateExampleVer',
15621617
'display_name': 'am-test-service',
1563-
'service_name': 'am-test-service',
15641618
'actions': ['am-test-service.test.delete', 'am-test-service.test.create'],
15651619
}
15661620

@@ -1779,6 +1833,24 @@ def test_delete_role_assignment_example(self):
17791833
except ApiException as e:
17801834
pytest.fail(str(e))
17811835

1836+
@needscredentials
1837+
def test_delete_role_policy_template_example(self):
1838+
"""
1839+
delete_role_policy_template request example
1840+
"""
1841+
try:
1842+
# begin-delete_role_policy_template
1843+
1844+
response = iam_policy_management_service.delete_policy_template(
1845+
policy_template_id=example_role_policy_template_id,
1846+
)
1847+
1848+
# end-delete_policy_template
1849+
print('\ndelete_role_policy_template() response status code: ', response.get_status_code())
1850+
1851+
except ApiException as e:
1852+
pytest.fail(str(e))
1853+
17821854
# @needscredentials
17831855
def test_delete_role_template_version_example(self):
17841856
"""

0 commit comments

Comments
 (0)