Feature - @mock_all() (#3756)

This commit is contained in:
Bert Blommers 2021-11-09 21:29:28 -01:00 committed by GitHub
parent db0738025a
commit e54e5cdb95
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 69 additions and 0 deletions

View File

@ -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::

View File

@ -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)

View File

@ -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")

View 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)