Began Documentation
This commit is contained in:
parent
73f03d1ccf
commit
d662895c5d
43 changed files with 16350 additions and 1 deletions
74
docs/_build/html/_sources/ec2_tut.txt
vendored
Normal file
74
docs/_build/html/_sources/ec2_tut.txt
vendored
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
.. _ec2_tut:
|
||||
|
||||
=======================
|
||||
Use Moto as EC2 backend
|
||||
=======================
|
||||
|
||||
This tutorial explains ``moto.ec2``'s features and how to use it. This
|
||||
tutorial assumes that you have already downloaded and installed boto and moto.
|
||||
Before all code examples the following snippet is launched::
|
||||
|
||||
>>> import boto.ec2, moto
|
||||
>>> mock_ec2 = moto.mock_ec2()
|
||||
>>> mock_ec2.start()
|
||||
>>> conn = boto.ec2.connect_to_region("eu-west-1")
|
||||
|
||||
Launching instances
|
||||
-------------------
|
||||
|
||||
After mock is started, the behavior is the same than previously::
|
||||
|
||||
>>> reservation = conn.run_instances('ami-f00ba4')
|
||||
>>> reservation.instances[0]
|
||||
Instance:i-91dd2f32
|
||||
|
||||
Moto set static or generate random object's attributes::
|
||||
|
||||
>>> vars(reservation.instances[0])
|
||||
{'_in_monitoring_element': False,
|
||||
'_placement': None,
|
||||
'_previous_state': None,
|
||||
'_state': pending(0),
|
||||
'ami_launch_index': u'0',
|
||||
'architecture': u'x86_64',
|
||||
'block_device_mapping': None,
|
||||
'client_token': '',
|
||||
'connection': EC2Connection:ec2.eu-west-1.amazonaws.com,
|
||||
'dns_name': u'ec2-54.214.135.84.compute-1.amazonaws.com',
|
||||
'ebs_optimized': False,
|
||||
'eventsSet': None,
|
||||
'group_name': None,
|
||||
'groups': [],
|
||||
'hypervisor': u'xen',
|
||||
'id': u'i-91dd2f32',
|
||||
'image_id': u'f00ba4',
|
||||
'instance_profile': None,
|
||||
'instance_type': u'm1.small',
|
||||
'interfaces': [NetworkInterface:eni-ed65f870],
|
||||
'ip_address': u'54.214.135.84',
|
||||
'item': u'\n ',
|
||||
'kernel': u'None',
|
||||
'key_name': u'None',
|
||||
'launch_time': u'2015-07-27T05:59:57Z',
|
||||
'monitored': True,
|
||||
'monitoring': u'\n ',
|
||||
'monitoring_state': u'enabled',
|
||||
'persistent': False,
|
||||
'platform': None,
|
||||
'private_dns_name': u'ip-10.136.187.180.ec2.internal',
|
||||
'private_ip_address': u'10.136.187.180',
|
||||
'product_codes': [],
|
||||
'public_dns_name': u'ec2-54.214.135.84.compute-1.amazonaws.com',
|
||||
'ramdisk': None,
|
||||
'reason': '',
|
||||
'region': RegionInfo:eu-west-1,
|
||||
'requester_id': None,
|
||||
'root_device_name': None,
|
||||
'root_device_type': None,
|
||||
'sourceDestCheck': u'true',
|
||||
'spot_instance_request_id': None,
|
||||
'state_reason': None,
|
||||
'subnet_id': None,
|
||||
'tags': {},
|
||||
'virtualization_type': u'paravirtual',
|
||||
'vpc_id': None}
|
||||
112
docs/_build/html/_sources/getting_started.txt
vendored
Normal file
112
docs/_build/html/_sources/getting_started.txt
vendored
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
=========================
|
||||
Getting Started with Moto
|
||||
=========================
|
||||
|
||||
Installing Moto
|
||||
---------------
|
||||
|
||||
You can use ``pip`` to install the latest released version of ``moto``::
|
||||
|
||||
pip install moto
|
||||
|
||||
If you want to install ``moto`` from source::
|
||||
|
||||
git clone git://github.com/spulec/moto.git
|
||||
cd moto
|
||||
python setup.py install
|
||||
|
||||
Moto usage
|
||||
----------
|
||||
|
||||
For example we have the following code we want to test:
|
||||
|
||||
.. sourcecode:: python
|
||||
|
||||
import boto
|
||||
from boto.s3.key import Key
|
||||
|
||||
class MyModel(object):
|
||||
def __init__(self, name, value):
|
||||
self.name = name
|
||||
self.value = value
|
||||
|
||||
def save(self):
|
||||
conn = boto.connect_s3()
|
||||
bucket = conn.get_bucket('mybucket')
|
||||
k = Key(bucket)
|
||||
k.key = self.name
|
||||
k.set_contents_from_string(self.value)
|
||||
|
||||
There are several method to do this, just keep in mind Moto creates a full blank environment.
|
||||
|
||||
Decorator
|
||||
~~~~~~~~~
|
||||
|
||||
With a decorator wrapping all the calls to S3 are automatically mocked out.
|
||||
|
||||
.. sourcecode:: python
|
||||
|
||||
import boto
|
||||
from moto import mock_s3
|
||||
from mymodule import MyModel
|
||||
|
||||
@mock_s3
|
||||
def test_my_model_save():
|
||||
conn = boto.connect_s3()
|
||||
# We need to create the bucket since this is all in Moto's 'virtual' AWS account
|
||||
conn.create_bucket('mybucket')
|
||||
|
||||
model_instance = MyModel('steve', 'is awesome')
|
||||
model_instance.save()
|
||||
|
||||
assert conn.get_bucket('mybucket').get_key('steve').get_contents_as_string() == 'is awesome'
|
||||
|
||||
Context manager
|
||||
~~~~~~~~~~~~~~~
|
||||
|
||||
Same as decorator, every call inside ``with`` statement are mocked out.
|
||||
|
||||
.. sourcecode:: python
|
||||
|
||||
def test_my_model_save():
|
||||
with mock_s3():
|
||||
conn = boto.connect_s3()
|
||||
conn.create_bucket('mybucket')
|
||||
|
||||
model_instance = MyModel('steve', 'is awesome')
|
||||
model_instance.save()
|
||||
|
||||
assert conn.get_bucket('mybucket').get_key('steve').get_contents_as_string() == 'is awesome'
|
||||
|
||||
Raw
|
||||
~~~
|
||||
|
||||
You can also start and stop manually the mocking.
|
||||
|
||||
.. sourcecode:: python
|
||||
|
||||
def test_my_model_save():
|
||||
mock = mock_s3()
|
||||
mock.start()
|
||||
|
||||
conn = boto.connect_s3()
|
||||
conn.create_bucket('mybucket')
|
||||
|
||||
model_instance = MyModel('steve', 'is awesome')
|
||||
model_instance.save()
|
||||
|
||||
assert conn.get_bucket('mybucket').get_key('steve').get_contents_as_string() == 'is awesome'
|
||||
|
||||
mock.stop()
|
||||
|
||||
Stand-alone server mode
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Moto comes with a stand-alone server allowing you to mock out an AWS HTTP endpoint. It is very useful to test even if you don't use Python.
|
||||
|
||||
.. sourcecode:: bash
|
||||
|
||||
$ moto_server ec2 -p3000
|
||||
* Running on http://0.0.0.0:3000/
|
||||
|
||||
This method isn't encouraged if you're using ``boto``, best is to use decorator method.
|
||||
91
docs/_build/html/_sources/index.txt
vendored
Normal file
91
docs/_build/html/_sources/index.txt
vendored
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
.. _index:
|
||||
|
||||
=============================
|
||||
Moto: A Mock library for boto
|
||||
=============================
|
||||
|
||||
A library that allows you to easily mock out tests based on
|
||||
_`AWS infrastructure`.
|
||||
|
||||
.. _AWS infrastructure: http://aws.amazon.com/
|
||||
|
||||
Getting Started
|
||||
---------------
|
||||
|
||||
If you've never used ``moto`` before, you should read the
|
||||
:doc:`Getting Started with Moto <getting_started>` guide to get familiar
|
||||
with ``moto`` & its usage.
|
||||
|
||||
Currently implemented Services
|
||||
------------------------------
|
||||
|
||||
* **Compute**
|
||||
|
||||
* :doc:`Elastic Compute Cloud <ec2_tut>`
|
||||
* AMI
|
||||
* EBS
|
||||
* Instances
|
||||
* Security groups
|
||||
* Tags
|
||||
* Auto Scaling
|
||||
|
||||
* **Storage and content delivery**
|
||||
|
||||
* S3
|
||||
* Glacier
|
||||
|
||||
* **Database**
|
||||
|
||||
* RDS
|
||||
* DynamoDB
|
||||
* Redshift
|
||||
|
||||
* **Networking**
|
||||
|
||||
* Route53
|
||||
|
||||
* **Administration and security**
|
||||
|
||||
* Identity & access management
|
||||
* CloudWatch
|
||||
|
||||
* **Deployment and management**
|
||||
|
||||
* CloudFormation
|
||||
|
||||
* **Analytics**
|
||||
|
||||
* Kinesis
|
||||
* EMR
|
||||
|
||||
* **Application service**
|
||||
|
||||
* SQS
|
||||
* SES
|
||||
|
||||
* **Mobile services**
|
||||
|
||||
* SNS
|
||||
|
||||
Additional Resources
|
||||
--------------------
|
||||
|
||||
* `Moto Source Repository`_
|
||||
* `Moto Issue Tracker`_
|
||||
|
||||
.. _Moto Issue Tracker: https://github.com/spulec/moto/issues
|
||||
.. _Moto Source Repository: https://github.com/spulec/moto
|
||||
|
||||
Indices and tables
|
||||
==================
|
||||
|
||||
* :ref:`genindex`
|
||||
* :ref:`modindex`
|
||||
* :ref:`search`
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 2
|
||||
:hidden:
|
||||
:glob:
|
||||
|
||||
getting_started
|
||||
Loading…
Add table
Add a link
Reference in a new issue