describe_event_bus returns json, not dict

Correct the assumption that describe_event_bus()['Policy'] is a dict
As per
http://boto3.readthedocs.io/en/latest/reference/services/events.html#CloudWatchEvents.Client.describe_event_bus
It should be a JSON encoded string

Here we decode the JSON before we look inside the policy
This commit is contained in:
cpitchford 2018-05-15 17:04:59 +01:00 committed by GitHub
parent 1e01356f99
commit e85106c708
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,7 @@
import random
import boto3
import json
from moto.events import mock_events
from botocore.exceptions import ClientError
@ -181,13 +182,15 @@ def test_permissions():
client.put_permission(Action='PutEvents', Principal='222222222222', StatementId='Account2')
resp = client.describe_event_bus()
assert len(resp['Policy']['Statement']) == 2
resp_policy = json.loads(resp['Policy'])
assert len(resp_policy['Statement']) == 2
client.remove_permission(StatementId='Account2')
resp = client.describe_event_bus()
assert len(resp['Policy']['Statement']) == 1
assert resp['Policy']['Statement'][0]['Sid'] == 'Account1'
resp_policy = json.loads(resp['Policy'])
assert len(resp_policy['Statement']) == 1
assert resp_policy['Statement'][0]['Sid'] == 'Account1'
@mock_events