diff --git a/moto/apigateway/__init__.py b/moto/apigateway/__init__.py index 47db4a703..f75a72add 100644 --- a/moto/apigateway/__init__.py +++ b/moto/apigateway/__init__.py @@ -1,12 +1,6 @@ from __future__ import unicode_literals from .models import apigateway_backends -from ..core.models import MockAWS +from ..core.models import MockAWS, base_decorator apigateway_backend = apigateway_backends['us-east-1'] - - -def mock_apigateway(func=None): - if func: - return MockAWS(apigateway_backends)(func) - else: - return MockAWS(apigateway_backends) +mock_apigateway = base_decorator(apigateway_backends) diff --git a/moto/autoscaling/__init__.py b/moto/autoscaling/__init__.py index cefcc3cf7..1d3cc9b3e 100644 --- a/moto/autoscaling/__init__.py +++ b/moto/autoscaling/__init__.py @@ -1,12 +1,6 @@ from __future__ import unicode_literals from .models import autoscaling_backends -from ..core.models import MockAWS +from ..core.models import MockAWS, base_decorator autoscaling_backend = autoscaling_backends['us-east-1'] - - -def mock_autoscaling(func=None): - if func: - return MockAWS(autoscaling_backends)(func) - else: - return MockAWS(autoscaling_backends) +mock_autoscaling = base_decorator(autoscaling_backends) diff --git a/moto/awslambda/__init__.py b/moto/awslambda/__init__.py index 0076f7f76..b27ff9a43 100644 --- a/moto/awslambda/__init__.py +++ b/moto/awslambda/__init__.py @@ -1,13 +1,7 @@ from __future__ import unicode_literals from .models import lambda_backends -from ..core.models import MockAWS +from ..core.models import MockAWS, base_decorator lambda_backend = lambda_backends['us-east-1'] - - -def mock_lambda(func=None): - if func: - return MockAWS(lambda_backends)(func) - else: - return MockAWS(lambda_backends) +mock_lambda = base_decorator(lambda_backends) diff --git a/moto/cloudformation/__init__.py b/moto/cloudformation/__init__.py index 98587fc41..0e4bd28dd 100644 --- a/moto/cloudformation/__init__.py +++ b/moto/cloudformation/__init__.py @@ -1,12 +1,6 @@ from __future__ import unicode_literals from .models import cloudformation_backends -from ..core.models import MockAWS +from ..core.models import MockAWS, base_decorator cloudformation_backend = cloudformation_backends['us-east-1'] - - -def mock_cloudformation(func=None): - if func: - return MockAWS(cloudformation_backends)(func) - else: - return MockAWS(cloudformation_backends) +mock_cloudformation = base_decorator(cloudformation_backends) diff --git a/moto/cloudwatch/__init__.py b/moto/cloudwatch/__init__.py index b354b3be7..ea4bf7185 100644 --- a/moto/cloudwatch/__init__.py +++ b/moto/cloudwatch/__init__.py @@ -1,11 +1,5 @@ from .models import cloudwatch_backends -from ..core.models import MockAWS - +from ..core.models import MockAWS, base_decorator cloudwatch_backend = cloudwatch_backends['us-east-1'] - -def mock_cloudwatch(func=None): - if func: - return MockAWS(cloudwatch_backends)(func) - else: - return MockAWS(cloudwatch_backends) +mock_cloudwatch = base_decorator(cloudwatch_backends) diff --git a/moto/core/models.py b/moto/core/models.py index 60e744ff5..b6f4f541f 100644 --- a/moto/core/models.py +++ b/moto/core/models.py @@ -186,3 +186,16 @@ class BaseBackend(object): return MockAWS({'global': self})(func) else: return MockAWS({'global': self}) + + +class base_decorator(object): + mock_backend = MockAWS + + def __init__(self, backends): + self.backends = backends + + def __call__(self, func=None): + if func: + return self.mock_backend(self.backends)(func) + else: + return self.mock_backend(self.backends) diff --git a/moto/datapipeline/__init__.py b/moto/datapipeline/__init__.py index dcfe2f427..dd013526e 100644 --- a/moto/datapipeline/__init__.py +++ b/moto/datapipeline/__init__.py @@ -1,12 +1,6 @@ from __future__ import unicode_literals from .models import datapipeline_backends -from ..core.models import MockAWS +from ..core.models import MockAWS, base_decorator datapipeline_backend = datapipeline_backends['us-east-1'] - - -def mock_datapipeline(func=None): - if func: - return MockAWS(datapipeline_backends)(func) - else: - return MockAWS(datapipeline_backends) +mock_datapipeline = base_decorator(datapipeline_backends) diff --git a/moto/ec2/__init__.py b/moto/ec2/__init__.py index 2b1cafd88..b269e933b 100644 --- a/moto/ec2/__init__.py +++ b/moto/ec2/__init__.py @@ -1,12 +1,6 @@ from __future__ import unicode_literals from .models import ec2_backends -from ..core.models import MockAWS +from ..core.models import MockAWS, base_decorator ec2_backend = ec2_backends['us-east-1'] - - -def mock_ec2(func=None): - if func: - return MockAWS(ec2_backends)(func) - else: - return MockAWS(ec2_backends) +mock_ec2 = base_decorator(ec2_backends) diff --git a/moto/ecs/__init__.py b/moto/ecs/__init__.py index 0844b256c..9c07a0d55 100644 --- a/moto/ecs/__init__.py +++ b/moto/ecs/__init__.py @@ -1,11 +1,6 @@ from __future__ import unicode_literals from .models import ecs_backends -from ..core.models import MockAWS +from ..core.models import MockAWS, base_decorator ecs_backend = ecs_backends['us-east-1'] - -def mock_ecs(func=None): - if func: - return MockAWS(ecs_backends)(func) - else: - return MockAWS(ecs_backends) +mock_ecs = base_decorator(ecs_backends) diff --git a/moto/elb/__init__.py b/moto/elb/__init__.py index fd53c8587..376dfe0e1 100644 --- a/moto/elb/__init__.py +++ b/moto/elb/__init__.py @@ -1,12 +1,6 @@ from __future__ import unicode_literals from .models import elb_backends -from ..core.models import MockAWS +from ..core.models import MockAWS, base_decorator elb_backend = elb_backends['us-east-1'] - - -def mock_elb(func=None): - if func: - return MockAWS(elb_backends)(func) - else: - return MockAWS(elb_backends) +mock_elb = base_decorator(elb_backends) diff --git a/moto/emr/__init__.py b/moto/emr/__init__.py index f0103319a..f79df39fa 100644 --- a/moto/emr/__init__.py +++ b/moto/emr/__init__.py @@ -1,12 +1,6 @@ from __future__ import unicode_literals from .models import emr_backends -from ..core.models import MockAWS +from ..core.models import MockAWS, base_decorator emr_backend = emr_backends['us-east-1'] - - -def mock_emr(func=None): - if func: - return MockAWS(emr_backends)(func) - else: - return MockAWS(emr_backends) +mock_emr = base_decorator(emr_backends) diff --git a/moto/glacier/__init__.py b/moto/glacier/__init__.py index bc6fd1ff4..3256462a3 100644 --- a/moto/glacier/__init__.py +++ b/moto/glacier/__init__.py @@ -1,12 +1,6 @@ from __future__ import unicode_literals from .models import glacier_backends -from ..core.models import MockAWS +from ..core.models import MockAWS, base_decorator glacier_backend = glacier_backends['us-east-1'] - - -def mock_glacier(func=None): - if func: - return MockAWS(glacier_backends)(func) - else: - return MockAWS(glacier_backends) +mock_glacier = base_decorator(glacier_backends) diff --git a/moto/kinesis/__init__.py b/moto/kinesis/__init__.py index 415b960e1..50bc07155 100644 --- a/moto/kinesis/__init__.py +++ b/moto/kinesis/__init__.py @@ -1,12 +1,6 @@ from __future__ import unicode_literals from .models import kinesis_backends -from ..core.models import MockAWS +from ..core.models import MockAWS, base_decorator kinesis_backend = kinesis_backends['us-east-1'] - - -def mock_kinesis(func=None): - if func: - return MockAWS(kinesis_backends)(func) - else: - return MockAWS(kinesis_backends) +mock_kinesis = base_decorator(kinesis_backends) diff --git a/moto/kms/__init__.py b/moto/kms/__init__.py index d406cc913..4ee6dd2f4 100644 --- a/moto/kms/__init__.py +++ b/moto/kms/__init__.py @@ -1,12 +1,6 @@ from __future__ import unicode_literals from .models import kms_backends -from ..core.models import MockAWS +from ..core.models import MockAWS, base_decorator kms_backend = kms_backends['us-east-1'] - - -def mock_kms(func=None): - if func: - return MockAWS(kms_backends)(func) - else: - return MockAWS(kms_backends) +mock_kms = base_decorator(kms_backends) diff --git a/moto/opsworks/__init__.py b/moto/opsworks/__init__.py index dfcd582e2..ef5190997 100644 --- a/moto/opsworks/__init__.py +++ b/moto/opsworks/__init__.py @@ -1,13 +1,6 @@ from __future__ import unicode_literals from .models import opsworks_backends -from ..core.models import MockAWS +from ..core.models import MockAWS, base_decorator opsworks_backend = opsworks_backends['us-east-1'] - - -def mock_opsworks(func=None): - if func: - return MockAWS(opsworks_backends)(func) - else: - return MockAWS(opsworks_backends) - +mock_opsworks = base_decorator(opsworks_backends) diff --git a/moto/rds/__init__.py b/moto/rds/__init__.py index 407f1680c..d3cafc066 100644 --- a/moto/rds/__init__.py +++ b/moto/rds/__init__.py @@ -1,12 +1,6 @@ from __future__ import unicode_literals from .models import rds_backends -from ..core.models import MockAWS +from ..core.models import MockAWS, base_decorator rds_backend = rds_backends['us-east-1'] - - -def mock_rds(func=None): - if func: - return MockAWS(rds_backends)(func) - else: - return MockAWS(rds_backends) +mock_rds = base_decorator(rds_backends) diff --git a/moto/rds2/__init__.py b/moto/rds2/__init__.py index 602c21ede..b200f9b11 100644 --- a/moto/rds2/__init__.py +++ b/moto/rds2/__init__.py @@ -1,12 +1,6 @@ from __future__ import unicode_literals from .models import rds2_backends -from ..core.models import MockAWS +from ..core.models import MockAWS, base_decorator rds2_backend = rds2_backends['us-west-1'] - - -def mock_rds2(func=None): - if func: - return MockAWS(rds2_backends)(func) - else: - return MockAWS(rds2_backends) +mock_rds2 = base_decorator(rds2_backends) diff --git a/moto/redshift/__init__.py b/moto/redshift/__init__.py index 7adf47865..821408493 100644 --- a/moto/redshift/__init__.py +++ b/moto/redshift/__init__.py @@ -1,12 +1,6 @@ from __future__ import unicode_literals from .models import redshift_backends -from ..core.models import MockAWS +from ..core.models import MockAWS, base_decorator redshift_backend = redshift_backends['us-east-1'] - - -def mock_redshift(func=None): - if func: - return MockAWS(redshift_backends)(func) - else: - return MockAWS(redshift_backends) +mock_redshift = base_decorator(redshift_backends) diff --git a/moto/sns/__init__.py b/moto/sns/__init__.py index 1aa1a0e3e..0ed85e813 100644 --- a/moto/sns/__init__.py +++ b/moto/sns/__init__.py @@ -1,12 +1,6 @@ from __future__ import unicode_literals from .models import sns_backends -from ..core.models import MockAWS +from ..core.models import MockAWS, base_decorator sns_backend = sns_backends['us-east-1'] - - -def mock_sns(func=None): - if func: - return MockAWS(sns_backends)(func) - else: - return MockAWS(sns_backends) +mock_sns = base_decorator(sns_backends) diff --git a/moto/sqs/__init__.py b/moto/sqs/__init__.py index 0a9de1a47..09b4ed9e9 100644 --- a/moto/sqs/__init__.py +++ b/moto/sqs/__init__.py @@ -1,12 +1,6 @@ from __future__ import unicode_literals from .models import sqs_backends -from ..core.models import MockAWS +from ..core.models import MockAWS, base_decorator sqs_backend = sqs_backends['us-east-1'] - - -def mock_sqs(func=None): - if func: - return MockAWS(sqs_backends)(func) - else: - return MockAWS(sqs_backends) +mock_sqs = base_decorator(sqs_backends) diff --git a/moto/swf/__init__.py b/moto/swf/__init__.py index 7e43ca392..180919320 100644 --- a/moto/swf/__init__.py +++ b/moto/swf/__init__.py @@ -1,12 +1,6 @@ from __future__ import unicode_literals from .models import swf_backends -from ..core.models import MockAWS +from ..core.models import MockAWS, base_decorator swf_backend = swf_backends['us-east-1'] - - -def mock_swf(func=None): - if func: - return MockAWS(swf_backends)(func) - else: - return MockAWS(swf_backends) +mock_swf = base_decorator(swf_backends)