Skip to content

Commit 24316b9

Browse files
author
Mike Kistler
committed
Working version of Configuration Governance examples test
1 parent ce4eb9f commit 24316b9

File tree

1 file changed

+37
-15
lines changed

1 file changed

+37
-15
lines changed

examples/test_configuration_governance_v1_examples.py

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,12 @@ def setup_class(cls):
7070
config = read_external_sources(ConfigurationGovernanceV1.DEFAULT_SERVICE_NAME)
7171

7272
account_id = config['ACCOUNT_ID']
73-
service_name = config['TEST_SERVICE_NAME']
73+
service_name = config['EXAMPLE_SERVICE_NAME']
7474
enterprise_scope_id = config['ENTERPRISE_SCOPE_ID']
7575
subacct_scope_id = config['SUBACCT_SCOPE_ID']
7676

77+
cls.clean_rules()
78+
7779
print('Setup complete.')
7880

7981
needscredentials = pytest.mark.skipif(
@@ -139,16 +141,16 @@ def test_create_attachments_example(self):
139141
try:
140142
# begin-create_attachments
141143

142-
rule_scope_model = {
143-
'note': 'My enterprise',
144-
'scope_id': enterprise_scope_id,
145-
'scope_type': 'enterprise'
144+
excluded_scope_model = {
145+
'note': 'Development account',
146+
'scope_id': subacct_scope_id,
147+
'scope_type': 'enterprise.account'
146148
}
147149

148150
attachment_request_model = {
149151
'account_id': account_id,
150152
'included_scope': {'note':'My enterprise','scope_id':enterprise_scope_id,'scope_type':'enterprise'},
151-
'excluded_scopes': [rule_scope_model]
153+
'excluded_scopes': [excluded_scope_model]
152154
}
153155

154156
create_attachments_response = configuration_governance_service.create_attachments(
@@ -183,7 +185,8 @@ def test_get_attachment_example(self):
183185
# end-get_attachment
184186

185187
global attachment_etag_link
186-
attachment_etag_link = attachment[''];
188+
attachment_etag_link = configuration_governance_service.get_attachment(
189+
rule_id=rule_id_link, attachment_id=attachment_id_link).get_headers().get('Etag')
187190
except ApiException as e:
188191
pytest.fail(str(e))
189192

@@ -204,7 +207,7 @@ def test_get_rule_example(self):
204207
# end-get_rule
205208

206209
global rule_etag_link
207-
rule_etag_link = rule[''];
210+
rule_etag_link = configuration_governance_service.get_rule(rule_id=rule_id_link).get_headers().get('etag')
208211
except ApiException as e:
209212
pytest.fail(str(e))
210213

@@ -257,7 +260,7 @@ def test_update_rule_example(self):
257260

258261
rule = configuration_governance_service.update_rule(
259262
rule_id=rule_id_link,
260-
if_match='testString',
263+
if_match=rule_etag_link,
261264
name='Disable public access',
262265
description='Ensure that public access to account resources is disabled.',
263266
target={'service_name':service_name,'resource_kind':'service','additional_target_attributes':[]},
@@ -303,19 +306,19 @@ def test_update_attachment_example(self):
303306
try:
304307
# begin-update_attachment
305308

306-
rule_scope_model = {
307-
'note': 'My enterprise',
308-
'scope_id': enterprise_scope_id,
309-
'scope_type': 'enterprise'
309+
excluded_scope_model = {
310+
'note': 'Development account',
311+
'scope_id': subacct_scope_id,
312+
'scope_type': 'enterprise.account'
310313
}
311314

312315
attachment = configuration_governance_service.update_attachment(
313316
rule_id=rule_id_link,
314317
attachment_id=attachment_id_link,
315-
if_match='testString',
318+
if_match=attachment_etag_link,
316319
account_id=account_id,
317320
included_scope={'note':'My enterprise','scope_id':enterprise_scope_id,'scope_type':'enterprise'},
318-
excluded_scopes=[rule_scope_model]
321+
excluded_scopes=[excluded_scope_model]
319322
).get_result()
320323

321324
print(json.dumps(attachment, indent=2))
@@ -364,6 +367,25 @@ def test_delete_rule_example(self):
364367
except ApiException as e:
365368
pytest.fail(str(e))
366369

370+
@classmethod
371+
def clean_rules(cls):
372+
"""
373+
Clean up rules from prior test runs
374+
"""
375+
try:
376+
rule_list = configuration_governance_service.list_rules(
377+
account_id=account_id,
378+
labels=test_label
379+
).get_result()
380+
381+
for rule in rule_list['rules']:
382+
rule_id = rule['rule_id']
383+
print(f'deleting rule {rule_id}')
384+
configuration_governance_service.delete_rule(rule_id)
385+
386+
except ApiException as e:
387+
print(str(e))
388+
367389
# endregion
368390
##############################################################################
369391
# End of Examples for Service: ConfigurationGovernanceV1

0 commit comments

Comments
 (0)