Hello,
Stubber(boto3.client('iam'))
works. But not:
Stubber(boto3.resource('iam'))
Traceback (most recent call last):
File "/Users/proj/tests/test_policy.py", line 26, in test_validate_statement
with Stubber(resource) as hey:
File "/Users/proj/env/lib/python2.7/site-packages/botocore/stub.py", line 172, in __enter__
self.activate()
File "/Users/proj/env/lib/python2.7/site-packages/botocore/stub.py", line 182, in activate
self.client.meta.events.register_first(
AttributeError: 'ResourceMeta' object has no attribute 'events'
I would like to stub:
role_policy = iam_resource.RolePolicy(role_name, inline_policy)
Is it not supported?
Thanks
Currently Stubber will only work for a client, but I think that you might be able to do:
iam = boto3.resource("iam")
iam.meta.client = Stubber(iam.meta.client)
I couldn't make that work, but I realised I didn't need to use a resource to get the RolePolicy:
iam_client.get_role_policy(RoleName=role_name, PolicyName=policy_name)
All good and unit tested, thanks!
For anyone running across this looking for a working solution, this works for me:
s3 = boto3.resource('s3')
stub = Stubber(s3.meta.client)
stub.add_response(...)
Most helpful comment
For anyone running across this looking for a working solution, this works for me: