Feature - @mock_all() (#3756)
This commit is contained in:
parent
db0738025a
commit
e54e5cdb95
@ -6,6 +6,23 @@ Implemented Services
|
||||
====================
|
||||
|
||||
Please see a list of all currently supported services. Each service will have a list of the endpoints that are implemented.
|
||||
Each service will also have an example on how to mock an individual service.
|
||||
|
||||
Note that you can mock multiple services at the same time:
|
||||
|
||||
.. sourcecode:: python
|
||||
|
||||
@mock_s3
|
||||
@mock_sqs
|
||||
def test_both_s3_and_sqs():
|
||||
...
|
||||
|
||||
|
||||
.. sourcecode:: python
|
||||
|
||||
@mock_all
|
||||
def test_all_supported_services_at_the_same_time():
|
||||
...
|
||||
|
||||
|
||||
.. toctree::
|
||||
|
@ -1,4 +1,5 @@
|
||||
import importlib
|
||||
import sys
|
||||
|
||||
|
||||
def lazy_load(
|
||||
@ -165,6 +166,25 @@ mock_mediastoredata = lazy_load(
|
||||
mock_efs = lazy_load(".efs", "mock_efs")
|
||||
mock_wafv2 = lazy_load(".wafv2", "mock_wafv2")
|
||||
|
||||
|
||||
def mock_all():
|
||||
dec_names = [
|
||||
d
|
||||
for d in dir(sys.modules["moto"])
|
||||
if d.startswith("mock_")
|
||||
and not d.endswith("_deprecated")
|
||||
and not d == "mock_all"
|
||||
]
|
||||
|
||||
def deco(f):
|
||||
for dec_name in reversed(dec_names):
|
||||
dec = globals()[dec_name]
|
||||
f = dec(f)
|
||||
return f
|
||||
|
||||
return deco
|
||||
|
||||
|
||||
# import logging
|
||||
# logging.getLogger('boto').setLevel(logging.CRITICAL)
|
||||
|
||||
|
@ -238,6 +238,18 @@ def write_implementation_coverage_to_docs(coverage):
|
||||
file.write("====================\n")
|
||||
file.write("\n")
|
||||
file.write("Please see a list of all currently supported services. Each service will have a list of the endpoints that are implemented.\n")
|
||||
file.write("Each service will also have an example on how to mock an individual service.\n\n")
|
||||
file.write("Note that you can mock multiple services at the same time:\n\n")
|
||||
file.write(".. sourcecode:: python\n\n")
|
||||
file.write(" @mock_s3\n")
|
||||
file.write(" @mock_sqs\n")
|
||||
file.write(" def test_both_s3_and_sqs():\n")
|
||||
file.write(" ...\n")
|
||||
file.write("\n\n")
|
||||
file.write(".. sourcecode:: python\n\n")
|
||||
file.write(" @mock_all\n")
|
||||
file.write(" def test_all_supported_services_at_the_same_time():\n")
|
||||
file.write(" ...\n")
|
||||
file.write("\n")
|
||||
|
||||
file.write("\n")
|
||||
|
20
tests/test_core/test_mock_all.py
Normal file
20
tests/test_core/test_mock_all.py
Normal file
@ -0,0 +1,20 @@
|
||||
import boto3
|
||||
import sure # noqa # pylint: disable=unused-import
|
||||
|
||||
from moto import mock_all
|
||||
|
||||
|
||||
@mock_all()
|
||||
def test_multiple_services():
|
||||
rgn = "us-east-1"
|
||||
sqs = boto3.client("sqs", region_name=rgn)
|
||||
r = sqs.list_queues() #
|
||||
r["ResponseMetadata"]["HTTPStatusCode"].should.equal(200)
|
||||
|
||||
lmbda = boto3.client("lambda", region_name=rgn)
|
||||
r = lmbda.list_event_source_mappings()
|
||||
r["ResponseMetadata"]["HTTPStatusCode"].should.equal(200)
|
||||
|
||||
ddb = boto3.client("dynamodb", region_name=rgn)
|
||||
r = ddb.list_tables()
|
||||
r["ResponseMetadata"]["HTTPStatusCode"].should.equal(200)
|
Loading…
Reference in New Issue
Block a user