Submit
Path:
~
/
/
proc
/
thread-self
/
root
/
usr
/
lib
/
python2.7
/
site-packages
/
botocore
/
File Content:
stub.pyc
� ?��Xc @ s� d d l Z d d l m Z d d l m Z d d l m Z d d l m Z m Z m Z d d l m Z d e f d � � YZ e � Z d e f d � � YZ d S( i����N( t deque( t pformat( t validate_parameters( t ParamValidationErrort StubResponseErrort StubAssertionError( t Responset _ANYc B s) e Z d Z d � Z d � Z d � Z RS( sZ A helper object that compares equal to everything. Copied from unittest.mock c C s t S( N( t True( t selft other( ( s/ /tmp/pip-build-uEGWVr/botocore/botocore/stub.pyt __eq__ s c C s t S( N( t False( R R ( ( s/ /tmp/pip-build-uEGWVr/botocore/botocore/stub.pyt __ne__ s c C s d S( Ns <ANY>( ( R ( ( s/ /tmp/pip-build-uEGWVr/botocore/botocore/stub.pyt __repr__# s ( t __name__t __module__t __doc__R R R ( ( ( s/ /tmp/pip-build-uEGWVr/botocore/botocore/stub.pyR s t Stubberc B s� e Z d Z d � Z d � Z d � Z d � Z d � Z d d � Z d � Z d d d d d d � Z d � Z d � Z d � Z d � Z d � Z RS( s� This class will allow you to stub out requests so you don't have to hit an endpoint to write tests. Responses are returned first in, first out. If operations are called out of order, or are called with no remaining queued responses, an error will be raised. **Example:** :: import datetime import botocore.session from botocore.stub import Stubber s3 = botocore.session.get_session().create_client('s3') stubber = Stubber(s3) response = { 'IsTruncated': False, 'Name': 'test-bucket', 'MaxKeys': 1000, 'Prefix': '', 'Contents': [{ 'Key': 'test.txt', 'ETag': '"abc123"', 'StorageClass': 'STANDARD', 'LastModified': datetime.datetime(2016, 1, 20, 22, 9), 'Owner': {'ID': 'abc123', 'DisplayName': 'myname'}, 'Size': 14814 }], 'EncodingType': 'url', 'ResponseMetadata': { 'RequestId': 'abc123', 'HTTPStatusCode': 200, 'HostId': 'abc123' }, 'Marker': '' } expected_params = {'Bucket': 'test-bucket'} stubber.add_response('list_objects', response, expected_params) stubber.activate() service_response = s3.list_objects(Bucket='test-bucket') assert service_response == response This class can also be called as a context manager, which will handle activation / deactivation for you. **Example:** :: import datetime import botocore.session from botocore.stub import Stubber s3 = botocore.session.get_session().create_client('s3') response = { "Owner": { "ID": "foo", "DisplayName": "bar" }, "Buckets": [{ "CreationDate": datetime.datetime(2016, 1, 20, 22, 9), "Name": "baz" }] } with Stubber(s3) as stubber: stubber.add_response('list_buckets', response, {}) service_response = s3.list_buckets() assert service_response == response If you have an input paramter that is a randomly generated value, or you otherwise don't care about its value, you can use stub.ANY to ignore it in validation. **Example:** :: import datetime import botocore.session from botocore.stub import Stubber, ANY s3 = botocore.session.get_session().create_client('s3') stubber = Stubber(s3) response = { 'IsTruncated': False, 'Name': 'test-bucket', 'MaxKeys': 1000, 'Prefix': '', 'Contents': [{ 'Key': 'test.txt', 'ETag': '"abc123"', 'StorageClass': 'STANDARD', 'LastModified': datetime.datetime(2016, 1, 20, 22, 9), 'Owner': {'ID': 'abc123', 'DisplayName': 'myname'}, 'Size': 14814 }], 'EncodingType': 'url', 'ResponseMetadata': { 'RequestId': 'abc123', 'HTTPStatusCode': 200, 'HostId': 'abc123' }, 'Marker': '' } expected_params = {'Bucket': ANY} stubber.add_response('list_objects', response, expected_params) with stubber: service_response = s3.list_objects(Bucket='test-bucket') assert service_response == response c C s+ | | _ d | _ d | _ t � | _ d S( sA :param client: The client to add your stubs to. t boto_stubbert boto_stubber_expected_paramsN( t clientt _event_idt _expected_params_event_idR t _queue( R R ( ( s/ /tmp/pip-build-uEGWVr/botocore/botocore/stub.pyt __init__� s c C s | j � | S( N( t activate( R ( ( s/ /tmp/pip-build-uEGWVr/botocore/botocore/stub.pyt __enter__� s c C s | j � d S( N( t deactivate( R t exception_typet exception_valuet traceback( ( s/ /tmp/pip-build-uEGWVr/botocore/botocore/stub.pyt __exit__� s c C sN | j j j j d | j d | j �| j j j j d | j d | j �d S( s5 Activates the stubber on the client s before-parameter-build.*.*t unique_ids before-call.*.*N( R t metat eventst register_firstt _assert_expected_paramsR t registert _get_response_handlerR ( R ( ( s/ /tmp/pip-build-uEGWVr/botocore/botocore/stub.pyR � s c C sN | j j j j d | j d | j �| j j j j d | j d | j �d S( s7 Deactivates the stubber on the client s before-parameter-build.*.*R! s before-call.*.*N( R R"