Generalize decorator code.

This commit is contained in:
Steve Pulec 2017-02-12 00:22:29 -05:00
parent 9076e48fee
commit d3df810065
21 changed files with 53 additions and 160 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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