Botocore: Stubber(client) works but not Stubber(resource)

Created on 11 Jan 2017  路  3Comments  路  Source: boto/botocore

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

question

Most helpful comment

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(...)

All 3 comments

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(...)
Was this page helpful?
0 / 5 - 0 ratings

Related issues

mjonescase picture mjonescase  路  3Comments

jagill picture jagill  路  3Comments

freddrake picture freddrake  路  5Comments

ThisGuyCodes picture ThisGuyCodes  路  5Comments

kapilt picture kapilt  路  5Comments