diff --git a/README.md b/README.md index 5485c63cd..2b4daeda6 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ [![Build Status](https://travis-ci.org/spulec/moto.png?branch=master)](https://travis-ci.org/spulec/moto) [![Coverage Status](https://coveralls.io/repos/spulec/moto/badge.png?branch=master)](https://coveralls.io/r/spulec/moto) +[![Docs](https://readthedocs.org/projects/pip/badge/?version=stable)](http://docs.getmoto.org) # In a nutshell diff --git a/docs/_build/doctrees/docs/ec2_tut.doctree b/docs/_build/doctrees/docs/ec2_tut.doctree new file mode 100644 index 000000000..d9f63cfa2 Binary files /dev/null and b/docs/_build/doctrees/docs/ec2_tut.doctree differ diff --git a/docs/_build/doctrees/docs/getting_started.doctree b/docs/_build/doctrees/docs/getting_started.doctree new file mode 100644 index 000000000..96db7c269 Binary files /dev/null and b/docs/_build/doctrees/docs/getting_started.doctree differ diff --git a/docs/_build/doctrees/docs/moto_apis.doctree b/docs/_build/doctrees/docs/moto_apis.doctree new file mode 100644 index 000000000..32d9752f6 Binary files /dev/null and b/docs/_build/doctrees/docs/moto_apis.doctree differ diff --git a/docs/_build/doctrees/docs/other_langs.doctree b/docs/_build/doctrees/docs/other_langs.doctree new file mode 100644 index 000000000..952300c9e Binary files /dev/null and b/docs/_build/doctrees/docs/other_langs.doctree differ diff --git a/docs/_build/doctrees/docs/server_mode.doctree b/docs/_build/doctrees/docs/server_mode.doctree new file mode 100644 index 000000000..0cd41aa56 Binary files /dev/null and b/docs/_build/doctrees/docs/server_mode.doctree differ diff --git a/docs/_build/doctrees/environment.pickle b/docs/_build/doctrees/environment.pickle index 9416cbe47..a1e8e8bbb 100644 Binary files a/docs/_build/doctrees/environment.pickle and b/docs/_build/doctrees/environment.pickle differ diff --git a/docs/_build/doctrees/index.doctree b/docs/_build/doctrees/index.doctree index a1f025778..318fbf735 100644 Binary files a/docs/_build/doctrees/index.doctree and b/docs/_build/doctrees/index.doctree differ diff --git a/docs/_build/doctrees/other_langs.doctree b/docs/_build/doctrees/other_langs.doctree index 7070542cb..eb8fa0473 100644 Binary files a/docs/_build/doctrees/other_langs.doctree and b/docs/_build/doctrees/other_langs.doctree differ diff --git a/docs/ec2_tut.rst b/docs/_build/html/_sources/docs/ec2_tut.rst.txt similarity index 100% rename from docs/ec2_tut.rst rename to docs/_build/html/_sources/docs/ec2_tut.rst.txt diff --git a/docs/_build/html/_sources/docs/getting_started.rst.txt b/docs/_build/html/_sources/docs/getting_started.rst.txt new file mode 100644 index 000000000..97f667d26 --- /dev/null +++ b/docs/_build/html/_sources/docs/getting_started.rst.txt @@ -0,0 +1,114 @@ +.. _getting_started: + +========================= +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://127.0.0.1:3000/ + +This method isn't encouraged if you're using ``boto``, best is to use decorator method. diff --git a/docs/moto_apis.rst b/docs/_build/html/_sources/docs/moto_apis.rst.txt similarity index 100% rename from docs/moto_apis.rst rename to docs/_build/html/_sources/docs/moto_apis.rst.txt diff --git a/docs/other_langs.rst b/docs/_build/html/_sources/docs/other_langs.rst.txt similarity index 78% rename from docs/other_langs.rst rename to docs/_build/html/_sources/docs/other_langs.rst.txt index 6fb617c39..664ce50b1 100644 --- a/docs/other_langs.rst +++ b/docs/_build/html/_sources/docs/other_langs.rst.txt @@ -4,7 +4,7 @@ Other languages =============== -You don't need to use Python to use Moto; it can be used with any language. To use it with another language, run moto_server and here are some examples in other languages. +You don't need to use Python to use Moto; it can be used with any language. To use it with another language, run moto_server. Here are some examples in other languages: * `Java`_ * `Ruby`_ diff --git a/docs/_build/html/_sources/docs/server_mode.rst.txt b/docs/_build/html/_sources/docs/server_mode.rst.txt new file mode 100644 index 000000000..e8139e04d --- /dev/null +++ b/docs/_build/html/_sources/docs/server_mode.rst.txt @@ -0,0 +1,67 @@ +.. _server_mode: + +=========== +Server mode +=========== + +Moto has a stand-alone server mode. This allows you to utilize +the backend structure of Moto even if you don't use Python. + +It uses flask, which isn't a default dependency. You can install the +server 'extra' package with: + +.. code:: bash + + pip install moto[server] + + +You can then start it running a service: + +.. code:: bash + + $ moto_server ec2 + +You can also pass the port: + +.. code-block:: bash + + $ moto_server ec2 -p3000 + * Running on http://127.0.0.1:3000/ + +If you want to be able to use the server externally you can pass an IP +address to bind to as a hostname or allow any of your external +interfaces with 0.0.0.0: + +.. code-block:: bash + + $ moto_server ec2 -H 0.0.0.0 + * Running on http://0.0.0.0:5000/ + +Please be aware this might allow other network users to access your +server. + +Then go to localhost_ to see a list of running instances (it will be empty since you haven't added any yet). + +If you want to use boto3 with this, you can pass an `endpoint_url` to the resource + +.. code-block:: python + + boto3.resource( + service_name='s3', + region_name='us-west-1', + endpoint_url='http://localhost:5000', + ) + +Other languages +--------------- + +You don't need to use Python to use Moto; it can be used with any language. Here are some examples to run it with other languages: + +* `Java`_ +* `Ruby`_ +* `Javascript`_ + +.. _Java: https://github.com/spulec/moto/blob/master/other_langs/sqsSample.java +.. _Ruby: https://github.com/spulec/moto/blob/master/other_langs/test.rb +.. _Javascript: https://github.com/spulec/moto/blob/master/other_langs/test.js +.. _localhost: http://localhost:5000/?Action=DescribeInstances diff --git a/docs/_build/html/_sources/index.rst.txt b/docs/_build/html/_sources/index.rst.txt index 560ebc661..2ce31febd 100644 --- a/docs/_build/html/_sources/index.rst.txt +++ b/docs/_build/html/_sources/index.rst.txt @@ -5,18 +5,17 @@ Moto: Mock AWS Services ============================= A library that allows you to easily mock out tests based on -_`AWS infrastructure`. - -.. _AWS infrastructure: http://aws.amazon.com/ +`AWS infrastructure`_. Getting Started --------------- If you've never used ``moto`` before, you should read the -:doc:`Getting Started with Moto ` guide to get familiar +:doc:`Getting Started with Moto ` guide to get familiar with ``moto`` and its usage. Currently implemented Services: +------------------------------- +-----------------------+---------------------+-----------------------------------+ | Service Name | Decorator | Development Status | @@ -79,11 +78,6 @@ Currently implemented Services: +-----------------------+---------------------+-----------------------------------+ -Moto APIs ---------- -some stuff - - Additional Resources -------------------- @@ -91,6 +85,7 @@ Additional Resources * `Moto Source Repository`_ * `Moto Issue Tracker`_ +.. _AWS infrastructure: http://aws.amazon.com/ .. _Moto Issue Tracker: https://github.com/spulec/moto/issues .. _Moto Source Repository: https://github.com/spulec/moto @@ -99,7 +94,7 @@ Additional Resources :hidden: :glob: - index - getting_started - other_langs - moto_apis + docs/getting_started + docs/server_mode + docs/moto_apis + docs/ec2_tut diff --git a/docs/_build/html/_sources/other_langs.rst.txt b/docs/_build/html/_sources/other_langs.rst.txt index 6fb617c39..664ce50b1 100644 --- a/docs/_build/html/_sources/other_langs.rst.txt +++ b/docs/_build/html/_sources/other_langs.rst.txt @@ -4,7 +4,7 @@ Other languages =============== -You don't need to use Python to use Moto; it can be used with any language. To use it with another language, run moto_server and here are some examples in other languages. +You don't need to use Python to use Moto; it can be used with any language. To use it with another language, run moto_server. Here are some examples in other languages: * `Java`_ * `Ruby`_ diff --git a/docs/_build/html/docs/ec2_tut.html b/docs/_build/html/docs/ec2_tut.html new file mode 100644 index 000000000..63b3adc24 --- /dev/null +++ b/docs/_build/html/docs/ec2_tut.html @@ -0,0 +1,306 @@ + + + + + + + + + + + Use Moto as EC2 backend — Moto 0.4.10 documentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ + + + + + +
+
+ + + + + + + + + + + + + + + + +
+ + + + +
+
+
+
+ +
+

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}
+
+
+
+
+ + +
+
+ +
+
+ + +
+
+ +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/docs/_build/html/docs/getting_started.html b/docs/_build/html/docs/getting_started.html new file mode 100644 index 000000000..5ab53fe72 --- /dev/null +++ b/docs/_build/html/docs/getting_started.html @@ -0,0 +1,343 @@ + + + + + + + + + + + Getting Started with Moto — Moto 0.4.10 documentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ + + + + + +
+
+ + + + + + + + + + + + + + + + +
+ + + + +
+
+
+
+ +
+

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:

+
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.

+
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.

+
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.

+
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.

+
$ moto_server ec2 -p3000
+ * Running on http://127.0.0.1:3000/
+
+
+

This method isn’t encouraged if you’re using boto, best is to use decorator method.

+
+
+
+ + +
+
+ +
+
+ + +
+
+ +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/docs/_build/html/docs/moto_apis.html b/docs/_build/html/docs/moto_apis.html new file mode 100644 index 000000000..690a8069e --- /dev/null +++ b/docs/_build/html/docs/moto_apis.html @@ -0,0 +1,256 @@ + + + + + + + + + + + Moto APIs — Moto 0.4.10 documentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ + + + + + +
+
+ + + + + + + + + + + + + + + + +
+ + + + +
+
+
+
+ +
+

Moto APIs

+

Moto provides some internal APIs to view and change the state of the backends.

+
+

Reset API

+

This API resets the state of all of the backends. Send an HTTP POST to reset:

+
requests.post("http://motoapi.amazonaws.com/moto-api/reset")
+
+
+
+
+

Dashboard

+

Moto comes with a dashboard to view the current state of the system:

+
http://localhost:5000/moto-api/
+
+
+
+
+ + +
+
+ +
+
+ + +
+
+ +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/docs/_build/html/docs/other_langs.html b/docs/_build/html/docs/other_langs.html new file mode 100644 index 000000000..3b5a91b53 --- /dev/null +++ b/docs/_build/html/docs/other_langs.html @@ -0,0 +1,243 @@ + + + + + + + + + + + Other languages — Moto 0.4.10 documentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ + + + + + +
+
+ + + + + + + + + + + + + + + + +
+ + + + +
+
+
+
+ +
+

Other languages

+

You don’t need to use Python to use Moto; it can be used with any language. To use it with another language, run moto_server. Here are some examples in other languages:

+ +
+ + +
+
+ +
+
+ + +
+
+ +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/docs/_build/html/docs/server_mode.html b/docs/_build/html/docs/server_mode.html new file mode 100644 index 000000000..c226df021 --- /dev/null +++ b/docs/_build/html/docs/server_mode.html @@ -0,0 +1,283 @@ + + + + + + + + + + + Server mode — Moto 0.4.10 documentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ + + + + + +
+
+ + + + + + + + + + + + + + + + +
+ + + + +
+
+
+
+ +
+

Server mode

+

Moto has a stand-alone server mode. This allows you to utilize +the backend structure of Moto even if you don’t use Python.

+

It uses flask, which isn’t a default dependency. You can install the +server ‘extra’ package with:

+
pip install moto[server]
+
+
+

You can then start it running a service:

+
$ moto_server ec2
+
+
+

You can also pass the port:

+
$ moto_server ec2 -p3000
+ * Running on http://127.0.0.1:3000/
+
+
+

If you want to be able to use the server externally you can pass an IP +address to bind to as a hostname or allow any of your external +interfaces with 0.0.0.0:

+
$ moto_server ec2 -H 0.0.0.0
+ * Running on http://0.0.0.0:5000/
+
+
+

Please be aware this might allow other network users to access your +server.

+

Then go to localhost to see a list of running instances (it will be empty since you haven’t added any yet).

+

If you want to use boto3 with this, you can pass an endpoint_url to the resource

+
boto3.resource(
+    service_name='s3',
+    region_name='us-west-1',
+    endpoint_url='http://localhost:5000',
+)
+
+
+
+

Other languages

+

You don’t need to use Python to use Moto; it can be used with any language. Here are some examples to run it with other languages:

+ +
+
+ + +
+
+ +
+
+ + +
+
+ +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/docs/_build/html/genindex.html b/docs/_build/html/genindex.html index 1a7b34098..d0445ccd1 100644 --- a/docs/_build/html/genindex.html +++ b/docs/_build/html/genindex.html @@ -90,10 +90,10 @@ diff --git a/docs/_build/html/index.html b/docs/_build/html/index.html index cab7668b9..9b6474caf 100644 --- a/docs/_build/html/index.html +++ b/docs/_build/html/index.html @@ -36,7 +36,7 @@ href="genindex.html"/> - + @@ -89,21 +89,11 @@ -