Created
August 19, 2019 15:31
-
-
Save mathewmoon/d7401b7c1a42ed4bb7c26a1c4cc529cb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3.7 | |
| import boto3 | |
| import botoinator | |
| from moto import mock_s3, mock_sqs | |
| import time | |
| import inspect | |
| def myDecorator(value1, value2, value3): | |
| def test_decorator(func): | |
| func.testValue = (value1, value2, value3) | |
| return func | |
| return test_decorator | |
| @mock_s3 | |
| def testRegisterClient(): | |
| s = boto3.session.Session() | |
| s.register_client_decorator('s3', 'create_bucket', myDecorator(time.time(), "string", True)) | |
| s.register_client_decorator('s3', 'get_bucket_acl', myDecorator(time.time(), "string", True)) | |
| client = s.client('s3') | |
| bucket = client.create_bucket | |
| assert isinstance(bucket.testValue[0], float) == 1 and bucket.testValue[1] == "string" and bucket.testValue[2] == True and isinstance(bucket.testValue, tuple) | |
| @mock_sqs | |
| def testRegisterResource(): | |
| s = boto3.session.Session() | |
| s.register_resource_decorator('sqs', 'Queue', 'delete', myDecorator(time.time(), "string", True)) | |
| sqs = s.resource('sqs', region_name='us-east-1') | |
| q = sqs.create_queue(QueueName='foo') | |
| obj = sqs.Queue('foo').delete | |
| assert isinstance(obj.testValue[0], float) == 1 and obj.testValue[1] == "string" and obj.testValue[2] == True and isinstance(obj.testValue, tuple) | |
| """ | |
| service_name -- the boto3 name of the service to apply the decorator to. | |
| resource_name -- the boto3 name of the resource of the service to apply the decorator to. | |
| method_names -- one or more method names of the resource to apply the decorator to. Single names can be a string. | |
| decorator -- the decorator function. Must be a function that takes a function and returns a function. The returned function must take (*args, **kwargs) as arguments | |
| """ | |
| testRegisterClient() | |
| testRegisterResource() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment