diff --git a/CHANGELOG.md b/CHANGELOG.md index 66610511f..790f6de95 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ Moto Changelog Latest ------ + BACKWARDS INCOMPATIBLE + * The normal @mock_ decorators will no longer work with boto. It is suggested that you upgrade to boto3 or use the standalone-server mode. If you would still like to use boto, you must use the @mock__deprecated decorators which will be removed in a future release. + * The @mock_s3bucket_path decorator is now deprecated. Use the @mock_s3 decorator instead. + 0.4.31 ------ diff --git a/README.md b/README.md index c05f1dff4..ae161dc5c 100644 --- a/README.md +++ b/README.md @@ -263,7 +263,3 @@ boto3.resource( ```console $ pip install moto ``` - -## Thanks - -A huge thanks to [Gabriel Falcão](https://github.com/gabrielfalcao) and his [HTTPretty](https://github.com/gabrielfalcao/HTTPretty) library. Moto would not exist without it. diff --git a/moto/__init__.py b/moto/__init__.py index afc98d14a..4accf1d0c 100644 --- a/moto/__init__.py +++ b/moto/__init__.py @@ -6,33 +6,32 @@ __title__ = 'moto' __version__ = '0.4.31' from .apigateway import mock_apigateway # flake8: noqa -from .autoscaling import mock_autoscaling # flake8: noqa +from .autoscaling import mock_autoscaling, mock_autoscaling_deprecated # flake8: noqa from .awslambda import mock_lambda # flake8: noqa -from .cloudformation import mock_cloudformation # flake8: noqa -from .cloudwatch import mock_cloudwatch # flake8: noqa -from .datapipeline import mock_datapipeline # flake8: noqa -from .dynamodb import mock_dynamodb # flake8: noqa -from .dynamodb2 import mock_dynamodb2 # flake8: noqa -from .ec2 import mock_ec2 # flake8: noqa +from .cloudformation import mock_cloudformation, mock_cloudformation_deprecated # flake8: noqa +from .cloudwatch import mock_cloudwatch, mock_cloudwatch_deprecated # flake8: noqa +from .datapipeline import mock_datapipeline, mock_datapipeline_deprecated # flake8: noqa +from .dynamodb import mock_dynamodb, mock_dynamodb_deprecated # flake8: noqa +from .dynamodb2 import mock_dynamodb2, mock_dynamodb2_deprecated # flake8: noqa +from .ec2 import mock_ec2, mock_ec2_deprecated # flake8: noqa from .ecs import mock_ecs # flake8: noqa -from .elb import mock_elb # flake8: noqa -from .emr import mock_emr # flake8: noqa -from .glacier import mock_glacier # flake8: noqa +from .elb import mock_elb, mock_elb_deprecated # flake8: noqa +from .emr import mock_emr, mock_emr_deprecated # flake8: noqa +from .glacier import mock_glacier, mock_glacier_deprecated # flake8: noqa from .opsworks import mock_opsworks # flake8: noqa -from .iam import mock_iam # flake8: noqa -from .kinesis import mock_kinesis # flake8: noqa -from .kms import mock_kms # flake8: noqa -from .rds import mock_rds # flake8: noqa -from .rds2 import mock_rds2 # flake8: noqa -from .redshift import mock_redshift # flake8: noqa -from .s3 import mock_s3 # flake8: noqa -from .s3bucket_path import mock_s3bucket_path # flake8: noqa -from .ses import mock_ses # flake8: noqa -from .sns import mock_sns # flake8: noqa -from .sqs import mock_sqs # flake8: noqa -from .sts import mock_sts # flake8: noqa -from .route53 import mock_route53 # flake8: noqa -from .swf import mock_swf # flake8: noqa +from .iam import mock_iam, mock_iam_deprecated # flake8: noqa +from .kinesis import mock_kinesis, mock_kinesis_deprecated # flake8: noqa +from .kms import mock_kms, mock_kms_deprecated # flake8: noqa +from .rds import mock_rds, mock_rds_deprecated # flake8: noqa +from .rds2 import mock_rds2, mock_rds2_deprecated # flake8: noqa +from .redshift import mock_redshift, mock_redshift_deprecated # flake8: noqa +from .s3 import mock_s3, mock_s3_deprecated # flake8: noqa +from .ses import mock_ses, mock_ses_deprecated # flake8: noqa +from .sns import mock_sns, mock_sns_deprecated # flake8: noqa +from .sqs import mock_sqs, mock_sqs_deprecated # flake8: noqa +from .sts import mock_sts, mock_sts_deprecated # flake8: noqa +from .route53 import mock_route53, mock_route53_deprecated # flake8: noqa +from .swf import mock_swf, mock_swf_deprecated # flake8: noqa try: diff --git a/moto/apigateway/__init__.py b/moto/apigateway/__init__.py index f75a72add..c6ea9a3bc 100644 --- a/moto/apigateway/__init__.py +++ b/moto/apigateway/__init__.py @@ -1,6 +1,7 @@ from __future__ import unicode_literals from .models import apigateway_backends -from ..core.models import MockAWS, base_decorator +from ..core.models import MockAWS, base_decorator, HttprettyMockAWS, deprecated_base_decorator apigateway_backend = apigateway_backends['us-east-1'] mock_apigateway = base_decorator(apigateway_backends) +mock_apigateway_deprecated = deprecated_base_decorator(apigateway_backends) diff --git a/moto/apigateway/models.py b/moto/apigateway/models.py index 11d650e05..be0bfa434 100644 --- a/moto/apigateway/models.py +++ b/moto/apigateway/models.py @@ -1,9 +1,10 @@ +from __future__ import absolute_import from __future__ import unicode_literals import datetime -import httpretty import requests +from moto.packages.responses import responses from moto.core import BaseBackend from moto.core.utils import iso_8601_datetime_with_milliseconds from .utils import create_id @@ -315,8 +316,12 @@ class RestAPI(object): return resource # TODO deal with no matching resource - def resource_callback(self, request, full_url, headers): - path_after_stage_name = '/'.join(request.path.split("/")[2:]) + def resource_callback(self, request, full_url=None, headers=None): + if not headers: + headers = request.headers + + path = request.path if hasattr(request, 'path') else request.path_url + path_after_stage_name = '/'.join(path.split("/")[2:]) if not path_after_stage_name: path_after_stage_name = '/' @@ -325,11 +330,8 @@ class RestAPI(object): return status_code, headers, response def update_integration_mocks(self, stage_name): - httpretty.enable() - stage_url = STAGE_URL.format(api_id=self.id, region_name=self.region_name, stage_name=stage_name) - for method in httpretty.httpretty.METHODS: - httpretty.register_uri(method, stage_url, body=self.resource_callback) + responses.add_callback(responses.GET, stage_url, callback=self.resource_callback) def create_stage(self, name, deployment_id,variables=None,description='',cacheClusterEnabled=None,cacheClusterSize=None): if variables is None: diff --git a/moto/autoscaling/__init__.py b/moto/autoscaling/__init__.py index 1d3cc9b3e..9b5842788 100644 --- a/moto/autoscaling/__init__.py +++ b/moto/autoscaling/__init__.py @@ -1,6 +1,7 @@ from __future__ import unicode_literals from .models import autoscaling_backends -from ..core.models import MockAWS, base_decorator +from ..core.models import MockAWS, base_decorator, HttprettyMockAWS, deprecated_base_decorator autoscaling_backend = autoscaling_backends['us-east-1'] mock_autoscaling = base_decorator(autoscaling_backends) +mock_autoscaling_deprecated = deprecated_base_decorator(autoscaling_backends) diff --git a/moto/awslambda/__init__.py b/moto/awslambda/__init__.py index b27ff9a43..46bc90fbd 100644 --- a/moto/awslambda/__init__.py +++ b/moto/awslambda/__init__.py @@ -1,7 +1,7 @@ from __future__ import unicode_literals from .models import lambda_backends -from ..core.models import MockAWS, base_decorator - +from ..core.models import MockAWS, base_decorator, HttprettyMockAWS, deprecated_base_decorator lambda_backend = lambda_backends['us-east-1'] mock_lambda = base_decorator(lambda_backends) +mock_lambda_deprecated = deprecated_base_decorator(lambda_backends) diff --git a/moto/awslambda/responses.py b/moto/awslambda/responses.py index 468a95766..708a8796e 100644 --- a/moto/awslambda/responses.py +++ b/moto/awslambda/responses.py @@ -9,7 +9,7 @@ from .models import lambda_backends class LambdaResponse(BaseResponse): - + @classmethod def root(cls, request, full_url, headers): if request.method == 'GET': @@ -38,11 +38,13 @@ class LambdaResponse(BaseResponse): def _invoke(self, request, full_url, headers): lambda_backend = self.get_lambda_backend(full_url) - function_name = request.path.split('/')[-2] + path = request.path if hasattr(request, 'path') else request.path_url + function_name = path.split('/')[-2] if lambda_backend.has_function(function_name): fn = lambda_backend.get_function(function_name) payload = fn.invoke(request, headers) + headers['Content-Length'] = str(len(payload)) return 202, headers, payload else: return 404, headers, "{}" @@ -68,7 +70,8 @@ class LambdaResponse(BaseResponse): def _delete_function(self, request, full_url, headers): lambda_backend = self.get_lambda_backend(full_url) - function_name = request.path.split('/')[-1] + path = request.path if hasattr(request, 'path') else request.path_url + function_name = path.split('/')[-1] if lambda_backend.has_function(function_name): lambda_backend.delete_function(function_name) @@ -79,7 +82,8 @@ class LambdaResponse(BaseResponse): def _get_function(self, request, full_url, headers): lambda_backend = self.get_lambda_backend(full_url) - function_name = request.path.split('/')[-1] + path = request.path if hasattr(request, 'path') else request.path_url + function_name = path.split('/')[-1] if lambda_backend.has_function(function_name): fn = lambda_backend.get_function(function_name) @@ -87,7 +91,7 @@ class LambdaResponse(BaseResponse): return 200, headers, json.dumps(code) else: return 404, headers, "{}" - + def get_lambda_backend(self, full_url): from moto.awslambda.models import lambda_backends region = self._get_aws_region(full_url) diff --git a/moto/cloudformation/__init__.py b/moto/cloudformation/__init__.py index 0e4bd28dd..47e840ec6 100644 --- a/moto/cloudformation/__init__.py +++ b/moto/cloudformation/__init__.py @@ -1,6 +1,7 @@ from __future__ import unicode_literals from .models import cloudformation_backends -from ..core.models import MockAWS, base_decorator +from ..core.models import MockAWS, base_decorator, HttprettyMockAWS, deprecated_base_decorator cloudformation_backend = cloudformation_backends['us-east-1'] mock_cloudformation = base_decorator(cloudformation_backends) +mock_cloudformation_deprecated = deprecated_base_decorator(cloudformation_backends) diff --git a/moto/cloudwatch/__init__.py b/moto/cloudwatch/__init__.py index ea4bf7185..17d1c0c50 100644 --- a/moto/cloudwatch/__init__.py +++ b/moto/cloudwatch/__init__.py @@ -1,5 +1,6 @@ from .models import cloudwatch_backends -from ..core.models import MockAWS, base_decorator +from ..core.models import MockAWS, base_decorator, HttprettyMockAWS, deprecated_base_decorator cloudwatch_backend = cloudwatch_backends['us-east-1'] mock_cloudwatch = base_decorator(cloudwatch_backends) +mock_cloudwatch_deprecated = deprecated_base_decorator(cloudwatch_backends) diff --git a/moto/core/models.py b/moto/core/models.py index b6f4f541f..fa6b74834 100644 --- a/moto/core/models.py +++ b/moto/core/models.py @@ -1,22 +1,23 @@ from __future__ import unicode_literals +from __future__ import absolute_import import functools import inspect import re -from httpretty import HTTPretty +from moto.packages.responses import responses +from moto.packages.httpretty import HTTPretty from .responses import metadata_response -from .utils import convert_regex_to_flask_path +from .utils import convert_regex_to_flask_path, convert_flask_to_responses_response - -class MockAWS(object): +class BaseMockAWS(object): nested_count = 0 def __init__(self, backends): self.backends = backends if self.__class__.nested_count == 0: - HTTPretty.reset() + self.reset() def __call__(self, func, reset=True): if inspect.isclass(func): @@ -35,24 +36,7 @@ class MockAWS(object): for backend in self.backends.values(): backend.reset() - if not HTTPretty.is_enabled(): - HTTPretty.enable() - - for method in HTTPretty.METHODS: - backend = list(self.backends.values())[0] - for key, value in backend.urls.items(): - HTTPretty.register_uri( - method=method, - uri=re.compile(key), - body=value, - ) - - # Mock out localhost instance metadata - HTTPretty.register_uri( - method=method, - uri=re.compile('http://169.254.169.254/latest/meta-data/.*'), - body=metadata_response - ) + self.enable_patching() def stop(self): self.__class__.nested_count -= 1 @@ -60,9 +44,7 @@ class MockAWS(object): if self.__class__.nested_count < 0: raise RuntimeError('Called stop() before start().') - if self.__class__.nested_count == 0: - HTTPretty.disable() - HTTPretty.reset() + self.disable_patching() def decorate_callable(self, func, reset): def wrapper(*args, **kwargs): @@ -97,6 +79,73 @@ class MockAWS(object): return klass +class HttprettyMockAWS(BaseMockAWS): + def reset(self): + HTTPretty.reset() + + def enable_patching(self): + if not HTTPretty.is_enabled(): + HTTPretty.enable() + + for method in HTTPretty.METHODS: + backend = list(self.backends.values())[0] + for key, value in backend.urls.items(): + HTTPretty.register_uri( + method=method, + uri=re.compile(key), + body=value, + ) + + # Mock out localhost instance metadata + HTTPretty.register_uri( + method=method, + uri=re.compile('http://169.254.169.254/latest/meta-data/.*'), + body=metadata_response + ) + + def disable_patching(self): + if self.__class__.nested_count == 0: + HTTPretty.disable() + HTTPretty.reset() + + +RESPONSES_METHODS = [responses.GET, responses.DELETE, responses.HEAD, + responses.OPTIONS, responses.PATCH, responses.POST, responses.PUT] + + +class ResponsesMockAWS(BaseMockAWS): + def reset(self): + responses.reset() + + def enable_patching(self): + responses.start() + for method in RESPONSES_METHODS: + backend = list(self.backends.values())[0] + for key, value in backend.urls.items(): + responses.add_callback( + method=method, + url=re.compile(key), + callback=convert_flask_to_responses_response(value), + ) + + # Mock out localhost instance metadata + responses.add_callback( + method=method, + url=re.compile('http://169.254.169.254/latest/meta-data/.*'), + callback=convert_flask_to_responses_response(metadata_response), + ) + for pattern in responses.mock._urls: + pattern['stream'] = True + + def disable_patching(self): + if self.__class__.nested_count == 0: + try: + responses.stop() + except AttributeError: + pass + responses.reset() +MockAWS = ResponsesMockAWS + class Model(type): def __new__(self, clsname, bases, namespace): cls = super(Model, self).__new__(self, clsname, bases, namespace) @@ -187,6 +236,12 @@ class BaseBackend(object): else: return MockAWS({'global': self}) + def deprecated_decorator(self, func=None): + if func: + return HttprettyMockAWS({'global': self})(func) + else: + return HttprettyMockAWS({'global': self}) + class base_decorator(object): mock_backend = MockAWS @@ -199,3 +254,7 @@ class base_decorator(object): return self.mock_backend(self.backends)(func) else: return self.mock_backend(self.backends) + + +class deprecated_base_decorator(base_decorator): + mock_backend = HttprettyMockAWS diff --git a/moto/core/responses.py b/moto/core/responses.py index af4217245..337227d3c 100644 --- a/moto/core/responses.py +++ b/moto/core/responses.py @@ -138,7 +138,7 @@ class BaseResponse(_TemplateEnvironmentMixin): flat = flatten_json_request_body('', decoded, input_spec) for key, value in flat.items(): querystring[key] = [value] - else: + elif self.body: querystring.update(parse_qs(self.body, keep_blank_values=True)) if not querystring: querystring.update(headers) @@ -152,6 +152,8 @@ class BaseResponse(_TemplateEnvironmentMixin): self.region = self.get_region_from_url(full_url) self.headers = request.headers + if 'host' not in self.headers: + self.headers['host'] = urlparse(full_url).netloc self.response_headers = headers def get_region_from_url(self, full_url): @@ -189,6 +191,9 @@ class BaseResponse(_TemplateEnvironmentMixin): body, new_headers = response status = new_headers.get('status', 200) headers.update(new_headers) + # Cast status to string + if "status" in headers: + headers['status'] = str(headers['status']) return status, headers, body raise NotImplementedError("The {0} action has not been implemented".format(action)) @@ -327,6 +332,7 @@ def metadata_response(request, full_url, headers): http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AESDG-chapter-instancedata.html """ + parsed_url = urlparse(full_url) tomorrow = datetime.datetime.utcnow() + datetime.timedelta(days=1) credentials = dict( diff --git a/moto/core/utils.py b/moto/core/utils.py index 0b30556ac..0f4b20b6d 100644 --- a/moto/core/utils.py +++ b/moto/core/utils.py @@ -103,6 +103,28 @@ class convert_flask_to_httpretty_response(object): return response, status, headers +class convert_flask_to_responses_response(object): + + def __init__(self, callback): + self.callback = callback + + @property + def __name__(self): + # For instance methods, use class and method names. Otherwise + # use module and method name + if inspect.ismethod(self.callback): + outer = self.callback.__self__.__class__.__name__ + else: + outer = self.callback.__module__ + return "{0}.{1}".format(outer, self.callback.__name__) + + def __call__(self, request, *args, **kwargs): + result = self.callback(request, request.url, request.headers) + # result is a status, headers, response tuple + status, headers, response = result + return status, headers, response + + def iso_8601_datetime_with_milliseconds(datetime): return datetime.strftime("%Y-%m-%dT%H:%M:%S.%f")[:-3] + 'Z' diff --git a/moto/datapipeline/__init__.py b/moto/datapipeline/__init__.py index dd013526e..cebcf22bf 100644 --- a/moto/datapipeline/__init__.py +++ b/moto/datapipeline/__init__.py @@ -1,6 +1,7 @@ from __future__ import unicode_literals from .models import datapipeline_backends -from ..core.models import MockAWS, base_decorator +from ..core.models import MockAWS, base_decorator, HttprettyMockAWS, deprecated_base_decorator datapipeline_backend = datapipeline_backends['us-east-1'] mock_datapipeline = base_decorator(datapipeline_backends) +mock_datapipeline_deprecated = deprecated_base_decorator(datapipeline_backends) diff --git a/moto/dynamodb/__init__.py b/moto/dynamodb/__init__.py index 6f2509f79..008050317 100644 --- a/moto/dynamodb/__init__.py +++ b/moto/dynamodb/__init__.py @@ -1,3 +1,4 @@ from __future__ import unicode_literals from .models import dynamodb_backend mock_dynamodb = dynamodb_backend.decorator +mock_dynamodb_deprecated = dynamodb_backend.deprecated_decorator diff --git a/moto/dynamodb2/__init__.py b/moto/dynamodb2/__init__.py index 8579c48df..f0892d13f 100644 --- a/moto/dynamodb2/__init__.py +++ b/moto/dynamodb2/__init__.py @@ -1,3 +1,4 @@ from __future__ import unicode_literals from .models import dynamodb_backend2 mock_dynamodb2 = dynamodb_backend2.decorator +mock_dynamodb2_deprecated = dynamodb_backend2.deprecated_decorator \ No newline at end of file diff --git a/moto/ec2/__init__.py b/moto/ec2/__init__.py index b269e933b..608173577 100644 --- a/moto/ec2/__init__.py +++ b/moto/ec2/__init__.py @@ -1,6 +1,7 @@ from __future__ import unicode_literals from .models import ec2_backends -from ..core.models import MockAWS, base_decorator +from ..core.models import MockAWS, base_decorator, HttprettyMockAWS, deprecated_base_decorator ec2_backend = ec2_backends['us-east-1'] mock_ec2 = base_decorator(ec2_backends) +mock_ec2_deprecated = deprecated_base_decorator(ec2_backends) diff --git a/moto/ecs/__init__.py b/moto/ecs/__init__.py index 9c07a0d55..6864355ad 100644 --- a/moto/ecs/__init__.py +++ b/moto/ecs/__init__.py @@ -1,6 +1,7 @@ from __future__ import unicode_literals from .models import ecs_backends -from ..core.models import MockAWS, base_decorator +from ..core.models import MockAWS, base_decorator, HttprettyMockAWS, deprecated_base_decorator ecs_backend = ecs_backends['us-east-1'] mock_ecs = base_decorator(ecs_backends) +mock_ecs_deprecated = deprecated_base_decorator(ecs_backends) diff --git a/moto/elb/__init__.py b/moto/elb/__init__.py index 376dfe0e1..a8e8dab8d 100644 --- a/moto/elb/__init__.py +++ b/moto/elb/__init__.py @@ -1,6 +1,7 @@ from __future__ import unicode_literals from .models import elb_backends -from ..core.models import MockAWS, base_decorator +from ..core.models import MockAWS, base_decorator, HttprettyMockAWS, deprecated_base_decorator elb_backend = elb_backends['us-east-1'] mock_elb = base_decorator(elb_backends) +mock_elb_deprecated = deprecated_base_decorator(elb_backends) diff --git a/moto/emr/__init__.py b/moto/emr/__init__.py index f79df39fa..fc6b4d4ab 100644 --- a/moto/emr/__init__.py +++ b/moto/emr/__init__.py @@ -1,6 +1,7 @@ from __future__ import unicode_literals from .models import emr_backends -from ..core.models import MockAWS, base_decorator +from ..core.models import MockAWS, base_decorator, HttprettyMockAWS, deprecated_base_decorator emr_backend = emr_backends['us-east-1'] mock_emr = base_decorator(emr_backends) +mock_emr_deprecated = deprecated_base_decorator(emr_backends) diff --git a/moto/glacier/__init__.py b/moto/glacier/__init__.py index 3256462a3..49b3375e1 100644 --- a/moto/glacier/__init__.py +++ b/moto/glacier/__init__.py @@ -1,6 +1,7 @@ from __future__ import unicode_literals from .models import glacier_backends -from ..core.models import MockAWS, base_decorator +from ..core.models import MockAWS, base_decorator, HttprettyMockAWS, deprecated_base_decorator glacier_backend = glacier_backends['us-east-1'] mock_glacier = base_decorator(glacier_backends) +mock_glacier_deprecated = deprecated_base_decorator(glacier_backends) diff --git a/moto/iam/__init__.py b/moto/iam/__init__.py index 483969e19..02519cbc9 100644 --- a/moto/iam/__init__.py +++ b/moto/iam/__init__.py @@ -1,3 +1,4 @@ from __future__ import unicode_literals from .models import iam_backend mock_iam = iam_backend.decorator +mock_iam_deprecated = iam_backend.deprecated_decorator \ No newline at end of file diff --git a/moto/kinesis/__init__.py b/moto/kinesis/__init__.py index 50bc07155..c3f06d5b1 100644 --- a/moto/kinesis/__init__.py +++ b/moto/kinesis/__init__.py @@ -1,6 +1,7 @@ from __future__ import unicode_literals from .models import kinesis_backends -from ..core.models import MockAWS, base_decorator +from ..core.models import MockAWS, base_decorator, HttprettyMockAWS, deprecated_base_decorator kinesis_backend = kinesis_backends['us-east-1'] mock_kinesis = base_decorator(kinesis_backends) +mock_kinesis_deprecated = deprecated_base_decorator(kinesis_backends) diff --git a/moto/kinesis/responses.py b/moto/kinesis/responses.py index 264f53a2c..d0a90a61e 100644 --- a/moto/kinesis/responses.py +++ b/moto/kinesis/responses.py @@ -19,7 +19,10 @@ class KinesisResponse(BaseResponse): @property def is_firehose(self): - host = self.headers.get('host') or self.headers['Host'] + try: + host = self.headers.get('host') or self.headers['Host'] + except KeyError: + import pdb;pdb.set_trace() return host.startswith('firehose') def create_stream(self): diff --git a/moto/kms/__init__.py b/moto/kms/__init__.py index 4ee6dd2f4..b6bffa804 100644 --- a/moto/kms/__init__.py +++ b/moto/kms/__init__.py @@ -1,6 +1,7 @@ from __future__ import unicode_literals from .models import kms_backends -from ..core.models import MockAWS, base_decorator +from ..core.models import MockAWS, base_decorator, HttprettyMockAWS, deprecated_base_decorator kms_backend = kms_backends['us-east-1'] mock_kms = base_decorator(kms_backends) +mock_kms_deprecated = deprecated_base_decorator(kms_backends) diff --git a/moto/opsworks/__init__.py b/moto/opsworks/__init__.py index ef5190997..75f49eba5 100644 --- a/moto/opsworks/__init__.py +++ b/moto/opsworks/__init__.py @@ -1,6 +1,6 @@ from __future__ import unicode_literals from .models import opsworks_backends -from ..core.models import MockAWS, base_decorator +from ..core.models import MockAWS, base_decorator, HttprettyMockAWS, deprecated_base_decorator opsworks_backend = opsworks_backends['us-east-1'] mock_opsworks = base_decorator(opsworks_backends) diff --git a/moto/opsworks/urls.py b/moto/opsworks/urls.py index 6913de6bb..3d72bb0dd 100644 --- a/moto/opsworks/urls.py +++ b/moto/opsworks/urls.py @@ -4,7 +4,7 @@ from .responses import OpsWorksResponse # AWS OpsWorks has a single endpoint: opsworks.us-east-1.amazonaws.com # and only supports HTTPS requests. url_bases = [ - "opsworks.us-east-1.amazonaws.com" + "https?://opsworks.us-east-1.amazonaws.com" ] url_paths = { diff --git a/moto/packages/__init__.py b/moto/packages/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/moto/packages/httpretty/__init__.py b/moto/packages/httpretty/__init__.py new file mode 100644 index 000000000..a752b452a --- /dev/null +++ b/moto/packages/httpretty/__init__.py @@ -0,0 +1,60 @@ +# #!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Copyright (C) <2011-2013> Gabriel Falcão +# +# Permission is hereby granted, free of charge, to any person +# obtaining a copy of this software and associated documentation +# files (the "Software"), to deal in the Software without +# restriction, including without limitation the rights to use, +# copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following +# conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +# OTHER DEALINGS IN THE SOFTWARE. +from __future__ import unicode_literals + +__version__ = version = '0.8.10' + +from .core import httpretty, httprettified, EmptyRequestHeaders +from .errors import HTTPrettyError, UnmockedError +from .core import URIInfo + +HTTPretty = httpretty +activate = httprettified + +enable = httpretty.enable +register_uri = httpretty.register_uri +disable = httpretty.disable +is_enabled = httpretty.is_enabled +reset = httpretty.reset +Response = httpretty.Response + +GET = httpretty.GET +PUT = httpretty.PUT +POST = httpretty.POST +DELETE = httpretty.DELETE +HEAD = httpretty.HEAD +PATCH = httpretty.PATCH +OPTIONS = httpretty.OPTIONS +CONNECT = httpretty.CONNECT + + +def last_request(): + """returns the last request""" + return httpretty.last_request + +def has_request(): + """returns a boolean indicating whether any request has been made""" + return not isinstance(httpretty.last_request.headers, EmptyRequestHeaders) diff --git a/moto/packages/httpretty/compat.py b/moto/packages/httpretty/compat.py new file mode 100644 index 000000000..6805cf638 --- /dev/null +++ b/moto/packages/httpretty/compat.py @@ -0,0 +1,100 @@ +# #!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# +# Copyright (C) <2011-2013> Gabriel Falcão +# +# Permission is hereby granted, free of charge, to any person +# obtaining a copy of this software and associated documentation +# files (the "Software"), to deal in the Software without +# restriction, including without limitation the rights to use, +# copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following +# conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +# OTHER DEALINGS IN THE SOFTWARE. +from __future__ import unicode_literals + +import sys +import types + +PY3 = sys.version_info[0] == 3 +if PY3: # pragma: no cover + text_type = str + byte_type = bytes + import io + StringIO = io.BytesIO + basestring = (str, bytes) + + class BaseClass(object): + def __repr__(self): + return self.__str__() +else: # pragma: no cover + text_type = unicode + byte_type = str + import StringIO + StringIO = StringIO.StringIO + basestring = basestring + + +class BaseClass(object): + def __repr__(self): + ret = self.__str__() + if PY3: # pragma: no cover + return ret + else: + return ret.encode('utf-8') + + +try: # pragma: no cover + from urllib.parse import urlsplit, urlunsplit, parse_qs, quote, quote_plus, unquote + unquote_utf8 = unquote +except ImportError: # pragma: no cover + from urlparse import urlsplit, urlunsplit, parse_qs, unquote + from urllib import quote, quote_plus + def unquote_utf8(qs): + if isinstance(qs, text_type): + qs = qs.encode('utf-8') + s = unquote(qs) + if isinstance(s, byte_type): + return s.decode("utf-8") + else: + return s + + +try: # pragma: no cover + from http.server import BaseHTTPRequestHandler +except ImportError: # pragma: no cover + from BaseHTTPServer import BaseHTTPRequestHandler + + +ClassTypes = (type,) +if not PY3: # pragma: no cover + ClassTypes = (type, types.ClassType) + + +__all__ = [ + 'PY3', + 'StringIO', + 'text_type', + 'byte_type', + 'BaseClass', + 'BaseHTTPRequestHandler', + 'quote', + 'quote_plus', + 'urlunsplit', + 'urlsplit', + 'parse_qs', + 'ClassTypes', +] diff --git a/moto/packages/httpretty/core.py b/moto/packages/httpretty/core.py new file mode 100644 index 000000000..4764cbba9 --- /dev/null +++ b/moto/packages/httpretty/core.py @@ -0,0 +1,1071 @@ +# #!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Copyright (C) <2011-2013> Gabriel Falcão +# +# Permission is hereby granted, free of charge, to any person +# obtaining a copy of this software and associated documentation +# files (the "Software"), to deal in the Software without +# restriction, including without limitation the rights to use, +# copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following +# conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +# OTHER DEALINGS IN THE SOFTWARE. +from __future__ import unicode_literals + +import re +import codecs +import inspect +import socket +import functools +import itertools +import warnings +import logging +import traceback +import json +import contextlib + + +from .compat import ( + PY3, + StringIO, + text_type, + BaseClass, + BaseHTTPRequestHandler, + quote, + quote_plus, + urlunsplit, + urlsplit, + parse_qs, + unquote, + unquote_utf8, + ClassTypes, + basestring +) +from .http import ( + STATUSES, + HttpBaseClass, + parse_requestline, + last_requestline, +) + +from .utils import ( + utf8, + decode_utf8, +) + +from .errors import HTTPrettyError, UnmockedError + +from datetime import datetime +from datetime import timedelta +from errno import EAGAIN + +old_socket = socket.socket +old_create_connection = socket.create_connection +old_gethostbyname = socket.gethostbyname +old_gethostname = socket.gethostname +old_getaddrinfo = socket.getaddrinfo +old_socksocket = None +old_ssl_wrap_socket = None +old_sslwrap_simple = None +old_sslsocket = None + +if PY3: # pragma: no cover + basestring = (bytes, str) +try: # pragma: no cover + import socks + old_socksocket = socks.socksocket +except ImportError: + socks = None + +try: # pragma: no cover + import ssl + old_ssl_wrap_socket = ssl.wrap_socket + if not PY3: + old_sslwrap_simple = ssl.sslwrap_simple + old_sslsocket = ssl.SSLSocket +except ImportError: # pragma: no cover + ssl = None + + +DEFAULT_HTTP_PORTS = frozenset([80]) +POTENTIAL_HTTP_PORTS = set(DEFAULT_HTTP_PORTS) +DEFAULT_HTTPS_PORTS = frozenset([443]) +POTENTIAL_HTTPS_PORTS = set(DEFAULT_HTTPS_PORTS) + + +class HTTPrettyRequest(BaseHTTPRequestHandler, BaseClass): + """Represents a HTTP request. It takes a valid multi-line, `\r\n` + separated string with HTTP headers and parse them out using the + internal `parse_request` method. + + It also replaces the `rfile` and `wfile` attributes with StringIO + instances so that we garantee that it won't make any I/O, neighter + for writing nor reading. + + It has some convenience attributes: + + `headers` -> a mimetype object that can be cast into a dictionary, + contains all the request headers + + `method` -> the HTTP method used in this request + + `querystring` -> a dictionary containing lists with the + attributes. Please notice that if you need a single value from a + query string you will need to get it manually like: + + ```python + >>> request.querystring + {'name': ['Gabriel Falcao']} + >>> print request.querystring['name'][0] + ``` + + `parsed_body` -> a dictionary containing parsed request body or + None if HTTPrettyRequest doesn't know how to parse it. It + currently supports parsing body data that was sent under the + `content-type` headers values: 'application/json' or + 'application/x-www-form-urlencoded' + """ + def __init__(self, headers, body=''): + # first of all, lets make sure that if headers or body are + # unicode strings, it must be converted into a utf-8 encoded + # byte string + self.raw_headers = utf8(headers.strip()) + self.body = utf8(body) + + # Now let's concatenate the headers with the body, and create + # `rfile` based on it + self.rfile = StringIO(b'\r\n\r\n'.join([self.raw_headers, self.body])) + self.wfile = StringIO() # Creating `wfile` as an empty + # StringIO, just to avoid any real + # I/O calls + + # parsing the request line preemptively + self.raw_requestline = self.rfile.readline() + + # initiating the error attributes with None + self.error_code = None + self.error_message = None + + # Parse the request based on the attributes above + if not self.parse_request(): + return + + # making the HTTP method string available as the command + self.method = self.command + + # Now 2 convenient attributes for the HTTPretty API: + + # `querystring` holds a dictionary with the parsed query string + try: + self.path = self.path.encode('iso-8859-1') + except UnicodeDecodeError: + pass + + self.path = decode_utf8(self.path) + + qstring = self.path.split("?", 1)[-1] + self.querystring = self.parse_querystring(qstring) + + # And the body will be attempted to be parsed as + # `application/json` or `application/x-www-form-urlencoded` + self.parsed_body = self.parse_request_body(self.body) + + def __str__(self): + return ''.format( + self.headers.get('content-type', ''), + len(self.headers), + len(self.body), + ) + + def parse_querystring(self, qs): + expanded = unquote_utf8(qs) + parsed = parse_qs(expanded) + result = {} + for k in parsed: + result[k] = list(map(decode_utf8, parsed[k])) + + return result + + def parse_request_body(self, body): + """ Attempt to parse the post based on the content-type passed. Return the regular body if not """ + + PARSING_FUNCTIONS = { + 'application/json': json.loads, + 'text/json': json.loads, + 'application/x-www-form-urlencoded': self.parse_querystring, + } + FALLBACK_FUNCTION = lambda x: x + + content_type = self.headers.get('content-type', '') + + do_parse = PARSING_FUNCTIONS.get(content_type, FALLBACK_FUNCTION) + try: + body = decode_utf8(body) + return do_parse(body) + except: + return body + + +class EmptyRequestHeaders(dict): + pass + + +class HTTPrettyRequestEmpty(object): + body = '' + headers = EmptyRequestHeaders() + + +class FakeSockFile(StringIO): + def close(self): + self.socket.close() + StringIO.close(self) + + +class FakeSSLSocket(object): + def __init__(self, sock, *args, **kw): + self._httpretty_sock = sock + + def __getattr__(self, attr): + return getattr(self._httpretty_sock, attr) + + +class fakesock(object): + class socket(object): + _entry = None + debuglevel = 0 + _sent_data = [] + + def __init__(self, family=socket.AF_INET, type=socket.SOCK_STREAM, + protocol=0): + self.truesock = (old_socket(family, type, protocol) + if httpretty.allow_net_connect + else None) + self._closed = True + self.fd = FakeSockFile() + self.fd.socket = self + self.timeout = socket._GLOBAL_DEFAULT_TIMEOUT + self._sock = self + self.is_http = False + self._bufsize = 1024 + + def getpeercert(self, *a, **kw): + now = datetime.now() + shift = now + timedelta(days=30 * 12) + return { + 'notAfter': shift.strftime('%b %d %H:%M:%S GMT'), + 'subjectAltName': ( + ('DNS', '*%s' % self._host), + ('DNS', self._host), + ('DNS', '*'), + ), + 'subject': ( + ( + ('organizationName', '*.%s' % self._host), + ), + ( + ('organizationalUnitName', + 'Domain Control Validated'), + ), + ( + ('commonName', '*.%s' % self._host), + ), + ), + } + + def ssl(self, sock, *args, **kw): + return sock + + def setsockopt(self, level, optname, value): + if self.truesock: + self.truesock.setsockopt(level, optname, value) + + def connect(self, address): + self._closed = False + + try: + self._address = (self._host, self._port) = address + except ValueError: + # We get here when the address is just a string pointing to a + # unix socket path/file + # + # See issue #206 + self.is_http = False + else: + self.is_http = self._port in POTENTIAL_HTTP_PORTS | POTENTIAL_HTTPS_PORTS + + if not self.is_http: + if self.truesock: + self.truesock.connect(self._address) + else: + raise UnmockedError() + + def close(self): + if not (self.is_http and self._closed): + if self.truesock: + self.truesock.close() + self._closed = True + + def makefile(self, mode='r', bufsize=-1): + """Returns this fake socket's own StringIO buffer. + + If there is an entry associated with the socket, the file + descriptor gets filled in with the entry data before being + returned. + """ + self._mode = mode + self._bufsize = bufsize + + if self._entry: + self._entry.fill_filekind(self.fd) + + return self.fd + + def real_sendall(self, data, *args, **kw): + """Sends data to the remote server. This method is called + when HTTPretty identifies that someone is trying to send + non-http data. + + The received bytes are written in this socket's StringIO + buffer so that HTTPretty can return it accordingly when + necessary. + """ + + if not self.truesock: + raise UnmockedError() + + if not self.is_http: + return self.truesock.sendall(data, *args, **kw) + + self.truesock.connect(self._address) + + self.truesock.setblocking(1) + self.truesock.sendall(data, *args, **kw) + + should_continue = True + while should_continue: + try: + received = self.truesock.recv(self._bufsize) + self.fd.write(received) + should_continue = len(received) == self._bufsize + + except socket.error as e: + if e.errno == EAGAIN: + continue + break + + self.fd.seek(0) + + def sendall(self, data, *args, **kw): + self._sent_data.append(data) + self.fd = FakeSockFile() + self.fd.socket = self + try: + requestline, _ = data.split(b'\r\n', 1) + method, path, version = parse_requestline(decode_utf8(requestline)) + is_parsing_headers = True + except ValueError: + is_parsing_headers = False + + if not self._entry: + # If the previous request wasn't mocked, don't mock the subsequent sending of data + return self.real_sendall(data, *args, **kw) + + self.fd.seek(0) + + if not is_parsing_headers: + if len(self._sent_data) > 1: + headers = utf8(last_requestline(self._sent_data)) + meta = self._entry.request.headers + body = utf8(self._sent_data[-1]) + if meta.get('transfer-encoding', '') == 'chunked': + if not body.isdigit() and body != b'\r\n' and body != b'0\r\n\r\n': + self._entry.request.body += body + else: + self._entry.request.body += body + + httpretty.historify_request(headers, body, False) + return + + # path might come with + s = urlsplit(path) + POTENTIAL_HTTP_PORTS.add(int(s.port or 80)) + headers, body = list(map(utf8, data.split(b'\r\n\r\n', 1))) + + request = httpretty.historify_request(headers, body) + + info = URIInfo(hostname=self._host, port=self._port, + path=s.path, + query=s.query, + last_request=request) + + matcher, entries = httpretty.match_uriinfo(info) + + if not entries: + self._entry = None + self.real_sendall(data) + return + + self._entry = matcher.get_next_entry(method, info, request) + + def debug(self, truesock_func, *a, **kw): + if self.is_http: + frame = inspect.stack()[0][0] + lines = list(map(utf8, traceback.format_stack(frame))) + + message = [ + "HTTPretty intercepted and unexpected socket method call.", + ("Please open an issue at " + "'https://github.com/gabrielfalcao/HTTPretty/issues'"), + "And paste the following traceback:\n", + "".join(decode_utf8(lines)), + ] + raise RuntimeError("\n".join(message)) + if not self.truesock: + raise UnmockedError() + return getattr(self.truesock, truesock_func)(*a, **kw) + + def settimeout(self, new_timeout): + self.timeout = new_timeout + + def send(self, *args, **kwargs): + return self.debug('send', *args, **kwargs) + + def sendto(self, *args, **kwargs): + return self.debug('sendto', *args, **kwargs) + + def recvfrom_into(self, *args, **kwargs): + return self.debug('recvfrom_into', *args, **kwargs) + + def recv_into(self, *args, **kwargs): + return self.debug('recv_into', *args, **kwargs) + + def recvfrom(self, *args, **kwargs): + return self.debug('recvfrom', *args, **kwargs) + + def recv(self, *args, **kwargs): + return self.debug('recv', *args, **kwargs) + + def __getattr__(self, name): + if not self.truesock: + raise UnmockedError() + return getattr(self.truesock, name) + + +def fake_wrap_socket(s, *args, **kw): + return s + + +def create_fake_connection(address, timeout=socket._GLOBAL_DEFAULT_TIMEOUT, source_address=None): + s = fakesock.socket(socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_TCP) + if timeout is not socket._GLOBAL_DEFAULT_TIMEOUT: + s.settimeout(timeout) + if source_address: + s.bind(source_address) + s.connect(address) + return s + + +def fake_gethostbyname(host): + return '127.0.0.1' + + +def fake_gethostname(): + return 'localhost' + + +def fake_getaddrinfo( + host, port, family=None, socktype=None, proto=None, flags=None): + return [(2, 1, 6, '', (host, port))] + + +class Entry(BaseClass): + def __init__(self, method, uri, body, + adding_headers=None, + forcing_headers=None, + status=200, + streaming=False, + **headers): + + self.method = method + self.uri = uri + self.info = None + self.request = None + + self.body_is_callable = False + if hasattr(body, "__call__"): + self.callable_body = body + self.body = None + self.body_is_callable = True + elif isinstance(body, text_type): + self.body = utf8(body) + else: + self.body = body + + self.streaming = streaming + if not streaming and not self.body_is_callable: + self.body_length = len(self.body or '') + else: + self.body_length = 0 + + self.adding_headers = adding_headers or {} + self.forcing_headers = forcing_headers or {} + self.status = int(status) + + for k, v in headers.items(): + name = "-".join(k.split("_")).title() + self.adding_headers[name] = v + + self.validate() + + def validate(self): + content_length_keys = 'Content-Length', 'content-length' + for key in content_length_keys: + got = self.adding_headers.get( + key, self.forcing_headers.get(key, None)) + + if got is None: + continue + + try: + igot = int(got) + except ValueError: + warnings.warn( + 'HTTPretty got to register the Content-Length header ' \ + 'with "%r" which is not a number' % got, + ) + + if igot > self.body_length: + raise HTTPrettyError( + 'HTTPretty got inconsistent parameters. The header ' \ + 'Content-Length you registered expects size "%d" but ' \ + 'the body you registered for that has actually length ' \ + '"%d".' % ( + igot, self.body_length, + ) + ) + + def __str__(self): + return r'' % ( + self.method, self.uri, self.status) + + def normalize_headers(self, headers): + new = {} + for k in headers: + new_k = '-'.join([s.lower() for s in k.split('-')]) + new[new_k] = headers[k] + + return new + + def fill_filekind(self, fk): + now = datetime.utcnow() + + headers = { + 'status': self.status, + 'date': now.strftime('%a, %d %b %Y %H:%M:%S GMT'), + 'server': 'Python/HTTPretty', + 'connection': 'close', + } + + if self.forcing_headers: + headers = self.forcing_headers + + if self.adding_headers: + headers.update(self.normalize_headers(self.adding_headers)) + + headers = self.normalize_headers(headers) + status = headers.get('status', self.status) + if self.body_is_callable: + status, headers, self.body = self.callable_body(self.request, self.info.full_url(), headers) + if self.request.method != "HEAD": + headers.update({ + 'content-length': len(self.body) + }) + + string_list = [ + 'HTTP/1.1 %d %s' % (status, STATUSES[status]), + ] + + if 'date' in headers: + string_list.append('date: %s' % headers.pop('date')) + + if not self.forcing_headers: + content_type = headers.pop('content-type', + 'text/plain; charset=utf-8') + + content_length = headers.pop('content-length', self.body_length) + + string_list.append('content-type: %s' % content_type) + if not self.streaming: + string_list.append('content-length: %s' % content_length) + + string_list.append('server: %s' % headers.pop('server')) + + for k, v in headers.items(): + string_list.append( + '{0}: {1}'.format(k, v), + ) + + for item in string_list: + fk.write(utf8(item) + b'\n') + + fk.write(b'\r\n') + + if self.streaming: + self.body, body = itertools.tee(self.body) + for chunk in body: + fk.write(utf8(chunk)) + else: + fk.write(utf8(self.body)) + + fk.seek(0) + + +def url_fix(s, charset='utf-8'): + scheme, netloc, path, querystring, fragment = urlsplit(s) + path = quote(path, b'/%') + querystring = quote_plus(querystring, b':&=') + return urlunsplit((scheme, netloc, path, querystring, fragment)) + + +class URIInfo(BaseClass): + def __init__(self, + username='', + password='', + hostname='', + port=80, + path='/', + query='', + fragment='', + scheme='', + last_request=None): + + self.username = username or '' + self.password = password or '' + self.hostname = hostname or '' + + if port: + port = int(port) + + elif scheme == 'https': + port = 443 + + self.port = port or 80 + self.path = path or '' + self.query = query or '' + if scheme: + self.scheme = scheme + elif self.port in POTENTIAL_HTTPS_PORTS: + self.scheme = 'https' + else: + self.scheme = 'http' + self.fragment = fragment or '' + self.last_request = last_request + + def __str__(self): + attrs = ( + 'username', + 'password', + 'hostname', + 'port', + 'path', + ) + fmt = ", ".join(['%s="%s"' % (k, getattr(self, k, '')) for k in attrs]) + return r'' % fmt + + def __hash__(self): + return hash(text_type(self)) + + def __eq__(self, other): + self_tuple = ( + self.port, + decode_utf8(self.hostname.lower()), + url_fix(decode_utf8(self.path)), + ) + other_tuple = ( + other.port, + decode_utf8(other.hostname.lower()), + url_fix(decode_utf8(other.path)), + ) + return self_tuple == other_tuple + + def full_url(self, use_querystring=True): + credentials = "" + if self.password: + credentials = "{0}:{1}@".format( + self.username, self.password) + + query = "" + if use_querystring and self.query: + query = "?{0}".format(decode_utf8(self.query)) + + result = "{scheme}://{credentials}{domain}{path}{query}".format( + scheme=self.scheme, + credentials=credentials, + domain=self.get_full_domain(), + path=decode_utf8(self.path), + query=query + ) + return result + + def get_full_domain(self): + hostname = decode_utf8(self.hostname) + # Port 80/443 should not be appended to the url + if self.port not in DEFAULT_HTTP_PORTS | DEFAULT_HTTPS_PORTS: + return ":".join([hostname, str(self.port)]) + + return hostname + + @classmethod + def from_uri(cls, uri, entry): + result = urlsplit(uri) + if result.scheme == 'https': + POTENTIAL_HTTPS_PORTS.add(int(result.port or 443)) + else: + POTENTIAL_HTTP_PORTS.add(int(result.port or 80)) + return cls(result.username, + result.password, + result.hostname, + result.port, + result.path, + result.query, + result.fragment, + result.scheme, + entry) + + +class URIMatcher(object): + regex = None + info = None + + def __init__(self, uri, entries, match_querystring=False): + self._match_querystring = match_querystring + if type(uri).__name__ == 'SRE_Pattern': + self.regex = uri + result = urlsplit(uri.pattern) + if result.scheme == 'https': + POTENTIAL_HTTPS_PORTS.add(int(result.port or 443)) + else: + POTENTIAL_HTTP_PORTS.add(int(result.port or 80)) + else: + self.info = URIInfo.from_uri(uri, entries) + + self.entries = entries + + #hash of current_entry pointers, per method. + self.current_entries = {} + + def matches(self, info): + if self.info: + return self.info == info + else: + return self.regex.search(info.full_url( + use_querystring=self._match_querystring)) + + def __str__(self): + wrap = 'URLMatcher({0})' + if self.info: + return wrap.format(text_type(self.info)) + else: + return wrap.format(self.regex.pattern) + + def get_next_entry(self, method, info, request): + """Cycle through available responses, but only once. + Any subsequent requests will receive the last response""" + + if method not in self.current_entries: + self.current_entries[method] = 0 + + #restrict selection to entries that match the requested method + entries_for_method = [e for e in self.entries if e.method == method] + + if self.current_entries[method] >= len(entries_for_method): + self.current_entries[method] = -1 + + if not self.entries or not entries_for_method: + raise ValueError('I have no entries for method %s: %s' + % (method, self)) + + entry = entries_for_method[self.current_entries[method]] + if self.current_entries[method] != -1: + self.current_entries[method] += 1 + + # Attach more info to the entry + # So the callback can be more clever about what to do + # This does also fix the case where the callback + # would be handed a compiled regex as uri instead of the + # real uri + entry.info = info + entry.request = request + return entry + + def __hash__(self): + return hash(text_type(self)) + + def __eq__(self, other): + return text_type(self) == text_type(other) + + +class httpretty(HttpBaseClass): + """The URI registration class""" + _entries = {} + latest_requests = [] + + last_request = HTTPrettyRequestEmpty() + _is_enabled = False + allow_net_connect = True + + @classmethod + def match_uriinfo(cls, info): + for matcher, value in cls._entries.items(): + if matcher.matches(info): + return (matcher, info) + + return (None, []) + + @classmethod + @contextlib.contextmanager + def record(cls, filename, indentation=4, encoding='utf-8'): + try: + import urllib3 + except ImportError: + raise RuntimeError('HTTPretty requires urllib3 installed for recording actual requests.') + + + http = urllib3.PoolManager() + + cls.enable() + calls = [] + def record_request(request, uri, headers): + cls.disable() + + response = http.request(request.method, uri) + calls.append({ + 'request': { + 'uri': uri, + 'method': request.method, + 'headers': dict(request.headers), + 'body': decode_utf8(request.body), + 'querystring': request.querystring + }, + 'response': { + 'status': response.status, + 'body': decode_utf8(response.data), + 'headers': dict(response.headers) + } + }) + cls.enable() + return response.status, response.headers, response.data + + for method in cls.METHODS: + cls.register_uri(method, re.compile(r'.*', re.M), body=record_request) + + yield + cls.disable() + with codecs.open(filename, 'w', encoding) as f: + f.write(json.dumps(calls, indent=indentation)) + + @classmethod + @contextlib.contextmanager + def playback(cls, origin): + cls.enable() + + data = json.loads(open(origin).read()) + for item in data: + uri = item['request']['uri'] + method = item['request']['method'] + cls.register_uri(method, uri, body=item['response']['body'], forcing_headers=item['response']['headers']) + + yield + cls.disable() + + @classmethod + def reset(cls): + POTENTIAL_HTTP_PORTS.intersection_update(DEFAULT_HTTP_PORTS) + POTENTIAL_HTTPS_PORTS.intersection_update(DEFAULT_HTTPS_PORTS) + cls._entries.clear() + cls.latest_requests = [] + cls.last_request = HTTPrettyRequestEmpty() + + @classmethod + def historify_request(cls, headers, body='', append=True): + request = HTTPrettyRequest(headers, body) + cls.last_request = request + if append or not cls.latest_requests: + cls.latest_requests.append(request) + else: + cls.latest_requests[-1] = request + return request + + @classmethod + def register_uri(cls, method, uri, body='HTTPretty :)', + adding_headers=None, + forcing_headers=None, + status=200, + responses=None, match_querystring=False, + **headers): + + uri_is_string = isinstance(uri, basestring) + + if uri_is_string and re.search(r'^\w+://[^/]+[.]\w{2,}$', uri): + uri += '/' + + if isinstance(responses, list) and len(responses) > 0: + for response in responses: + response.uri = uri + response.method = method + entries_for_this_uri = responses + else: + headers[str('body')] = body + headers[str('adding_headers')] = adding_headers + headers[str('forcing_headers')] = forcing_headers + headers[str('status')] = status + + entries_for_this_uri = [ + cls.Response(method=method, uri=uri, **headers), + ] + + matcher = URIMatcher(uri, entries_for_this_uri, + match_querystring) + if matcher in cls._entries: + matcher.entries.extend(cls._entries[matcher]) + del cls._entries[matcher] + + cls._entries[matcher] = entries_for_this_uri + + def __str__(self): + return '' % len(self._entries) + + @classmethod + def Response(cls, body, method=None, uri=None, adding_headers=None, forcing_headers=None, + status=200, streaming=False, **headers): + + headers[str('body')] = body + headers[str('adding_headers')] = adding_headers + headers[str('forcing_headers')] = forcing_headers + headers[str('status')] = int(status) + headers[str('streaming')] = streaming + return Entry(method, uri, **headers) + + @classmethod + def disable(cls): + cls._is_enabled = False + socket.socket = old_socket + socket.SocketType = old_socket + socket._socketobject = old_socket + + socket.create_connection = old_create_connection + socket.gethostname = old_gethostname + socket.gethostbyname = old_gethostbyname + socket.getaddrinfo = old_getaddrinfo + + socket.__dict__['socket'] = old_socket + socket.__dict__['_socketobject'] = old_socket + socket.__dict__['SocketType'] = old_socket + + socket.__dict__['create_connection'] = old_create_connection + socket.__dict__['gethostname'] = old_gethostname + socket.__dict__['gethostbyname'] = old_gethostbyname + socket.__dict__['getaddrinfo'] = old_getaddrinfo + + if socks: + socks.socksocket = old_socksocket + socks.__dict__['socksocket'] = old_socksocket + + if ssl: + ssl.wrap_socket = old_ssl_wrap_socket + ssl.SSLSocket = old_sslsocket + ssl.__dict__['wrap_socket'] = old_ssl_wrap_socket + ssl.__dict__['SSLSocket'] = old_sslsocket + + if not PY3: + ssl.sslwrap_simple = old_sslwrap_simple + ssl.__dict__['sslwrap_simple'] = old_sslwrap_simple + + @classmethod + def is_enabled(cls): + return cls._is_enabled + + @classmethod + def enable(cls): + cls._is_enabled = True + # Some versions of python internally shadowed the + # SocketType variable incorrectly https://bugs.python.org/issue20386 + bad_socket_shadow = (socket.socket != socket.SocketType) + + socket.socket = fakesock.socket + socket._socketobject = fakesock.socket + if not bad_socket_shadow: + socket.SocketType = fakesock.socket + + socket.create_connection = create_fake_connection + socket.gethostname = fake_gethostname + socket.gethostbyname = fake_gethostbyname + socket.getaddrinfo = fake_getaddrinfo + + socket.__dict__['socket'] = fakesock.socket + socket.__dict__['_socketobject'] = fakesock.socket + if not bad_socket_shadow: + socket.__dict__['SocketType'] = fakesock.socket + + socket.__dict__['create_connection'] = create_fake_connection + socket.__dict__['gethostname'] = fake_gethostname + socket.__dict__['gethostbyname'] = fake_gethostbyname + socket.__dict__['getaddrinfo'] = fake_getaddrinfo + + if socks: + socks.socksocket = fakesock.socket + socks.__dict__['socksocket'] = fakesock.socket + + if ssl: + ssl.wrap_socket = fake_wrap_socket + ssl.SSLSocket = FakeSSLSocket + + ssl.__dict__['wrap_socket'] = fake_wrap_socket + ssl.__dict__['SSLSocket'] = FakeSSLSocket + + if not PY3: + ssl.sslwrap_simple = fake_wrap_socket + ssl.__dict__['sslwrap_simple'] = fake_wrap_socket + + +def httprettified(test): + "A decorator tests that use HTTPretty" + def decorate_class(klass): + for attr in dir(klass): + if not attr.startswith('test_'): + continue + + attr_value = getattr(klass, attr) + if not hasattr(attr_value, "__call__"): + continue + + setattr(klass, attr, decorate_callable(attr_value)) + return klass + + def decorate_callable(test): + @functools.wraps(test) + def wrapper(*args, **kw): + httpretty.reset() + httpretty.enable() + try: + return test(*args, **kw) + finally: + httpretty.disable() + return wrapper + + if isinstance(test, ClassTypes): + return decorate_class(test) + return decorate_callable(test) diff --git a/moto/packages/httpretty/errors.py b/moto/packages/httpretty/errors.py new file mode 100644 index 000000000..cb6479bf5 --- /dev/null +++ b/moto/packages/httpretty/errors.py @@ -0,0 +1,39 @@ +# #!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# +# Copyright (C) <2011-2013> Gabriel Falcão +# +# Permission is hereby granted, free of charge, to any person +# obtaining a copy of this software and associated documentation +# files (the "Software"), to deal in the Software without +# restriction, including without limitation the rights to use, +# copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following +# conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +# OTHER DEALINGS IN THE SOFTWARE. +from __future__ import unicode_literals + + +class HTTPrettyError(Exception): + pass + + +class UnmockedError(HTTPrettyError): + def __init__(self): + super(UnmockedError, self).__init__( + 'No mocking was registered, and real connections are ' + 'not allowed (httpretty.allow_net_connect = False).' + ) diff --git a/moto/packages/httpretty/http.py b/moto/packages/httpretty/http.py new file mode 100644 index 000000000..7e9a56885 --- /dev/null +++ b/moto/packages/httpretty/http.py @@ -0,0 +1,155 @@ +# #!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Copyright (C) <2011-2013> Gabriel Falcão +# +# Permission is hereby granted, free of charge, to any person +# obtaining a copy of this software and associated documentation +# files (the "Software"), to deal in the Software without +# restriction, including without limitation the rights to use, +# copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following +# conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +# OTHER DEALINGS IN THE SOFTWARE. +from __future__ import unicode_literals + +import re +from .compat import BaseClass +from .utils import decode_utf8 + + +STATUSES = { + 100: "Continue", + 101: "Switching Protocols", + 102: "Processing", + 200: "OK", + 201: "Created", + 202: "Accepted", + 203: "Non-Authoritative Information", + 204: "No Content", + 205: "Reset Content", + 206: "Partial Content", + 207: "Multi-Status", + 208: "Already Reported", + 226: "IM Used", + 300: "Multiple Choices", + 301: "Moved Permanently", + 302: "Found", + 303: "See Other", + 304: "Not Modified", + 305: "Use Proxy", + 306: "Switch Proxy", + 307: "Temporary Redirect", + 308: "Permanent Redirect", + 400: "Bad Request", + 401: "Unauthorized", + 402: "Payment Required", + 403: "Forbidden", + 404: "Not Found", + 405: "Method Not Allowed", + 406: "Not Acceptable", + 407: "Proxy Authentication Required", + 408: "Request a Timeout", + 409: "Conflict", + 410: "Gone", + 411: "Length Required", + 412: "Precondition Failed", + 413: "Request Entity Too Large", + 414: "Request-URI Too Long", + 415: "Unsupported Media Type", + 416: "Requested Range Not Satisfiable", + 417: "Expectation Failed", + 418: "I'm a teapot", + 420: "Enhance Your Calm", + 422: "Unprocessable Entity", + 423: "Locked", + 424: "Failed Dependency", + 424: "Method Failure", + 425: "Unordered Collection", + 426: "Upgrade Required", + 428: "Precondition Required", + 429: "Too Many Requests", + 431: "Request Header Fields Too Large", + 444: "No Response", + 449: "Retry With", + 450: "Blocked by Windows Parental Controls", + 451: "Unavailable For Legal Reasons", + 451: "Redirect", + 494: "Request Header Too Large", + 495: "Cert Error", + 496: "No Cert", + 497: "HTTP to HTTPS", + 499: "Client Closed Request", + 500: "Internal Server Error", + 501: "Not Implemented", + 502: "Bad Gateway", + 503: "Service Unavailable", + 504: "Gateway Timeout", + 505: "HTTP Version Not Supported", + 506: "Variant Also Negotiates", + 507: "Insufficient Storage", + 508: "Loop Detected", + 509: "Bandwidth Limit Exceeded", + 510: "Not Extended", + 511: "Network Authentication Required", + 598: "Network read timeout error", + 599: "Network connect timeout error", +} + + +class HttpBaseClass(BaseClass): + GET = 'GET' + PUT = 'PUT' + POST = 'POST' + DELETE = 'DELETE' + HEAD = 'HEAD' + PATCH = 'PATCH' + OPTIONS = 'OPTIONS' + CONNECT = 'CONNECT' + METHODS = (GET, PUT, POST, DELETE, HEAD, PATCH, OPTIONS, CONNECT) + + +def parse_requestline(s): + """ + http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html#sec5 + + >>> parse_requestline('GET / HTTP/1.0') + ('GET', '/', '1.0') + >>> parse_requestline('post /testurl htTP/1.1') + ('POST', '/testurl', '1.1') + >>> parse_requestline('Im not a RequestLine') + Traceback (most recent call last): + ... + ValueError: Not a Request-Line + """ + methods = '|'.join(HttpBaseClass.METHODS) + m = re.match(r'(' + methods + ')\s+(.*)\s+HTTP/(1.[0|1])', s, re.I) + if m: + return m.group(1).upper(), m.group(2), m.group(3) + else: + raise ValueError('Not a Request-Line') + + +def last_requestline(sent_data): + """ + Find the last line in sent_data that can be parsed with parse_requestline + """ + for line in reversed(sent_data): + try: + parse_requestline(decode_utf8(line)) + except ValueError: + pass + else: + return line diff --git a/moto/packages/httpretty/utils.py b/moto/packages/httpretty/utils.py new file mode 100644 index 000000000..caa8fa13b --- /dev/null +++ b/moto/packages/httpretty/utils.py @@ -0,0 +1,48 @@ +# #!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Copyright (C) <2011-2013> Gabriel Falcão +# +# Permission is hereby granted, free of charge, to any person +# obtaining a copy of this software and associated documentation +# files (the "Software"), to deal in the Software without +# restriction, including without limitation the rights to use, +# copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following +# conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +# OTHER DEALINGS IN THE SOFTWARE. +from __future__ import unicode_literals + +from .compat import ( + byte_type, text_type +) + + +def utf8(s): + if isinstance(s, text_type): + s = s.encode('utf-8') + elif s is None: + return byte_type() + + return byte_type(s) + + +def decode_utf8(s): + if isinstance(s, byte_type): + s = s.decode("utf-8") + elif s is None: + return text_type() + + return text_type(s) diff --git a/moto/packages/responses b/moto/packages/responses new file mode 160000 index 000000000..8d500447e --- /dev/null +++ b/moto/packages/responses @@ -0,0 +1 @@ +Subproject commit 8d500447e3d5c2b96ace2eb7ab0f60158e921ed8 diff --git a/moto/rds/__init__.py b/moto/rds/__init__.py index d3cafc066..2c8c0ba97 100644 --- a/moto/rds/__init__.py +++ b/moto/rds/__init__.py @@ -1,6 +1,7 @@ from __future__ import unicode_literals from .models import rds_backends -from ..core.models import MockAWS, base_decorator +from ..core.models import MockAWS, base_decorator, HttprettyMockAWS, deprecated_base_decorator rds_backend = rds_backends['us-east-1'] mock_rds = base_decorator(rds_backends) +mock_rds_deprecated = deprecated_base_decorator(rds_backends) diff --git a/moto/rds2/__init__.py b/moto/rds2/__init__.py index b200f9b11..0feecfac4 100644 --- a/moto/rds2/__init__.py +++ b/moto/rds2/__init__.py @@ -1,6 +1,7 @@ from __future__ import unicode_literals from .models import rds2_backends -from ..core.models import MockAWS, base_decorator +from ..core.models import MockAWS, base_decorator, deprecated_base_decorator rds2_backend = rds2_backends['us-west-1'] mock_rds2 = base_decorator(rds2_backends) +mock_rds2_deprecated = deprecated_base_decorator(rds2_backends) diff --git a/moto/redshift/__init__.py b/moto/redshift/__init__.py index 821408493..58be5fc70 100644 --- a/moto/redshift/__init__.py +++ b/moto/redshift/__init__.py @@ -1,6 +1,7 @@ from __future__ import unicode_literals from .models import redshift_backends -from ..core.models import MockAWS, base_decorator +from ..core.models import MockAWS, base_decorator, HttprettyMockAWS, deprecated_base_decorator redshift_backend = redshift_backends['us-east-1'] mock_redshift = base_decorator(redshift_backends) +mock_redshift_deprecated = deprecated_base_decorator(redshift_backends) diff --git a/moto/route53/__init__.py b/moto/route53/__init__.py index 2c6bd223f..df629880f 100644 --- a/moto/route53/__init__.py +++ b/moto/route53/__init__.py @@ -1,3 +1,4 @@ from __future__ import unicode_literals from .models import route53_backend mock_route53 = route53_backend.decorator +mock_route53_deprecated = route53_backend.deprecated_decorator diff --git a/moto/s3/__init__.py b/moto/s3/__init__.py index 6590d4324..7d0df53bd 100644 --- a/moto/s3/__init__.py +++ b/moto/s3/__init__.py @@ -1,3 +1,4 @@ from __future__ import unicode_literals from .models import s3_backend mock_s3 = s3_backend.decorator +mock_s3_deprecated = s3_backend.deprecated_decorator \ No newline at end of file diff --git a/moto/s3/models.py b/moto/s3/models.py index c41ff3901..40370b5dd 100644 --- a/moto/s3/models.py +++ b/moto/s3/models.py @@ -25,7 +25,7 @@ class FakeKey(object): self.value = value self.last_modified = datetime.datetime.utcnow() self.acl = get_canned_acl('private') - self._storage_class = storage + self._storage_class = storage if storage else "STANDARD" self._metadata = {} self._expiry = None self._etag = etag @@ -92,6 +92,7 @@ class FakeKey(object): r = { 'etag': self.etag, 'last-modified': self.last_modified_RFC1123, + 'content-length': str(len(self.value)), } if self._storage_class != 'STANDARD': r['x-amz-storage-class'] = self._storage_class @@ -100,7 +101,7 @@ class FakeKey(object): r['x-amz-restore'] = rhdr.format(self.expiry_date) if self._is_versioned: - r['x-amz-version-id'] = self._version_id + r['x-amz-version-id'] = str(self._version_id) return r diff --git a/moto/s3/responses.py b/moto/s3/responses.py index d6855265e..3fbd058f2 100644 --- a/moto/s3/responses.py +++ b/moto/s3/responses.py @@ -49,6 +49,8 @@ class ResponseObject(_TemplateEnvironmentMixin): def subdomain_based_buckets(self, request): host = request.headers.get('host', request.headers.get('Host')) + if not host: + host = urlparse(request.url).netloc if not host or host.startswith("localhost"): # For localhost, default to path-based buckets @@ -130,6 +132,8 @@ class ResponseObject(_TemplateEnvironmentMixin): else: # Flask server body = request.data + if body is None: + body = '' body = body.decode('utf-8') if method == 'HEAD': @@ -334,7 +338,8 @@ class ResponseObject(_TemplateEnvironmentMixin): return 409, headers, template.render(bucket=removed_bucket) def _bucket_response_post(self, request, body, bucket_name, headers): - if self.is_delete_keys(request, request.path, bucket_name): + path = request.path if hasattr(request, 'path') else request.path_url + if self.is_delete_keys(request, path, bucket_name): return self._bucket_response_delete_keys(request, body, bucket_name, headers) # POST to bucket-url should create file from form @@ -344,7 +349,7 @@ class ResponseObject(_TemplateEnvironmentMixin): else: # HTTPretty, build new form object form = {} - for kv in request.body.decode('utf-8').split('&'): + for kv in body.decode('utf-8').split('&'): k, v = kv.split('=') form[k] = v @@ -428,9 +433,13 @@ class ResponseObject(_TemplateEnvironmentMixin): if hasattr(request, 'body'): # Boto body = request.body + if hasattr(body, 'read'): + body = body.read() else: # Flask server body = request.data + if body is None: + body = b'' if method == 'GET': return self._key_response_get(bucket_name, query, key_name, headers) @@ -546,7 +555,7 @@ class ResponseObject(_TemplateEnvironmentMixin): if key: headers.update(key.metadata) headers.update(key.response_dict) - return 200, headers, key.value + return 200, headers, "" else: return 404, headers, "" diff --git a/moto/s3bucket_path/__init__.py b/moto/s3bucket_path/__init__.py index 85031a06e..baffc4882 100644 --- a/moto/s3bucket_path/__init__.py +++ b/moto/s3bucket_path/__init__.py @@ -1,4 +1 @@ from __future__ import unicode_literals - -from moto import mock_s3 -mock_s3bucket_path = mock_s3 diff --git a/moto/ses/__init__.py b/moto/ses/__init__.py index 3b0e93c14..e1ec4b41a 100644 --- a/moto/ses/__init__.py +++ b/moto/ses/__init__.py @@ -1,3 +1,4 @@ from __future__ import unicode_literals from .models import ses_backend mock_ses = ses_backend.decorator +mock_ses_deprecated = ses_backend.deprecated_decorator \ No newline at end of file diff --git a/moto/sns/__init__.py b/moto/sns/__init__.py index 0ed85e813..a50911e3b 100644 --- a/moto/sns/__init__.py +++ b/moto/sns/__init__.py @@ -1,6 +1,7 @@ from __future__ import unicode_literals from .models import sns_backends -from ..core.models import MockAWS, base_decorator +from ..core.models import MockAWS, base_decorator, HttprettyMockAWS, deprecated_base_decorator sns_backend = sns_backends['us-east-1'] mock_sns = base_decorator(sns_backends) +mock_sns_deprecated = deprecated_base_decorator(sns_backends) diff --git a/moto/sqs/__init__.py b/moto/sqs/__init__.py index 09b4ed9e9..946ba8f47 100644 --- a/moto/sqs/__init__.py +++ b/moto/sqs/__init__.py @@ -1,6 +1,7 @@ from __future__ import unicode_literals from .models import sqs_backends -from ..core.models import MockAWS, base_decorator +from ..core.models import MockAWS, base_decorator, HttprettyMockAWS, deprecated_base_decorator sqs_backend = sqs_backends['us-east-1'] mock_sqs = base_decorator(sqs_backends) +mock_sqs_deprecated = deprecated_base_decorator(sqs_backends) diff --git a/moto/sqs/responses.py b/moto/sqs/responses.py index 15c067613..d57ec3430 100644 --- a/moto/sqs/responses.py +++ b/moto/sqs/responses.py @@ -122,6 +122,7 @@ class SQSResponse(BaseResponse): queue = self.sqs_backend.delete_queue(queue_name) if not queue: return "A queue with name {0} does not exist".format(queue_name), dict(status=404) + template = self.response_template(DELETE_QUEUE_RESPONSE) return template.render(queue=queue) diff --git a/moto/sts/__init__.py b/moto/sts/__init__.py index 04e93e2e7..57456c1b3 100644 --- a/moto/sts/__init__.py +++ b/moto/sts/__init__.py @@ -1,3 +1,4 @@ from __future__ import unicode_literals from .models import sts_backend mock_sts = sts_backend.decorator +mock_sts_deprecated = sts_backend.deprecated_decorator diff --git a/moto/swf/__init__.py b/moto/swf/__init__.py index 180919320..5ac59fbb6 100644 --- a/moto/swf/__init__.py +++ b/moto/swf/__init__.py @@ -1,6 +1,7 @@ from __future__ import unicode_literals from .models import swf_backends -from ..core.models import MockAWS, base_decorator +from ..core.models import MockAWS, base_decorator, HttprettyMockAWS, deprecated_base_decorator swf_backend = swf_backends['us-east-1'] mock_swf = base_decorator(swf_backends) +mock_swf_deprecated = deprecated_base_decorator(swf_backends) diff --git a/setup.py b/setup.py index bfd8bbb87..52635d00b 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,6 @@ from setuptools import setup, find_packages install_requires = [ "Jinja2>=2.8", "boto>=2.36.0", - "httpretty==0.8.10", "requests", "xmltodict", "six", diff --git a/tests/__init__.py b/tests/__init__.py index baffc4882..bf582e0b3 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1 +1,8 @@ from __future__ import unicode_literals + +import logging +# Disable extra logging for tests +logging.getLogger('boto').setLevel(logging.CRITICAL) +logging.getLogger('boto3').setLevel(logging.CRITICAL) +logging.getLogger('botocore').setLevel(logging.CRITICAL) +logging.getLogger('nose').setLevel(logging.CRITICAL) diff --git a/tests/test_apigateway/test_apigateway.py b/tests/test_apigateway/test_apigateway.py index fc41d3bc0..6bd6eb5e5 100644 --- a/tests/test_apigateway/test_apigateway.py +++ b/tests/test_apigateway/test_apigateway.py @@ -5,11 +5,11 @@ from datetime import datetime from dateutil.tz import tzutc import boto3 from freezegun import freeze_time -import httpretty import requests import sure # noqa from botocore.exceptions import ClientError +from moto.packages.responses import responses from moto import mock_apigateway @@ -883,11 +883,10 @@ def test_deployment(): stage['description'].should.equal('_new_description_') -@httpretty.activate @mock_apigateway def test_http_proxying_integration(): - httpretty.register_uri( - httpretty.GET, "http://httpbin.org/robots.txt", body='a fake response' + responses.add( + responses.GET, "http://httpbin.org/robots.txt", body='a fake response' ) region_name = 'us-west-2' diff --git a/tests/test_autoscaling/test_autoscaling.py b/tests/test_autoscaling/test_autoscaling.py index a048e81f5..4d0905196 100644 --- a/tests/test_autoscaling/test_autoscaling.py +++ b/tests/test_autoscaling/test_autoscaling.py @@ -8,12 +8,12 @@ from boto.ec2.autoscale import Tag import boto.ec2.elb import sure # noqa -from moto import mock_autoscaling, mock_ec2, mock_elb +from moto import mock_autoscaling, mock_ec2_deprecated, mock_elb_deprecated, mock_autoscaling_deprecated from tests.helpers import requires_boto_gte -@mock_autoscaling -@mock_elb +@mock_autoscaling_deprecated +@mock_elb_deprecated def test_create_autoscaling_group(): elb_conn = boto.ec2.elb.connect_to_region('us-east-1') elb_conn.create_load_balancer('test_lb', zones=[], listeners=[(80, 8080, 'http')]) @@ -73,7 +73,7 @@ def test_create_autoscaling_group(): tag.propagate_at_launch.should.equal(True) -@mock_autoscaling +@mock_autoscaling_deprecated def test_create_autoscaling_groups_defaults(): """ Test with the minimum inputs and check that all of the proper defaults are assigned for the other attributes """ @@ -112,7 +112,7 @@ def test_create_autoscaling_groups_defaults(): list(group.tags).should.equal([]) -@mock_autoscaling +@mock_autoscaling_deprecated def test_autoscaling_group_describe_filter(): conn = boto.connect_autoscale() config = LaunchConfiguration( @@ -138,7 +138,7 @@ def test_autoscaling_group_describe_filter(): conn.get_all_groups().should.have.length_of(3) -@mock_autoscaling +@mock_autoscaling_deprecated def test_autoscaling_update(): conn = boto.connect_autoscale() config = LaunchConfiguration( @@ -169,7 +169,7 @@ def test_autoscaling_update(): group.vpc_zone_identifier.should.equal('subnet-5678efgh') -@mock_autoscaling +@mock_autoscaling_deprecated def test_autoscaling_tags_update(): conn = boto.connect_autoscale() config = LaunchConfiguration( @@ -211,7 +211,7 @@ def test_autoscaling_tags_update(): group.tags.should.have.length_of(2) -@mock_autoscaling +@mock_autoscaling_deprecated def test_autoscaling_group_delete(): conn = boto.connect_autoscale() config = LaunchConfiguration( @@ -235,8 +235,8 @@ def test_autoscaling_group_delete(): conn.get_all_groups().should.have.length_of(0) -@mock_ec2 -@mock_autoscaling +@mock_ec2_deprecated +@mock_autoscaling_deprecated def test_autoscaling_group_describe_instances(): conn = boto.connect_autoscale() config = LaunchConfiguration( @@ -269,7 +269,7 @@ def test_autoscaling_group_describe_instances(): @requires_boto_gte("2.8") -@mock_autoscaling +@mock_autoscaling_deprecated def test_set_desired_capacity_up(): conn = boto.connect_autoscale() config = LaunchConfiguration( @@ -304,7 +304,7 @@ def test_set_desired_capacity_up(): @requires_boto_gte("2.8") -@mock_autoscaling +@mock_autoscaling_deprecated def test_set_desired_capacity_down(): conn = boto.connect_autoscale() config = LaunchConfiguration( @@ -339,7 +339,7 @@ def test_set_desired_capacity_down(): @requires_boto_gte("2.8") -@mock_autoscaling +@mock_autoscaling_deprecated def test_set_desired_capacity_the_same(): conn = boto.connect_autoscale() config = LaunchConfiguration( @@ -372,8 +372,8 @@ def test_set_desired_capacity_the_same(): instances = list(conn.get_all_autoscaling_instances()) instances.should.have.length_of(2) -@mock_autoscaling -@mock_elb +@mock_autoscaling_deprecated +@mock_elb_deprecated def test_autoscaling_group_with_elb(): elb_conn = boto.connect_elb() zones = ['us-east-1a', 'us-east-1b'] diff --git a/tests/test_autoscaling/test_launch_configurations.py b/tests/test_autoscaling/test_launch_configurations.py index 8020e46f6..b2e21b03e 100644 --- a/tests/test_autoscaling/test_launch_configurations.py +++ b/tests/test_autoscaling/test_launch_configurations.py @@ -5,11 +5,11 @@ from boto.ec2.blockdevicemapping import BlockDeviceType, BlockDeviceMapping import sure # noqa -from moto import mock_autoscaling +from moto import mock_autoscaling_deprecated from tests.helpers import requires_boto_gte -@mock_autoscaling +@mock_autoscaling_deprecated def test_create_launch_configuration(): conn = boto.connect_autoscale() config = LaunchConfiguration( @@ -38,7 +38,7 @@ def test_create_launch_configuration(): @requires_boto_gte("2.27.0") -@mock_autoscaling +@mock_autoscaling_deprecated def test_create_launch_configuration_with_block_device_mappings(): block_device_mapping = BlockDeviceMapping() @@ -101,7 +101,7 @@ def test_create_launch_configuration_with_block_device_mappings(): @requires_boto_gte("2.12") -@mock_autoscaling +@mock_autoscaling_deprecated def test_create_launch_configuration_for_2_12(): conn = boto.connect_autoscale() config = LaunchConfiguration( @@ -116,7 +116,7 @@ def test_create_launch_configuration_for_2_12(): @requires_boto_gte("2.25.0") -@mock_autoscaling +@mock_autoscaling_deprecated def test_create_launch_configuration_using_ip_association(): conn = boto.connect_autoscale() config = LaunchConfiguration( @@ -131,7 +131,7 @@ def test_create_launch_configuration_using_ip_association(): @requires_boto_gte("2.25.0") -@mock_autoscaling +@mock_autoscaling_deprecated def test_create_launch_configuration_using_ip_association_should_default_to_false(): conn = boto.connect_autoscale() config = LaunchConfiguration( @@ -144,7 +144,7 @@ def test_create_launch_configuration_using_ip_association_should_default_to_fals launch_config.associate_public_ip_address.should.equal(False) -@mock_autoscaling +@mock_autoscaling_deprecated def test_create_launch_configuration_defaults(): """ Test with the minimum inputs and check that all of the proper defaults are assigned for the other attributes """ @@ -171,7 +171,7 @@ def test_create_launch_configuration_defaults(): @requires_boto_gte("2.12") -@mock_autoscaling +@mock_autoscaling_deprecated def test_create_launch_configuration_defaults_for_2_12(): conn = boto.connect_autoscale() config = LaunchConfiguration( @@ -184,7 +184,7 @@ def test_create_launch_configuration_defaults_for_2_12(): launch_config.ebs_optimized.should.equal(False) -@mock_autoscaling +@mock_autoscaling_deprecated def test_launch_configuration_describe_filter(): conn = boto.connect_autoscale() config = LaunchConfiguration( @@ -202,7 +202,7 @@ def test_launch_configuration_describe_filter(): conn.get_all_launch_configurations().should.have.length_of(3) -@mock_autoscaling +@mock_autoscaling_deprecated def test_launch_configuration_delete(): conn = boto.connect_autoscale() config = LaunchConfiguration( diff --git a/tests/test_autoscaling/test_policies.py b/tests/test_autoscaling/test_policies.py index 8ca585e89..54c64b749 100644 --- a/tests/test_autoscaling/test_policies.py +++ b/tests/test_autoscaling/test_policies.py @@ -5,7 +5,7 @@ from boto.ec2.autoscale.group import AutoScalingGroup from boto.ec2.autoscale.policy import ScalingPolicy import sure # noqa -from moto import mock_autoscaling +from moto import mock_autoscaling_deprecated def setup_autoscale_group(): @@ -27,7 +27,7 @@ def setup_autoscale_group(): return group -@mock_autoscaling +@mock_autoscaling_deprecated def test_create_policy(): setup_autoscale_group() conn = boto.connect_autoscale() @@ -48,7 +48,7 @@ def test_create_policy(): policy.cooldown.should.equal(60) -@mock_autoscaling +@mock_autoscaling_deprecated def test_create_policy_default_values(): setup_autoscale_group() conn = boto.connect_autoscale() @@ -67,7 +67,7 @@ def test_create_policy_default_values(): policy.cooldown.should.equal(300) -@mock_autoscaling +@mock_autoscaling_deprecated def test_update_policy(): setup_autoscale_group() conn = boto.connect_autoscale() @@ -94,7 +94,7 @@ def test_update_policy(): policy.scaling_adjustment.should.equal(2) -@mock_autoscaling +@mock_autoscaling_deprecated def test_delete_policy(): setup_autoscale_group() conn = boto.connect_autoscale() @@ -112,7 +112,7 @@ def test_delete_policy(): conn.get_all_policies().should.have.length_of(0) -@mock_autoscaling +@mock_autoscaling_deprecated def test_execute_policy_exact_capacity(): setup_autoscale_group() conn = boto.connect_autoscale() @@ -130,7 +130,7 @@ def test_execute_policy_exact_capacity(): instances.should.have.length_of(3) -@mock_autoscaling +@mock_autoscaling_deprecated def test_execute_policy_positive_change_in_capacity(): setup_autoscale_group() conn = boto.connect_autoscale() @@ -148,7 +148,7 @@ def test_execute_policy_positive_change_in_capacity(): instances.should.have.length_of(5) -@mock_autoscaling +@mock_autoscaling_deprecated def test_execute_policy_percent_change_in_capacity(): setup_autoscale_group() conn = boto.connect_autoscale() @@ -166,7 +166,7 @@ def test_execute_policy_percent_change_in_capacity(): instances.should.have.length_of(3) -@mock_autoscaling +@mock_autoscaling_deprecated def test_execute_policy_small_percent_change_in_capacity(): """ http://docs.aws.amazon.com/AutoScaling/latest/DeveloperGuide/as-scale-based-on-demand.html If PercentChangeInCapacity returns a value between 0 and 1, diff --git a/tests/test_cloudformation/test_cloudformation_stack_crud.py b/tests/test_cloudformation/test_cloudformation_stack_crud.py index e45dafbfa..3d41c9d91 100644 --- a/tests/test_cloudformation/test_cloudformation_stack_crud.py +++ b/tests/test_cloudformation/test_cloudformation_stack_crud.py @@ -12,7 +12,7 @@ import sure # noqa import tests.backport_assert_raises # noqa from nose.tools import assert_raises -from moto import mock_cloudformation, mock_s3 +from moto import mock_cloudformation_deprecated, mock_s3_deprecated from moto.cloudformation import cloudformation_backends dummy_template = { @@ -46,7 +46,7 @@ dummy_template_json2 = json.dumps(dummy_template2) dummy_template_json3 = json.dumps(dummy_template3) -@mock_cloudformation +@mock_cloudformation_deprecated def test_create_stack(): conn = boto.connect_cloudformation() conn.create_stack( @@ -69,7 +69,7 @@ def test_create_stack(): }) -@mock_cloudformation +@mock_cloudformation_deprecated def test_creating_stacks_across_regions(): west1_conn = boto.cloudformation.connect_to_region("us-west-1") west1_conn.create_stack("test_stack", template_body=dummy_template_json) @@ -81,7 +81,7 @@ def test_creating_stacks_across_regions(): list(west2_conn.describe_stacks()).should.have.length_of(1) -@mock_cloudformation +@mock_cloudformation_deprecated def test_create_stack_with_notification_arn(): conn = boto.connect_cloudformation() conn.create_stack( @@ -94,8 +94,8 @@ def test_create_stack_with_notification_arn(): [n.value for n in stack.notification_arns].should.contain('arn:aws:sns:us-east-1:123456789012:fake-queue') -@mock_cloudformation -@mock_s3 +@mock_cloudformation_deprecated +@mock_s3_deprecated def test_create_stack_from_s3_url(): s3_conn = boto.s3.connect_to_region('us-west-1') bucket = s3_conn.create_bucket("foobar") @@ -123,7 +123,7 @@ def test_create_stack_from_s3_url(): }) -@mock_cloudformation +@mock_cloudformation_deprecated def test_describe_stack_by_name(): conn = boto.connect_cloudformation() conn.create_stack( @@ -135,7 +135,7 @@ def test_describe_stack_by_name(): stack.stack_name.should.equal('test_stack') -@mock_cloudformation +@mock_cloudformation_deprecated def test_describe_stack_by_stack_id(): conn = boto.connect_cloudformation() conn.create_stack( @@ -149,7 +149,7 @@ def test_describe_stack_by_stack_id(): stack_by_id.stack_name.should.equal("test_stack") -@mock_cloudformation +@mock_cloudformation_deprecated def test_describe_deleted_stack(): conn = boto.connect_cloudformation() conn.create_stack( @@ -166,7 +166,7 @@ def test_describe_deleted_stack(): stack_by_id.stack_status.should.equal("DELETE_COMPLETE") -@mock_cloudformation +@mock_cloudformation_deprecated def test_get_template_by_name(): conn = boto.connect_cloudformation() conn.create_stack( @@ -188,7 +188,7 @@ def test_get_template_by_name(): }) -@mock_cloudformation +@mock_cloudformation_deprecated def test_list_stacks(): conn = boto.connect_cloudformation() conn.create_stack( @@ -205,7 +205,7 @@ def test_list_stacks(): stacks[0].template_description.should.equal("Stack 1") -@mock_cloudformation +@mock_cloudformation_deprecated def test_delete_stack_by_name(): conn = boto.connect_cloudformation() conn.create_stack( @@ -218,7 +218,7 @@ def test_delete_stack_by_name(): conn.list_stacks().should.have.length_of(0) -@mock_cloudformation +@mock_cloudformation_deprecated def test_delete_stack_by_id(): conn = boto.connect_cloudformation() stack_id = conn.create_stack( @@ -235,7 +235,7 @@ def test_delete_stack_by_id(): conn.describe_stacks(stack_id).should.have.length_of(1) -@mock_cloudformation +@mock_cloudformation_deprecated def test_delete_stack_with_resource_missing_delete_attr(): conn = boto.connect_cloudformation() conn.create_stack( @@ -248,14 +248,14 @@ def test_delete_stack_with_resource_missing_delete_attr(): conn.list_stacks().should.have.length_of(0) -@mock_cloudformation +@mock_cloudformation_deprecated def test_bad_describe_stack(): conn = boto.connect_cloudformation() with assert_raises(BotoServerError): conn.describe_stacks("bad_stack") -@mock_cloudformation() +@mock_cloudformation_deprecated() def test_cloudformation_params(): dummy_template = { "AWSTemplateFormatVersion": "2010-09-09", @@ -279,7 +279,7 @@ def test_cloudformation_params(): param.value.should.equal('testing123') -@mock_cloudformation +@mock_cloudformation_deprecated def test_stack_tags(): conn = boto.connect_cloudformation() conn.create_stack( @@ -292,7 +292,7 @@ def test_stack_tags(): dict(stack.tags).should.equal({"foo": "bar", "baz": "bleh"}) -@mock_cloudformation +@mock_cloudformation_deprecated def test_update_stack(): conn = boto.connect_cloudformation() conn.create_stack( @@ -316,7 +316,7 @@ def test_update_stack(): }) -@mock_cloudformation +@mock_cloudformation_deprecated def test_update_stack(): conn = boto.connect_cloudformation() conn.create_stack( @@ -339,7 +339,7 @@ def test_update_stack(): }) -@mock_cloudformation +@mock_cloudformation_deprecated def test_update_stack_when_rolled_back(): conn = boto.connect_cloudformation() stack_id = conn.create_stack("test_stack", template_body=dummy_template_json) @@ -355,7 +355,7 @@ def test_update_stack_when_rolled_back(): ex.reason.should.equal('Bad Request') ex.status.should.equal(400) -@mock_cloudformation +@mock_cloudformation_deprecated def test_describe_stack_events_shows_create_update_and_delete(): conn = boto.connect_cloudformation() stack_id = conn.create_stack("test_stack", template_body=dummy_template_json) diff --git a/tests/test_cloudformation/test_cloudformation_stack_crud_boto3.py b/tests/test_cloudformation/test_cloudformation_stack_crud_boto3.py index 97c3e864a..95ac6ede4 100644 --- a/tests/test_cloudformation/test_cloudformation_stack_crud_boto3.py +++ b/tests/test_cloudformation/test_cloudformation_stack_crud_boto3.py @@ -5,7 +5,7 @@ import boto import boto.s3 import boto.s3.key from botocore.exceptions import ClientError -from moto import mock_cloudformation, mock_s3 +from moto import mock_cloudformation, mock_s3_deprecated import json import sure # noqa @@ -118,7 +118,7 @@ def test_create_stack_with_role_arn(): @mock_cloudformation -@mock_s3 +@mock_s3_deprecated def test_create_stack_from_s3_url(): s3_conn = boto.s3.connect_to_region('us-west-1') bucket = s3_conn.create_bucket("foobar") diff --git a/tests/test_cloudformation/test_cloudformation_stack_integration.py b/tests/test_cloudformation/test_cloudformation_stack_integration.py index 4237bee19..1b9330a9f 100644 --- a/tests/test_cloudformation/test_cloudformation_stack_integration.py +++ b/tests/test_cloudformation/test_cloudformation_stack_integration.py @@ -18,20 +18,26 @@ import boto3 import sure # noqa from moto import ( - mock_autoscaling, + mock_autoscaling_deprecated, mock_cloudformation, - mock_datapipeline, + mock_cloudformation_deprecated, + mock_datapipeline_deprecated, mock_ec2, + mock_ec2_deprecated, mock_elb, - mock_iam, + mock_elb_deprecated, + mock_iam_deprecated, mock_kms, mock_lambda, - mock_rds, + mock_rds_deprecated, mock_rds2, + mock_rds2_deprecated, mock_redshift, - mock_route53, - mock_sns, + mock_redshift_deprecated, + mock_route53_deprecated, + mock_sns_deprecated, mock_sqs, + mock_sqs_deprecated, ) from .fixtures import ( @@ -49,7 +55,7 @@ from .fixtures import ( ) -@mock_cloudformation() +@mock_cloudformation_deprecated() def test_stack_sqs_integration(): sqs_template = { "AWSTemplateFormatVersion": "2010-09-09", @@ -79,7 +85,7 @@ def test_stack_sqs_integration(): queue.physical_resource_id.should.equal("my-queue") -@mock_cloudformation() +@mock_cloudformation_deprecated() def test_stack_list_resources(): sqs_template = { "AWSTemplateFormatVersion": "2010-09-09", @@ -110,8 +116,8 @@ def test_stack_list_resources(): queue.physical_resource_id.should.equal("my-queue") -@mock_cloudformation() -@mock_sqs() +@mock_cloudformation_deprecated() +@mock_sqs_deprecated() def test_update_stack(): sqs_template = { "AWSTemplateFormatVersion": "2010-09-09", @@ -148,8 +154,8 @@ def test_update_stack(): queues[0].get_attributes('VisibilityTimeout')['VisibilityTimeout'].should.equal('100') -@mock_cloudformation() -@mock_sqs() +@mock_cloudformation_deprecated() +@mock_sqs_deprecated() def test_update_stack_and_remove_resource(): sqs_template = { "AWSTemplateFormatVersion": "2010-09-09", @@ -184,8 +190,8 @@ def test_update_stack_and_remove_resource(): queues.should.have.length_of(0) -@mock_cloudformation() -@mock_sqs() +@mock_cloudformation_deprecated() +@mock_sqs_deprecated() def test_update_stack_and_add_resource(): sqs_template = { "AWSTemplateFormatVersion": "2010-09-09", @@ -223,8 +229,8 @@ def test_update_stack_and_add_resource(): queues.should.have.length_of(1) -@mock_ec2() -@mock_cloudformation() +@mock_ec2_deprecated() +@mock_cloudformation_deprecated() def test_stack_ec2_integration(): ec2_template = { "AWSTemplateFormatVersion": "2010-09-09", @@ -257,9 +263,9 @@ def test_stack_ec2_integration(): instance.physical_resource_id.should.equal(ec2_instance.id) -@mock_ec2() -@mock_elb() -@mock_cloudformation() +@mock_ec2_deprecated() +@mock_elb_deprecated() +@mock_cloudformation_deprecated() def test_stack_elb_integration_with_attached_ec2_instances(): elb_template = { "AWSTemplateFormatVersion": "2010-09-09", @@ -307,8 +313,8 @@ def test_stack_elb_integration_with_attached_ec2_instances(): list(load_balancer.availability_zones).should.equal(['us-east-1']) -@mock_elb() -@mock_cloudformation() +@mock_elb_deprecated() +@mock_cloudformation_deprecated() def test_stack_elb_integration_with_health_check(): elb_template = { "AWSTemplateFormatVersion": "2010-09-09", @@ -355,8 +361,8 @@ def test_stack_elb_integration_with_health_check(): health_check.unhealthy_threshold.should.equal(2) -@mock_elb() -@mock_cloudformation() +@mock_elb_deprecated() +@mock_cloudformation_deprecated() def test_stack_elb_integration_with_update(): elb_template = { "AWSTemplateFormatVersion": "2010-09-09", @@ -399,9 +405,9 @@ def test_stack_elb_integration_with_update(): load_balancer.availability_zones[0].should.equal('us-west-1b') -@mock_ec2() -@mock_redshift() -@mock_cloudformation() +@mock_ec2_deprecated() +@mock_redshift_deprecated() +@mock_cloudformation_deprecated() def test_redshift_stack(): redshift_template_json = json.dumps(redshift.template) @@ -443,8 +449,8 @@ def test_redshift_stack(): group.rules[0].grants[0].cidr_ip.should.equal("10.0.0.1/16") -@mock_ec2() -@mock_cloudformation() +@mock_ec2_deprecated() +@mock_cloudformation_deprecated() def test_stack_security_groups(): security_group_template = { "AWSTemplateFormatVersion": "2010-09-09", @@ -519,9 +525,9 @@ def test_stack_security_groups(): rule2.grants[0].group_id.should.equal(other_group.id) -@mock_autoscaling() -@mock_elb() -@mock_cloudformation() +@mock_autoscaling_deprecated() +@mock_elb_deprecated() +@mock_cloudformation_deprecated() def test_autoscaling_group_with_elb(): web_setup_template = { @@ -601,8 +607,8 @@ def test_autoscaling_group_with_elb(): elb_resource.physical_resource_id.should.contain("my-elb") -@mock_autoscaling() -@mock_cloudformation() +@mock_autoscaling_deprecated() +@mock_cloudformation_deprecated() def test_autoscaling_group_update(): asg_template = { "AWSTemplateFormatVersion": "2010-09-09", @@ -650,8 +656,8 @@ def test_autoscaling_group_update(): asg.max_size.should.equal(3) -@mock_ec2() -@mock_cloudformation() +@mock_ec2_deprecated() +@mock_cloudformation_deprecated() def test_vpc_single_instance_in_subnet(): template_json = json.dumps(vpc_single_instance_in_subnet.template) @@ -695,8 +701,8 @@ def test_vpc_single_instance_in_subnet(): eip_resource = [resource for resource in resources if resource.resource_type == 'AWS::EC2::EIP'][0] eip_resource.physical_resource_id.should.equal(eip.allocation_id) -@mock_cloudformation() -@mock_ec2() +@mock_cloudformation_deprecated() +@mock_ec2_deprecated() @mock_rds2() def test_rds_db_parameter_groups(): ec2_conn = boto.ec2.connect_to_region("us-west-1") @@ -734,9 +740,9 @@ def test_rds_db_parameter_groups(): -@mock_cloudformation() -@mock_ec2() -@mock_rds() +@mock_cloudformation_deprecated() +@mock_ec2_deprecated() +@mock_rds_deprecated() def test_rds_mysql_with_read_replica(): ec2_conn = boto.ec2.connect_to_region("us-west-1") ec2_conn.create_security_group('application', 'Our Application Group') @@ -776,9 +782,9 @@ def test_rds_mysql_with_read_replica(): security_group.ec2_groups[0].name.should.equal("application") -@mock_cloudformation() -@mock_ec2() -@mock_rds() +@mock_cloudformation_deprecated() +@mock_ec2_deprecated() +@mock_rds_deprecated() def test_rds_mysql_with_read_replica_in_vpc(): template_json = json.dumps(rds_mysql_with_read_replica.template) conn = boto.cloudformation.connect_to_region("eu-central-1") @@ -804,9 +810,9 @@ def test_rds_mysql_with_read_replica_in_vpc(): subnet_group.description.should.equal("my db subnet group") -@mock_autoscaling() -@mock_iam() -@mock_cloudformation() +@mock_autoscaling_deprecated() +@mock_iam_deprecated() +@mock_cloudformation_deprecated() def test_iam_roles(): iam_template = { "AWSTemplateFormatVersion": "2010-09-09", @@ -923,8 +929,8 @@ def test_iam_roles(): role_resource.physical_resource_id.should.equal(role.role_id) -@mock_ec2() -@mock_cloudformation() +@mock_ec2_deprecated() +@mock_cloudformation_deprecated() def test_single_instance_with_ebs_volume(): template_json = json.dumps(single_instance_with_ebs_volume.template) @@ -951,7 +957,7 @@ def test_single_instance_with_ebs_volume(): ebs_volumes[0].physical_resource_id.should.equal(volume.id) -@mock_cloudformation() +@mock_cloudformation_deprecated() def test_create_template_without_required_param(): template_json = json.dumps(single_instance_with_ebs_volume.template) conn = boto.cloudformation.connect_to_region("us-west-1") @@ -961,8 +967,8 @@ def test_create_template_without_required_param(): ).should.throw(BotoServerError) -@mock_ec2() -@mock_cloudformation() +@mock_ec2_deprecated() +@mock_cloudformation_deprecated() def test_classic_eip(): template_json = json.dumps(ec2_classic_eip.template) @@ -977,8 +983,8 @@ def test_classic_eip(): cfn_eip.physical_resource_id.should.equal(eip.public_ip) -@mock_ec2() -@mock_cloudformation() +@mock_ec2_deprecated() +@mock_cloudformation_deprecated() def test_vpc_eip(): template_json = json.dumps(vpc_eip.template) @@ -993,8 +999,8 @@ def test_vpc_eip(): cfn_eip.physical_resource_id.should.equal(eip.allocation_id) -@mock_ec2() -@mock_cloudformation() +@mock_ec2_deprecated() +@mock_cloudformation_deprecated() def test_fn_join(): template_json = json.dumps(fn_join.template) @@ -1008,8 +1014,8 @@ def test_fn_join(): fn_join_output.value.should.equal('test eip:{0}'.format(eip.public_ip)) -@mock_cloudformation() -@mock_sqs() +@mock_cloudformation_deprecated() +@mock_sqs_deprecated() def test_conditional_resources(): sqs_template = { "AWSTemplateFormatVersion": "2010-09-09", @@ -1054,8 +1060,8 @@ def test_conditional_resources(): list(sqs_conn.get_all_queues()).should.have.length_of(1) -@mock_cloudformation() -@mock_ec2() +@mock_cloudformation_deprecated() +@mock_ec2_deprecated() def test_conditional_if_handling(): dummy_template = { "AWSTemplateFormatVersion": "2010-09-09", @@ -1110,8 +1116,8 @@ def test_conditional_if_handling(): ec2_instance.image_id.should.equal("ami-00000000") -@mock_cloudformation() -@mock_ec2() +@mock_cloudformation_deprecated() +@mock_ec2_deprecated() def test_cloudformation_mapping(): dummy_template = { "AWSTemplateFormatVersion": "2010-09-09", @@ -1155,8 +1161,8 @@ def test_cloudformation_mapping(): ec2_instance.image_id.should.equal("ami-c9c7978c") -@mock_cloudformation() -@mock_route53() +@mock_cloudformation_deprecated() +@mock_route53_deprecated() def test_route53_roundrobin(): route53_conn = boto.connect_route53() @@ -1198,9 +1204,9 @@ def test_route53_roundrobin(): output.value.should.equal('arn:aws:route53:::hostedzone/{0}'.format(zone_id)) -@mock_cloudformation() -@mock_ec2() -@mock_route53() +@mock_cloudformation_deprecated() +@mock_ec2_deprecated() +@mock_route53_deprecated() def test_route53_ec2_instance_with_public_ip(): route53_conn = boto.connect_route53() ec2_conn = boto.ec2.connect_to_region("us-west-1") @@ -1233,8 +1239,8 @@ def test_route53_ec2_instance_with_public_ip(): record_set1.resource_records[0].should.equal("10.0.0.25") -@mock_cloudformation() -@mock_route53() +@mock_cloudformation_deprecated() +@mock_route53_deprecated() def test_route53_associate_health_check(): route53_conn = boto.connect_route53() @@ -1270,8 +1276,8 @@ def test_route53_associate_health_check(): record_set.health_check.should.equal(health_check_id) -@mock_cloudformation() -@mock_route53() +@mock_cloudformation_deprecated() +@mock_route53_deprecated() def test_route53_with_update(): route53_conn = boto.connect_route53() @@ -1314,8 +1320,8 @@ def test_route53_with_update(): record_set.resource_records.should.equal(["my_other.example.com"]) -@mock_cloudformation() -@mock_sns() +@mock_cloudformation_deprecated() +@mock_sns_deprecated() def test_sns_topic(): dummy_template = { "AWSTemplateFormatVersion": "2010-09-09", @@ -1367,8 +1373,8 @@ def test_sns_topic(): topic_arn_output.value.should.equal(topic_arn) -@mock_cloudformation -@mock_ec2 +@mock_cloudformation_deprecated +@mock_ec2_deprecated def test_vpc_gateway_attachment_creation_should_attach_itself_to_vpc(): template = { "AWSTemplateFormatVersion": "2010-09-09", @@ -1415,8 +1421,8 @@ def test_vpc_gateway_attachment_creation_should_attach_itself_to_vpc(): igws.should.have.length_of(1) -@mock_cloudformation -@mock_ec2 +@mock_cloudformation_deprecated +@mock_ec2_deprecated def test_vpc_peering_creation(): vpc_conn = boto.vpc.connect_to_region("us-west-1") vpc_source = vpc_conn.create_vpc("10.0.0.0/16") @@ -1445,8 +1451,8 @@ def test_vpc_peering_creation(): peering_connections.should.have.length_of(1) -@mock_cloudformation -@mock_ec2 +@mock_cloudformation_deprecated +@mock_ec2_deprecated def test_multiple_security_group_ingress_separate_from_security_group_by_id(): template = { "AWSTemplateFormatVersion": "2010-09-09", @@ -1507,8 +1513,8 @@ def test_multiple_security_group_ingress_separate_from_security_group_by_id(): security_group1.rules[0].to_port.should.equal('8080') -@mock_cloudformation -@mock_ec2 +@mock_cloudformation_deprecated +@mock_ec2_deprecated def test_security_group_ingress_separate_from_security_group_by_id(): ec2_conn = boto.ec2.connect_to_region("us-west-1") ec2_conn.create_security_group("test-security-group1", "test security group") @@ -1558,8 +1564,8 @@ def test_security_group_ingress_separate_from_security_group_by_id(): security_group1.rules[0].to_port.should.equal('8080') -@mock_cloudformation -@mock_ec2 +@mock_cloudformation_deprecated +@mock_ec2_deprecated def test_security_group_ingress_separate_from_security_group_by_id_using_vpc(): vpc_conn = boto.vpc.connect_to_region("us-west-1") vpc = vpc_conn.create_vpc("10.0.0.0/16") @@ -1624,8 +1630,8 @@ def test_security_group_ingress_separate_from_security_group_by_id_using_vpc(): security_group1.rules[0].to_port.should.equal('8080') -@mock_cloudformation -@mock_ec2 +@mock_cloudformation_deprecated +@mock_ec2_deprecated def test_security_group_with_update(): vpc_conn = boto.vpc.connect_to_region("us-west-1") vpc1 = vpc_conn.create_vpc("10.0.0.0/16") @@ -1669,8 +1675,8 @@ def test_security_group_with_update(): security_group.vpc_id.should.equal(vpc2.id) -@mock_cloudformation -@mock_ec2 +@mock_cloudformation_deprecated +@mock_ec2_deprecated def test_subnets_should_be_created_with_availability_zone(): vpc_conn = boto.vpc.connect_to_region('us-west-1') vpc = vpc_conn.create_vpc("10.0.0.0/16") @@ -1698,8 +1704,8 @@ def test_subnets_should_be_created_with_availability_zone(): subnet.availability_zone.should.equal('us-west-1b') -@mock_cloudformation -@mock_datapipeline +@mock_cloudformation_deprecated +@mock_datapipeline_deprecated def test_datapipeline(): dp_template = { "AWSTemplateFormatVersion": "2010-09-09", @@ -1796,11 +1802,10 @@ def lambda_handler(event, context): return _process_lamda(pfunc) -@mock_cloudformation +@mock_cloudformation_deprecated @mock_lambda def test_lambda_function(): # switch this to python as backend lambda only supports python execution. - conn = boto3.client('lambda', 'us-east-1') template = { "AWSTemplateFormatVersion": "2010-09-09", "Resources": { @@ -1827,6 +1832,7 @@ def test_lambda_function(): template_body=template_json, ) + conn = boto3.client('lambda', 'us-east-1') result = conn.list_functions() result['Functions'].should.have.length_of(1) result['Functions'][0]['Description'].should.equal('Test function') diff --git a/tests/test_cloudwatch/test_cloudwatch.py b/tests/test_cloudwatch/test_cloudwatch.py index 7354241f0..88a3190c6 100644 --- a/tests/test_cloudwatch/test_cloudwatch.py +++ b/tests/test_cloudwatch/test_cloudwatch.py @@ -2,7 +2,7 @@ import boto from boto.ec2.cloudwatch.alarm import MetricAlarm import sure # noqa -from moto import mock_cloudwatch +from moto import mock_cloudwatch_deprecated def alarm_fixture(name="tester", action=None): action = action or ['arn:alarm'] @@ -23,7 +23,7 @@ def alarm_fixture(name="tester", action=None): unit='Seconds', ) -@mock_cloudwatch +@mock_cloudwatch_deprecated def test_create_alarm(): conn = boto.connect_cloudwatch() @@ -49,7 +49,7 @@ def test_create_alarm(): alarm.unit.should.equal('Seconds') -@mock_cloudwatch +@mock_cloudwatch_deprecated def test_delete_alarm(): conn = boto.connect_cloudwatch() @@ -68,7 +68,7 @@ def test_delete_alarm(): alarms.should.have.length_of(0) -@mock_cloudwatch +@mock_cloudwatch_deprecated def test_put_metric_data(): conn = boto.connect_cloudwatch() @@ -87,7 +87,7 @@ def test_put_metric_data(): dict(metric.dimensions).should.equal({'InstanceId': ['i-0123456,i-0123457']}) -@mock_cloudwatch +@mock_cloudwatch_deprecated def test_describe_alarms(): conn = boto.connect_cloudwatch() @@ -114,7 +114,7 @@ def test_describe_alarms(): alarms = conn.describe_alarms() alarms.should.have.length_of(0) -@mock_cloudwatch +@mock_cloudwatch_deprecated def test_describe_state_value_unimplemented(): conn = boto.connect_cloudwatch() diff --git a/tests/test_core/test_decorator_calls.py b/tests/test_core/test_decorator_calls.py index 7d32bc8b3..81dc0639a 100644 --- a/tests/test_core/test_decorator_calls.py +++ b/tests/test_core/test_decorator_calls.py @@ -7,19 +7,19 @@ import unittest import tests.backport_assert_raises # noqa from nose.tools import assert_raises -from moto import mock_ec2, mock_s3 +from moto import mock_ec2_deprecated, mock_s3_deprecated ''' Test the different ways that the decorator can be used ''' -@mock_ec2 +@mock_ec2_deprecated def test_basic_connect(): boto.connect_ec2() -@mock_ec2 +@mock_ec2_deprecated def test_basic_decorator(): conn = boto.connect_ec2('the_key', 'the_secret') list(conn.get_all_instances()).should.equal([]) @@ -30,7 +30,7 @@ def test_context_manager(): with assert_raises(EC2ResponseError): conn.get_all_instances() - with mock_ec2(): + with mock_ec2_deprecated(): conn = boto.connect_ec2('the_key', 'the_secret') list(conn.get_all_instances()).should.equal([]) @@ -44,7 +44,7 @@ def test_decorator_start_and_stop(): with assert_raises(EC2ResponseError): conn.get_all_instances() - mock = mock_ec2() + mock = mock_ec2_deprecated() mock.start() conn = boto.connect_ec2('the_key', 'the_secret') list(conn.get_all_instances()).should.equal([]) @@ -54,7 +54,7 @@ def test_decorator_start_and_stop(): conn.get_all_instances() -@mock_ec2 +@mock_ec2_deprecated def test_decorater_wrapped_gets_set(): """ Moto decorator's __wrapped__ should get set to the tests function @@ -62,7 +62,7 @@ def test_decorater_wrapped_gets_set(): test_decorater_wrapped_gets_set.__wrapped__.__name__.should.equal('test_decorater_wrapped_gets_set') -@mock_ec2 +@mock_ec2_deprecated class Tester(object): def test_the_class(self): conn = boto.connect_ec2() @@ -73,7 +73,7 @@ class Tester(object): list(conn.get_all_instances()).should.have.length_of(0) -@mock_s3 +@mock_s3_deprecated class TesterWithSetup(unittest.TestCase): def setUp(self): self.conn = boto.connect_s3() diff --git a/tests/test_core/test_nested.py b/tests/test_core/test_nested.py index 09967d743..7c0b8f687 100644 --- a/tests/test_core/test_nested.py +++ b/tests/test_core/test_nested.py @@ -5,12 +5,12 @@ from boto.sqs.connection import SQSConnection from boto.sqs.message import Message from boto.ec2 import EC2Connection -from moto import mock_sqs, mock_ec2 +from moto import mock_sqs_deprecated, mock_ec2_deprecated class TestNestedDecorators(unittest.TestCase): - @mock_sqs + @mock_sqs_deprecated def setup_sqs_queue(self): conn = SQSConnection() q = conn.create_queue('some-queue') @@ -21,7 +21,7 @@ class TestNestedDecorators(unittest.TestCase): self.assertEqual(q.count(), 1) - @mock_ec2 + @mock_ec2_deprecated def test_nested(self): self.setup_sqs_queue() diff --git a/tests/test_datapipeline/test_datapipeline.py b/tests/test_datapipeline/test_datapipeline.py index 5a958492f..aaa9f7f77 100644 --- a/tests/test_datapipeline/test_datapipeline.py +++ b/tests/test_datapipeline/test_datapipeline.py @@ -3,7 +3,7 @@ from __future__ import unicode_literals import boto.datapipeline import sure # noqa -from moto import mock_datapipeline +from moto import mock_datapipeline_deprecated from moto.datapipeline.utils import remove_capitalization_of_dict_keys @@ -13,7 +13,7 @@ def get_value_from_fields(key, fields): return field['stringValue'] -@mock_datapipeline +@mock_datapipeline_deprecated def test_create_pipeline(): conn = boto.datapipeline.connect_to_region("us-west-2") @@ -78,7 +78,7 @@ PIPELINE_OBJECTS = [ ] -@mock_datapipeline +@mock_datapipeline_deprecated def test_creating_pipeline_definition(): conn = boto.datapipeline.connect_to_region("us-west-2") res = conn.create_pipeline("mypipeline", "some-unique-id") @@ -97,7 +97,7 @@ def test_creating_pipeline_definition(): }]) -@mock_datapipeline +@mock_datapipeline_deprecated def test_describing_pipeline_objects(): conn = boto.datapipeline.connect_to_region("us-west-2") res = conn.create_pipeline("mypipeline", "some-unique-id") @@ -116,7 +116,7 @@ def test_describing_pipeline_objects(): }]) -@mock_datapipeline +@mock_datapipeline_deprecated def test_activate_pipeline(): conn = boto.datapipeline.connect_to_region("us-west-2") @@ -133,7 +133,7 @@ def test_activate_pipeline(): get_value_from_fields('@pipelineState', fields).should.equal("SCHEDULED") -@mock_datapipeline +@mock_datapipeline_deprecated def test_listing_pipelines(): conn = boto.datapipeline.connect_to_region("us-west-2") res1 = conn.create_pipeline("mypipeline1", "some-unique-id1") diff --git a/tests/test_dynamodb/test_dynamodb.py b/tests/test_dynamodb/test_dynamodb.py index 1f85ce4d8..7ea56faa9 100644 --- a/tests/test_dynamodb/test_dynamodb.py +++ b/tests/test_dynamodb/test_dynamodb.py @@ -7,13 +7,13 @@ import requests import tests.backport_assert_raises from nose.tools import assert_raises -from moto import mock_dynamodb +from moto import mock_dynamodb, mock_dynamodb_deprecated from moto.dynamodb import dynamodb_backend from boto.exception import DynamoDBResponseError -@mock_dynamodb +@mock_dynamodb_deprecated def test_list_tables(): name = 'TestTable' dynamodb_backend.create_table(name, hash_key_attr="name", hash_key_type="S") @@ -21,7 +21,7 @@ def test_list_tables(): assert conn.list_tables() == ['TestTable'] -@mock_dynamodb +@mock_dynamodb_deprecated def test_list_tables_layer_1(): dynamodb_backend.create_table("test_1", hash_key_attr="name", hash_key_type="S") dynamodb_backend.create_table("test_2", hash_key_attr="name", hash_key_type="S") @@ -35,7 +35,7 @@ def test_list_tables_layer_1(): res.should.equal(expected) -@mock_dynamodb +@mock_dynamodb_deprecated def test_describe_missing_table(): conn = boto.connect_dynamodb('the_key', 'the_secret') with assert_raises(DynamoDBResponseError): @@ -49,7 +49,7 @@ def test_sts_handler(): res.text.should.contain("SecretAccessKey") -@mock_dynamodb +@mock_dynamodb_deprecated def test_dynamodb_with_connect_to_region(): # this will work if connected with boto.connect_dynamodb() dynamodb = boto.dynamodb.connect_to_region('us-west-2') diff --git a/tests/test_dynamodb/test_dynamodb_table_with_range_key.py b/tests/test_dynamodb/test_dynamodb_table_with_range_key.py index f6ba9b307..c7832b08f 100644 --- a/tests/test_dynamodb/test_dynamodb_table_with_range_key.py +++ b/tests/test_dynamodb/test_dynamodb_table_with_range_key.py @@ -4,7 +4,7 @@ import boto import sure # noqa from freezegun import freeze_time -from moto import mock_dynamodb +from moto import mock_dynamodb_deprecated from boto.dynamodb import condition from boto.dynamodb.exceptions import DynamoDBKeyNotFoundError, DynamoDBValidationError @@ -29,7 +29,7 @@ def create_table(conn): @freeze_time("2012-01-14") -@mock_dynamodb +@mock_dynamodb_deprecated def test_create_table(): conn = boto.connect_dynamodb() create_table(conn) @@ -60,7 +60,7 @@ def test_create_table(): conn.describe_table('messages').should.equal(expected) -@mock_dynamodb +@mock_dynamodb_deprecated def test_delete_table(): conn = boto.connect_dynamodb() create_table(conn) @@ -72,7 +72,7 @@ def test_delete_table(): conn.layer1.delete_table.when.called_with('messages').should.throw(DynamoDBResponseError) -@mock_dynamodb +@mock_dynamodb_deprecated def test_update_table_throughput(): conn = boto.connect_dynamodb() table = create_table(conn) @@ -86,7 +86,7 @@ def test_update_table_throughput(): table.write_units.should.equal(6) -@mock_dynamodb +@mock_dynamodb_deprecated def test_item_add_and_describe_and_update(): conn = boto.connect_dynamodb() table = create_table(conn) @@ -133,7 +133,7 @@ def test_item_add_and_describe_and_update(): }) -@mock_dynamodb +@mock_dynamodb_deprecated def test_item_put_without_table(): conn = boto.connect_dynamodb() @@ -146,7 +146,7 @@ def test_item_put_without_table(): ).should.throw(DynamoDBResponseError) -@mock_dynamodb +@mock_dynamodb_deprecated def test_get_missing_item(): conn = boto.connect_dynamodb() table = create_table(conn) @@ -158,7 +158,7 @@ def test_get_missing_item(): table.has_item("foobar", "more").should.equal(False) -@mock_dynamodb +@mock_dynamodb_deprecated def test_get_item_with_undeclared_table(): conn = boto.connect_dynamodb() @@ -171,7 +171,7 @@ def test_get_item_with_undeclared_table(): ).should.throw(DynamoDBKeyNotFoundError) -@mock_dynamodb +@mock_dynamodb_deprecated def test_get_item_without_range_key(): conn = boto.connect_dynamodb() message_table_schema = conn.create_schema( @@ -195,7 +195,7 @@ def test_get_item_without_range_key(): table.get_item.when.called_with(hash_key=hash_key).should.throw(DynamoDBValidationError) -@mock_dynamodb +@mock_dynamodb_deprecated def test_delete_item(): conn = boto.connect_dynamodb() table = create_table(conn) @@ -223,7 +223,7 @@ def test_delete_item(): item.delete.when.called_with().should.throw(DynamoDBResponseError) -@mock_dynamodb +@mock_dynamodb_deprecated def test_delete_item_with_attribute_response(): conn = boto.connect_dynamodb() table = create_table(conn) @@ -260,7 +260,7 @@ def test_delete_item_with_attribute_response(): item.delete.when.called_with().should.throw(DynamoDBResponseError) -@mock_dynamodb +@mock_dynamodb_deprecated def test_delete_item_with_undeclared_table(): conn = boto.connect_dynamodb() @@ -273,7 +273,7 @@ def test_delete_item_with_undeclared_table(): ).should.throw(DynamoDBResponseError) -@mock_dynamodb +@mock_dynamodb_deprecated def test_query(): conn = boto.connect_dynamodb() table = create_table(conn) @@ -323,7 +323,7 @@ def test_query(): results.response['Items'].should.have.length_of(1) -@mock_dynamodb +@mock_dynamodb_deprecated def test_query_with_undeclared_table(): conn = boto.connect_dynamodb() @@ -339,7 +339,7 @@ def test_query_with_undeclared_table(): ).should.throw(DynamoDBResponseError) -@mock_dynamodb +@mock_dynamodb_deprecated def test_scan(): conn = boto.connect_dynamodb() table = create_table(conn) @@ -402,7 +402,7 @@ def test_scan(): results.response['Items'].should.have.length_of(1) -@mock_dynamodb +@mock_dynamodb_deprecated def test_scan_with_undeclared_table(): conn = boto.connect_dynamodb() @@ -419,7 +419,7 @@ def test_scan_with_undeclared_table(): ).should.throw(DynamoDBResponseError) -@mock_dynamodb +@mock_dynamodb_deprecated def test_scan_after_has_item(): conn = boto.connect_dynamodb() table = create_table(conn) @@ -430,7 +430,7 @@ def test_scan_after_has_item(): list(table.scan()).should.equal([]) -@mock_dynamodb +@mock_dynamodb_deprecated def test_write_batch(): conn = boto.connect_dynamodb() table = create_table(conn) @@ -474,7 +474,7 @@ def test_write_batch(): table.item_count.should.equal(1) -@mock_dynamodb +@mock_dynamodb_deprecated def test_batch_read(): conn = boto.connect_dynamodb() table = create_table(conn) diff --git a/tests/test_dynamodb/test_dynamodb_table_without_range_key.py b/tests/test_dynamodb/test_dynamodb_table_without_range_key.py index fa8492620..18d353928 100644 --- a/tests/test_dynamodb/test_dynamodb_table_without_range_key.py +++ b/tests/test_dynamodb/test_dynamodb_table_without_range_key.py @@ -4,7 +4,7 @@ import boto import sure # noqa from freezegun import freeze_time -from moto import mock_dynamodb +from moto import mock_dynamodb_deprecated from boto.dynamodb import condition from boto.dynamodb.exceptions import DynamoDBKeyNotFoundError @@ -27,7 +27,7 @@ def create_table(conn): @freeze_time("2012-01-14") -@mock_dynamodb +@mock_dynamodb_deprecated def test_create_table(): conn = boto.connect_dynamodb() create_table(conn) @@ -54,7 +54,7 @@ def test_create_table(): conn.describe_table('messages').should.equal(expected) -@mock_dynamodb +@mock_dynamodb_deprecated def test_delete_table(): conn = boto.connect_dynamodb() create_table(conn) @@ -66,7 +66,7 @@ def test_delete_table(): conn.layer1.delete_table.when.called_with('messages').should.throw(DynamoDBResponseError) -@mock_dynamodb +@mock_dynamodb_deprecated def test_update_table_throughput(): conn = boto.connect_dynamodb() table = create_table(conn) @@ -80,7 +80,7 @@ def test_update_table_throughput(): table.write_units.should.equal(6) -@mock_dynamodb +@mock_dynamodb_deprecated def test_item_add_and_describe_and_update(): conn = boto.connect_dynamodb() table = create_table(conn) @@ -120,7 +120,7 @@ def test_item_add_and_describe_and_update(): }) -@mock_dynamodb +@mock_dynamodb_deprecated def test_item_put_without_table(): conn = boto.connect_dynamodb() @@ -132,7 +132,7 @@ def test_item_put_without_table(): ).should.throw(DynamoDBResponseError) -@mock_dynamodb +@mock_dynamodb_deprecated def test_get_missing_item(): conn = boto.connect_dynamodb() table = create_table(conn) @@ -142,7 +142,7 @@ def test_get_missing_item(): ).should.throw(DynamoDBKeyNotFoundError) -@mock_dynamodb +@mock_dynamodb_deprecated def test_get_item_with_undeclared_table(): conn = boto.connect_dynamodb() @@ -154,7 +154,7 @@ def test_get_item_with_undeclared_table(): ).should.throw(DynamoDBKeyNotFoundError) -@mock_dynamodb +@mock_dynamodb_deprecated def test_delete_item(): conn = boto.connect_dynamodb() table = create_table(conn) @@ -181,7 +181,7 @@ def test_delete_item(): item.delete.when.called_with().should.throw(DynamoDBResponseError) -@mock_dynamodb +@mock_dynamodb_deprecated def test_delete_item_with_attribute_response(): conn = boto.connect_dynamodb() table = create_table(conn) @@ -216,7 +216,7 @@ def test_delete_item_with_attribute_response(): item.delete.when.called_with().should.throw(DynamoDBResponseError) -@mock_dynamodb +@mock_dynamodb_deprecated def test_delete_item_with_undeclared_table(): conn = boto.connect_dynamodb() @@ -228,7 +228,7 @@ def test_delete_item_with_undeclared_table(): ).should.throw(DynamoDBResponseError) -@mock_dynamodb +@mock_dynamodb_deprecated def test_query(): conn = boto.connect_dynamodb() table = create_table(conn) @@ -248,7 +248,7 @@ def test_query(): results.response['Items'].should.have.length_of(1) -@mock_dynamodb +@mock_dynamodb_deprecated def test_query_with_undeclared_table(): conn = boto.connect_dynamodb() @@ -258,7 +258,7 @@ def test_query_with_undeclared_table(): ).should.throw(DynamoDBResponseError) -@mock_dynamodb +@mock_dynamodb_deprecated def test_scan(): conn = boto.connect_dynamodb() table = create_table(conn) @@ -318,7 +318,7 @@ def test_scan(): results.response['Items'].should.have.length_of(1) -@mock_dynamodb +@mock_dynamodb_deprecated def test_scan_with_undeclared_table(): conn = boto.connect_dynamodb() @@ -335,7 +335,7 @@ def test_scan_with_undeclared_table(): ).should.throw(DynamoDBResponseError) -@mock_dynamodb +@mock_dynamodb_deprecated def test_scan_after_has_item(): conn = boto.connect_dynamodb() table = create_table(conn) @@ -346,7 +346,7 @@ def test_scan_after_has_item(): list(table.scan()).should.equal([]) -@mock_dynamodb +@mock_dynamodb_deprecated def test_write_batch(): conn = boto.connect_dynamodb() table = create_table(conn) @@ -388,7 +388,7 @@ def test_write_batch(): table.item_count.should.equal(1) -@mock_dynamodb +@mock_dynamodb_deprecated def test_batch_read(): conn = boto.connect_dynamodb() table = create_table(conn) diff --git a/tests/test_dynamodb2/test_dynamodb.py b/tests/test_dynamodb2/test_dynamodb.py index 552611fa6..d66d36d9f 100644 --- a/tests/test_dynamodb2/test_dynamodb.py +++ b/tests/test_dynamodb2/test_dynamodb.py @@ -4,7 +4,7 @@ import six import boto import sure # noqa import requests -from moto import mock_dynamodb2 +from moto import mock_dynamodb2, mock_dynamodb2_deprecated from moto.dynamodb2 import dynamodb_backend2 from boto.exception import JSONResponseError from tests.helpers import requires_boto_gte @@ -16,7 +16,7 @@ except ImportError: print("This boto version is not supported") @requires_boto_gte("2.9") -@mock_dynamodb2 +@mock_dynamodb2_deprecated def test_list_tables(): name = 'TestTable' #{'schema': } @@ -32,7 +32,7 @@ def test_list_tables(): @requires_boto_gte("2.9") -@mock_dynamodb2 +@mock_dynamodb2_deprecated def test_list_tables_layer_1(): dynamodb_backend2.create_table("test_1",schema=[ {u'KeyType': u'HASH', u'AttributeName': u'name'} @@ -55,7 +55,7 @@ def test_list_tables_layer_1(): @requires_boto_gte("2.9") -@mock_dynamodb2 +@mock_dynamodb2_deprecated def test_describe_missing_table(): conn = boto.dynamodb2.connect_to_region( 'us-west-2', diff --git a/tests/test_dynamodb2/test_dynamodb_table_with_range_key.py b/tests/test_dynamodb2/test_dynamodb_table_with_range_key.py index 7e4403daa..029506378 100644 --- a/tests/test_dynamodb2/test_dynamodb_table_with_range_key.py +++ b/tests/test_dynamodb2/test_dynamodb_table_with_range_key.py @@ -7,7 +7,7 @@ import boto3 from boto3.dynamodb.conditions import Key import sure # noqa from freezegun import freeze_time -from moto import mock_dynamodb2 +from moto import mock_dynamodb2, mock_dynamodb2_deprecated from boto.exception import JSONResponseError from tests.helpers import requires_boto_gte try: @@ -61,7 +61,7 @@ def iterate_results(res): @requires_boto_gte("2.9") -@mock_dynamodb2 +@mock_dynamodb2_deprecated @freeze_time("2012-01-14") def test_create_table(): table = create_table() @@ -90,7 +90,7 @@ def test_create_table(): @requires_boto_gte("2.9") -@mock_dynamodb2 +@mock_dynamodb2_deprecated @freeze_time("2012-01-14") def test_create_table_with_local_index(): table = create_table_with_local_indexes() @@ -132,7 +132,7 @@ def test_create_table_with_local_index(): @requires_boto_gte("2.9") -@mock_dynamodb2 +@mock_dynamodb2_deprecated def test_delete_table(): conn = boto.dynamodb2.layer1.DynamoDBConnection() table = create_table() @@ -144,7 +144,7 @@ def test_delete_table(): @requires_boto_gte("2.9") -@mock_dynamodb2 +@mock_dynamodb2_deprecated def test_update_table_throughput(): table = create_table() table.throughput["read"].should.equal(10) @@ -169,7 +169,7 @@ def test_update_table_throughput(): @requires_boto_gte("2.9") -@mock_dynamodb2 +@mock_dynamodb2_deprecated def test_item_add_and_describe_and_update(): table = create_table() ok = table.put_item(data={ @@ -212,7 +212,7 @@ def test_item_add_and_describe_and_update(): @requires_boto_gte("2.9") -@mock_dynamodb2 +@mock_dynamodb2_deprecated def test_item_partial_save(): table = create_table() @@ -242,7 +242,7 @@ def test_item_partial_save(): @requires_boto_gte("2.9") -@mock_dynamodb2 +@mock_dynamodb2_deprecated def test_item_put_without_table(): table = Table('undeclared-table') item_data = { @@ -256,7 +256,7 @@ def test_item_put_without_table(): @requires_boto_gte("2.9") -@mock_dynamodb2 +@mock_dynamodb2_deprecated def test_get_missing_item(): table = create_table() @@ -267,14 +267,14 @@ def test_get_missing_item(): @requires_boto_gte("2.9") -@mock_dynamodb2 +@mock_dynamodb2_deprecated def test_get_item_with_undeclared_table(): table = Table('undeclared-table') table.get_item.when.called_with(test_hash=3241526475).should.throw(JSONResponseError) @requires_boto_gte("2.9") -@mock_dynamodb2 +@mock_dynamodb2_deprecated def test_get_item_without_range_key(): table = Table.create('messages', schema=[ HashKey('test_hash'), @@ -291,7 +291,7 @@ def test_get_item_without_range_key(): @requires_boto_gte("2.30.0") -@mock_dynamodb2 +@mock_dynamodb2_deprecated def test_delete_item(): table = create_table() item_data = { @@ -313,7 +313,7 @@ def test_delete_item(): @requires_boto_gte("2.9") -@mock_dynamodb2 +@mock_dynamodb2_deprecated def test_delete_item_with_undeclared_table(): table = Table("undeclared-table") item_data = { @@ -327,7 +327,7 @@ def test_delete_item_with_undeclared_table(): @requires_boto_gte("2.9") -@mock_dynamodb2 +@mock_dynamodb2_deprecated def test_query(): table = create_table() @@ -384,7 +384,7 @@ def test_query(): @requires_boto_gte("2.9") -@mock_dynamodb2 +@mock_dynamodb2_deprecated def test_query_with_undeclared_table(): table = Table('undeclared') results = table.query( @@ -396,7 +396,7 @@ def test_query_with_undeclared_table(): @requires_boto_gte("2.9") -@mock_dynamodb2 +@mock_dynamodb2_deprecated def test_scan(): table = create_table() item_data = { @@ -451,7 +451,7 @@ def test_scan(): @requires_boto_gte("2.9") -@mock_dynamodb2 +@mock_dynamodb2_deprecated def test_scan_with_undeclared_table(): conn = boto.dynamodb2.layer1.DynamoDBConnection() conn.scan.when.called_with( @@ -468,7 +468,7 @@ def test_scan_with_undeclared_table(): @requires_boto_gte("2.9") -@mock_dynamodb2 +@mock_dynamodb2_deprecated def test_write_batch(): table = create_table() with table.batch_write() as batch: @@ -498,7 +498,7 @@ def test_write_batch(): @requires_boto_gte("2.9") -@mock_dynamodb2 +@mock_dynamodb2_deprecated def test_batch_read(): table = create_table() item_data = { @@ -542,14 +542,14 @@ def test_batch_read(): @requires_boto_gte("2.9") -@mock_dynamodb2 +@mock_dynamodb2_deprecated def test_get_key_fields(): table = create_table() kf = table.get_key_fields() kf.should.equal(['forum_name', 'subject']) -@mock_dynamodb2 +@mock_dynamodb2_deprecated def test_create_with_global_indexes(): conn = boto.dynamodb2.layer1.DynamoDBConnection() @@ -594,7 +594,7 @@ def test_create_with_global_indexes(): ]) -@mock_dynamodb2 +@mock_dynamodb2_deprecated def test_query_with_global_indexes(): table = Table.create('messages', schema=[ HashKey('subject'), @@ -638,7 +638,7 @@ def test_query_with_global_indexes(): list(results).should.have.length_of(0) -@mock_dynamodb2 +@mock_dynamodb2_deprecated def test_query_with_local_indexes(): table = create_table_with_local_indexes() item_data = { @@ -658,7 +658,7 @@ def test_query_with_local_indexes(): @requires_boto_gte("2.9") -@mock_dynamodb2 +@mock_dynamodb2_deprecated def test_query_filter_eq(): table = create_table_with_local_indexes() item_data = [ @@ -691,7 +691,7 @@ def test_query_filter_eq(): @requires_boto_gte("2.9") -@mock_dynamodb2 +@mock_dynamodb2_deprecated def test_query_filter_lt(): table = create_table_with_local_indexes() item_data = [ @@ -726,7 +726,7 @@ def test_query_filter_lt(): @requires_boto_gte("2.9") -@mock_dynamodb2 +@mock_dynamodb2_deprecated def test_query_filter_gt(): table = create_table_with_local_indexes() item_data = [ @@ -760,7 +760,7 @@ def test_query_filter_gt(): @requires_boto_gte("2.9") -@mock_dynamodb2 +@mock_dynamodb2_deprecated def test_query_filter_lte(): table = create_table_with_local_indexes() item_data = [ @@ -794,7 +794,7 @@ def test_query_filter_lte(): @requires_boto_gte("2.9") -@mock_dynamodb2 +@mock_dynamodb2_deprecated def test_query_filter_gte(): table = create_table_with_local_indexes() item_data = [ @@ -827,7 +827,7 @@ def test_query_filter_gte(): list(results).should.have.length_of(2) -@mock_dynamodb2 +@mock_dynamodb2_deprecated def test_reverse_query(): conn = boto.dynamodb2.layer1.DynamoDBConnection() @@ -851,7 +851,7 @@ def test_reverse_query(): [r['created_at'] for r in results].should.equal(expected) -@mock_dynamodb2 +@mock_dynamodb2_deprecated def test_lookup(): from decimal import Decimal table = Table.create('messages', schema=[ @@ -871,7 +871,7 @@ def test_lookup(): message.get('test_range').should.equal(Decimal(range_key)) -@mock_dynamodb2 +@mock_dynamodb2_deprecated def test_failed_overwrite(): table = Table.create('messages', schema=[ HashKey('id'), @@ -900,7 +900,7 @@ def test_failed_overwrite(): dict(returned_item).should.equal(data4) -@mock_dynamodb2 +@mock_dynamodb2_deprecated def test_conflicting_writes(): table = Table.create('messages', schema=[ HashKey('id'), diff --git a/tests/test_dynamodb2/test_dynamodb_table_without_range_key.py b/tests/test_dynamodb2/test_dynamodb_table_without_range_key.py index 691e14818..83eff6519 100644 --- a/tests/test_dynamodb2/test_dynamodb_table_without_range_key.py +++ b/tests/test_dynamodb2/test_dynamodb_table_without_range_key.py @@ -6,7 +6,7 @@ from boto3.dynamodb.conditions import Key import sure # noqa from freezegun import freeze_time from boto.exception import JSONResponseError -from moto import mock_dynamodb2 +from moto import mock_dynamodb2, mock_dynamodb2_deprecated from tests.helpers import requires_boto_gte import botocore try: @@ -29,7 +29,7 @@ def create_table(): @requires_boto_gte("2.9") -@mock_dynamodb2 +@mock_dynamodb2_deprecated @freeze_time("2012-01-14") def test_create_table(): create_table() @@ -62,7 +62,7 @@ def test_create_table(): @requires_boto_gte("2.9") -@mock_dynamodb2 +@mock_dynamodb2_deprecated def test_delete_table(): create_table() conn = boto.dynamodb2.layer1.DynamoDBConnection() @@ -75,7 +75,7 @@ def test_delete_table(): @requires_boto_gte("2.9") -@mock_dynamodb2 +@mock_dynamodb2_deprecated def test_update_table_throughput(): table = create_table() table.throughput["read"].should.equal(10) @@ -91,7 +91,7 @@ def test_update_table_throughput(): @requires_boto_gte("2.9") -@mock_dynamodb2 +@mock_dynamodb2_deprecated def test_item_add_and_describe_and_update(): table = create_table() @@ -125,7 +125,7 @@ def test_item_add_and_describe_and_update(): @requires_boto_gte("2.9") -@mock_dynamodb2 +@mock_dynamodb2_deprecated def test_item_partial_save(): table = create_table() @@ -152,7 +152,7 @@ def test_item_partial_save(): @requires_boto_gte("2.9") -@mock_dynamodb2 +@mock_dynamodb2_deprecated def test_item_put_without_table(): conn = boto.dynamodb2.layer1.DynamoDBConnection() @@ -167,7 +167,7 @@ def test_item_put_without_table(): @requires_boto_gte("2.9") -@mock_dynamodb2 +@mock_dynamodb2_deprecated def test_get_item_with_undeclared_table(): conn = boto.dynamodb2.layer1.DynamoDBConnection() @@ -178,7 +178,7 @@ def test_get_item_with_undeclared_table(): @requires_boto_gte("2.30.0") -@mock_dynamodb2 +@mock_dynamodb2_deprecated def test_delete_item(): table = create_table() @@ -202,7 +202,7 @@ def test_delete_item(): @requires_boto_gte("2.9") -@mock_dynamodb2 +@mock_dynamodb2_deprecated def test_delete_item_with_undeclared_table(): conn = boto.dynamodb2.layer1.DynamoDBConnection() @@ -213,7 +213,7 @@ def test_delete_item_with_undeclared_table(): @requires_boto_gte("2.9") -@mock_dynamodb2 +@mock_dynamodb2_deprecated def test_query(): table = create_table() @@ -233,7 +233,7 @@ def test_query(): @requires_boto_gte("2.9") -@mock_dynamodb2 +@mock_dynamodb2_deprecated def test_query_with_undeclared_table(): conn = boto.dynamodb2.layer1.DynamoDBConnection() @@ -244,7 +244,7 @@ def test_query_with_undeclared_table(): @requires_boto_gte("2.9") -@mock_dynamodb2 +@mock_dynamodb2_deprecated def test_scan(): table = create_table() @@ -295,7 +295,7 @@ def test_scan(): @requires_boto_gte("2.9") -@mock_dynamodb2 +@mock_dynamodb2_deprecated def test_scan_with_undeclared_table(): conn = boto.dynamodb2.layer1.DynamoDBConnection() @@ -313,7 +313,7 @@ def test_scan_with_undeclared_table(): @requires_boto_gte("2.9") -@mock_dynamodb2 +@mock_dynamodb2_deprecated def test_write_batch(): table = create_table() @@ -344,7 +344,7 @@ def test_write_batch(): @requires_boto_gte("2.9") -@mock_dynamodb2 +@mock_dynamodb2_deprecated def test_batch_read(): table = create_table() @@ -385,7 +385,7 @@ def test_batch_read(): @requires_boto_gte("2.9") -@mock_dynamodb2 +@mock_dynamodb2_deprecated def test_get_key_fields(): table = create_table() kf = table.get_key_fields() @@ -393,14 +393,14 @@ def test_get_key_fields(): @requires_boto_gte("2.9") -@mock_dynamodb2 +@mock_dynamodb2_deprecated def test_get_missing_item(): table = create_table() table.get_item.when.called_with(forum_name='missing').should.throw(ItemNotFound) @requires_boto_gte("2.9") -@mock_dynamodb2 +@mock_dynamodb2_deprecated def test_get_special_item(): table = Table.create('messages', schema=[ HashKey('date-joined') @@ -418,7 +418,7 @@ def test_get_special_item(): dict(returned_item).should.equal(data) -@mock_dynamodb2 +@mock_dynamodb2_deprecated def test_update_item_remove(): conn = boto.dynamodb2.connect_to_region("us-west-2") table = Table.create('messages', schema=[ @@ -444,7 +444,7 @@ def test_update_item_remove(): }) -@mock_dynamodb2 +@mock_dynamodb2_deprecated def test_update_item_set(): conn = boto.dynamodb2.connect_to_region("us-west-2") table = Table.create('messages', schema=[ @@ -471,7 +471,7 @@ def test_update_item_set(): -@mock_dynamodb2 +@mock_dynamodb2_deprecated def test_failed_overwrite(): table = Table.create('messages', schema=[ HashKey('id'), @@ -499,7 +499,7 @@ def test_failed_overwrite(): dict(returned_item).should.equal(data4) -@mock_dynamodb2 +@mock_dynamodb2_deprecated def test_conflicting_writes(): table = Table.create('messages', schema=[ HashKey('id'), diff --git a/tests/test_ec2/test_amis.py b/tests/test_ec2/test_amis.py index 095979f74..9c3fbd40d 100755 --- a/tests/test_ec2/test_amis.py +++ b/tests/test_ec2/test_amis.py @@ -9,11 +9,11 @@ from boto.exception import EC2ResponseError, JSONResponseError import sure # noqa -from moto import mock_ec2 +from moto import mock_emr_deprecated from tests.helpers import requires_boto_gte -@mock_ec2 +@mock_emr_deprecated def test_ami_create_and_delete(): conn = boto.connect_ec2('the_key', 'the_secret') reservation = conn.run_instances('ami-1234abcd') @@ -69,7 +69,7 @@ def test_ami_create_and_delete(): @requires_boto_gte("2.14.0") -@mock_ec2 +@mock_emr_deprecated def test_ami_copy(): conn = boto.ec2.connect_to_region("us-west-1") reservation = conn.run_instances('ami-1234abcd') @@ -119,7 +119,7 @@ def test_ami_copy(): cm.exception.request_id.should_not.be.none -@mock_ec2 +@mock_emr_deprecated def test_ami_tagging(): conn = boto.connect_vpc('the_key', 'the_secret') reservation = conn.run_instances('ami-1234abcd') @@ -145,7 +145,7 @@ def test_ami_tagging(): image.tags["a key"].should.equal("some value") -@mock_ec2 +@mock_emr_deprecated def test_ami_create_from_missing_instance(): conn = boto.connect_ec2('the_key', 'the_secret') args = ["i-abcdefg", "test-ami", "this is a test ami"] @@ -157,7 +157,7 @@ def test_ami_create_from_missing_instance(): cm.exception.request_id.should_not.be.none -@mock_ec2 +@mock_emr_deprecated def test_ami_pulls_attributes_from_instance(): conn = boto.connect_ec2('the_key', 'the_secret') reservation = conn.run_instances('ami-1234abcd') @@ -169,7 +169,7 @@ def test_ami_pulls_attributes_from_instance(): image.kernel_id.should.equal('test-kernel') -@mock_ec2 +@mock_emr_deprecated def test_ami_filters(): conn = boto.connect_ec2('the_key', 'the_secret') @@ -220,7 +220,7 @@ def test_ami_filters(): set([ami.id for ami in amis_by_nonpublic]).should.equal(set([imageA.id])) -@mock_ec2 +@mock_emr_deprecated def test_ami_filtering_via_tag(): conn = boto.connect_vpc('the_key', 'the_secret') @@ -243,7 +243,7 @@ def test_ami_filtering_via_tag(): set([ami.id for ami in amis_by_tagB]).should.equal(set([imageB.id])) -@mock_ec2 +@mock_emr_deprecated def test_getting_missing_ami(): conn = boto.connect_ec2('the_key', 'the_secret') @@ -254,7 +254,7 @@ def test_getting_missing_ami(): cm.exception.request_id.should_not.be.none -@mock_ec2 +@mock_emr_deprecated def test_getting_malformed_ami(): conn = boto.connect_ec2('the_key', 'the_secret') @@ -265,7 +265,7 @@ def test_getting_malformed_ami(): cm.exception.request_id.should_not.be.none -@mock_ec2 +@mock_emr_deprecated def test_ami_attribute_group_permissions(): conn = boto.connect_ec2('the_key', 'the_secret') reservation = conn.run_instances('ami-1234abcd') @@ -318,7 +318,7 @@ def test_ami_attribute_group_permissions(): conn.modify_image_attribute.when.called_with(**REMOVE_GROUP_ARGS).should_not.throw(EC2ResponseError) -@mock_ec2 +@mock_emr_deprecated def test_ami_attribute_user_permissions(): conn = boto.connect_ec2('the_key', 'the_secret') reservation = conn.run_instances('ami-1234abcd') @@ -383,7 +383,7 @@ def test_ami_attribute_user_permissions(): conn.modify_image_attribute.when.called_with(**REMOVE_USERS_ARGS).should_not.throw(EC2ResponseError) -@mock_ec2 +@mock_emr_deprecated def test_ami_attribute_user_and_group_permissions(): """ Boto supports adding/removing both users and groups at the same time. @@ -435,7 +435,7 @@ def test_ami_attribute_user_and_group_permissions(): image.is_public.should.equal(False) -@mock_ec2 +@mock_emr_deprecated def test_ami_attribute_error_cases(): conn = boto.connect_ec2('the_key', 'the_secret') reservation = conn.run_instances('ami-1234abcd') diff --git a/tests/test_ec2/test_availability_zones_and_regions.py b/tests/test_ec2/test_availability_zones_and_regions.py index 88453e10b..7226cacaf 100644 --- a/tests/test_ec2/test_availability_zones_and_regions.py +++ b/tests/test_ec2/test_availability_zones_and_regions.py @@ -4,10 +4,10 @@ import boto.ec2 import boto3 import sure # noqa -from moto import mock_ec2 +from moto import mock_ec2, mock_ec2_deprecated -@mock_ec2 +@mock_ec2_deprecated def test_describe_regions(): conn = boto.connect_ec2('the_key', 'the_secret') regions = conn.get_all_regions() @@ -16,7 +16,7 @@ def test_describe_regions(): region.endpoint.should.contain(region.name) -@mock_ec2 +@mock_ec2_deprecated def test_availability_zones(): conn = boto.connect_ec2('the_key', 'the_secret') regions = conn.get_all_regions() diff --git a/tests/test_ec2/test_customer_gateways.py b/tests/test_ec2/test_customer_gateways.py index efd6ce993..93e35dc6a 100644 --- a/tests/test_ec2/test_customer_gateways.py +++ b/tests/test_ec2/test_customer_gateways.py @@ -5,10 +5,10 @@ from nose.tools import assert_raises from nose.tools import assert_false from boto.exception import EC2ResponseError -from moto import mock_ec2 +from moto import mock_ec2_deprecated -@mock_ec2 +@mock_ec2_deprecated def test_create_customer_gateways(): conn = boto.connect_vpc('the_key', 'the_secret') @@ -19,7 +19,7 @@ def test_create_customer_gateways(): customer_gateway.bgp_asn.should.equal(65534) customer_gateway.ip_address.should.equal('205.251.242.54') -@mock_ec2 +@mock_ec2_deprecated def test_describe_customer_gateways(): conn = boto.connect_vpc('the_key', 'the_secret') customer_gateway = conn.create_customer_gateway('ipsec.1', '205.251.242.54', 65534) @@ -27,7 +27,7 @@ def test_describe_customer_gateways(): cgws.should.have.length_of(1) cgws[0].id.should.match(customer_gateway.id) -@mock_ec2 +@mock_ec2_deprecated def test_delete_customer_gateways(): conn = boto.connect_vpc('the_key', 'the_secret') @@ -39,7 +39,7 @@ def test_delete_customer_gateways(): cgws = conn.get_all_customer_gateways() cgws.should.have.length_of(0) -@mock_ec2 +@mock_ec2_deprecated def test_delete_customer_gateways_bad_id(): conn = boto.connect_vpc('the_key', 'the_secret') with assert_raises(EC2ResponseError) as cm: diff --git a/tests/test_ec2/test_dhcp_options.py b/tests/test_ec2/test_dhcp_options.py index ef671ec11..0279a3d54 100644 --- a/tests/test_ec2/test_dhcp_options.py +++ b/tests/test_ec2/test_dhcp_options.py @@ -9,13 +9,13 @@ from boto.exception import EC2ResponseError import sure # noqa -from moto import mock_ec2 +from moto import mock_ec2, mock_ec2_deprecated SAMPLE_DOMAIN_NAME = u'example.com' SAMPLE_NAME_SERVERS = [u'10.0.0.6', u'10.0.0.7'] -@mock_ec2 +@mock_ec2_deprecated def test_dhcp_options_associate(): """ associate dhcp option """ conn = boto.connect_vpc('the_key', 'the_secret') @@ -26,7 +26,7 @@ def test_dhcp_options_associate(): rval.should.be.equal(True) -@mock_ec2 +@mock_ec2_deprecated def test_dhcp_options_associate_invalid_dhcp_id(): """ associate dhcp option bad dhcp options id """ conn = boto.connect_vpc('the_key', 'the_secret') @@ -39,7 +39,7 @@ def test_dhcp_options_associate_invalid_dhcp_id(): cm.exception.request_id.should_not.be.none -@mock_ec2 +@mock_ec2_deprecated def test_dhcp_options_associate_invalid_vpc_id(): """ associate dhcp option invalid vpc id """ conn = boto.connect_vpc('the_key', 'the_secret') @@ -52,7 +52,7 @@ def test_dhcp_options_associate_invalid_vpc_id(): cm.exception.request_id.should_not.be.none -@mock_ec2 +@mock_ec2_deprecated def test_dhcp_options_delete_with_vpc(): """Test deletion of dhcp options with vpc""" conn = boto.connect_vpc('the_key', 'the_secret') @@ -78,7 +78,7 @@ def test_dhcp_options_delete_with_vpc(): cm.exception.request_id.should_not.be.none -@mock_ec2 +@mock_ec2_deprecated def test_create_dhcp_options(): """Create most basic dhcp option""" conn = boto.connect_vpc('the_key', 'the_secret') @@ -89,7 +89,7 @@ def test_create_dhcp_options(): dhcp_option.options[u'domain-name-servers'][1].should.be.equal(SAMPLE_NAME_SERVERS[1]) -@mock_ec2 +@mock_ec2_deprecated def test_create_dhcp_options_invalid_options(): """Create invalid dhcp options""" conn = boto.connect_vpc('the_key', 'the_secret') @@ -108,7 +108,7 @@ def test_create_dhcp_options_invalid_options(): cm.exception.request_id.should_not.be.none -@mock_ec2 +@mock_ec2_deprecated def test_describe_dhcp_options(): """Test dhcp options lookup by id""" conn = boto.connect_vpc('the_key', 'the_secret') @@ -121,7 +121,7 @@ def test_describe_dhcp_options(): dhcp_options.should.be.length_of(1) -@mock_ec2 +@mock_ec2_deprecated def test_describe_dhcp_options_invalid_id(): """get error on invalid dhcp_option_id lookup""" conn = boto.connect_vpc('the_key', 'the_secret') @@ -133,7 +133,7 @@ def test_describe_dhcp_options_invalid_id(): cm.exception.request_id.should_not.be.none -@mock_ec2 +@mock_ec2_deprecated def test_delete_dhcp_options(): """delete dhcp option""" conn = boto.connect_vpc('the_key', 'the_secret') @@ -151,7 +151,7 @@ def test_delete_dhcp_options(): cm.exception.request_id.should_not.be.none -@mock_ec2 +@mock_ec2_deprecated def test_delete_dhcp_options_invalid_id(): conn = boto.connect_vpc('the_key', 'the_secret') @@ -164,7 +164,7 @@ def test_delete_dhcp_options_invalid_id(): cm.exception.request_id.should_not.be.none -@mock_ec2 +@mock_ec2_deprecated def test_delete_dhcp_options_malformed_id(): conn = boto.connect_vpc('the_key', 'the_secret') @@ -177,7 +177,7 @@ def test_delete_dhcp_options_malformed_id(): cm.exception.request_id.should_not.be.none -@mock_ec2 +@mock_ec2_deprecated def test_dhcp_tagging(): conn = boto.connect_vpc('the_key', 'the_secret') dhcp_option = conn.create_dhcp_options() @@ -194,7 +194,7 @@ def test_dhcp_tagging(): dhcp_option.tags["a key"].should.equal("some value") -@mock_ec2 +@mock_ec2_deprecated def test_dhcp_options_get_by_tag(): conn = boto.connect_vpc('the_key', 'the_secret') @@ -230,7 +230,7 @@ def test_dhcp_options_get_by_tag(): dhcp_options_sets.should.have.length_of(2) -@mock_ec2 +@mock_ec2_deprecated def test_dhcp_options_get_by_id(): conn = boto.connect_vpc('the_key', 'the_secret') @@ -308,7 +308,7 @@ def test_dhcp_options_get_by_key_filter(): dhcp_options_sets.should.have.length_of(3) -@mock_ec2 +@mock_ec2_deprecated def test_dhcp_options_get_by_invalid_filter(): conn = boto.connect_vpc('the_key', 'the_secret') diff --git a/tests/test_ec2/test_elastic_block_store.py b/tests/test_ec2/test_elastic_block_store.py index f99cef5e4..c4794b1c8 100644 --- a/tests/test_ec2/test_elastic_block_store.py +++ b/tests/test_ec2/test_elastic_block_store.py @@ -8,10 +8,10 @@ import boto from boto.exception import EC2ResponseError, JSONResponseError import sure # noqa -from moto import mock_ec2 +from moto import mock_ec2_deprecated -@mock_ec2 +@mock_ec2_deprecated def test_create_and_delete_volume(): conn = boto.connect_ec2('the_key', 'the_secret') volume = conn.create_volume(80, "us-east-1a") @@ -43,7 +43,7 @@ def test_create_and_delete_volume(): -@mock_ec2 +@mock_ec2_deprecated def test_create_encrypted_volume_dryrun(): conn = boto.connect_ec2('the_key', 'the_secret') with assert_raises(JSONResponseError) as ex: @@ -53,7 +53,7 @@ def test_create_encrypted_volume_dryrun(): ex.exception.message.should.equal('An error occurred (DryRunOperation) when calling the CreateVolume operation: Request would have succeeded, but DryRun flag is set') -@mock_ec2 +@mock_ec2_deprecated def test_create_encrypted_volume(): conn = boto.connect_ec2('the_key', 'the_secret') conn.create_volume(80, "us-east-1a", encrypted=True) @@ -68,7 +68,7 @@ def test_create_encrypted_volume(): all_volumes[0].encrypted.should.be(True) -@mock_ec2 +@mock_ec2_deprecated def test_filter_volume_by_id(): conn = boto.connect_ec2('the_key', 'the_secret') volume1 = conn.create_volume(80, "us-east-1a") @@ -82,7 +82,7 @@ def test_filter_volume_by_id(): vol2.should.have.length_of(2) -@mock_ec2 +@mock_ec2_deprecated def test_volume_filters(): conn = boto.connect_ec2('the_key', 'the_secret') @@ -155,7 +155,7 @@ def test_volume_filters(): ) -@mock_ec2 +@mock_ec2_deprecated def test_volume_attach_and_detach(): conn = boto.connect_ec2('the_key', 'the_secret') reservation = conn.run_instances('ami-1234abcd') @@ -209,7 +209,7 @@ def test_volume_attach_and_detach(): cm3.exception.request_id.should_not.be.none -@mock_ec2 +@mock_ec2_deprecated def test_create_snapshot(): conn = boto.connect_ec2('the_key', 'the_secret') volume = conn.create_volume(80, "us-east-1a") @@ -245,7 +245,7 @@ def test_create_snapshot(): cm.exception.request_id.should_not.be.none -@mock_ec2 +@mock_ec2_deprecated def test_create_encrypted_snapshot(): conn = boto.connect_ec2('the_key', 'the_secret') volume = conn.create_volume(80, "us-east-1a", encrypted=True) @@ -260,7 +260,7 @@ def test_create_encrypted_snapshot(): snapshots[0].encrypted.should.be(True) -@mock_ec2 +@mock_ec2_deprecated def test_filter_snapshot_by_id(): conn = boto.connect_ec2('the_key', 'the_secret') volume1 = conn.create_volume(36, "us-east-1a") @@ -281,7 +281,7 @@ def test_filter_snapshot_by_id(): s.region.name.should.equal(conn.region.name) -@mock_ec2 +@mock_ec2_deprecated def test_snapshot_filters(): conn = boto.connect_ec2('the_key', 'the_secret') volume1 = conn.create_volume(20, "us-east-1a", encrypted=False) @@ -322,7 +322,7 @@ def test_snapshot_filters(): set([snap.id for snap in snapshots_by_encrypted]).should.equal(set([snapshot3.id])) -@mock_ec2 +@mock_ec2_deprecated def test_snapshot_attribute(): import copy @@ -418,7 +418,7 @@ def test_snapshot_attribute(): user_ids=['user']).should.throw(NotImplementedError) -@mock_ec2 +@mock_ec2_deprecated def test_create_volume_from_snapshot(): conn = boto.connect_ec2('the_key', 'the_secret') volume = conn.create_volume(80, "us-east-1a") @@ -439,7 +439,7 @@ def test_create_volume_from_snapshot(): new_volume.snapshot_id.should.equal(snapshot.id) -@mock_ec2 +@mock_ec2_deprecated def test_create_volume_from_encrypted_snapshot(): conn = boto.connect_ec2('the_key', 'the_secret') volume = conn.create_volume(80, "us-east-1a", encrypted=True) @@ -454,7 +454,7 @@ def test_create_volume_from_encrypted_snapshot(): new_volume.encrypted.should.be(True) -@mock_ec2 +@mock_ec2_deprecated def test_modify_attribute_blockDeviceMapping(): """ Reproduces the missing feature explained at [0], where we want to mock a @@ -481,7 +481,7 @@ def test_modify_attribute_blockDeviceMapping(): instance.block_device_mapping['/dev/sda1'].delete_on_termination.should.be(True) -@mock_ec2 +@mock_ec2_deprecated def test_volume_tag_escaping(): conn = boto.connect_ec2('the_key', 'the_secret') vol = conn.create_volume(10, 'us-east-1a') diff --git a/tests/test_ec2/test_elastic_ip_addresses.py b/tests/test_ec2/test_elastic_ip_addresses.py index df939a313..dc7910379 100644 --- a/tests/test_ec2/test_elastic_ip_addresses.py +++ b/tests/test_ec2/test_elastic_ip_addresses.py @@ -10,12 +10,12 @@ import six import sure # noqa -from moto import mock_ec2 +from moto import mock_ec2, mock_ec2_deprecated import logging -@mock_ec2 +@mock_ec2_deprecated def test_eip_allocate_classic(): """Allocate/release Classic EIP""" conn = boto.connect_ec2('the_key', 'the_secret') @@ -42,7 +42,7 @@ def test_eip_allocate_classic(): standard.should_not.be.within(conn.get_all_addresses()) -@mock_ec2 +@mock_ec2_deprecated def test_eip_allocate_vpc(): """Allocate/release VPC EIP""" conn = boto.connect_ec2('the_key', 'the_secret') @@ -60,7 +60,7 @@ def test_eip_allocate_vpc(): vpc.release() -@mock_ec2 +@mock_ec2_deprecated def test_eip_allocate_invalid_domain(): """Allocate EIP invalid domain""" conn = boto.connect_ec2('the_key', 'the_secret') @@ -72,7 +72,7 @@ def test_eip_allocate_invalid_domain(): cm.exception.request_id.should_not.be.none -@mock_ec2 +@mock_ec2_deprecated def test_eip_associate_classic(): """Associate/Disassociate EIP to classic instance""" conn = boto.connect_ec2('the_key', 'the_secret') @@ -114,7 +114,7 @@ def test_eip_associate_classic(): instance.terminate() -@mock_ec2 +@mock_ec2_deprecated def test_eip_associate_vpc(): """Associate/Disassociate EIP to VPC instance""" conn = boto.connect_ec2('the_key', 'the_secret') @@ -176,7 +176,7 @@ def test_eip_boto3_vpc_association(): instance.public_dns_name.should_not.be.none -@mock_ec2 +@mock_ec2_deprecated def test_eip_associate_network_interface(): """Associate/Disassociate EIP to NIC""" conn = boto.connect_vpc('the_key', 'the_secret') @@ -204,7 +204,7 @@ def test_eip_associate_network_interface(): eip.release() eip = None -@mock_ec2 +@mock_ec2_deprecated def test_eip_reassociate(): """reassociate EIP""" conn = boto.connect_ec2('the_key', 'the_secret') @@ -233,7 +233,7 @@ def test_eip_reassociate(): instance1.terminate() instance2.terminate() -@mock_ec2 +@mock_ec2_deprecated def test_eip_reassociate_nic(): """reassociate EIP""" conn = boto.connect_vpc('the_key', 'the_secret') @@ -261,7 +261,7 @@ def test_eip_reassociate_nic(): eip.release() eip = None -@mock_ec2 +@mock_ec2_deprecated def test_eip_associate_invalid_args(): """Associate EIP, invalid args """ conn = boto.connect_ec2('the_key', 'the_secret') @@ -280,7 +280,7 @@ def test_eip_associate_invalid_args(): instance.terminate() -@mock_ec2 +@mock_ec2_deprecated def test_eip_disassociate_bogus_association(): """Disassociate bogus EIP""" conn = boto.connect_ec2('the_key', 'the_secret') @@ -291,7 +291,7 @@ def test_eip_disassociate_bogus_association(): cm.exception.status.should.equal(400) cm.exception.request_id.should_not.be.none -@mock_ec2 +@mock_ec2_deprecated def test_eip_release_bogus_eip(): """Release bogus EIP""" conn = boto.connect_ec2('the_key', 'the_secret') @@ -303,7 +303,7 @@ def test_eip_release_bogus_eip(): cm.exception.request_id.should_not.be.none -@mock_ec2 +@mock_ec2_deprecated def test_eip_disassociate_arg_error(): """Invalid arguments disassociate address""" conn = boto.connect_ec2('the_key', 'the_secret') @@ -315,7 +315,7 @@ def test_eip_disassociate_arg_error(): cm.exception.request_id.should_not.be.none -@mock_ec2 +@mock_ec2_deprecated def test_eip_release_arg_error(): """Invalid arguments release address""" conn = boto.connect_ec2('the_key', 'the_secret') @@ -327,7 +327,7 @@ def test_eip_release_arg_error(): cm.exception.request_id.should_not.be.none -@mock_ec2 +@mock_ec2_deprecated def test_eip_describe(): """Listing of allocated Elastic IP Addresses.""" conn = boto.connect_ec2('the_key', 'the_secret') @@ -363,7 +363,7 @@ def test_eip_describe(): len(conn.get_all_addresses()).should.be.equal(0) -@mock_ec2 +@mock_ec2_deprecated def test_eip_describe_none(): """Error when search for bogus IP""" conn = boto.connect_ec2('the_key', 'the_secret') diff --git a/tests/test_ec2/test_elastic_network_interfaces.py b/tests/test_ec2/test_elastic_network_interfaces.py index 9b3f88a45..6f60c85a8 100644 --- a/tests/test_ec2/test_elastic_network_interfaces.py +++ b/tests/test_ec2/test_elastic_network_interfaces.py @@ -10,13 +10,13 @@ import boto.ec2 from boto.exception import EC2ResponseError, JSONResponseError import sure # noqa -from moto import mock_ec2, mock_cloudformation +from moto import mock_ec2, mock_cloudformation_deprecated, mock_ec2_deprecated from tests.helpers import requires_boto_gte from tests.test_cloudformation.fixtures import vpc_eni import json -@mock_ec2 +@mock_ec2_deprecated def test_elastic_network_interfaces(): conn = boto.connect_vpc('the_key', 'the_secret') vpc = conn.create_vpc("10.0.0.0/16") @@ -54,7 +54,7 @@ def test_elastic_network_interfaces(): cm.exception.request_id.should_not.be.none -@mock_ec2 +@mock_ec2_deprecated def test_elastic_network_interfaces_subnet_validation(): conn = boto.connect_vpc('the_key', 'the_secret') @@ -65,7 +65,7 @@ def test_elastic_network_interfaces_subnet_validation(): cm.exception.request_id.should_not.be.none -@mock_ec2 +@mock_ec2_deprecated def test_elastic_network_interfaces_with_private_ip(): conn = boto.connect_vpc('the_key', 'the_secret') vpc = conn.create_vpc("10.0.0.0/16") @@ -83,7 +83,7 @@ def test_elastic_network_interfaces_with_private_ip(): eni.private_ip_addresses[0].private_ip_address.should.equal(private_ip) -@mock_ec2 +@mock_ec2_deprecated def test_elastic_network_interfaces_with_groups(): conn = boto.connect_vpc('the_key', 'the_secret') vpc = conn.create_vpc("10.0.0.0/16") @@ -101,7 +101,7 @@ def test_elastic_network_interfaces_with_groups(): @requires_boto_gte("2.12.0") -@mock_ec2 +@mock_ec2_deprecated def test_elastic_network_interfaces_modify_attribute(): conn = boto.connect_vpc('the_key', 'the_secret') vpc = conn.create_vpc("10.0.0.0/16") @@ -133,7 +133,7 @@ def test_elastic_network_interfaces_modify_attribute(): eni.groups[0].id.should.equal(security_group2.id) -@mock_ec2 +@mock_ec2_deprecated def test_elastic_network_interfaces_filtering(): conn = boto.connect_vpc('the_key', 'the_secret') vpc = conn.create_vpc("10.0.0.0/16") @@ -281,8 +281,8 @@ def test_elastic_network_interfaces_get_by_subnet_id(): enis.should.have.length_of(0) -@mock_ec2 -@mock_cloudformation +@mock_ec2_deprecated +@mock_cloudformation_deprecated def test_elastic_network_interfaces_cloudformation(): template = vpc_eni.template template_json = json.dumps(template) diff --git a/tests/test_ec2/test_general.py b/tests/test_ec2/test_general.py index 83225bc0e..1dc77df82 100644 --- a/tests/test_ec2/test_general.py +++ b/tests/test_ec2/test_general.py @@ -7,10 +7,10 @@ import boto from boto.exception import EC2ResponseError import sure # noqa -from moto import mock_ec2 +from moto import mock_ec2_deprecated -@mock_ec2 +@mock_ec2_deprecated def test_console_output(): conn = boto.connect_ec2('the_key', 'the_secret') reservation = conn.run_instances('ami-1234abcd') @@ -20,7 +20,7 @@ def test_console_output(): output.output.should_not.equal(None) -@mock_ec2 +@mock_ec2_deprecated def test_console_output_without_instance(): conn = boto.connect_ec2('the_key', 'the_secret') diff --git a/tests/test_ec2/test_instances.py b/tests/test_ec2/test_instances.py index 7b0d734ea..a310c05a4 100644 --- a/tests/test_ec2/test_instances.py +++ b/tests/test_ec2/test_instances.py @@ -12,7 +12,7 @@ from boto.exception import EC2ResponseError, JSONResponseError from freezegun import freeze_time import sure # noqa -from moto import mock_ec2 +from moto import mock_ec2_deprecated from tests.helpers import requires_boto_gte @@ -23,7 +23,7 @@ def add_servers(ami_id, count): conn.run_instances(ami_id) -@mock_ec2 +@mock_ec2_deprecated def test_add_servers(): add_servers('ami-1234abcd', 2) @@ -37,7 +37,7 @@ def test_add_servers(): @freeze_time("2014-01-01 05:00:00") -@mock_ec2 +@mock_ec2_deprecated def test_instance_launch_and_terminate(): conn = boto.connect_ec2('the_key', 'the_secret') @@ -87,14 +87,14 @@ def test_instance_launch_and_terminate(): instance.state.should.equal('terminated') -@mock_ec2 +@mock_ec2_deprecated def test_terminate_empty_instances(): conn = boto.connect_ec2('the_key', 'the_secret') conn.terminate_instances.when.called_with([]).should.throw(EC2ResponseError) @freeze_time("2014-01-01 05:00:00") -@mock_ec2 +@mock_ec2_deprecated def test_instance_attach_volume(): conn = boto.connect_ec2('the_key', 'the_secret') reservation = conn.run_instances('ami-1234abcd') @@ -123,7 +123,7 @@ def test_instance_attach_volume(): v.status.should.equal('in-use') -@mock_ec2 +@mock_ec2_deprecated def test_get_instances_by_id(): conn = boto.connect_ec2() reservation = conn.run_instances('ami-1234abcd', min_count=2) @@ -150,7 +150,7 @@ def test_get_instances_by_id(): cm.exception.request_id.should_not.be.none -@mock_ec2 +@mock_ec2_deprecated def test_get_instances_filtering_by_state(): conn = boto.connect_ec2() reservation = conn.run_instances('ami-1234abcd', min_count=3) @@ -178,7 +178,7 @@ def test_get_instances_filtering_by_state(): conn.get_all_instances.when.called_with(filters={'not-implemented-filter': 'foobar'}).should.throw(NotImplementedError) -@mock_ec2 +@mock_ec2_deprecated def test_get_instances_filtering_by_instance_id(): conn = boto.connect_ec2() reservation = conn.run_instances('ami-1234abcd', min_count=3) @@ -197,7 +197,7 @@ def test_get_instances_filtering_by_instance_id(): reservations.should.have.length_of(0) -@mock_ec2 +@mock_ec2_deprecated def test_get_instances_filtering_by_instance_type(): conn = boto.connect_ec2() reservation1 = conn.run_instances('ami-1234abcd', instance_type='m1.small') @@ -238,7 +238,7 @@ def test_get_instances_filtering_by_instance_type(): #bogus instance-type should return none reservations.should.have.length_of(0) -@mock_ec2 +@mock_ec2_deprecated def test_get_instances_filtering_by_reason_code(): conn = boto.connect_ec2() reservation = conn.run_instances('ami-1234abcd', min_count=3) @@ -257,7 +257,7 @@ def test_get_instances_filtering_by_reason_code(): reservations[0].instances[0].id.should.equal(instance3.id) -@mock_ec2 +@mock_ec2_deprecated def test_get_instances_filtering_by_source_dest_check(): conn = boto.connect_ec2() reservation = conn.run_instances('ami-1234abcd', min_count=2) @@ -274,7 +274,7 @@ def test_get_instances_filtering_by_source_dest_check(): source_dest_check_true[0].instances[0].id.should.equal(instance2.id) -@mock_ec2 +@mock_ec2_deprecated def test_get_instances_filtering_by_vpc_id(): conn = boto.connect_vpc('the_key', 'the_secret') vpc1 = conn.create_vpc("10.0.0.0/16") @@ -298,7 +298,7 @@ def test_get_instances_filtering_by_vpc_id(): reservations2[0].instances[0].id.should.equal(instance2.id) -@mock_ec2 +@mock_ec2_deprecated def test_get_instances_filtering_by_architecture(): conn = boto.connect_ec2() reservation = conn.run_instances('ami-1234abcd', min_count=1) @@ -309,7 +309,7 @@ def test_get_instances_filtering_by_architecture(): reservations[0].instances.should.have.length_of(1) -@mock_ec2 +@mock_ec2_deprecated def test_get_instances_filtering_by_tag(): conn = boto.connect_ec2() reservation = conn.run_instances('ami-1234abcd', min_count=3) @@ -351,7 +351,7 @@ def test_get_instances_filtering_by_tag(): reservations[0].instances[1].id.should.equal(instance3.id) -@mock_ec2 +@mock_ec2_deprecated def test_get_instances_filtering_by_tag_value(): conn = boto.connect_ec2() reservation = conn.run_instances('ami-1234abcd', min_count=3) @@ -388,7 +388,7 @@ def test_get_instances_filtering_by_tag_value(): reservations[0].instances[0].id.should.equal(instance1.id) reservations[0].instances[1].id.should.equal(instance3.id) -@mock_ec2 +@mock_ec2_deprecated def test_get_instances_filtering_by_tag_name(): conn = boto.connect_ec2() reservation = conn.run_instances('ami-1234abcd', min_count=3) @@ -418,7 +418,7 @@ def test_get_instances_filtering_by_tag_name(): reservations[0].instances[1].id.should.equal(instance2.id) reservations[0].instances[2].id.should.equal(instance3.id) -@mock_ec2 +@mock_ec2_deprecated def test_instance_start_and_stop(): conn = boto.connect_ec2('the_key', 'the_secret') reservation = conn.run_instances('ami-1234abcd', min_count=2) @@ -448,7 +448,7 @@ def test_instance_start_and_stop(): started_instances[0].state.should.equal('pending') -@mock_ec2 +@mock_ec2_deprecated def test_instance_reboot(): conn = boto.connect_ec2('the_key', 'the_secret') reservation = conn.run_instances('ami-1234abcd') @@ -464,7 +464,7 @@ def test_instance_reboot(): instance.state.should.equal('pending') -@mock_ec2 +@mock_ec2_deprecated def test_instance_attribute_instance_type(): conn = boto.connect_ec2('the_key', 'the_secret') reservation = conn.run_instances('ami-1234abcd') @@ -482,7 +482,7 @@ def test_instance_attribute_instance_type(): instance_attribute.should.be.a(InstanceAttribute) instance_attribute.get('instanceType').should.equal("m1.small") -@mock_ec2 +@mock_ec2_deprecated def test_modify_instance_attribute_security_groups(): conn = boto.connect_ec2('the_key', 'the_secret') reservation = conn.run_instances('ami-1234abcd') @@ -506,7 +506,7 @@ def test_modify_instance_attribute_security_groups(): any(g.id == sg_id2 for g in group_list).should.be.ok -@mock_ec2 +@mock_ec2_deprecated def test_instance_attribute_user_data(): conn = boto.connect_ec2('the_key', 'the_secret') reservation = conn.run_instances('ami-1234abcd') @@ -525,7 +525,7 @@ def test_instance_attribute_user_data(): instance_attribute.get("userData").should.equal("this is my user data") -@mock_ec2 +@mock_ec2_deprecated def test_instance_attribute_source_dest_check(): conn = boto.connect_ec2('the_key', 'the_secret') reservation = conn.run_instances('ami-1234abcd') @@ -566,7 +566,7 @@ def test_instance_attribute_source_dest_check(): instance_attribute.get("sourceDestCheck").should.equal(True) -@mock_ec2 +@mock_ec2_deprecated def test_user_data_with_run_instance(): user_data = b"some user data" conn = boto.connect_ec2('the_key', 'the_secret') @@ -580,7 +580,7 @@ def test_user_data_with_run_instance(): decoded_user_data.should.equal(b"some user data") -@mock_ec2 +@mock_ec2_deprecated def test_run_instance_with_security_group_name(): conn = boto.connect_ec2('the_key', 'the_secret') @@ -600,7 +600,7 @@ def test_run_instance_with_security_group_name(): instance.groups[0].name.should.equal("group1") -@mock_ec2 +@mock_ec2_deprecated def test_run_instance_with_security_group_id(): conn = boto.connect_ec2('the_key', 'the_secret') group = conn.create_security_group('group1', "some description") @@ -612,7 +612,7 @@ def test_run_instance_with_security_group_id(): instance.groups[0].name.should.equal("group1") -@mock_ec2 +@mock_ec2_deprecated def test_run_instance_with_instance_type(): conn = boto.connect_ec2('the_key', 'the_secret') reservation = conn.run_instances('ami-1234abcd', instance_type="t1.micro") @@ -621,7 +621,7 @@ def test_run_instance_with_instance_type(): instance.instance_type.should.equal("t1.micro") -@mock_ec2 +@mock_ec2_deprecated def test_run_instance_with_default_placement(): conn = boto.connect_ec2('the_key', 'the_secret') reservation = conn.run_instances('ami-1234abcd') @@ -630,7 +630,7 @@ def test_run_instance_with_default_placement(): instance.placement.should.equal("us-east-1a") -@mock_ec2 +@mock_ec2_deprecated def test_run_instance_with_placement(): conn = boto.connect_ec2('the_key', 'the_secret') reservation = conn.run_instances('ami-1234abcd', placement="us-east-1b") @@ -639,7 +639,7 @@ def test_run_instance_with_placement(): instance.placement.should.equal("us-east-1b") -@mock_ec2 +@mock_ec2_deprecated def test_run_instance_with_subnet(): conn = boto.connect_vpc('the_key', 'the_secret') vpc = conn.create_vpc("10.0.0.0/16") @@ -653,7 +653,7 @@ def test_run_instance_with_subnet(): all_enis.should.have.length_of(1) -@mock_ec2 +@mock_ec2_deprecated def test_run_instance_with_nic_autocreated(): conn = boto.connect_vpc('the_key', 'the_secret') vpc = conn.create_vpc("10.0.0.0/16") @@ -686,7 +686,7 @@ def test_run_instance_with_nic_autocreated(): eni.private_ip_addresses[0].private_ip_address.should.equal(private_ip) -@mock_ec2 +@mock_ec2_deprecated def test_run_instance_with_nic_preexisting(): conn = boto.connect_vpc('the_key', 'the_secret') vpc = conn.create_vpc("10.0.0.0/16") @@ -724,7 +724,7 @@ def test_run_instance_with_nic_preexisting(): @requires_boto_gte("2.32.0") -@mock_ec2 +@mock_ec2_deprecated def test_instance_with_nic_attach_detach(): conn = boto.connect_vpc('the_key', 'the_secret') vpc = conn.create_vpc("10.0.0.0/16") @@ -790,7 +790,7 @@ def test_instance_with_nic_attach_detach(): cm.exception.request_id.should_not.be.none -@mock_ec2 +@mock_ec2_deprecated def test_ec2_classic_has_public_ip_address(): conn = boto.connect_ec2('the_key', 'the_secret') reservation = conn.run_instances('ami-1234abcd', key_name="keypair_name") @@ -802,7 +802,7 @@ def test_ec2_classic_has_public_ip_address(): instance.private_dns_name.should.contain(instance.private_ip_address) -@mock_ec2 +@mock_ec2_deprecated def test_run_instance_with_keypair(): conn = boto.connect_ec2('the_key', 'the_secret') reservation = conn.run_instances('ami-1234abcd', key_name="keypair_name") @@ -811,14 +811,14 @@ def test_run_instance_with_keypair(): instance.key_name.should.equal("keypair_name") -@mock_ec2 +@mock_ec2_deprecated def test_describe_instance_status_no_instances(): conn = boto.connect_ec2('the_key', 'the_secret') all_status = conn.get_all_instance_status() len(all_status).should.equal(0) -@mock_ec2 +@mock_ec2_deprecated def test_describe_instance_status_with_instances(): conn = boto.connect_ec2('the_key', 'the_secret') conn.run_instances('ami-1234abcd', key_name="keypair_name") @@ -829,7 +829,7 @@ def test_describe_instance_status_with_instances(): all_status[0].system_status.status.should.equal('ok') -@mock_ec2 +@mock_ec2_deprecated def test_describe_instance_status_with_instance_filter(): conn = boto.connect_ec2('the_key', 'the_secret') @@ -852,7 +852,7 @@ def test_describe_instance_status_with_instance_filter(): cm.exception.request_id.should_not.be.none @requires_boto_gte("2.32.0") -@mock_ec2 +@mock_ec2_deprecated def test_describe_instance_status_with_non_running_instances(): conn = boto.connect_ec2('the_key', 'the_secret') reservation = conn.run_instances('ami-1234abcd', min_count=3) @@ -877,7 +877,7 @@ def test_describe_instance_status_with_non_running_instances(): status3 = next((s for s in all_status if s.id == instance3.id), None) status3.state_name.should.equal('running') -@mock_ec2 +@mock_ec2_deprecated def test_get_instance_by_security_group(): conn = boto.connect_ec2('the_key', 'the_secret') diff --git a/tests/test_ec2/test_internet_gateways.py b/tests/test_ec2/test_internet_gateways.py index 4a08fe108..12b37860e 100644 --- a/tests/test_ec2/test_internet_gateways.py +++ b/tests/test_ec2/test_internet_gateways.py @@ -10,14 +10,14 @@ from boto.exception import EC2ResponseError, JSONResponseError import sure # noqa -from moto import mock_ec2 +from moto import mock_ec2_deprecated VPC_CIDR="10.0.0.0/16" BAD_VPC="vpc-deadbeef" BAD_IGW="igw-deadbeef" -@mock_ec2 +@mock_ec2_deprecated def test_igw_create(): """ internet gateway create """ conn = boto.connect_vpc('the_key', 'the_secret') @@ -37,7 +37,7 @@ def test_igw_create(): igw = conn.get_all_internet_gateways()[0] igw.attachments.should.have.length_of(0) -@mock_ec2 +@mock_ec2_deprecated def test_igw_attach(): """ internet gateway attach """ conn = boto.connect_vpc('the_key', 'the_secret') @@ -55,7 +55,7 @@ def test_igw_attach(): igw = conn.get_all_internet_gateways()[0] igw.attachments[0].vpc_id.should.be.equal(vpc.id) -@mock_ec2 +@mock_ec2_deprecated def test_igw_attach_bad_vpc(): """ internet gateway fail to attach w/ bad vpc """ conn = boto.connect_vpc('the_key', 'the_secret') @@ -67,7 +67,7 @@ def test_igw_attach_bad_vpc(): cm.exception.status.should.equal(400) cm.exception.request_id.should_not.be.none -@mock_ec2 +@mock_ec2_deprecated def test_igw_attach_twice(): """ internet gateway fail to attach twice """ conn = boto.connect_vpc('the_key', 'the_secret') @@ -82,7 +82,7 @@ def test_igw_attach_twice(): cm.exception.status.should.equal(400) cm.exception.request_id.should_not.be.none -@mock_ec2 +@mock_ec2_deprecated def test_igw_detach(): """ internet gateway detach""" conn = boto.connect_vpc('the_key', 'the_secret') @@ -100,7 +100,7 @@ def test_igw_detach(): igw = conn.get_all_internet_gateways()[0] igw.attachments.should.have.length_of(0) -@mock_ec2 +@mock_ec2_deprecated def test_igw_detach_wrong_vpc(): """ internet gateway fail to detach w/ wrong vpc """ conn = boto.connect_vpc('the_key', 'the_secret') @@ -115,7 +115,7 @@ def test_igw_detach_wrong_vpc(): cm.exception.status.should.equal(400) cm.exception.request_id.should_not.be.none -@mock_ec2 +@mock_ec2_deprecated def test_igw_detach_invalid_vpc(): """ internet gateway fail to detach w/ invalid vpc """ conn = boto.connect_vpc('the_key', 'the_secret') @@ -129,7 +129,7 @@ def test_igw_detach_invalid_vpc(): cm.exception.status.should.equal(400) cm.exception.request_id.should_not.be.none -@mock_ec2 +@mock_ec2_deprecated def test_igw_detach_unattached(): """ internet gateway fail to detach unattached """ conn = boto.connect_vpc('the_key', 'the_secret') @@ -142,7 +142,7 @@ def test_igw_detach_unattached(): cm.exception.status.should.equal(400) cm.exception.request_id.should_not.be.none -@mock_ec2 +@mock_ec2_deprecated def test_igw_delete(): """ internet gateway delete""" conn = boto.connect_vpc('the_key', 'the_secret') @@ -160,7 +160,7 @@ def test_igw_delete(): conn.delete_internet_gateway(igw.id) conn.get_all_internet_gateways().should.have.length_of(0) -@mock_ec2 +@mock_ec2_deprecated def test_igw_delete_attached(): """ internet gateway fail to delete attached """ conn = boto.connect_vpc('the_key', 'the_secret') @@ -174,7 +174,7 @@ def test_igw_delete_attached(): cm.exception.status.should.equal(400) cm.exception.request_id.should_not.be.none -@mock_ec2 +@mock_ec2_deprecated def test_igw_desribe(): """ internet gateway fetch by id """ conn = boto.connect_vpc('the_key', 'the_secret') @@ -182,7 +182,7 @@ def test_igw_desribe(): igw_by_search = conn.get_all_internet_gateways([igw.id])[0] igw.id.should.equal(igw_by_search.id) -@mock_ec2 +@mock_ec2_deprecated def test_igw_desribe_bad_id(): """ internet gateway fail to fetch by bad id """ conn = boto.connect_vpc('the_key', 'the_secret') @@ -193,7 +193,7 @@ def test_igw_desribe_bad_id(): cm.exception.request_id.should_not.be.none -@mock_ec2 +@mock_ec2_deprecated def test_igw_filter_by_vpc_id(): """ internet gateway filter by vpc id """ conn = boto.connect_vpc('the_key', 'the_secret') @@ -208,7 +208,7 @@ def test_igw_filter_by_vpc_id(): result[0].id.should.equal(igw1.id) -@mock_ec2 +@mock_ec2_deprecated def test_igw_filter_by_tags(): """ internet gateway filter by vpc id """ conn = boto.connect_vpc('the_key', 'the_secret') @@ -222,7 +222,7 @@ def test_igw_filter_by_tags(): result[0].id.should.equal(igw1.id) -@mock_ec2 +@mock_ec2_deprecated def test_igw_filter_by_internet_gateway_id(): """ internet gateway filter by internet gateway id """ conn = boto.connect_vpc('the_key', 'the_secret') @@ -235,7 +235,7 @@ def test_igw_filter_by_internet_gateway_id(): result[0].id.should.equal(igw1.id) -@mock_ec2 +@mock_ec2_deprecated def test_igw_filter_by_attachment_state(): """ internet gateway filter by attachment state """ conn = boto.connect_vpc('the_key', 'the_secret') diff --git a/tests/test_ec2/test_key_pairs.py b/tests/test_ec2/test_key_pairs.py index 7d45e79db..a35f0b962 100644 --- a/tests/test_ec2/test_key_pairs.py +++ b/tests/test_ec2/test_key_pairs.py @@ -8,16 +8,16 @@ import six import sure # noqa from boto.exception import EC2ResponseError, JSONResponseError -from moto import mock_ec2 +from moto import mock_ec2_deprecated -@mock_ec2 +@mock_ec2_deprecated def test_key_pairs_empty(): conn = boto.connect_ec2('the_key', 'the_secret') assert len(conn.get_all_key_pairs()) == 0 -@mock_ec2 +@mock_ec2_deprecated def test_key_pairs_invalid_id(): conn = boto.connect_ec2('the_key', 'the_secret') @@ -28,7 +28,7 @@ def test_key_pairs_invalid_id(): cm.exception.request_id.should_not.be.none -@mock_ec2 +@mock_ec2_deprecated def test_key_pairs_create(): conn = boto.connect_ec2('the_key', 'the_secret') @@ -45,7 +45,7 @@ def test_key_pairs_create(): assert kps[0].name == 'foo' -@mock_ec2 +@mock_ec2_deprecated def test_key_pairs_create_two(): conn = boto.connect_ec2('the_key', 'the_secret') kp = conn.create_key_pair('foo') @@ -60,7 +60,7 @@ def test_key_pairs_create_two(): kps[0].name.should.equal('foo') -@mock_ec2 +@mock_ec2_deprecated def test_key_pairs_create_exist(): conn = boto.connect_ec2('the_key', 'the_secret') kp = conn.create_key_pair('foo') @@ -74,7 +74,7 @@ def test_key_pairs_create_exist(): cm.exception.request_id.should_not.be.none -@mock_ec2 +@mock_ec2_deprecated def test_key_pairs_delete_no_exist(): conn = boto.connect_ec2('the_key', 'the_secret') assert len(conn.get_all_key_pairs()) == 0 @@ -82,7 +82,7 @@ def test_key_pairs_delete_no_exist(): r.should.be.ok -@mock_ec2 +@mock_ec2_deprecated def test_key_pairs_delete_exist(): conn = boto.connect_ec2('the_key', 'the_secret') conn.create_key_pair('foo') @@ -98,7 +98,7 @@ def test_key_pairs_delete_exist(): assert len(conn.get_all_key_pairs()) == 0 -@mock_ec2 +@mock_ec2_deprecated def test_key_pairs_import(): conn = boto.connect_ec2('the_key', 'the_secret') @@ -115,7 +115,7 @@ def test_key_pairs_import(): assert kps[0].name == 'foo' -@mock_ec2 +@mock_ec2_deprecated def test_key_pairs_import_exist(): conn = boto.connect_ec2('the_key', 'the_secret') kp = conn.import_key_pair('foo', b'content') diff --git a/tests/test_ec2/test_network_acls.py b/tests/test_ec2/test_network_acls.py index 5ab16b51b..91158e0bf 100644 --- a/tests/test_ec2/test_network_acls.py +++ b/tests/test_ec2/test_network_acls.py @@ -2,10 +2,10 @@ from __future__ import unicode_literals import boto import sure # noqa -from moto import mock_ec2 +from moto import mock_ec2_deprecated -@mock_ec2 +@mock_ec2_deprecated def test_default_network_acl_created_with_vpc(): conn = boto.connect_vpc('the_key', 'the secret') vpc = conn.create_vpc("10.0.0.0/16") @@ -13,7 +13,7 @@ def test_default_network_acl_created_with_vpc(): all_network_acls.should.have.length_of(2) -@mock_ec2 +@mock_ec2_deprecated def test_network_acls(): conn = boto.connect_vpc('the_key', 'the secret') vpc = conn.create_vpc("10.0.0.0/16") @@ -22,7 +22,7 @@ def test_network_acls(): all_network_acls.should.have.length_of(3) -@mock_ec2 +@mock_ec2_deprecated def test_new_subnet_associates_with_default_network_acl(): conn = boto.connect_vpc('the_key', 'the secret') vpc = conn.get_all_vpcs()[0] @@ -36,7 +36,7 @@ def test_new_subnet_associates_with_default_network_acl(): [a.subnet_id for a in acl.associations].should.contain(subnet.id) -@mock_ec2 +@mock_ec2_deprecated def test_network_acl_entries(): conn = boto.connect_vpc('the_key', 'the secret') vpc = conn.create_vpc("10.0.0.0/16") @@ -62,7 +62,7 @@ def test_network_acl_entries(): entries[0].rule_action.should.equal('ALLOW') -@mock_ec2 +@mock_ec2_deprecated def test_associate_new_network_acl_with_subnet(): conn = boto.connect_vpc('the_key', 'the secret') vpc = conn.create_vpc("10.0.0.0/16") @@ -81,7 +81,7 @@ def test_associate_new_network_acl_with_subnet(): test_network_acl.associations[0].subnet_id.should.equal(subnet.id) -@mock_ec2 +@mock_ec2_deprecated def test_delete_network_acl(): conn = boto.connect_vpc('the_key', 'the secret') vpc = conn.create_vpc("10.0.0.0/16") @@ -101,7 +101,7 @@ def test_delete_network_acl(): any(acl.id == network_acl.id for acl in updated_network_acls).shouldnt.be.ok -@mock_ec2 +@mock_ec2_deprecated def test_network_acl_tagging(): conn = boto.connect_vpc('the_key', 'the secret') vpc = conn.create_vpc("10.0.0.0/16") diff --git a/tests/test_ec2/test_regions.py b/tests/test_ec2/test_regions.py index 9375314d4..07e02c526 100644 --- a/tests/test_ec2/test_regions.py +++ b/tests/test_ec2/test_regions.py @@ -3,7 +3,7 @@ import boto.ec2 import boto.ec2.autoscale import boto.ec2.elb import sure -from moto import mock_ec2, mock_autoscaling, mock_elb +from moto import mock_ec2_deprecated, mock_autoscaling_deprecated, mock_elb_deprecated def add_servers_to_region(ami_id, count, region): @@ -12,7 +12,7 @@ def add_servers_to_region(ami_id, count, region): conn.run_instances(ami_id) -@mock_ec2 +@mock_ec2_deprecated def test_add_servers_to_a_single_region(): region = 'ap-northeast-1' add_servers_to_region('ami-1234abcd', 1, region) @@ -27,7 +27,7 @@ def test_add_servers_to_a_single_region(): reservations[1].instances[0].image_id.should.equal('ami-5678efgh') -@mock_ec2 +@mock_ec2_deprecated def test_add_servers_to_multiple_regions(): region1 = 'us-east-1' region2 = 'ap-northeast-1' @@ -46,8 +46,8 @@ def test_add_servers_to_multiple_regions(): ap_reservations[0].instances[0].image_id.should.equal('ami-5678efgh') -@mock_autoscaling -@mock_elb +@mock_autoscaling_deprecated +@mock_elb_deprecated def test_create_autoscaling_group(): elb_conn = boto.ec2.elb.connect_to_region('us-east-1') elb_conn.create_load_balancer('us_test_lb', zones=[], listeners=[(80, 8080, 'http')]) diff --git a/tests/test_ec2/test_route_tables.py b/tests/test_ec2/test_route_tables.py index 41e5786e6..3aa4b460a 100644 --- a/tests/test_ec2/test_route_tables.py +++ b/tests/test_ec2/test_route_tables.py @@ -8,11 +8,11 @@ import boto3 from boto.exception import EC2ResponseError import sure # noqa -from moto import mock_ec2 +from moto import mock_ec2, mock_ec2_deprecated from tests.helpers import requires_boto_gte -@mock_ec2 +@mock_ec2_deprecated def test_route_tables_defaults(): conn = boto.connect_vpc('the_key', 'the_secret') vpc = conn.create_vpc("10.0.0.0/16") @@ -37,7 +37,7 @@ def test_route_tables_defaults(): all_route_tables.should.have.length_of(0) -@mock_ec2 +@mock_ec2_deprecated def test_route_tables_additional(): conn = boto.connect_vpc('the_key', 'the_secret') vpc = conn.create_vpc("10.0.0.0/16") @@ -77,7 +77,7 @@ def test_route_tables_additional(): cm.exception.request_id.should_not.be.none -@mock_ec2 +@mock_ec2_deprecated def test_route_tables_filters_standard(): conn = boto.connect_vpc('the_key', 'the_secret') @@ -115,7 +115,7 @@ def test_route_tables_filters_standard(): conn.get_all_route_tables.when.called_with(filters={'not-implemented-filter': 'foobar'}).should.throw(NotImplementedError) -@mock_ec2 +@mock_ec2_deprecated def test_route_tables_filters_associations(): conn = boto.connect_vpc('the_key', 'the_secret') @@ -152,7 +152,7 @@ def test_route_tables_filters_associations(): association1_route_tables[0].associations.should.have.length_of(2) -@mock_ec2 +@mock_ec2_deprecated def test_route_table_associations(): conn = boto.connect_vpc('the_key', 'the_secret') vpc = conn.create_vpc("10.0.0.0/16") @@ -219,7 +219,7 @@ def test_route_table_associations(): @requires_boto_gte("2.16.0") -@mock_ec2 +@mock_ec2_deprecated def test_route_table_replace_route_table_association(): """ Note: Boto has deprecated replace_route_table_assocation (which returns status) @@ -289,7 +289,7 @@ def test_route_table_replace_route_table_association(): cm.exception.request_id.should_not.be.none -@mock_ec2 +@mock_ec2_deprecated def test_route_table_get_by_tag(): conn = boto.connect_vpc('the_key', 'the_secret') @@ -326,7 +326,7 @@ def test_route_table_get_by_tag_boto3(): route_tables[0].tags[0].should.equal({'Key': 'Name', 'Value': 'TestRouteTable'}) -@mock_ec2 +@mock_ec2_deprecated def test_routes_additional(): conn = boto.connect_vpc('the_key', 'the_secret') vpc = conn.create_vpc("10.0.0.0/16") @@ -364,7 +364,7 @@ def test_routes_additional(): cm.exception.request_id.should_not.be.none -@mock_ec2 +@mock_ec2_deprecated def test_routes_replace(): conn = boto.connect_vpc('the_key', 'the_secret') vpc = conn.create_vpc("10.0.0.0/16") @@ -412,7 +412,7 @@ def test_routes_replace(): @requires_boto_gte("2.19.0") -@mock_ec2 +@mock_ec2_deprecated def test_routes_not_supported(): conn = boto.connect_vpc('the_key', 'the_secret') vpc = conn.create_vpc("10.0.0.0/16") @@ -431,7 +431,7 @@ def test_routes_not_supported(): @requires_boto_gte("2.34.0") -@mock_ec2 +@mock_ec2_deprecated def test_routes_vpc_peering_connection(): conn = boto.connect_vpc('the_key', 'the_secret') vpc = conn.create_vpc("10.0.0.0/16") @@ -458,7 +458,7 @@ def test_routes_vpc_peering_connection(): @requires_boto_gte("2.34.0") -@mock_ec2 +@mock_ec2_deprecated def test_routes_vpn_gateway(): conn = boto.connect_vpc('the_key', 'the_secret') @@ -480,7 +480,7 @@ def test_routes_vpn_gateway(): new_route.vpc_peering_connection_id.should.be.none -@mock_ec2 +@mock_ec2_deprecated def test_network_acl_tagging(): conn = boto.connect_vpc('the_key', 'the secret') diff --git a/tests/test_ec2/test_security_groups.py b/tests/test_ec2/test_security_groups.py index 19f43862d..3968d9151 100644 --- a/tests/test_ec2/test_security_groups.py +++ b/tests/test_ec2/test_security_groups.py @@ -12,10 +12,10 @@ from botocore.exceptions import ClientError from boto.exception import EC2ResponseError, JSONResponseError import sure # noqa -from moto import mock_ec2 +from moto import mock_ec2, mock_ec2_deprecated -@mock_ec2 +@mock_ec2_deprecated def test_create_and_describe_security_group(): conn = boto.connect_ec2('the_key', 'the_secret') @@ -43,7 +43,7 @@ def test_create_and_describe_security_group(): set(group_names).should.equal(set(["default", "test security group"])) -@mock_ec2 +@mock_ec2_deprecated def test_create_security_group_without_description_raises_error(): conn = boto.connect_ec2('the_key', 'the_secret') @@ -54,7 +54,7 @@ def test_create_security_group_without_description_raises_error(): cm.exception.request_id.should_not.be.none -@mock_ec2 +@mock_ec2_deprecated def test_default_security_group(): conn = boto.ec2.connect_to_region('us-east-1') groups = conn.get_all_security_groups() @@ -62,7 +62,7 @@ def test_default_security_group(): groups[0].name.should.equal("default") -@mock_ec2 +@mock_ec2_deprecated def test_create_and_describe_vpc_security_group(): conn = boto.connect_ec2('the_key', 'the_secret') vpc_id = 'vpc-5300000c' @@ -88,7 +88,7 @@ def test_create_and_describe_vpc_security_group(): all_groups[0].name.should.equal('test security group') -@mock_ec2 +@mock_ec2_deprecated def test_create_two_security_groups_with_same_name_in_different_vpc(): conn = boto.connect_ec2('the_key', 'the_secret') vpc_id = 'vpc-5300000c' @@ -105,7 +105,7 @@ def test_create_two_security_groups_with_same_name_in_different_vpc(): set(group_names).should.equal(set(["default", "test security group"])) -@mock_ec2 +@mock_ec2_deprecated def test_deleting_security_groups(): conn = boto.connect_ec2('the_key', 'the_secret') security_group1 = conn.create_security_group('test1', 'test1') @@ -135,7 +135,7 @@ def test_deleting_security_groups(): conn.get_all_security_groups().should.have.length_of(2) -@mock_ec2 +@mock_ec2_deprecated def test_delete_security_group_in_vpc(): conn = boto.connect_ec2('the_key', 'the_secret') vpc_id = "vpc-12345" @@ -145,7 +145,7 @@ def test_delete_security_group_in_vpc(): conn.delete_security_group(group_id=security_group1.id) -@mock_ec2 +@mock_ec2_deprecated def test_authorize_ip_range_and_revoke(): conn = boto.connect_ec2('the_key', 'the_secret') security_group = conn.create_security_group('test', 'test') @@ -216,7 +216,7 @@ def test_authorize_ip_range_and_revoke(): egress_security_group.rules_egress.should.have.length_of(1) -@mock_ec2 +@mock_ec2_deprecated def test_authorize_other_group_and_revoke(): conn = boto.connect_ec2('the_key', 'the_secret') security_group = conn.create_security_group('test', 'test') @@ -269,7 +269,7 @@ def test_authorize_other_group_egress_and_revoke(): sg01.ip_permissions_egress.should.have.length_of(1) -@mock_ec2 +@mock_ec2_deprecated def test_authorize_group_in_vpc(): conn = boto.connect_ec2('the_key', 'the_secret') vpc_id = "vpc-12345" @@ -295,7 +295,7 @@ def test_authorize_group_in_vpc(): security_group.rules.should.have.length_of(0) -@mock_ec2 +@mock_ec2_deprecated def test_get_all_security_groups(): conn = boto.connect_ec2() sg1 = conn.create_security_group(name='test1', description='test1', vpc_id='vpc-mjm05d27') @@ -321,7 +321,7 @@ def test_get_all_security_groups(): resp.should.have.length_of(4) -@mock_ec2 +@mock_ec2_deprecated def test_authorize_bad_cidr_throws_invalid_parameter_value(): conn = boto.connect_ec2('the_key', 'the_secret') security_group = conn.create_security_group('test', 'test') @@ -332,7 +332,7 @@ def test_authorize_bad_cidr_throws_invalid_parameter_value(): cm.exception.request_id.should_not.be.none -@mock_ec2 +@mock_ec2_deprecated def test_security_group_tagging(): conn = boto.connect_vpc() vpc = conn.create_vpc("10.0.0.0/16") @@ -356,7 +356,7 @@ def test_security_group_tagging(): group.tags["Test"].should.equal("Tag") -@mock_ec2 +@mock_ec2_deprecated def test_security_group_tag_filtering(): conn = boto.connect_ec2() sg = conn.create_security_group("test-sg", "Test SG") @@ -366,7 +366,7 @@ def test_security_group_tag_filtering(): groups.should.have.length_of(1) -@mock_ec2 +@mock_ec2_deprecated def test_authorize_all_protocols_with_no_port_specification(): conn = boto.connect_ec2() sg = conn.create_security_group('test', 'test') @@ -379,7 +379,7 @@ def test_authorize_all_protocols_with_no_port_specification(): sg.rules[0].to_port.should.equal(None) -@mock_ec2 +@mock_ec2_deprecated def test_sec_group_rule_limit(): ec2_conn = boto.connect_ec2() sg = ec2_conn.create_security_group('test', 'test') @@ -441,7 +441,7 @@ def test_sec_group_rule_limit(): cm.exception.error_code.should.equal('RulesPerSecurityGroupLimitExceeded') -@mock_ec2 +@mock_ec2_deprecated def test_sec_group_rule_limit_vpc(): ec2_conn = boto.connect_ec2() vpc_conn = boto.connect_vpc() @@ -611,7 +611,7 @@ def test_authorize_and_revoke_in_bulk(): for ip_permission in expected_ip_permissions: sg01.ip_permissions_egress.shouldnt.contain(ip_permission) -@mock_ec2 +@mock_ec2_deprecated def test_get_all_security_groups_filter_with_same_vpc_id(): conn = boto.connect_ec2('the_key', 'the_secret') vpc_id = 'vpc-5300000c' diff --git a/tests/test_ec2/test_spot_instances.py b/tests/test_ec2/test_spot_instances.py index 790ffeb65..1933613e8 100644 --- a/tests/test_ec2/test_spot_instances.py +++ b/tests/test_ec2/test_spot_instances.py @@ -7,12 +7,13 @@ import boto3 import sure # noqa from boto.exception import JSONResponseError -from moto import mock_ec2 +from moto import mock_ec2, mock_ec2_deprecated from moto.backends import get_model from moto.core.utils import iso_8601_datetime_with_milliseconds @mock_ec2 +@mock_ec2_deprecated def test_request_spot_instances(): conn = boto3.client('ec2', 'us-east-1') vpc = conn.create_vpc(CidrBlock="10.0.0.0/8")['Vpc'] @@ -73,7 +74,7 @@ def test_request_spot_instances(): request.launch_specification.subnet_id.should.equal(subnet_id) -@mock_ec2 +@mock_ec2_deprecated def test_request_spot_instances_default_arguments(): """ Test that moto set the correct default arguments @@ -106,7 +107,7 @@ def test_request_spot_instances_default_arguments(): request.launch_specification.subnet_id.should.equal(None) -@mock_ec2 +@mock_ec2_deprecated def test_cancel_spot_instance_request(): conn = boto.connect_ec2() @@ -130,7 +131,7 @@ def test_cancel_spot_instance_request(): requests.should.have.length_of(0) -@mock_ec2 +@mock_ec2_deprecated def test_request_spot_instances_fulfilled(): """ Test that moto correctly fullfills a spot instance request @@ -156,7 +157,7 @@ def test_request_spot_instances_fulfilled(): request.state.should.equal("active") -@mock_ec2 +@mock_ec2_deprecated def test_tag_spot_instance_request(): """ Test that moto correctly tags a spot instance request @@ -177,7 +178,7 @@ def test_tag_spot_instance_request(): tag_dict.should.equal({'tag1': 'value1', 'tag2': 'value2'}) -@mock_ec2 +@mock_ec2_deprecated def test_get_all_spot_instance_requests_filtering(): """ Test that moto correctly filters spot instance requests @@ -211,7 +212,7 @@ def test_get_all_spot_instance_requests_filtering(): requests.should.have.length_of(1) -@mock_ec2 +@mock_ec2_deprecated def test_request_spot_instances_setting_instance_id(): conn = boto.ec2.connect_to_region("us-east-1") request = conn.request_spot_instances( diff --git a/tests/test_ec2/test_subnets.py b/tests/test_ec2/test_subnets.py index 8e6a2a4ea..0a9b41b8e 100644 --- a/tests/test_ec2/test_subnets.py +++ b/tests/test_ec2/test_subnets.py @@ -11,10 +11,10 @@ from botocore.exceptions import ParamValidationError import json import sure # noqa -from moto import mock_cloudformation, mock_ec2 +from moto import mock_cloudformation_deprecated, mock_ec2, mock_ec2_deprecated -@mock_ec2 +@mock_ec2_deprecated def test_subnets(): ec2 = boto.connect_ec2('the_key', 'the_secret') conn = boto.connect_vpc('the_key', 'the_secret') @@ -36,7 +36,7 @@ def test_subnets(): cm.exception.request_id.should_not.be.none -@mock_ec2 +@mock_ec2_deprecated def test_subnet_create_vpc_validation(): conn = boto.connect_vpc('the_key', 'the_secret') @@ -47,7 +47,7 @@ def test_subnet_create_vpc_validation(): cm.exception.request_id.should_not.be.none -@mock_ec2 +@mock_ec2_deprecated def test_subnet_tagging(): conn = boto.connect_vpc('the_key', 'the_secret') vpc = conn.create_vpc("10.0.0.0/16") @@ -65,7 +65,7 @@ def test_subnet_tagging(): subnet.tags["a key"].should.equal("some value") -@mock_ec2 +@mock_ec2_deprecated def test_subnet_should_have_proper_availability_zone_set(): conn = boto.vpc.connect_to_region('us-west-1') vpcA = conn.create_vpc("10.0.0.0/16") @@ -87,7 +87,7 @@ def test_default_subnet(): subnet.map_public_ip_on_launch.shouldnt.be.ok -@mock_ec2 +@mock_ec2_deprecated def test_non_default_subnet(): vpc_cli = boto.vpc.connect_to_region('us-west-1') @@ -150,7 +150,7 @@ def test_modify_subnet_attribute_validation(): client.modify_subnet_attribute(SubnetId=subnet.id, MapPublicIpOnLaunch={'Value': 'invalid'}) -@mock_ec2 +@mock_ec2_deprecated def test_get_subnets_filtering(): ec2 = boto.ec2.connect_to_region('us-west-1') conn = boto.vpc.connect_to_region('us-west-1') @@ -205,8 +205,8 @@ def test_get_subnets_filtering(): conn.get_all_subnets.when.called_with(filters={'not-implemented-filter': 'foobar'}).should.throw(NotImplementedError) -@mock_ec2 -@mock_cloudformation +@mock_ec2_deprecated +@mock_cloudformation_deprecated def test_subnet_tags_through_cloudformation(): vpc_conn = boto.vpc.connect_to_region('us-west-1') vpc = vpc_conn.create_vpc("10.0.0.0/16") diff --git a/tests/test_ec2/test_tags.py b/tests/test_ec2/test_tags.py index 4a85eb6e1..1084e44c4 100644 --- a/tests/test_ec2/test_tags.py +++ b/tests/test_ec2/test_tags.py @@ -8,11 +8,11 @@ from boto.exception import EC2ResponseError, JSONResponseError from boto.ec2.instance import Reservation import sure # noqa -from moto import mock_ec2 +from moto import mock_ec2_deprecated from nose.tools import assert_raises -@mock_ec2 +@mock_ec2_deprecated def test_add_tag(): conn = boto.connect_ec2('the_key', 'the_secret') reservation = conn.run_instances('ami-1234abcd') @@ -32,7 +32,7 @@ def test_add_tag(): existing_instance.tags["a key"].should.equal("some value") -@mock_ec2 +@mock_ec2_deprecated def test_remove_tag(): conn = boto.connect_ec2('the_key', 'the_secret') reservation = conn.run_instances('ami-1234abcd') @@ -59,7 +59,7 @@ def test_remove_tag(): instance.remove_tag("a key", "some value") -@mock_ec2 +@mock_ec2_deprecated def test_get_all_tags(): conn = boto.connect_ec2('the_key', 'the_secret') reservation = conn.run_instances('ami-1234abcd') @@ -73,7 +73,7 @@ def test_get_all_tags(): tag.value.should.equal("some value") -@mock_ec2 +@mock_ec2_deprecated def test_get_all_tags_with_special_characters(): conn = boto.connect_ec2('the_key', 'the_secret') reservation = conn.run_instances('ami-1234abcd') @@ -87,7 +87,7 @@ def test_get_all_tags_with_special_characters(): tag.value.should.equal("some<> value") -@mock_ec2 +@mock_ec2_deprecated def test_create_tags(): conn = boto.connect_ec2('the_key', 'the_secret') reservation = conn.run_instances('ami-1234abcd') @@ -108,7 +108,7 @@ def test_create_tags(): set([tag_dict[key] for key in tag_dict]).should.equal(set([tag.value for tag in tags])) -@mock_ec2 +@mock_ec2_deprecated def test_tag_limit_exceeded(): conn = boto.connect_ec2('the_key', 'the_secret') reservation = conn.run_instances('ami-1234abcd') @@ -137,7 +137,7 @@ def test_tag_limit_exceeded(): tag.value.should.equal("a value") -@mock_ec2 +@mock_ec2_deprecated def test_invalid_parameter_tag_null(): conn = boto.connect_ec2('the_key', 'the_secret') reservation = conn.run_instances('ami-1234abcd') @@ -150,7 +150,7 @@ def test_invalid_parameter_tag_null(): cm.exception.request_id.should_not.be.none -@mock_ec2 +@mock_ec2_deprecated def test_invalid_id(): conn = boto.connect_ec2('the_key', 'the_secret') with assert_raises(EC2ResponseError) as cm: @@ -166,7 +166,7 @@ def test_invalid_id(): cm.exception.request_id.should_not.be.none -@mock_ec2 +@mock_ec2_deprecated def test_get_all_tags_resource_id_filter(): conn = boto.connect_ec2('the_key', 'the_secret') reservation = conn.run_instances('ami-1234abcd') @@ -193,7 +193,7 @@ def test_get_all_tags_resource_id_filter(): tag.value.should.equal("some value") -@mock_ec2 +@mock_ec2_deprecated def test_get_all_tags_resource_type_filter(): conn = boto.connect_ec2('the_key', 'the_secret') reservation = conn.run_instances('ami-1234abcd') @@ -220,7 +220,7 @@ def test_get_all_tags_resource_type_filter(): tag.value.should.equal("some value") -@mock_ec2 +@mock_ec2_deprecated def test_get_all_tags_key_filter(): conn = boto.connect_ec2('the_key', 'the_secret') reservation = conn.run_instances('ami-1234abcd') @@ -239,7 +239,7 @@ def test_get_all_tags_key_filter(): tag.value.should.equal("some value") -@mock_ec2 +@mock_ec2_deprecated def test_get_all_tags_value_filter(): conn = boto.connect_ec2('the_key', 'the_secret') reservation = conn.run_instances('ami-1234abcd') @@ -283,7 +283,7 @@ def test_get_all_tags_value_filter(): tags.should.have.length_of(1) -@mock_ec2 +@mock_ec2_deprecated def test_retrieved_instances_must_contain_their_tags(): tag_key = 'Tag name' tag_value = 'Tag value' @@ -314,7 +314,7 @@ def test_retrieved_instances_must_contain_their_tags(): retrieved_tags[tag_key].should.equal(tag_value) -@mock_ec2 +@mock_ec2_deprecated def test_retrieved_volumes_must_contain_their_tags(): tag_key = 'Tag name' tag_value = 'Tag value' @@ -337,7 +337,7 @@ def test_retrieved_volumes_must_contain_their_tags(): retrieved_tags[tag_key].should.equal(tag_value) -@mock_ec2 +@mock_ec2_deprecated def test_retrieved_snapshots_must_contain_their_tags(): tag_key = 'Tag name' tag_value = 'Tag value' @@ -359,7 +359,7 @@ def test_retrieved_snapshots_must_contain_their_tags(): retrieved_tags[tag_key].should.equal(tag_value) -@mock_ec2 +@mock_ec2_deprecated def test_filter_instances_by_wildcard_tags(): conn = boto.connect_ec2(aws_access_key_id='the_key', aws_secret_access_key='the_secret') reservation = conn.run_instances('ami-1234abcd') diff --git a/tests/test_ec2/test_virtual_private_gateways.py b/tests/test_ec2/test_virtual_private_gateways.py index 8050559f1..0a7e34ea5 100644 --- a/tests/test_ec2/test_virtual_private_gateways.py +++ b/tests/test_ec2/test_virtual_private_gateways.py @@ -2,10 +2,10 @@ from __future__ import unicode_literals import boto import sure # noqa -from moto import mock_ec2 +from moto import mock_ec2_deprecated -@mock_ec2 +@mock_ec2_deprecated def test_virtual_private_gateways(): conn = boto.connect_vpc('the_key', 'the_secret') @@ -16,7 +16,7 @@ def test_virtual_private_gateways(): vpn_gateway.state.should.equal('available') vpn_gateway.availability_zone.should.equal('us-east-1a') -@mock_ec2 +@mock_ec2_deprecated def test_describe_vpn_gateway(): conn = boto.connect_vpc('the_key', 'the_secret') vpn_gateway = conn.create_vpn_gateway('ipsec.1', 'us-east-1a') @@ -32,7 +32,7 @@ def test_describe_vpn_gateway(): vpn_gateway.availability_zone.should.equal('us-east-1a') -@mock_ec2 +@mock_ec2_deprecated def test_vpn_gateway_vpc_attachment(): conn = boto.connect_vpc('the_key', 'the_secret') vpc = conn.create_vpc("10.0.0.0/16") @@ -50,7 +50,7 @@ def test_vpn_gateway_vpc_attachment(): attachments[0].state.should.equal('attached') -@mock_ec2 +@mock_ec2_deprecated def test_delete_vpn_gateway(): conn = boto.connect_vpc('the_key', 'the_secret') vpn_gateway = conn.create_vpn_gateway('ipsec.1', 'us-east-1a') @@ -60,7 +60,7 @@ def test_delete_vpn_gateway(): vgws.should.have.length_of(0) -@mock_ec2 +@mock_ec2_deprecated def test_vpn_gateway_tagging(): conn = boto.connect_vpc('the_key', 'the_secret') vpn_gateway = conn.create_vpn_gateway('ipsec.1', 'us-east-1a') @@ -76,7 +76,7 @@ def test_vpn_gateway_tagging(): vpn_gateway.tags["a key"].should.equal("some value") -@mock_ec2 +@mock_ec2_deprecated def test_detach_vpn_gateway(): conn = boto.connect_vpc('the_key', 'the_secret') diff --git a/tests/test_ec2/test_vpc_peering.py b/tests/test_ec2/test_vpc_peering.py index d41c3ab7b..c6a2feffb 100644 --- a/tests/test_ec2/test_vpc_peering.py +++ b/tests/test_ec2/test_vpc_peering.py @@ -7,12 +7,12 @@ import boto from boto.exception import EC2ResponseError import sure # noqa -from moto import mock_ec2 +from moto import mock_ec2_deprecated from tests.helpers import requires_boto_gte @requires_boto_gte("2.32.0") -@mock_ec2 +@mock_ec2_deprecated def test_vpc_peering_connections(): conn = boto.connect_vpc('the_key', 'the_secret') vpc = conn.create_vpc("10.0.0.0/16") @@ -25,7 +25,7 @@ def test_vpc_peering_connections(): @requires_boto_gte("2.32.0") -@mock_ec2 +@mock_ec2_deprecated def test_vpc_peering_connections_get_all(): conn = boto.connect_vpc('the_key', 'the_secret') vpc_pcx = test_vpc_peering_connections() @@ -37,7 +37,7 @@ def test_vpc_peering_connections_get_all(): @requires_boto_gte("2.32.0") -@mock_ec2 +@mock_ec2_deprecated def test_vpc_peering_connections_accept(): conn = boto.connect_vpc('the_key', 'the_secret') vpc_pcx = test_vpc_peering_connections() @@ -57,7 +57,7 @@ def test_vpc_peering_connections_accept(): @requires_boto_gte("2.32.0") -@mock_ec2 +@mock_ec2_deprecated def test_vpc_peering_connections_reject(): conn = boto.connect_vpc('the_key', 'the_secret') vpc_pcx = test_vpc_peering_connections() @@ -77,7 +77,7 @@ def test_vpc_peering_connections_reject(): @requires_boto_gte("2.32.1") -@mock_ec2 +@mock_ec2_deprecated def test_vpc_peering_connections_delete(): conn = boto.connect_vpc('the_key', 'the_secret') vpc_pcx = test_vpc_peering_connections() diff --git a/tests/test_ec2/test_vpcs.py b/tests/test_ec2/test_vpcs.py index 513238001..c4dbf788e 100644 --- a/tests/test_ec2/test_vpcs.py +++ b/tests/test_ec2/test_vpcs.py @@ -8,13 +8,13 @@ import boto from boto.exception import EC2ResponseError import sure # noqa -from moto import mock_ec2 +from moto import mock_ec2, mock_ec2_deprecated SAMPLE_DOMAIN_NAME = u'example.com' SAMPLE_NAME_SERVERS = [u'10.0.0.6', u'10.0.0.7'] -@mock_ec2 +@mock_ec2_deprecated def test_vpcs(): conn = boto.connect_vpc('the_key', 'the_secret') vpc = conn.create_vpc("10.0.0.0/16") @@ -35,7 +35,7 @@ def test_vpcs(): cm.exception.request_id.should_not.be.none -@mock_ec2 +@mock_ec2_deprecated def test_vpc_defaults(): conn = boto.connect_vpc('the_key', 'the_secret') vpc = conn.create_vpc("10.0.0.0/16") @@ -50,7 +50,7 @@ def test_vpc_defaults(): conn.get_all_route_tables().should.have.length_of(1) conn.get_all_security_groups(filters={'vpc-id': [vpc.id]}).should.have.length_of(0) -@mock_ec2 +@mock_ec2_deprecated def test_vpc_isdefault_filter(): conn = boto.connect_vpc('the_key', 'the_secret') vpc = conn.create_vpc("10.0.0.0/16") @@ -59,7 +59,7 @@ def test_vpc_isdefault_filter(): conn.get_all_vpcs(filters={'isDefault': 'true'}).should.have.length_of(1) -@mock_ec2 +@mock_ec2_deprecated def test_multiple_vpcs_default_filter(): conn = boto.connect_vpc('the_key', 'the_secret') conn.create_vpc("10.8.0.0/16") @@ -71,7 +71,7 @@ def test_multiple_vpcs_default_filter(): vpc[0].cidr_block.should.equal('172.31.0.0/16') -@mock_ec2 +@mock_ec2_deprecated def test_vpc_state_available_filter(): conn = boto.connect_vpc('the_key', 'the_secret') vpc = conn.create_vpc("10.0.0.0/16") @@ -80,7 +80,7 @@ def test_vpc_state_available_filter(): vpc.delete() conn.get_all_vpcs(filters={'state': 'available'}).should.have.length_of(2) -@mock_ec2 +@mock_ec2_deprecated def test_vpc_tagging(): conn = boto.connect_vpc() vpc = conn.create_vpc("10.0.0.0/16") @@ -96,7 +96,7 @@ def test_vpc_tagging(): vpc.tags["a key"].should.equal("some value") -@mock_ec2 +@mock_ec2_deprecated def test_vpc_get_by_id(): conn = boto.connect_vpc() vpc1 = conn.create_vpc("10.0.0.0/16") @@ -110,7 +110,7 @@ def test_vpc_get_by_id(): vpc2.id.should.be.within(vpc_ids) -@mock_ec2 +@mock_ec2_deprecated def test_vpc_get_by_cidr_block(): conn = boto.connect_vpc() vpc1 = conn.create_vpc("10.0.0.0/16") @@ -124,7 +124,7 @@ def test_vpc_get_by_cidr_block(): vpc2.id.should.be.within(vpc_ids) -@mock_ec2 +@mock_ec2_deprecated def test_vpc_get_by_dhcp_options_id(): conn = boto.connect_vpc() dhcp_options = conn.create_dhcp_options(SAMPLE_DOMAIN_NAME, SAMPLE_NAME_SERVERS) @@ -142,7 +142,7 @@ def test_vpc_get_by_dhcp_options_id(): vpc2.id.should.be.within(vpc_ids) -@mock_ec2 +@mock_ec2_deprecated def test_vpc_get_by_tag(): conn = boto.connect_vpc() vpc1 = conn.create_vpc("10.0.0.0/16") @@ -160,7 +160,7 @@ def test_vpc_get_by_tag(): vpc2.id.should.be.within(vpc_ids) -@mock_ec2 +@mock_ec2_deprecated def test_vpc_get_by_tag_key_superset(): conn = boto.connect_vpc() vpc1 = conn.create_vpc("10.0.0.0/16") @@ -180,7 +180,7 @@ def test_vpc_get_by_tag_key_superset(): vpc2.id.should.be.within(vpc_ids) -@mock_ec2 +@mock_ec2_deprecated def test_vpc_get_by_tag_key_subset(): conn = boto.connect_vpc() vpc1 = conn.create_vpc("10.0.0.0/16") @@ -200,7 +200,7 @@ def test_vpc_get_by_tag_key_subset(): vpc2.id.should.be.within(vpc_ids) -@mock_ec2 +@mock_ec2_deprecated def test_vpc_get_by_tag_value_superset(): conn = boto.connect_vpc() vpc1 = conn.create_vpc("10.0.0.0/16") @@ -220,7 +220,7 @@ def test_vpc_get_by_tag_value_superset(): vpc2.id.should.be.within(vpc_ids) -@mock_ec2 +@mock_ec2_deprecated def test_vpc_get_by_tag_value_subset(): conn = boto.connect_vpc() vpc1 = conn.create_vpc("10.0.0.0/16") @@ -339,7 +339,7 @@ def test_vpc_modify_enable_dns_hostnames(): attr = response.get('EnableDnsHostnames') attr.get('Value').should.be.ok -@mock_ec2 +@mock_ec2_deprecated def test_vpc_associate_dhcp_options(): conn = boto.connect_vpc() dhcp_options = conn.create_dhcp_options(SAMPLE_DOMAIN_NAME, SAMPLE_NAME_SERVERS) diff --git a/tests/test_ec2/test_vpn_connections.py b/tests/test_ec2/test_vpn_connections.py index dd96e7b65..864c1c3ee 100644 --- a/tests/test_ec2/test_vpn_connections.py +++ b/tests/test_ec2/test_vpn_connections.py @@ -4,10 +4,10 @@ from nose.tools import assert_raises import sure # noqa from boto.exception import EC2ResponseError -from moto import mock_ec2 +from moto import mock_ec2_deprecated -@mock_ec2 +@mock_ec2_deprecated def test_create_vpn_connections(): conn = boto.connect_vpc('the_key', 'the_secret') vpn_connection = conn.create_vpn_connection('ipsec.1', 'vgw-0123abcd', 'cgw-0123abcd') @@ -15,7 +15,7 @@ def test_create_vpn_connections(): vpn_connection.id.should.match(r'vpn-\w+') vpn_connection.type.should.equal('ipsec.1') -@mock_ec2 +@mock_ec2_deprecated def test_delete_vpn_connections(): conn = boto.connect_vpc('the_key', 'the_secret') vpn_connection = conn.create_vpn_connection('ipsec.1', 'vgw-0123abcd', 'cgw-0123abcd') @@ -25,13 +25,13 @@ def test_delete_vpn_connections(): list_of_vpn_connections = conn.get_all_vpn_connections() list_of_vpn_connections.should.have.length_of(0) -@mock_ec2 +@mock_ec2_deprecated def test_delete_vpn_connections_bad_id(): conn = boto.connect_vpc('the_key', 'the_secret') with assert_raises(EC2ResponseError): conn.delete_vpn_connection('vpn-0123abcd') -@mock_ec2 +@mock_ec2_deprecated def test_describe_vpn_connections(): conn = boto.connect_vpc('the_key', 'the_secret') list_of_vpn_connections = conn.get_all_vpn_connections() diff --git a/tests/test_elb/test_elb.py b/tests/test_elb/test_elb.py index 4f7687941..fa13fc23b 100644 --- a/tests/test_elb/test_elb.py +++ b/tests/test_elb/test_elb.py @@ -18,9 +18,9 @@ from boto.ec2.elb.policies import ( from boto.exception import BotoServerError import sure # noqa -from moto import mock_elb, mock_ec2 +from moto import mock_elb, mock_ec2, mock_elb_deprecated, mock_ec2_deprecated -@mock_elb +@mock_elb_deprecated def test_create_load_balancer(): conn = boto.connect_elb() @@ -43,13 +43,13 @@ def test_create_load_balancer(): listener2.protocol.should.equal("TCP") -@mock_elb +@mock_elb_deprecated def test_getting_missing_elb(): conn = boto.connect_elb() conn.get_all_load_balancers.when.called_with(load_balancer_names='aaa').should.throw(BotoServerError) -@mock_elb +@mock_elb_deprecated def test_create_elb_in_multiple_region(): zones = ['us-east-1a', 'us-east-1b'] ports = [(80, 8080, 'http'), (443, 8443, 'tcp')] @@ -63,7 +63,7 @@ def test_create_elb_in_multiple_region(): list(west1_conn.get_all_load_balancers()).should.have.length_of(1) list(west2_conn.get_all_load_balancers()).should.have.length_of(1) -@mock_elb +@mock_elb_deprecated def test_create_load_balancer_with_certificate(): conn = boto.connect_elb() @@ -99,7 +99,7 @@ def test_create_and_delete_boto3_support(): ) list(client.describe_load_balancers()['LoadBalancerDescriptions']).should.have.length_of(0) -@mock_elb +@mock_elb_deprecated def test_add_listener(): conn = boto.connect_elb() zones = ['us-east-1a', 'us-east-1b'] @@ -119,7 +119,7 @@ def test_add_listener(): listener2.protocol.should.equal("TCP") -@mock_elb +@mock_elb_deprecated def test_delete_listener(): conn = boto.connect_elb() @@ -161,7 +161,7 @@ def test_create_and_delete_listener_boto3_support(): balancer['ListenerDescriptions'][1]['Listener']['InstancePort'].should.equal(8443) -@mock_elb +@mock_elb_deprecated def test_set_sslcertificate(): conn = boto.connect_elb() @@ -178,7 +178,7 @@ def test_set_sslcertificate(): listener1.ssl_certificate_id.should.equal("arn:certificate") -@mock_elb +@mock_elb_deprecated def test_get_load_balancers_by_name(): conn = boto.connect_elb() @@ -193,7 +193,7 @@ def test_get_load_balancers_by_name(): conn.get_all_load_balancers(load_balancer_names=['my-lb1', 'my-lb2']).should.have.length_of(2) -@mock_elb +@mock_elb_deprecated def test_delete_load_balancer(): conn = boto.connect_elb() @@ -209,7 +209,7 @@ def test_delete_load_balancer(): balancers.should.have.length_of(0) -@mock_elb +@mock_elb_deprecated def test_create_health_check(): conn = boto.connect_elb() @@ -262,8 +262,8 @@ def test_create_health_check_boto3(): balancer['HealthCheck']['UnhealthyThreshold'].should.equal(5) -@mock_ec2 -@mock_elb +@mock_ec2_deprecated +@mock_elb_deprecated def test_register_instances(): ec2_conn = boto.connect_ec2() reservation = ec2_conn.run_instances('ami-1234abcd', 2) @@ -307,8 +307,8 @@ def test_register_instances_boto3(): set(instance_ids).should.equal(set([instance_id1, instance_id2])) -@mock_ec2 -@mock_elb +@mock_ec2_deprecated +@mock_elb_deprecated def test_deregister_instances(): ec2_conn = boto.connect_ec2() reservation = ec2_conn.run_instances('ami-1234abcd', 2) @@ -365,7 +365,7 @@ def test_deregister_instances_boto3(): balancer['Instances'][0]['InstanceId'].should.equal(instance_id2) -@mock_elb +@mock_elb_deprecated def test_default_attributes(): conn = boto.connect_elb() ports = [(80, 8080, 'http'), (443, 8443, 'tcp')] @@ -378,7 +378,7 @@ def test_default_attributes(): attributes.connecting_settings.idle_timeout.should.equal(60) -@mock_elb +@mock_elb_deprecated def test_cross_zone_load_balancing_attribute(): conn = boto.connect_elb() ports = [(80, 8080, 'http'), (443, 8443, 'tcp')] @@ -393,7 +393,7 @@ def test_cross_zone_load_balancing_attribute(): attributes.cross_zone_load_balancing.enabled.should.be.false -@mock_elb +@mock_elb_deprecated def test_connection_draining_attribute(): conn = boto.connect_elb() ports = [(80, 8080, 'http'), (443, 8443, 'tcp')] @@ -419,7 +419,7 @@ def test_connection_draining_attribute(): attributes.connection_draining.enabled.should.be.false -@mock_elb +@mock_elb_deprecated def test_access_log_attribute(): conn = boto.connect_elb() ports = [(80, 8080, 'http'), (443, 8443, 'tcp')] @@ -444,7 +444,7 @@ def test_access_log_attribute(): attributes.access_log.enabled.should.be.false -@mock_elb +@mock_elb_deprecated def test_connection_settings_attribute(): conn = boto.connect_elb() ports = [(80, 8080, 'http'), (443, 8443, 'tcp')] @@ -462,7 +462,7 @@ def test_connection_settings_attribute(): attributes = lb.get_attributes(force=True) attributes.connecting_settings.idle_timeout.should.equal(60) -@mock_elb +@mock_elb_deprecated def test_create_lb_cookie_stickiness_policy(): conn = boto.connect_elb() ports = [(80, 8080, 'http'), (443, 8443, 'tcp')] @@ -482,7 +482,7 @@ def test_create_lb_cookie_stickiness_policy(): int(cookie_expiration_period_response_str).should.equal(cookie_expiration_period) lb.policies.lb_cookie_stickiness_policies[0].policy_name.should.equal(policy_name) -@mock_elb +@mock_elb_deprecated def test_create_lb_cookie_stickiness_policy_no_expiry(): conn = boto.connect_elb() ports = [(80, 8080, 'http'), (443, 8443, 'tcp')] @@ -495,7 +495,7 @@ def test_create_lb_cookie_stickiness_policy_no_expiry(): lb.policies.lb_cookie_stickiness_policies[0].cookie_expiration_period.should.be.none lb.policies.lb_cookie_stickiness_policies[0].policy_name.should.equal(policy_name) -@mock_elb +@mock_elb_deprecated def test_create_app_cookie_stickiness_policy(): conn = boto.connect_elb() ports = [(80, 8080, 'http'), (443, 8443, 'tcp')] @@ -509,7 +509,7 @@ def test_create_app_cookie_stickiness_policy(): lb.policies.app_cookie_stickiness_policies[0].cookie_name.should.equal(cookie_name) lb.policies.app_cookie_stickiness_policies[0].policy_name.should.equal(policy_name) -@mock_elb +@mock_elb_deprecated def test_create_lb_policy(): conn = boto.connect_elb() ports = [(80, 8080, 'http'), (443, 8443, 'tcp')] @@ -521,7 +521,7 @@ def test_create_lb_policy(): lb = conn.get_all_load_balancers()[0] lb.policies.other_policies[0].policy_name.should.equal(policy_name) -@mock_elb +@mock_elb_deprecated def test_set_policies_of_listener(): conn = boto.connect_elb() ports = [(80, 8080, 'http'), (443, 8443, 'tcp')] @@ -543,7 +543,7 @@ def test_set_policies_of_listener(): # by contrast to a backend, a listener stores only policy name strings listener.policy_names[0].should.equal(policy_name) -@mock_elb +@mock_elb_deprecated def test_set_policies_of_backend_server(): conn = boto.connect_elb() ports = [(80, 8080, 'http'), (443, 8443, 'tcp')] @@ -562,8 +562,8 @@ def test_set_policies_of_backend_server(): # by contrast to a listener, a backend stores OtherPolicy objects backend.policies[0].policy_name.should.equal(policy_name) -@mock_ec2 -@mock_elb +@mock_ec2_deprecated +@mock_elb_deprecated def test_describe_instance_health(): ec2_conn = boto.connect_ec2() reservation = ec2_conn.run_instances('ami-1234abcd', 2) @@ -765,7 +765,7 @@ def test_subnets(): lb.should.have.key('VPCId').which.should.equal(vpc.id) -@mock_elb +@mock_elb_deprecated def test_create_load_balancer_duplicate(): conn = boto.connect_elb() ports = [(80, 8080, 'http'), (443, 8443, 'tcp')] diff --git a/tests/test_emr/test_emr.py b/tests/test_emr/test_emr.py index 71b3b8ec5..a24aa4bd4 100644 --- a/tests/test_emr/test_emr.py +++ b/tests/test_emr/test_emr.py @@ -11,7 +11,7 @@ from boto.emr.step import StreamingStep import six import sure # noqa -from moto import mock_emr +from moto import mock_emr_deprecated from tests.helpers import requires_boto_gte @@ -35,7 +35,7 @@ input_instance_groups = [ ] -@mock_emr +@mock_emr_deprecated def test_describe_cluster(): conn = boto.connect_emr() args = run_jobflow_args.copy() @@ -106,7 +106,7 @@ def test_describe_cluster(): cluster.visibletoallusers.should.equal('true') -@mock_emr +@mock_emr_deprecated def test_describe_jobflows(): conn = boto.connect_emr() args = run_jobflow_args.copy() @@ -158,7 +158,7 @@ def test_describe_jobflows(): resp.should.have.length_of(200) -@mock_emr +@mock_emr_deprecated def test_describe_jobflow(): conn = boto.connect_emr() args = run_jobflow_args.copy() @@ -241,7 +241,7 @@ def test_describe_jobflow(): jf.visibletoallusers.should.equal('true') -@mock_emr +@mock_emr_deprecated def test_list_clusters(): conn = boto.connect_emr() args = run_jobflow_args.copy() @@ -309,7 +309,7 @@ def test_list_clusters(): resp.clusters.should.have.length_of(30) -@mock_emr +@mock_emr_deprecated def test_run_jobflow(): conn = boto.connect_emr() args = run_jobflow_args.copy() @@ -326,7 +326,7 @@ def test_run_jobflow(): job_flow.steps.should.have.length_of(0) -@mock_emr +@mock_emr_deprecated def test_run_jobflow_in_multiple_regions(): regions = {} for region in ['us-east-1', 'eu-west-1']: @@ -343,7 +343,7 @@ def test_run_jobflow_in_multiple_regions(): @requires_boto_gte("2.8") -@mock_emr +@mock_emr_deprecated def test_run_jobflow_with_new_params(): # Test that run_jobflow works with newer params conn = boto.connect_emr() @@ -351,7 +351,7 @@ def test_run_jobflow_with_new_params(): @requires_boto_gte("2.8") -@mock_emr +@mock_emr_deprecated def test_run_jobflow_with_visible_to_all_users(): conn = boto.connect_emr() for expected in (True, False): @@ -364,7 +364,7 @@ def test_run_jobflow_with_visible_to_all_users(): @requires_boto_gte("2.8") -@mock_emr +@mock_emr_deprecated def test_run_jobflow_with_instance_groups(): input_groups = dict((g.name, g) for g in input_instance_groups) conn = boto.connect_emr() @@ -384,7 +384,7 @@ def test_run_jobflow_with_instance_groups(): @requires_boto_gte("2.8") -@mock_emr +@mock_emr_deprecated def test_set_termination_protection(): conn = boto.connect_emr() job_id = conn.run_jobflow(**run_jobflow_args) @@ -401,7 +401,7 @@ def test_set_termination_protection(): @requires_boto_gte("2.8") -@mock_emr +@mock_emr_deprecated def test_set_visible_to_all_users(): conn = boto.connect_emr() args = run_jobflow_args.copy() @@ -419,7 +419,7 @@ def test_set_visible_to_all_users(): job_flow.visibletoallusers.should.equal('false') -@mock_emr +@mock_emr_deprecated def test_terminate_jobflow(): conn = boto.connect_emr() job_id = conn.run_jobflow(**run_jobflow_args) @@ -433,7 +433,7 @@ def test_terminate_jobflow(): # testing multiple end points for each feature -@mock_emr +@mock_emr_deprecated def test_bootstrap_actions(): bootstrap_actions = [ BootstrapAction( @@ -466,7 +466,7 @@ def test_bootstrap_actions(): list(arg.value for arg in x.args).should.equal(y.args()) -@mock_emr +@mock_emr_deprecated def test_instance_groups(): input_groups = dict((g.name, g) for g in input_instance_groups) @@ -536,7 +536,7 @@ def test_instance_groups(): int(igs['task-2'].instancerunningcount).should.equal(3) -@mock_emr +@mock_emr_deprecated def test_steps(): input_steps = [ StreamingStep( @@ -633,7 +633,7 @@ def test_steps(): test_list_steps_with_states() -@mock_emr +@mock_emr_deprecated def test_tags(): input_tags = {"tag1": "val1", "tag2": "val2"} diff --git a/tests/test_glacier/test_glacier_archives.py b/tests/test_glacier/test_glacier_archives.py index 6a139a91c..e8fa6045e 100644 --- a/tests/test_glacier/test_glacier_archives.py +++ b/tests/test_glacier/test_glacier_archives.py @@ -4,10 +4,10 @@ from tempfile import NamedTemporaryFile import boto.glacier import sure # noqa -from moto import mock_glacier +from moto import mock_glacier_deprecated -@mock_glacier +@mock_glacier_deprecated def test_create_and_delete_archive(): the_file = NamedTemporaryFile(delete=False) the_file.write(b"some stuff") diff --git a/tests/test_glacier/test_glacier_jobs.py b/tests/test_glacier/test_glacier_jobs.py index 7eff3566e..ef4a00b75 100644 --- a/tests/test_glacier/test_glacier_jobs.py +++ b/tests/test_glacier/test_glacier_jobs.py @@ -5,10 +5,10 @@ import json from boto.glacier.layer1 import Layer1 import sure # noqa -from moto import mock_glacier +from moto import mock_glacier_deprecated -@mock_glacier +@mock_glacier_deprecated def test_init_glacier_job(): conn = Layer1(region_name="us-west-2") vault_name = "my_vault" @@ -23,7 +23,7 @@ def test_init_glacier_job(): job_response['Location'].should.equal("//vaults/my_vault/jobs/{0}".format(job_id)) -@mock_glacier +@mock_glacier_deprecated def test_describe_job(): conn = Layer1(region_name="us-west-2") vault_name = "my_vault" @@ -56,7 +56,7 @@ def test_describe_job(): }) -@mock_glacier +@mock_glacier_deprecated def test_list_glacier_jobs(): conn = Layer1(region_name="us-west-2") vault_name = "my_vault" @@ -77,7 +77,7 @@ def test_list_glacier_jobs(): len(jobs['JobList']).should.equal(2) -@mock_glacier +@mock_glacier_deprecated def test_get_job_output(): conn = Layer1(region_name="us-west-2") vault_name = "my_vault" diff --git a/tests/test_glacier/test_glacier_vaults.py b/tests/test_glacier/test_glacier_vaults.py index 40f20e58e..e64f40a90 100644 --- a/tests/test_glacier/test_glacier_vaults.py +++ b/tests/test_glacier/test_glacier_vaults.py @@ -3,10 +3,10 @@ from __future__ import unicode_literals import boto.glacier import sure # noqa -from moto import mock_glacier +from moto import mock_glacier_deprecated -@mock_glacier +@mock_glacier_deprecated def test_create_vault(): conn = boto.glacier.connect_to_region("us-west-2") @@ -17,7 +17,7 @@ def test_create_vault(): vaults[0].name.should.equal("my_vault") -@mock_glacier +@mock_glacier_deprecated def test_delete_vault(): conn = boto.glacier.connect_to_region("us-west-2") diff --git a/tests/test_iam/test_iam.py b/tests/test_iam/test_iam.py index de8f89a59..a51240b2f 100644 --- a/tests/test_iam/test_iam.py +++ b/tests/test_iam/test_iam.py @@ -6,7 +6,7 @@ import boto3 import sure # noqa from boto.exception import BotoServerError from botocore.exceptions import ClientError -from moto import mock_iam +from moto import mock_iam, mock_iam_deprecated from moto.iam.models import aws_managed_policies from nose.tools import assert_raises, assert_equals, assert_not_equals from nose.tools import raises @@ -14,7 +14,7 @@ from nose.tools import raises from tests.helpers import requires_boto_gte -@mock_iam() +@mock_iam_deprecated() def test_get_all_server_certs(): conn = boto.connect_iam() @@ -26,7 +26,7 @@ def test_get_all_server_certs(): cert1.arn.should.equal("arn:aws:iam::123456789012:server-certificate/certname") -@mock_iam() +@mock_iam_deprecated() def test_get_server_cert_doesnt_exist(): conn = boto.connect_iam() @@ -34,7 +34,7 @@ def test_get_server_cert_doesnt_exist(): conn.get_server_certificate("NonExistant") -@mock_iam() +@mock_iam_deprecated() def test_get_server_cert(): conn = boto.connect_iam() @@ -44,7 +44,7 @@ def test_get_server_cert(): cert.arn.should.equal("arn:aws:iam::123456789012:server-certificate/certname") -@mock_iam() +@mock_iam_deprecated() def test_upload_server_cert(): conn = boto.connect_iam() @@ -54,7 +54,7 @@ def test_upload_server_cert(): cert.arn.should.equal("arn:aws:iam::123456789012:server-certificate/certname") -@mock_iam() +@mock_iam_deprecated() @raises(BotoServerError) def test_get_role__should_throw__when_role_does_not_exist(): conn = boto.connect_iam() @@ -62,7 +62,7 @@ def test_get_role__should_throw__when_role_does_not_exist(): conn.get_role('unexisting_role') -@mock_iam() +@mock_iam_deprecated() @raises(BotoServerError) def test_get_instance_profile__should_throw__when_instance_profile_does_not_exist(): conn = boto.connect_iam() @@ -70,7 +70,7 @@ def test_get_instance_profile__should_throw__when_instance_profile_does_not_exis conn.get_instance_profile('unexisting_instance_profile') -@mock_iam() +@mock_iam_deprecated() def test_create_role_and_instance_profile(): conn = boto.connect_iam() conn.create_instance_profile("my-profile", path="my-path") @@ -91,7 +91,7 @@ def test_create_role_and_instance_profile(): conn.list_roles().roles[0].role_name.should.equal('my-role') -@mock_iam() +@mock_iam_deprecated() def test_remove_role_from_instance_profile(): conn = boto.connect_iam() conn.create_instance_profile("my-profile", path="my-path") @@ -108,7 +108,7 @@ def test_remove_role_from_instance_profile(): dict(profile.roles).should.be.empty -@mock_iam() +@mock_iam_deprecated() def test_list_instance_profiles(): conn = boto.connect_iam() conn.create_instance_profile("my-profile", path="my-path") @@ -123,7 +123,7 @@ def test_list_instance_profiles(): profiles[0].roles.role_name.should.equal("my-role") -@mock_iam() +@mock_iam_deprecated() def test_list_instance_profiles_for_role(): conn = boto.connect_iam() @@ -153,7 +153,7 @@ def test_list_instance_profiles_for_role(): len(profile_list).should.equal(0) -@mock_iam() +@mock_iam_deprecated() def test_list_role_policies(): conn = boto.connect_iam() conn.create_role("my-role") @@ -162,7 +162,7 @@ def test_list_role_policies(): role.policy_names[0].should.equal("test policy") -@mock_iam() +@mock_iam_deprecated() def test_put_role_policy(): conn = boto.connect_iam() conn.create_role("my-role", assume_role_policy_document="some policy", path="my-path") @@ -171,7 +171,7 @@ def test_put_role_policy(): policy.should.equal("test policy") -@mock_iam() +@mock_iam_deprecated() def test_update_assume_role_policy(): conn = boto.connect_iam() role = conn.create_role("my-role") @@ -180,7 +180,7 @@ def test_update_assume_role_policy(): role.assume_role_policy_document.should.equal("my-policy") -@mock_iam() +@mock_iam_deprecated() def test_create_user(): conn = boto.connect_iam() conn.create_user('my-user') @@ -188,7 +188,7 @@ def test_create_user(): conn.create_user('my-user') -@mock_iam() +@mock_iam_deprecated() def test_get_user(): conn = boto.connect_iam() with assert_raises(BotoServerError): @@ -210,7 +210,7 @@ def test_list_users(): user['Arn'].should.equal('arn:aws:iam::123456789012:user/my-user') -@mock_iam() +@mock_iam_deprecated() def test_create_login_profile(): conn = boto.connect_iam() with assert_raises(BotoServerError): @@ -221,7 +221,7 @@ def test_create_login_profile(): conn.create_login_profile('my-user', 'my-pass') -@mock_iam() +@mock_iam_deprecated() def test_delete_login_profile(): conn = boto.connect_iam() conn.create_user('my-user') @@ -231,7 +231,7 @@ def test_delete_login_profile(): conn.delete_login_profile('my-user') -@mock_iam() +@mock_iam_deprecated() def test_create_access_key(): conn = boto.connect_iam() with assert_raises(BotoServerError): @@ -240,7 +240,7 @@ def test_create_access_key(): conn.create_access_key('my-user') -@mock_iam() +@mock_iam_deprecated() def test_get_all_access_keys(): conn = boto.connect_iam() conn.create_user('my-user') @@ -257,7 +257,7 @@ def test_get_all_access_keys(): ) -@mock_iam() +@mock_iam_deprecated() def test_delete_access_key(): conn = boto.connect_iam() conn.create_user('my-user') @@ -265,7 +265,7 @@ def test_delete_access_key(): conn.delete_access_key(access_key_id, 'my-user') -@mock_iam() +@mock_iam_deprecated() def test_delete_user(): conn = boto.connect_iam() with assert_raises(BotoServerError): @@ -274,7 +274,7 @@ def test_delete_user(): conn.delete_user('my-user') -@mock_iam() +@mock_iam_deprecated() def test_generate_credential_report(): conn = boto.connect_iam() result = conn.generate_credential_report() @@ -283,7 +283,7 @@ def test_generate_credential_report(): result['generate_credential_report_response']['generate_credential_report_result']['state'].should.equal('COMPLETE') -@mock_iam() +@mock_iam_deprecated() def test_get_credential_report(): conn = boto.connect_iam() conn.create_user('my-user') @@ -298,7 +298,7 @@ def test_get_credential_report(): @requires_boto_gte('2.39') -@mock_iam() +@mock_iam_deprecated() def test_managed_policy(): conn = boto.connect_iam() diff --git a/tests/test_iam/test_iam_groups.py b/tests/test_iam/test_iam_groups.py index 412484a70..6fd0f47dd 100644 --- a/tests/test_iam/test_iam_groups.py +++ b/tests/test_iam/test_iam_groups.py @@ -4,10 +4,10 @@ import sure # noqa from nose.tools import assert_raises from boto.exception import BotoServerError -from moto import mock_iam +from moto import mock_iam, mock_iam_deprecated -@mock_iam() +@mock_iam_deprecated() def test_create_group(): conn = boto.connect_iam() conn.create_group('my-group') @@ -15,7 +15,7 @@ def test_create_group(): conn.create_group('my-group') -@mock_iam() +@mock_iam_deprecated() def test_get_group(): conn = boto.connect_iam() conn.create_group('my-group') @@ -24,7 +24,7 @@ def test_get_group(): conn.get_group('not-group') -@mock_iam() +@mock_iam_deprecated() def test_get_all_groups(): conn = boto.connect_iam() conn.create_group('my-group1') @@ -33,7 +33,7 @@ def test_get_all_groups(): groups.should.have.length_of(2) -@mock_iam() +@mock_iam_deprecated() def test_add_user_to_group(): conn = boto.connect_iam() with assert_raises(BotoServerError): @@ -45,7 +45,7 @@ def test_add_user_to_group(): conn.add_user_to_group('my-group', 'my-user') -@mock_iam() +@mock_iam_deprecated() def test_remove_user_from_group(): conn = boto.connect_iam() with assert_raises(BotoServerError): @@ -58,7 +58,7 @@ def test_remove_user_from_group(): conn.remove_user_from_group('my-group', 'my-user') -@mock_iam() +@mock_iam_deprecated() def test_get_groups_for_user(): conn = boto.connect_iam() conn.create_group('my-group1') diff --git a/tests/test_kinesis/test_kinesis.py b/tests/test_kinesis/test_kinesis.py index 0e4f29625..a86bce44c 100644 --- a/tests/test_kinesis/test_kinesis.py +++ b/tests/test_kinesis/test_kinesis.py @@ -4,10 +4,10 @@ import boto.kinesis from boto.kinesis.exceptions import ResourceNotFoundException, InvalidArgumentException import sure # noqa -from moto import mock_kinesis +from moto import mock_kinesis_deprecated -@mock_kinesis +@mock_kinesis_deprecated def test_create_cluster(): conn = boto.kinesis.connect_to_region("us-west-2") @@ -25,13 +25,13 @@ def test_create_cluster(): shards.should.have.length_of(2) -@mock_kinesis +@mock_kinesis_deprecated def test_describe_non_existant_stream(): conn = boto.kinesis.connect_to_region("us-east-1") conn.describe_stream.when.called_with("not-a-stream").should.throw(ResourceNotFoundException) -@mock_kinesis +@mock_kinesis_deprecated def test_list_and_delete_stream(): conn = boto.kinesis.connect_to_region("us-west-2") @@ -48,7 +48,7 @@ def test_list_and_delete_stream(): conn.delete_stream.when.called_with("not-a-stream").should.throw(ResourceNotFoundException) -@mock_kinesis +@mock_kinesis_deprecated def test_basic_shard_iterator(): conn = boto.kinesis.connect_to_region("us-west-2") @@ -66,7 +66,7 @@ def test_basic_shard_iterator(): response['Records'].should.equal([]) -@mock_kinesis +@mock_kinesis_deprecated def test_get_invalid_shard_iterator(): conn = boto.kinesis.connect_to_region("us-west-2") @@ -76,7 +76,7 @@ def test_get_invalid_shard_iterator(): conn.get_shard_iterator.when.called_with(stream_name, "123", 'TRIM_HORIZON').should.throw(ResourceNotFoundException) -@mock_kinesis +@mock_kinesis_deprecated def test_put_records(): conn = boto.kinesis.connect_to_region("us-west-2") @@ -107,7 +107,7 @@ def test_put_records(): record["SequenceNumber"].should.equal("1") -@mock_kinesis +@mock_kinesis_deprecated def test_get_records_limit(): conn = boto.kinesis.connect_to_region("us-west-2") @@ -136,7 +136,7 @@ def test_get_records_limit(): response['Records'].should.have.length_of(2) -@mock_kinesis +@mock_kinesis_deprecated def test_get_records_at_sequence_number(): # AT_SEQUENCE_NUMBER - Start reading exactly from the position denoted by a specific sequence number. conn = boto.kinesis.connect_to_region("us-west-2") @@ -167,7 +167,7 @@ def test_get_records_at_sequence_number(): response['Records'][0]['Data'].should.equal('2') -@mock_kinesis +@mock_kinesis_deprecated def test_get_records_after_sequence_number(): # AFTER_SEQUENCE_NUMBER - Start reading right after the position denoted by a specific sequence number. conn = boto.kinesis.connect_to_region("us-west-2") @@ -197,7 +197,7 @@ def test_get_records_after_sequence_number(): response['Records'][0]['Data'].should.equal('3') -@mock_kinesis +@mock_kinesis_deprecated def test_get_records_latest(): # LATEST - Start reading just after the most recent record in the shard, so that you always read the most recent data in the shard. conn = boto.kinesis.connect_to_region("us-west-2") @@ -232,7 +232,7 @@ def test_get_records_latest(): response['Records'][0]['Data'].should.equal('last_record') -@mock_kinesis +@mock_kinesis_deprecated def test_invalid_shard_iterator_type(): conn = boto.kinesis.connect_to_region("us-west-2") stream_name = "my_stream" @@ -244,7 +244,7 @@ def test_invalid_shard_iterator_type(): stream_name, shard_id, 'invalid-type').should.throw(InvalidArgumentException) -@mock_kinesis +@mock_kinesis_deprecated def test_add_tags(): conn = boto.kinesis.connect_to_region("us-west-2") stream_name = "my_stream" @@ -257,7 +257,7 @@ def test_add_tags(): conn.add_tags_to_stream(stream_name, {'tag2':'val4'}) -@mock_kinesis +@mock_kinesis_deprecated def test_list_tags(): conn = boto.kinesis.connect_to_region("us-west-2") stream_name = "my_stream" @@ -278,7 +278,7 @@ def test_list_tags(): tags.get('tag2').should.equal('val4') -@mock_kinesis +@mock_kinesis_deprecated def test_remove_tags(): conn = boto.kinesis.connect_to_region("us-west-2") stream_name = "my_stream" @@ -300,7 +300,7 @@ def test_remove_tags(): tags.get('tag2').should.equal(None) -@mock_kinesis +@mock_kinesis_deprecated def test_split_shard(): conn = boto.kinesis.connect_to_region("us-west-2") stream_name = 'my_stream' @@ -341,7 +341,7 @@ def test_split_shard(): sum([shard['SequenceNumberRange']['EndingSequenceNumber'] for shard in shards]).should.equal(99) -@mock_kinesis +@mock_kinesis_deprecated def test_merge_shards(): conn = boto.kinesis.connect_to_region("us-west-2") stream_name = 'my_stream' diff --git a/tests/test_kms/test_kms.py b/tests/test_kms/test_kms.py index 04e6fbb4b..27850d4ad 100644 --- a/tests/test_kms/test_kms.py +++ b/tests/test_kms/test_kms.py @@ -5,10 +5,10 @@ import boto.kms from boto.exception import JSONResponseError from boto.kms.exceptions import AlreadyExistsException, NotFoundException import sure # noqa -from moto import mock_kms +from moto import mock_kms_deprecated from nose.tools import assert_raises -@mock_kms +@mock_kms_deprecated def test_create_key(): conn = boto.kms.connect_to_region("us-west-2") @@ -19,7 +19,7 @@ def test_create_key(): key['KeyMetadata']['Enabled'].should.equal(True) -@mock_kms +@mock_kms_deprecated def test_describe_key(): conn = boto.kms.connect_to_region("us-west-2") key = conn.create_key(policy="my policy", description="my key", key_usage='ENCRYPT_DECRYPT') @@ -30,7 +30,7 @@ def test_describe_key(): key['KeyMetadata']['KeyUsage'].should.equal("ENCRYPT_DECRYPT") -@mock_kms +@mock_kms_deprecated def test_describe_key_via_alias(): conn = boto.kms.connect_to_region("us-west-2") key = conn.create_key(policy="my policy", description="my key", key_usage='ENCRYPT_DECRYPT') @@ -42,7 +42,7 @@ def test_describe_key_via_alias(): alias_key['KeyMetadata']['Arn'].should.equal(key['KeyMetadata']['Arn']) -@mock_kms +@mock_kms_deprecated def test_describe_key_via_alias_not_found(): conn = boto.kms.connect_to_region("us-west-2") key = conn.create_key(policy="my policy", description="my key", key_usage='ENCRYPT_DECRYPT') @@ -51,7 +51,7 @@ def test_describe_key_via_alias_not_found(): conn.describe_key.when.called_with('alias/not-found-alias').should.throw(JSONResponseError) -@mock_kms +@mock_kms_deprecated def test_describe_key_via_arn(): conn = boto.kms.connect_to_region("us-west-2") key = conn.create_key(policy="my policy", description="my key", key_usage='ENCRYPT_DECRYPT') @@ -63,13 +63,13 @@ def test_describe_key_via_arn(): the_key['KeyMetadata']['KeyId'].should.equal(key['KeyMetadata']['KeyId']) -@mock_kms +@mock_kms_deprecated def test_describe_missing_key(): conn = boto.kms.connect_to_region("us-west-2") conn.describe_key.when.called_with("not-a-key").should.throw(JSONResponseError) -@mock_kms +@mock_kms_deprecated def test_list_keys(): conn = boto.kms.connect_to_region("us-west-2") @@ -80,7 +80,7 @@ def test_list_keys(): keys['Keys'].should.have.length_of(2) -@mock_kms +@mock_kms_deprecated def test_enable_key_rotation(): conn = boto.kms.connect_to_region("us-west-2") @@ -91,7 +91,7 @@ def test_enable_key_rotation(): conn.get_key_rotation_status(key_id)['KeyRotationEnabled'].should.equal(True) -@mock_kms +@mock_kms_deprecated def test_enable_key_rotation_via_arn(): conn = boto.kms.connect_to_region("us-west-2") @@ -104,13 +104,13 @@ def test_enable_key_rotation_via_arn(): -@mock_kms +@mock_kms_deprecated def test_enable_key_rotation_with_missing_key(): conn = boto.kms.connect_to_region("us-west-2") conn.enable_key_rotation.when.called_with("not-a-key").should.throw(JSONResponseError) -@mock_kms +@mock_kms_deprecated def test_enable_key_rotation_with_alias_name_should_fail(): conn = boto.kms.connect_to_region("us-west-2") key = conn.create_key(policy="my policy", description="my key", key_usage='ENCRYPT_DECRYPT') @@ -122,7 +122,7 @@ def test_enable_key_rotation_with_alias_name_should_fail(): conn.enable_key_rotation.when.called_with('alias/my-alias').should.throw(JSONResponseError) -@mock_kms +@mock_kms_deprecated def test_disable_key_rotation(): conn = boto.kms.connect_to_region("us-west-2") @@ -136,7 +136,7 @@ def test_disable_key_rotation(): conn.get_key_rotation_status(key_id)['KeyRotationEnabled'].should.equal(False) -@mock_kms +@mock_kms_deprecated def test_encrypt(): """ test_encrypt @@ -147,26 +147,26 @@ def test_encrypt(): response['CiphertextBlob'].should.equal(b'ZW5jcnlwdG1l') -@mock_kms +@mock_kms_deprecated def test_decrypt(): conn = boto.kms.connect_to_region('us-west-2') response = conn.decrypt('ZW5jcnlwdG1l'.encode('utf-8')) response['Plaintext'].should.equal(b'encryptme') -@mock_kms +@mock_kms_deprecated def test_disable_key_rotation_with_missing_key(): conn = boto.kms.connect_to_region("us-west-2") conn.disable_key_rotation.when.called_with("not-a-key").should.throw(JSONResponseError) -@mock_kms +@mock_kms_deprecated def test_get_key_rotation_status_with_missing_key(): conn = boto.kms.connect_to_region("us-west-2") conn.get_key_rotation_status.when.called_with("not-a-key").should.throw(JSONResponseError) -@mock_kms +@mock_kms_deprecated def test_get_key_rotation_status(): conn = boto.kms.connect_to_region("us-west-2") @@ -176,7 +176,7 @@ def test_get_key_rotation_status(): conn.get_key_rotation_status(key_id)['KeyRotationEnabled'].should.equal(False) -@mock_kms +@mock_kms_deprecated def test_create_key_defaults_key_rotation(): conn = boto.kms.connect_to_region("us-west-2") @@ -186,7 +186,7 @@ def test_create_key_defaults_key_rotation(): conn.get_key_rotation_status(key_id)['KeyRotationEnabled'].should.equal(False) -@mock_kms +@mock_kms_deprecated def test_get_key_policy(): conn = boto.kms.connect_to_region('us-west-2') @@ -196,7 +196,7 @@ def test_get_key_policy(): policy = conn.get_key_policy(key_id, 'default') policy['Policy'].should.equal('my policy') -@mock_kms +@mock_kms_deprecated def test_get_key_policy_via_arn(): conn = boto.kms.connect_to_region('us-west-2') @@ -205,7 +205,7 @@ def test_get_key_policy_via_arn(): policy['Policy'].should.equal('my policy') -@mock_kms +@mock_kms_deprecated def test_put_key_policy(): conn = boto.kms.connect_to_region('us-west-2') @@ -217,7 +217,7 @@ def test_put_key_policy(): policy['Policy'].should.equal('new policy') -@mock_kms +@mock_kms_deprecated def test_put_key_policy_via_arn(): conn = boto.kms.connect_to_region('us-west-2') @@ -229,7 +229,7 @@ def test_put_key_policy_via_arn(): policy['Policy'].should.equal('new policy') -@mock_kms +@mock_kms_deprecated def test_put_key_policy_via_alias_should_not_update(): conn = boto.kms.connect_to_region('us-west-2') @@ -242,7 +242,7 @@ def test_put_key_policy_via_alias_should_not_update(): policy['Policy'].should.equal('my policy') -@mock_kms +@mock_kms_deprecated def test_put_key_policy(): conn = boto.kms.connect_to_region('us-west-2') @@ -253,7 +253,7 @@ def test_put_key_policy(): policy['Policy'].should.equal('new policy') -@mock_kms +@mock_kms_deprecated def test_list_key_policies(): conn = boto.kms.connect_to_region('us-west-2') @@ -264,7 +264,7 @@ def test_list_key_policies(): policies['PolicyNames'].should.equal(['default']) -@mock_kms +@mock_kms_deprecated def test__create_alias__returns_none_if_correct(): kms = boto.connect_kms() create_resp = kms.create_key() @@ -275,7 +275,7 @@ def test__create_alias__returns_none_if_correct(): resp.should.be.none -@mock_kms +@mock_kms_deprecated def test__create_alias__raises_if_reserved_alias(): kms = boto.connect_kms() create_resp = kms.create_key() @@ -300,7 +300,7 @@ def test__create_alias__raises_if_reserved_alias(): ex.status.should.equal(400) -@mock_kms +@mock_kms_deprecated def test__create_alias__can_create_multiple_aliases_for_same_key_id(): kms = boto.connect_kms() create_resp = kms.create_key() @@ -311,7 +311,7 @@ def test__create_alias__can_create_multiple_aliases_for_same_key_id(): kms.create_alias('alias/my-alias5', key_id).should.be.none -@mock_kms +@mock_kms_deprecated def test__create_alias__raises_if_wrong_prefix(): kms = boto.connect_kms() create_resp = kms.create_key() @@ -328,7 +328,7 @@ def test__create_alias__raises_if_wrong_prefix(): ex.status.should.equal(400) -@mock_kms +@mock_kms_deprecated def test__create_alias__raises_if_duplicate(): region = 'us-west-2' kms = boto.kms.connect_to_region(region) @@ -354,7 +354,7 @@ def test__create_alias__raises_if_duplicate(): ex.status.should.equal(400) -@mock_kms +@mock_kms_deprecated def test__create_alias__raises_if_alias_has_restricted_characters(): kms = boto.connect_kms() create_resp = kms.create_key() @@ -378,7 +378,7 @@ def test__create_alias__raises_if_alias_has_restricted_characters(): ex.status.should.equal(400) -@mock_kms +@mock_kms_deprecated def test__create_alias__raises_if_alias_has_colon_character(): # For some reason, colons are not accepted for an alias, even though they are accepted by regex ^[a-zA-Z0-9:/_-]+$ kms = boto.connect_kms() @@ -401,7 +401,7 @@ def test__create_alias__raises_if_alias_has_colon_character(): ex.status.should.equal(400) -@mock_kms +@mock_kms_deprecated def test__create_alias__accepted_characters(): kms = boto.connect_kms() create_resp = kms.create_key() @@ -416,7 +416,7 @@ def test__create_alias__accepted_characters(): kms.create_alias(alias_name, key_id) -@mock_kms +@mock_kms_deprecated def test__create_alias__raises_if_target_key_id_is_existing_alias(): kms = boto.connect_kms() create_resp = kms.create_key() @@ -437,7 +437,7 @@ def test__create_alias__raises_if_target_key_id_is_existing_alias(): ex.status.should.equal(400) -@mock_kms +@mock_kms_deprecated def test__delete_alias(): kms = boto.connect_kms() create_resp = kms.create_key() @@ -454,7 +454,7 @@ def test__delete_alias(): kms.create_alias(alias, key_id) -@mock_kms +@mock_kms_deprecated def test__delete_alias__raises_if_wrong_prefix(): kms = boto.connect_kms() @@ -470,7 +470,7 @@ def test__delete_alias__raises_if_wrong_prefix(): ex.status.should.equal(400) -@mock_kms +@mock_kms_deprecated def test__delete_alias__raises_if_alias_is_not_found(): region = 'us-west-2' kms = boto.kms.connect_to_region(region) @@ -490,7 +490,7 @@ def test__delete_alias__raises_if_alias_is_not_found(): ex.status.should.equal(400) -@mock_kms +@mock_kms_deprecated def test__list_aliases(): region = "eu-west-1" kms = boto.kms.connect_to_region(region) @@ -532,7 +532,7 @@ def test__list_aliases(): len(aliases).should.equal(7) -@mock_kms +@mock_kms_deprecated def test__assert_valid_key_id(): from moto.kms.responses import _assert_valid_key_id import uuid @@ -541,7 +541,7 @@ def test__assert_valid_key_id(): _assert_valid_key_id.when.called_with(str(uuid.uuid4())).should_not.throw(JSONResponseError) -@mock_kms +@mock_kms_deprecated def test__assert_default_policy(): from moto.kms.responses import _assert_default_policy diff --git a/tests/test_opsworks/test_layers.py b/tests/test_opsworks/test_layers.py index 1392d8c6e..dc268bbe5 100644 --- a/tests/test_opsworks/test_layers.py +++ b/tests/test_opsworks/test_layers.py @@ -66,7 +66,7 @@ def test_describe_layers(): rv1 = client.describe_layers(StackId=stack_id) rv2 = client.describe_layers(LayerIds=[layer_id]) - rv1.should.equal(rv2) + rv1['Layers'].should.equal(rv2['Layers']) rv1['Layers'][0]['Name'].should.equal("TestLayer") diff --git a/tests/test_rds/test_rds.py b/tests/test_rds/test_rds.py index 6078b5f6b..7a6cab633 100644 --- a/tests/test_rds/test_rds.py +++ b/tests/test_rds/test_rds.py @@ -5,12 +5,12 @@ import boto.vpc from boto.exception import BotoServerError import sure # noqa -from moto import mock_ec2, mock_rds +from moto import mock_ec2_deprecated, mock_rds_deprecated from tests.helpers import disable_on_py3 @disable_on_py3() -@mock_rds +@mock_rds_deprecated def test_create_database(): conn = boto.rds.connect_to_region("us-west-2") @@ -27,7 +27,7 @@ def test_create_database(): @disable_on_py3() -@mock_rds +@mock_rds_deprecated def test_get_databases(): conn = boto.rds.connect_to_region("us-west-2") @@ -44,14 +44,14 @@ def test_get_databases(): databases[0].id.should.equal("db-master-1") -@mock_rds +@mock_rds_deprecated def test_describe_non_existant_database(): conn = boto.rds.connect_to_region("us-west-2") conn.get_all_dbinstances.when.called_with("not-a-db").should.throw(BotoServerError) @disable_on_py3() -@mock_rds +@mock_rds_deprecated def test_delete_database(): conn = boto.rds.connect_to_region("us-west-2") list(conn.get_all_dbinstances()).should.have.length_of(0) @@ -63,13 +63,13 @@ def test_delete_database(): list(conn.get_all_dbinstances()).should.have.length_of(0) -@mock_rds +@mock_rds_deprecated def test_delete_non_existant_database(): conn = boto.rds.connect_to_region("us-west-2") conn.delete_dbinstance.when.called_with("not-a-db").should.throw(BotoServerError) -@mock_rds +@mock_rds_deprecated def test_create_database_security_group(): conn = boto.rds.connect_to_region("us-west-2") @@ -79,7 +79,7 @@ def test_create_database_security_group(): list(security_group.ip_ranges).should.equal([]) -@mock_rds +@mock_rds_deprecated def test_get_security_groups(): conn = boto.rds.connect_to_region("us-west-2") @@ -96,13 +96,13 @@ def test_get_security_groups(): databases[0].name.should.equal("db_sg1") -@mock_rds +@mock_rds_deprecated def test_get_non_existant_security_group(): conn = boto.rds.connect_to_region("us-west-2") conn.get_all_dbsecurity_groups.when.called_with("not-a-sg").should.throw(BotoServerError) -@mock_rds +@mock_rds_deprecated def test_delete_database_security_group(): conn = boto.rds.connect_to_region("us-west-2") conn.create_dbsecurity_group('db_sg', 'DB Security Group') @@ -113,14 +113,14 @@ def test_delete_database_security_group(): list(conn.get_all_dbsecurity_groups()).should.have.length_of(0) -@mock_rds +@mock_rds_deprecated def test_delete_non_existant_security_group(): conn = boto.rds.connect_to_region("us-west-2") conn.delete_dbsecurity_group.when.called_with("not-a-db").should.throw(BotoServerError) @disable_on_py3() -@mock_rds +@mock_rds_deprecated def test_security_group_authorize(): conn = boto.rds.connect_to_region("us-west-2") security_group = conn.create_dbsecurity_group('db_sg', 'DB Security Group') @@ -133,7 +133,7 @@ def test_security_group_authorize(): @disable_on_py3() -@mock_rds +@mock_rds_deprecated def test_add_security_group_to_database(): conn = boto.rds.connect_to_region("us-west-2") @@ -147,8 +147,8 @@ def test_add_security_group_to_database(): database.security_groups[0].name.should.equal("db_sg") -@mock_ec2 -@mock_rds +@mock_ec2_deprecated +@mock_rds_deprecated def test_add_database_subnet_group(): vpc_conn = boto.vpc.connect_to_region("us-west-2") vpc = vpc_conn.create_vpc("10.0.0.0/16") @@ -163,8 +163,8 @@ def test_add_database_subnet_group(): list(subnet_group.subnet_ids).should.equal(subnet_ids) -@mock_ec2 -@mock_rds +@mock_ec2_deprecated +@mock_rds_deprecated def test_describe_database_subnet_group(): vpc_conn = boto.vpc.connect_to_region("us-west-2") vpc = vpc_conn.create_vpc("10.0.0.0/16") @@ -180,8 +180,8 @@ def test_describe_database_subnet_group(): conn.get_all_db_subnet_groups.when.called_with("not-a-subnet").should.throw(BotoServerError) -@mock_ec2 -@mock_rds +@mock_ec2_deprecated +@mock_rds_deprecated def test_delete_database_subnet_group(): vpc_conn = boto.vpc.connect_to_region("us-west-2") vpc = vpc_conn.create_vpc("10.0.0.0/16") @@ -198,8 +198,8 @@ def test_delete_database_subnet_group(): @disable_on_py3() -@mock_ec2 -@mock_rds +@mock_ec2_deprecated +@mock_rds_deprecated def test_create_database_in_subnet_group(): vpc_conn = boto.vpc.connect_to_region("us-west-2") vpc = vpc_conn.create_vpc("10.0.0.0/16") @@ -216,7 +216,7 @@ def test_create_database_in_subnet_group(): @disable_on_py3() -@mock_rds +@mock_rds_deprecated def test_create_database_replica(): conn = boto.rds.connect_to_region("us-west-2") @@ -239,7 +239,7 @@ def test_create_database_replica(): list(primary.read_replica_dbinstance_identifiers).should.have.length_of(0) @disable_on_py3() -@mock_rds +@mock_rds_deprecated def test_create_cross_region_database_replica(): west_1_conn = boto.rds.connect_to_region("us-west-1") west_2_conn = boto.rds.connect_to_region("us-west-2") @@ -266,7 +266,7 @@ def test_create_cross_region_database_replica(): @disable_on_py3() -@mock_rds +@mock_rds_deprecated def test_connecting_to_us_east_1(): # boto does not use us-east-1 in the URL for RDS, # and that broke moto in the past: @@ -286,7 +286,7 @@ def test_connecting_to_us_east_1(): @disable_on_py3() -@mock_rds +@mock_rds_deprecated def test_create_database_with_iops(): conn = boto.rds.connect_to_region("us-west-2") diff --git a/tests/test_rds2/test_rds2.py b/tests/test_rds2/test_rds2.py index 4e1c2b73c..581209655 100644 --- a/tests/test_rds2/test_rds2.py +++ b/tests/test_rds2/test_rds2.py @@ -1,7 +1,5 @@ from __future__ import unicode_literals -import boto.rds2 -import boto.vpc from botocore.exceptions import ClientError, ParamValidationError import boto3 import sure # noqa diff --git a/tests/test_redshift/test_redshift.py b/tests/test_redshift/test_redshift.py index 700301418..13acf6d7c 100644 --- a/tests/test_redshift/test_redshift.py +++ b/tests/test_redshift/test_redshift.py @@ -10,10 +10,10 @@ from boto.redshift.exceptions import ( ) import sure # noqa -from moto import mock_ec2, mock_redshift +from moto import mock_ec2_deprecated, mock_redshift_deprecated -@mock_redshift +@mock_redshift_deprecated def test_create_cluster(): conn = boto.redshift.connect_to_region("us-east-1") cluster_identifier = 'my_cluster' @@ -54,7 +54,7 @@ def test_create_cluster(): cluster['NumberOfNodes'].should.equal(3) -@mock_redshift +@mock_redshift_deprecated def test_create_single_node_cluster(): conn = boto.redshift.connect_to_region("us-east-1") cluster_identifier = 'my_cluster' @@ -78,7 +78,7 @@ def test_create_single_node_cluster(): cluster['NumberOfNodes'].should.equal(1) -@mock_redshift +@mock_redshift_deprecated def test_default_cluster_attibutes(): conn = boto.redshift.connect_to_region("us-east-1") cluster_identifier = 'my_cluster' @@ -105,8 +105,8 @@ def test_default_cluster_attibutes(): cluster['NumberOfNodes'].should.equal(1) -@mock_redshift -@mock_ec2 +@mock_redshift_deprecated +@mock_ec2_deprecated def test_create_cluster_in_subnet_group(): vpc_conn = boto.connect_vpc() vpc = vpc_conn.create_vpc("10.0.0.0/16") @@ -131,7 +131,7 @@ def test_create_cluster_in_subnet_group(): cluster['ClusterSubnetGroupName'].should.equal('my_subnet_group') -@mock_redshift +@mock_redshift_deprecated def test_create_cluster_with_security_group(): conn = boto.redshift.connect_to_region("us-east-1") conn.create_cluster_security_group( @@ -158,8 +158,8 @@ def test_create_cluster_with_security_group(): set(group_names).should.equal(set(["security_group1", "security_group2"])) -@mock_redshift -@mock_ec2 +@mock_redshift_deprecated +@mock_ec2_deprecated def test_create_cluster_with_vpc_security_groups(): vpc_conn = boto.connect_vpc() ec2_conn = boto.connect_ec2() @@ -181,7 +181,7 @@ def test_create_cluster_with_vpc_security_groups(): list(group_ids).should.equal([security_group.id]) -@mock_redshift +@mock_redshift_deprecated def test_create_cluster_with_parameter_group(): conn = boto.connect_redshift() conn.create_cluster_parameter_group( @@ -203,13 +203,13 @@ def test_create_cluster_with_parameter_group(): cluster['ClusterParameterGroups'][0]['ParameterGroupName'].should.equal("my_parameter_group") -@mock_redshift +@mock_redshift_deprecated def test_describe_non_existant_cluster(): conn = boto.redshift.connect_to_region("us-east-1") conn.describe_clusters.when.called_with("not-a-cluster").should.throw(ClusterNotFound) -@mock_redshift +@mock_redshift_deprecated def test_delete_cluster(): conn = boto.connect_redshift() cluster_identifier = 'my_cluster' @@ -233,7 +233,7 @@ def test_delete_cluster(): conn.delete_cluster.when.called_with("not-a-cluster").should.throw(ClusterNotFound) -@mock_redshift +@mock_redshift_deprecated def test_modify_cluster(): conn = boto.connect_redshift() cluster_identifier = 'my_cluster' @@ -281,8 +281,8 @@ def test_modify_cluster(): cluster['NumberOfNodes'].should.equal(2) -@mock_redshift -@mock_ec2 +@mock_redshift_deprecated +@mock_ec2_deprecated def test_create_cluster_subnet_group(): vpc_conn = boto.connect_vpc() vpc = vpc_conn.create_vpc("10.0.0.0/16") @@ -306,8 +306,8 @@ def test_create_cluster_subnet_group(): set(subnet_ids).should.equal(set([subnet1.id, subnet2.id])) -@mock_redshift -@mock_ec2 +@mock_redshift_deprecated +@mock_ec2_deprecated def test_create_invalid_cluster_subnet_group(): redshift_conn = boto.connect_redshift() redshift_conn.create_cluster_subnet_group.when.called_with( @@ -317,14 +317,14 @@ def test_create_invalid_cluster_subnet_group(): ).should.throw(InvalidSubnet) -@mock_redshift +@mock_redshift_deprecated def test_describe_non_existant_subnet_group(): conn = boto.redshift.connect_to_region("us-east-1") conn.describe_cluster_subnet_groups.when.called_with("not-a-subnet-group").should.throw(ClusterSubnetGroupNotFound) -@mock_redshift -@mock_ec2 +@mock_redshift_deprecated +@mock_ec2_deprecated def test_delete_cluster_subnet_group(): vpc_conn = boto.connect_vpc() vpc = vpc_conn.create_vpc("10.0.0.0/16") @@ -351,7 +351,7 @@ def test_delete_cluster_subnet_group(): redshift_conn.delete_cluster_subnet_group.when.called_with("not-a-subnet-group").should.throw(ClusterSubnetGroupNotFound) -@mock_redshift +@mock_redshift_deprecated def test_create_cluster_security_group(): conn = boto.connect_redshift() conn.create_cluster_security_group( @@ -367,13 +367,13 @@ def test_create_cluster_security_group(): list(my_group['IPRanges']).should.equal([]) -@mock_redshift +@mock_redshift_deprecated def test_describe_non_existant_security_group(): conn = boto.redshift.connect_to_region("us-east-1") conn.describe_cluster_security_groups.when.called_with("not-a-security-group").should.throw(ClusterSecurityGroupNotFound) -@mock_redshift +@mock_redshift_deprecated def test_delete_cluster_security_group(): conn = boto.connect_redshift() conn.create_cluster_security_group( @@ -395,7 +395,7 @@ def test_delete_cluster_security_group(): conn.delete_cluster_security_group.when.called_with("not-a-security-group").should.throw(ClusterSecurityGroupNotFound) -@mock_redshift +@mock_redshift_deprecated def test_create_cluster_parameter_group(): conn = boto.connect_redshift() conn.create_cluster_parameter_group( @@ -412,13 +412,13 @@ def test_create_cluster_parameter_group(): my_group['Description'].should.equal("This is my parameter group") -@mock_redshift +@mock_redshift_deprecated def test_describe_non_existant_parameter_group(): conn = boto.redshift.connect_to_region("us-east-1") conn.describe_cluster_parameter_groups.when.called_with("not-a-parameter-group").should.throw(ClusterParameterGroupNotFound) -@mock_redshift +@mock_redshift_deprecated def test_delete_cluster_parameter_group(): conn = boto.connect_redshift() conn.create_cluster_parameter_group( diff --git a/tests/test_route53/test_route53.py b/tests/test_route53/test_route53.py index b5b2000cc..dd68eec0e 100644 --- a/tests/test_route53/test_route53.py +++ b/tests/test_route53/test_route53.py @@ -9,10 +9,10 @@ import sure # noqa import uuid -from moto import mock_route53 +from moto import mock_route53, mock_route53_deprecated -@mock_route53 +@mock_route53_deprecated def test_hosted_zone(): conn = boto.connect_route53('the_key', 'the_secret') firstzone = conn.create_hosted_zone("testdns.aws.com") @@ -34,7 +34,7 @@ def test_hosted_zone(): conn.get_hosted_zone.when.called_with("abcd").should.throw(boto.route53.exception.DNSServerError, "404 Not Found") -@mock_route53 +@mock_route53_deprecated def test_rrset(): conn = boto.connect_route53('the_key', 'the_secret') @@ -117,7 +117,7 @@ def test_rrset(): rrsets.should.have.length_of(0) -@mock_route53 +@mock_route53_deprecated def test_rrset_with_multiple_values(): conn = boto.connect_route53('the_key', 'the_secret') zone = conn.create_hosted_zone("testdns.aws.com") @@ -134,7 +134,7 @@ def test_rrset_with_multiple_values(): set(rrsets[0].resource_records).should.equal(set(['1.2.3.4', '5.6.7.8'])) -@mock_route53 +@mock_route53_deprecated def test_alias_rrset(): conn = boto.connect_route53('the_key', 'the_secret') zone = conn.create_hosted_zone("testdns.aws.com") @@ -153,7 +153,7 @@ def test_alias_rrset(): rrsets[0].resource_records[0].should.equal('bar.testdns.aws.com') -@mock_route53 +@mock_route53_deprecated def test_create_health_check(): conn = boto.connect_route53('the_key', 'the_secret') @@ -183,7 +183,7 @@ def test_create_health_check(): config['FailureThreshold'].should.equal("2") -@mock_route53 +@mock_route53_deprecated def test_delete_health_check(): conn = boto.connect_route53('the_key', 'the_secret') @@ -204,7 +204,7 @@ def test_delete_health_check(): list(checks).should.have.length_of(0) -@mock_route53 +@mock_route53_deprecated def test_use_health_check_in_resource_record_set(): conn = boto.connect_route53('the_key', 'the_secret') @@ -229,7 +229,7 @@ def test_use_health_check_in_resource_record_set(): record_sets[0].health_check.should.equal(check_id) -@mock_route53 +@mock_route53_deprecated def test_hosted_zone_comment_preserved(): conn = boto.connect_route53('the_key', 'the_secret') @@ -246,7 +246,7 @@ def test_hosted_zone_comment_preserved(): zone.config["Comment"].should.equal("test comment") -@mock_route53 +@mock_route53_deprecated def test_deleting_weighted_route(): conn = boto.connect_route53() @@ -266,7 +266,7 @@ def test_deleting_weighted_route(): cname.identifier.should.equal('success-test-bar') -@mock_route53 +@mock_route53_deprecated def test_deleting_latency_route(): conn = boto.connect_route53() @@ -288,7 +288,7 @@ def test_deleting_latency_route(): cname.region.should.equal('us-west-1') -@mock_route53 +@mock_route53_deprecated def test_hosted_zone_private_zone_preserved(): conn = boto.connect_route53('the_key', 'the_secret') diff --git a/tests/test_s3/test_s3.py b/tests/test_s3/test_s3.py index 4990d7324..874230737 100644 --- a/tests/test_s3/test_s3.py +++ b/tests/test_s3/test_s3.py @@ -20,7 +20,7 @@ from nose.tools import assert_raises import sure # noqa -from moto import mock_s3 +from moto import mock_s3, mock_s3_deprecated REDUCED_PART_SIZE = 256 @@ -56,7 +56,7 @@ class MyModel(object): k.set_contents_from_string(self.value) -@mock_s3 +@mock_s3_deprecated def test_my_model_save(): # Create Bucket so that test can run conn = boto.connect_s3('the_key', 'the_secret') @@ -69,7 +69,7 @@ def test_my_model_save(): conn.get_bucket('mybucket').get_key('steve').get_contents_as_string().should.equal(b'is awesome') -@mock_s3 +@mock_s3_deprecated def test_key_etag(): # Create Bucket so that test can run conn = boto.connect_s3('the_key', 'the_secret') @@ -83,7 +83,7 @@ def test_key_etag(): '"d32bda93738f7e03adb22e66c90fbc04"') -@mock_s3 +@mock_s3_deprecated def test_multipart_upload_too_small(): conn = boto.connect_s3('the_key', 'the_secret') bucket = conn.create_bucket("foobar") @@ -95,7 +95,7 @@ def test_multipart_upload_too_small(): multipart.complete_upload.should.throw(S3ResponseError) -@mock_s3 +@mock_s3_deprecated @reduced_min_part_size def test_multipart_upload(): conn = boto.connect_s3('the_key', 'the_secret') @@ -112,7 +112,7 @@ def test_multipart_upload(): bucket.get_key("the-key").get_contents_as_string().should.equal(part1 + part2) -@mock_s3 +@mock_s3_deprecated @reduced_min_part_size def test_multipart_upload_out_of_order(): conn = boto.connect_s3('the_key', 'the_secret') @@ -129,7 +129,7 @@ def test_multipart_upload_out_of_order(): bucket.get_key("the-key").get_contents_as_string().should.equal(part1 + part2) -@mock_s3 +@mock_s3_deprecated @reduced_min_part_size def test_multipart_upload_with_headers(): conn = boto.connect_s3('the_key', 'the_secret') @@ -144,7 +144,7 @@ def test_multipart_upload_with_headers(): key.metadata.should.equal({"foo": "bar"}) -@mock_s3 +@mock_s3_deprecated @reduced_min_part_size def test_multipart_upload_with_copy_key(): conn = boto.connect_s3('the_key', 'the_secret') @@ -161,7 +161,7 @@ def test_multipart_upload_with_copy_key(): bucket.get_key("the-key").get_contents_as_string().should.equal(part1 + b"key_") -@mock_s3 +@mock_s3_deprecated @reduced_min_part_size def test_multipart_upload_cancel(): conn = boto.connect_s3('the_key', 'the_secret') @@ -175,7 +175,7 @@ def test_multipart_upload_cancel(): # have the ability to list mulipart uploads for a bucket. -@mock_s3 +@mock_s3_deprecated @reduced_min_part_size def test_multipart_etag(): # Create Bucket so that test can run @@ -194,7 +194,7 @@ def test_multipart_etag(): '"66d1a1a2ed08fd05c137f316af4ff255-2"') -@mock_s3 +@mock_s3_deprecated @reduced_min_part_size def test_multipart_invalid_order(): # Create Bucket so that test can run @@ -214,7 +214,7 @@ def test_multipart_invalid_order(): multipart.key_name, multipart.id, xml).should.throw(S3ResponseError) -@mock_s3 +@mock_s3_deprecated @reduced_min_part_size def test_multipart_duplicate_upload(): conn = boto.connect_s3('the_key', 'the_secret') @@ -232,7 +232,7 @@ def test_multipart_duplicate_upload(): bucket.get_key("the-key").get_contents_as_string().should.equal(part1 + part2) -@mock_s3 +@mock_s3_deprecated def test_list_multiparts(): # Create Bucket so that test can run conn = boto.connect_s3('the_key', 'the_secret') @@ -253,7 +253,7 @@ def test_list_multiparts(): uploads.should.be.empty -@mock_s3 +@mock_s3_deprecated def test_key_save_to_missing_bucket(): conn = boto.connect_s3('the_key', 'the_secret') bucket = conn.get_bucket('mybucket', validate=False) @@ -263,14 +263,14 @@ def test_key_save_to_missing_bucket(): key.set_contents_from_string.when.called_with("foobar").should.throw(S3ResponseError) -@mock_s3 +@mock_s3_deprecated def test_missing_key(): conn = boto.connect_s3('the_key', 'the_secret') bucket = conn.create_bucket("foobar") bucket.get_key("the-key").should.equal(None) -@mock_s3 +@mock_s3_deprecated def test_missing_key_urllib2(): conn = boto.connect_s3('the_key', 'the_secret') conn.create_bucket("foobar") @@ -278,7 +278,7 @@ def test_missing_key_urllib2(): urlopen.when.called_with("http://foobar.s3.amazonaws.com/the-key").should.throw(HTTPError) -@mock_s3 +@mock_s3_deprecated def test_empty_key(): conn = boto.connect_s3('the_key', 'the_secret') bucket = conn.create_bucket("foobar") @@ -291,7 +291,7 @@ def test_empty_key(): key.get_contents_as_string().should.equal(b'') -@mock_s3 +@mock_s3_deprecated def test_empty_key_set_on_existing_key(): conn = boto.connect_s3('the_key', 'the_secret') bucket = conn.create_bucket("foobar") @@ -307,7 +307,7 @@ def test_empty_key_set_on_existing_key(): bucket.get_key("the-key").get_contents_as_string().should.equal(b'') -@mock_s3 +@mock_s3_deprecated def test_large_key_save(): conn = boto.connect_s3('the_key', 'the_secret') bucket = conn.create_bucket("foobar") @@ -318,7 +318,7 @@ def test_large_key_save(): bucket.get_key("the-key").get_contents_as_string().should.equal(b'foobar' * 100000) -@mock_s3 +@mock_s3_deprecated def test_copy_key(): conn = boto.connect_s3('the_key', 'the_secret') bucket = conn.create_bucket("foobar") @@ -332,7 +332,7 @@ def test_copy_key(): bucket.get_key("new-key").get_contents_as_string().should.equal(b"some value") -@mock_s3 +@mock_s3_deprecated def test_copy_key_with_version(): conn = boto.connect_s3('the_key', 'the_secret') bucket = conn.create_bucket("foobar") @@ -348,7 +348,7 @@ def test_copy_key_with_version(): bucket.get_key("new-key").get_contents_as_string().should.equal(b"some value") -@mock_s3 +@mock_s3_deprecated def test_set_metadata(): conn = boto.connect_s3('the_key', 'the_secret') bucket = conn.create_bucket("foobar") @@ -360,7 +360,7 @@ def test_set_metadata(): bucket.get_key('the-key').get_metadata('md').should.equal('Metadatastring') -@mock_s3 +@mock_s3_deprecated def test_copy_key_replace_metadata(): conn = boto.connect_s3('the_key', 'the_secret') bucket = conn.create_bucket("foobar") @@ -377,7 +377,7 @@ def test_copy_key_replace_metadata(): @freeze_time("2012-01-01 12:00:00") -@mock_s3 +@mock_s3_deprecated def test_last_modified(): # See https://github.com/boto/boto/issues/466 conn = boto.connect_s3() @@ -392,19 +392,19 @@ def test_last_modified(): bucket.get_key("the-key").last_modified.should.equal('Sun, 01 Jan 2012 12:00:00 GMT') -@mock_s3 +@mock_s3_deprecated def test_missing_bucket(): conn = boto.connect_s3('the_key', 'the_secret') conn.get_bucket.when.called_with('mybucket').should.throw(S3ResponseError) -@mock_s3 +@mock_s3_deprecated def test_bucket_with_dash(): conn = boto.connect_s3('the_key', 'the_secret') conn.get_bucket.when.called_with('mybucket-test').should.throw(S3ResponseError) -@mock_s3 +@mock_s3_deprecated def test_create_existing_bucket(): "Trying to create a bucket that already exists should raise an Error" conn = boto.s3.connect_to_region("us-west-2") @@ -413,7 +413,7 @@ def test_create_existing_bucket(): conn.create_bucket('foobar') -@mock_s3 +@mock_s3_deprecated def test_create_existing_bucket_in_us_east_1(): "Trying to create a bucket that already exists in us-east-1 returns the bucket" @@ -430,14 +430,14 @@ def test_create_existing_bucket_in_us_east_1(): bucket.name.should.equal("foobar") -@mock_s3 +@mock_s3_deprecated def test_other_region(): conn = S3Connection('key', 'secret', host='s3-website-ap-southeast-2.amazonaws.com') conn.create_bucket("foobar") list(conn.get_bucket("foobar").get_all_keys()).should.equal([]) -@mock_s3 +@mock_s3_deprecated def test_bucket_deletion(): conn = boto.connect_s3('the_key', 'the_secret') bucket = conn.create_bucket("foobar") @@ -459,7 +459,7 @@ def test_bucket_deletion(): conn.delete_bucket.when.called_with("foobar").should.throw(S3ResponseError) -@mock_s3 +@mock_s3_deprecated def test_get_all_buckets(): conn = boto.connect_s3('the_key', 'the_secret') conn.create_bucket("foobar") @@ -470,6 +470,7 @@ def test_get_all_buckets(): @mock_s3 +@mock_s3_deprecated def test_post_to_bucket(): conn = boto.connect_s3('the_key', 'the_secret') bucket = conn.create_bucket("foobar") @@ -483,6 +484,7 @@ def test_post_to_bucket(): @mock_s3 +@mock_s3_deprecated def test_post_with_metadata_to_bucket(): conn = boto.connect_s3('the_key', 'the_secret') bucket = conn.create_bucket("foobar") @@ -496,7 +498,7 @@ def test_post_with_metadata_to_bucket(): bucket.get_key('the-key').get_metadata('test').should.equal('metadata') -@mock_s3 +@mock_s3_deprecated def test_delete_missing_key(): conn = boto.connect_s3('the_key', 'the_secret') bucket = conn.create_bucket('foobar') @@ -505,7 +507,7 @@ def test_delete_missing_key(): deleted_key.key.should.equal("foobar") -@mock_s3 +@mock_s3_deprecated def test_delete_keys(): conn = boto.connect_s3('the_key', 'the_secret') bucket = conn.create_bucket('foobar') @@ -523,7 +525,7 @@ def test_delete_keys(): keys[0].name.should.equal('file1') -@mock_s3 +@mock_s3_deprecated def test_delete_keys_with_invalid(): conn = boto.connect_s3('the_key', 'the_secret') bucket = conn.create_bucket('foobar') @@ -552,7 +554,7 @@ def test_key_method_not_implemented(): requests.post.when.called_with("https://foobar.s3.amazonaws.com/foo").should.throw(NotImplementedError) -@mock_s3 +@mock_s3_deprecated def test_bucket_name_with_dot(): conn = boto.connect_s3() bucket = conn.create_bucket('firstname.lastname') @@ -561,7 +563,7 @@ def test_bucket_name_with_dot(): k.set_contents_from_string('somedata') -@mock_s3 +@mock_s3_deprecated def test_key_with_special_characters(): conn = boto.connect_s3() bucket = conn.create_bucket('test_bucket_name') @@ -574,7 +576,7 @@ def test_key_with_special_characters(): keys[0].name.should.equal("test_list_keys_2/x?y") -@mock_s3 +@mock_s3_deprecated def test_unicode_key_with_slash(): conn = boto.connect_s3('the_key', 'the_secret') bucket = conn.create_bucket("foobar") @@ -586,7 +588,7 @@ def test_unicode_key_with_slash(): key.get_contents_as_string().should.equal(b'value') -@mock_s3 +@mock_s3_deprecated def test_bucket_key_listing_order(): conn = boto.connect_s3() bucket = conn.create_bucket('test_bucket') @@ -628,7 +630,7 @@ def test_bucket_key_listing_order(): keys.should.equal([u'toplevel/x/']) -@mock_s3 +@mock_s3_deprecated def test_key_with_reduced_redundancy(): conn = boto.connect_s3() bucket = conn.create_bucket('test_bucket_name') @@ -640,7 +642,7 @@ def test_key_with_reduced_redundancy(): list(bucket)[0].storage_class.should.equal('REDUCED_REDUNDANCY') -@mock_s3 +@mock_s3_deprecated def test_copy_key_reduced_redundancy(): conn = boto.connect_s3('the_key', 'the_secret') bucket = conn.create_bucket("foobar") @@ -658,7 +660,7 @@ def test_copy_key_reduced_redundancy(): @freeze_time("2012-01-01 12:00:00") -@mock_s3 +@mock_s3_deprecated def test_restore_key(): conn = boto.connect_s3('the_key', 'the_secret') bucket = conn.create_bucket("foobar") @@ -679,7 +681,7 @@ def test_restore_key(): @freeze_time("2012-01-01 12:00:00") -@mock_s3 +@mock_s3_deprecated def test_restore_key_headers(): conn = boto.connect_s3('the_key', 'the_secret') bucket = conn.create_bucket("foobar") @@ -693,7 +695,7 @@ def test_restore_key_headers(): key.expiry_date.should.equal("Mon, 02 Jan 2012 12:00:00 GMT") -@mock_s3 +@mock_s3_deprecated def test_get_versioning_status(): conn = boto.connect_s3('the_key', 'the_secret') bucket = conn.create_bucket('foobar') @@ -710,7 +712,7 @@ def test_get_versioning_status(): d.should.have.key('Versioning').being.equal('Suspended') -@mock_s3 +@mock_s3_deprecated def test_key_version(): conn = boto.connect_s3('the_key', 'the_secret') bucket = conn.create_bucket('foobar') @@ -728,7 +730,7 @@ def test_key_version(): key.version_id.should.equal('1') -@mock_s3 +@mock_s3_deprecated def test_list_versions(): conn = boto.connect_s3('the_key', 'the_secret') bucket = conn.create_bucket('foobar') @@ -754,7 +756,7 @@ def test_list_versions(): versions[1].get_contents_as_string().should.equal(b"Version 2") -@mock_s3 +@mock_s3_deprecated def test_acl_setting(): conn = boto.connect_s3() bucket = conn.create_bucket('foobar') @@ -775,7 +777,7 @@ def test_acl_setting(): g.permission == 'READ' for g in grants), grants -@mock_s3 +@mock_s3_deprecated def test_acl_setting_via_headers(): conn = boto.connect_s3() bucket = conn.create_bucket('foobar') @@ -797,7 +799,7 @@ def test_acl_setting_via_headers(): g.permission == 'FULL_CONTROL' for g in grants), grants -@mock_s3 +@mock_s3_deprecated def test_acl_switching(): conn = boto.connect_s3() bucket = conn.create_bucket('foobar') @@ -814,7 +816,7 @@ def test_acl_switching(): g.permission == 'READ' for g in grants), grants -@mock_s3 +@mock_s3_deprecated def test_bucket_acl_setting(): conn = boto.connect_s3() bucket = conn.create_bucket('foobar') @@ -826,7 +828,7 @@ def test_bucket_acl_setting(): g.permission == 'READ' for g in grants), grants -@mock_s3 +@mock_s3_deprecated def test_bucket_acl_switching(): conn = boto.connect_s3() bucket = conn.create_bucket('foobar') @@ -839,7 +841,7 @@ def test_bucket_acl_switching(): g.permission == 'READ' for g in grants), grants -@mock_s3 +@mock_s3_deprecated def test_unicode_key(): conn = boto.connect_s3() bucket = conn.create_bucket('mybucket') @@ -852,7 +854,7 @@ def test_unicode_key(): assert fetched_key.get_contents_as_string().decode("utf-8") == 'Hello world!' -@mock_s3 +@mock_s3_deprecated def test_unicode_value(): conn = boto.connect_s3() bucket = conn.create_bucket('mybucket') @@ -864,7 +866,7 @@ def test_unicode_value(): assert key.get_contents_as_string().decode("utf-8") == u'こんにちは.jpg' -@mock_s3 +@mock_s3_deprecated def test_setting_content_encoding(): conn = boto.connect_s3() bucket = conn.create_bucket('mybucket') @@ -877,14 +879,14 @@ def test_setting_content_encoding(): key.content_encoding.should.equal("gzip") -@mock_s3 +@mock_s3_deprecated def test_bucket_location(): conn = boto.s3.connect_to_region("us-west-2") bucket = conn.create_bucket('mybucket') bucket.get_location().should.equal("us-west-2") -@mock_s3 +@mock_s3_deprecated def test_ranged_get(): conn = boto.connect_s3() bucket = conn.create_bucket('mybucket') @@ -926,7 +928,7 @@ def test_ranged_get(): key.size.should.equal(100) -@mock_s3 +@mock_s3_deprecated def test_policy(): conn = boto.connect_s3() bucket_name = 'mybucket' @@ -976,6 +978,31 @@ def test_policy(): bucket.get_policy() +@mock_s3_deprecated +def test_website_configuration_xml(): + conn = boto.connect_s3() + bucket = conn.create_bucket('test-bucket') + bucket.set_website_configuration_xml(TEST_XML) + bucket.get_website_configuration_xml().should.equal(TEST_XML) + + +@mock_s3_deprecated +def test_key_with_trailing_slash_in_ordinary_calling_format(): + conn = boto.connect_s3( + 'access_key', + 'secret_key', + calling_format=boto.s3.connection.OrdinaryCallingFormat() + ) + bucket = conn.create_bucket('test_bucket_name') + + key_name = 'key_with_slash/' + + key = Key(bucket, key_name) + key.set_contents_from_string('some value') + + [k.name for k in bucket.get_all_keys()].should.contain(key_name) + + """ boto3 """ @@ -1235,28 +1262,3 @@ TEST_XML = """\ """ - - -@mock_s3 -def test_website_configuration_xml(): - conn = boto.connect_s3() - bucket = conn.create_bucket('test-bucket') - bucket.set_website_configuration_xml(TEST_XML) - bucket.get_website_configuration_xml().should.equal(TEST_XML) - - -@mock_s3 -def test_key_with_trailing_slash_in_ordinary_calling_format(): - conn = boto.connect_s3( - 'access_key', - 'secret_key', - calling_format=boto.s3.connection.OrdinaryCallingFormat() - ) - bucket = conn.create_bucket('test_bucket_name') - - key_name = 'key_with_slash/' - - key = Key(bucket, key_name) - key.set_contents_from_string('some value') - - [k.name for k in bucket.get_all_keys()].should.contain(key_name) diff --git a/tests/test_s3/test_s3_lifecycle.py b/tests/test_s3/test_s3_lifecycle.py index 60613de44..f0a70bc6f 100644 --- a/tests/test_s3/test_s3_lifecycle.py +++ b/tests/test_s3/test_s3_lifecycle.py @@ -6,10 +6,10 @@ from boto.s3.lifecycle import Lifecycle, Transition, Expiration, Rule import sure # noqa -from moto import mock_s3 +from moto import mock_s3_deprecated -@mock_s3 +@mock_s3_deprecated def test_lifecycle_create(): conn = boto.s3.connect_to_region("us-west-1") bucket = conn.create_bucket("foobar") @@ -26,7 +26,7 @@ def test_lifecycle_create(): list(lifecycle.transition).should.equal([]) -@mock_s3 +@mock_s3_deprecated def test_lifecycle_with_glacier_transition(): conn = boto.s3.connect_to_region("us-west-1") bucket = conn.create_bucket("foobar") @@ -44,7 +44,7 @@ def test_lifecycle_with_glacier_transition(): transition.date.should.equal(None) -@mock_s3 +@mock_s3_deprecated def test_lifecycle_multi(): conn = boto.s3.connect_to_region("us-west-1") bucket = conn.create_bucket("foobar") @@ -86,7 +86,7 @@ def test_lifecycle_multi(): assert False, "Invalid rule id" -@mock_s3 +@mock_s3_deprecated def test_lifecycle_delete(): conn = boto.s3.connect_to_region("us-west-1") bucket = conn.create_bucket("foobar") diff --git a/tests/test_s3bucket_path/test_s3bucket_path.py b/tests/test_s3bucket_path/test_s3bucket_path.py index eff01bf55..24c5f7fa5 100644 --- a/tests/test_s3bucket_path/test_s3bucket_path.py +++ b/tests/test_s3bucket_path/test_s3bucket_path.py @@ -12,7 +12,7 @@ import requests import sure # noqa -from moto import mock_s3bucket_path +from moto import mock_s3, mock_s3_deprecated def create_connection(key=None, secret=None): @@ -32,7 +32,7 @@ class MyModel(object): k.set_contents_from_string(self.value) -@mock_s3bucket_path +@mock_s3_deprecated def test_my_model_save(): # Create Bucket so that test can run conn = create_connection('the_key', 'the_secret') @@ -45,14 +45,14 @@ def test_my_model_save(): conn.get_bucket('mybucket').get_key('steve').get_contents_as_string().should.equal(b'is awesome') -@mock_s3bucket_path +@mock_s3_deprecated def test_missing_key(): conn = create_connection('the_key', 'the_secret') bucket = conn.create_bucket("foobar") bucket.get_key("the-key").should.equal(None) -@mock_s3bucket_path +@mock_s3_deprecated def test_missing_key_urllib2(): conn = create_connection('the_key', 'the_secret') conn.create_bucket("foobar") @@ -60,7 +60,7 @@ def test_missing_key_urllib2(): urlopen.when.called_with("http://s3.amazonaws.com/foobar/the-key").should.throw(HTTPError) -@mock_s3bucket_path +@mock_s3_deprecated def test_empty_key(): conn = create_connection('the_key', 'the_secret') bucket = conn.create_bucket("foobar") @@ -71,7 +71,7 @@ def test_empty_key(): bucket.get_key("the-key").get_contents_as_string().should.equal(b'') -@mock_s3bucket_path +@mock_s3_deprecated def test_empty_key_set_on_existing_key(): conn = create_connection('the_key', 'the_secret') bucket = conn.create_bucket("foobar") @@ -85,7 +85,7 @@ def test_empty_key_set_on_existing_key(): bucket.get_key("the-key").get_contents_as_string().should.equal(b'') -@mock_s3bucket_path +@mock_s3_deprecated def test_large_key_save(): conn = create_connection('the_key', 'the_secret') bucket = conn.create_bucket("foobar") @@ -96,7 +96,7 @@ def test_large_key_save(): bucket.get_key("the-key").get_contents_as_string().should.equal(b'foobar' * 100000) -@mock_s3bucket_path +@mock_s3_deprecated def test_copy_key(): conn = create_connection('the_key', 'the_secret') bucket = conn.create_bucket("foobar") @@ -110,7 +110,7 @@ def test_copy_key(): bucket.get_key("new-key").get_contents_as_string().should.equal(b"some value") -@mock_s3bucket_path +@mock_s3_deprecated def test_set_metadata(): conn = create_connection('the_key', 'the_secret') bucket = conn.create_bucket("foobar") @@ -123,7 +123,7 @@ def test_set_metadata(): @freeze_time("2012-01-01 12:00:00") -@mock_s3bucket_path +@mock_s3_deprecated def test_last_modified(): # See https://github.com/boto/boto/issues/466 conn = create_connection() @@ -138,19 +138,19 @@ def test_last_modified(): bucket.get_key("the-key").last_modified.should.equal('Sun, 01 Jan 2012 12:00:00 GMT') -@mock_s3bucket_path +@mock_s3_deprecated def test_missing_bucket(): conn = create_connection('the_key', 'the_secret') conn.get_bucket.when.called_with('mybucket').should.throw(S3ResponseError) -@mock_s3bucket_path +@mock_s3_deprecated def test_bucket_with_dash(): conn = create_connection('the_key', 'the_secret') conn.get_bucket.when.called_with('mybucket-test').should.throw(S3ResponseError) -@mock_s3bucket_path +@mock_s3_deprecated def test_bucket_deletion(): conn = create_connection('the_key', 'the_secret') bucket = conn.create_bucket("foobar") @@ -172,7 +172,7 @@ def test_bucket_deletion(): conn.delete_bucket.when.called_with("foobar").should.throw(S3ResponseError) -@mock_s3bucket_path +@mock_s3_deprecated def test_get_all_buckets(): conn = create_connection('the_key', 'the_secret') conn.create_bucket("foobar") @@ -182,7 +182,8 @@ def test_get_all_buckets(): buckets.should.have.length_of(2) -@mock_s3bucket_path +@mock_s3 +@mock_s3_deprecated def test_post_to_bucket(): conn = create_connection('the_key', 'the_secret') bucket = conn.create_bucket("foobar") @@ -195,7 +196,8 @@ def test_post_to_bucket(): bucket.get_key('the-key').get_contents_as_string().should.equal(b'nothing') -@mock_s3bucket_path +@mock_s3 +@mock_s3_deprecated def test_post_with_metadata_to_bucket(): conn = create_connection('the_key', 'the_secret') bucket = conn.create_bucket("foobar") @@ -209,17 +211,17 @@ def test_post_with_metadata_to_bucket(): bucket.get_key('the-key').get_metadata('test').should.equal('metadata') -@mock_s3bucket_path +@mock_s3 def test_bucket_method_not_implemented(): requests.patch.when.called_with("https://s3.amazonaws.com/foobar").should.throw(NotImplementedError) -@mock_s3bucket_path +@mock_s3 def test_key_method_not_implemented(): requests.post.when.called_with("https://s3.amazonaws.com/foobar/foo").should.throw(NotImplementedError) -@mock_s3bucket_path +@mock_s3_deprecated def test_bucket_name_with_dot(): conn = create_connection() bucket = conn.create_bucket('firstname.lastname') @@ -228,7 +230,7 @@ def test_bucket_name_with_dot(): k.set_contents_from_string('somedata') -@mock_s3bucket_path +@mock_s3_deprecated def test_key_with_special_characters(): conn = create_connection() bucket = conn.create_bucket('test_bucket_name') @@ -241,7 +243,7 @@ def test_key_with_special_characters(): keys[0].name.should.equal("test_list_keys_2/*x+?^@~!y") -@mock_s3bucket_path +@mock_s3_deprecated def test_bucket_key_listing_order(): conn = create_connection() bucket = conn.create_bucket('test_bucket') @@ -283,7 +285,7 @@ def test_bucket_key_listing_order(): keys.should.equal(['toplevel/x/']) -@mock_s3bucket_path +@mock_s3_deprecated def test_delete_keys(): conn = create_connection() bucket = conn.create_bucket('foobar') @@ -301,7 +303,7 @@ def test_delete_keys(): keys[0].name.should.equal('file1') -@mock_s3bucket_path +@mock_s3_deprecated def test_delete_keys_with_invalid(): conn = create_connection() bucket = conn.create_bucket('foobar') diff --git a/tests/test_s3bucket_path/test_s3bucket_path_combo.py b/tests/test_s3bucket_path/test_s3bucket_path_combo.py index 48d65d497..e1b1075ee 100644 --- a/tests/test_s3bucket_path/test_s3bucket_path_combo.py +++ b/tests/test_s3bucket_path/test_s3bucket_path_combo.py @@ -3,7 +3,7 @@ from __future__ import unicode_literals import boto from boto.s3.connection import OrdinaryCallingFormat -from moto import mock_s3bucket_path, mock_s3 +from moto import mock_s3_deprecated def create_connection(key=None, secret=None): @@ -11,12 +11,12 @@ def create_connection(key=None, secret=None): def test_bucketpath_combo_serial(): - @mock_s3bucket_path + @mock_s3_deprecated def make_bucket_path(): conn = create_connection() conn.create_bucket('mybucketpath') - @mock_s3 + @mock_s3_deprecated def make_bucket(): conn = boto.connect_s3('the_key', 'the_secret') conn.create_bucket('mybucket') diff --git a/tests/test_ses/test_ses.py b/tests/test_ses/test_ses.py index e9b64b78b..7771b9a65 100644 --- a/tests/test_ses/test_ses.py +++ b/tests/test_ses/test_ses.py @@ -6,10 +6,10 @@ from boto.exception import BotoServerError import sure # noqa -from moto import mock_ses +from moto import mock_ses_deprecated -@mock_ses +@mock_ses_deprecated def test_verify_email_identity(): conn = boto.connect_ses('the_key', 'the_secret') conn.verify_email_identity("test@example.com") @@ -19,7 +19,7 @@ def test_verify_email_identity(): address.should.equal('test@example.com') -@mock_ses +@mock_ses_deprecated def test_domain_verify(): conn = boto.connect_ses('the_key', 'the_secret') @@ -31,7 +31,7 @@ def test_domain_verify(): domains.should.equal(['domain1.com', 'domain2.com']) -@mock_ses +@mock_ses_deprecated def test_delete_identity(): conn = boto.connect_ses('the_key', 'the_secret') conn.verify_email_identity("test@example.com") @@ -41,7 +41,7 @@ def test_delete_identity(): conn.list_identities()['ListIdentitiesResponse']['ListIdentitiesResult']['Identities'].should.have.length_of(0) -@mock_ses +@mock_ses_deprecated def test_send_email(): conn = boto.connect_ses('the_key', 'the_secret') @@ -56,7 +56,7 @@ def test_send_email(): sent_count = int(send_quota['GetSendQuotaResponse']['GetSendQuotaResult']['SentLast24Hours']) sent_count.should.equal(1) -@mock_ses +@mock_ses_deprecated def test_send_html_email(): conn = boto.connect_ses('the_key', 'the_secret') @@ -71,7 +71,7 @@ def test_send_html_email(): sent_count = int(send_quota['GetSendQuotaResponse']['GetSendQuotaResult']['SentLast24Hours']) sent_count.should.equal(1) -@mock_ses +@mock_ses_deprecated def test_send_raw_email(): conn = boto.connect_ses('the_key', 'the_secret') diff --git a/tests/test_sns/test_application.py b/tests/test_sns/test_application.py index 0566adeb3..31db73f62 100644 --- a/tests/test_sns/test_application.py +++ b/tests/test_sns/test_application.py @@ -2,11 +2,11 @@ from __future__ import unicode_literals import boto from boto.exception import BotoServerError -from moto import mock_sns +from moto import mock_sns_deprecated import sure # noqa -@mock_sns +@mock_sns_deprecated def test_create_platform_application(): conn = boto.connect_sns() platform_application = conn.create_platform_application( @@ -21,7 +21,7 @@ def test_create_platform_application(): application_arn.should.equal('arn:aws:sns:us-east-1:123456789012:app/APNS/my-application') -@mock_sns +@mock_sns_deprecated def test_get_platform_application_attributes(): conn = boto.connect_sns() platform_application = conn.create_platform_application( @@ -40,13 +40,13 @@ def test_get_platform_application_attributes(): }) -@mock_sns +@mock_sns_deprecated def test_get_missing_platform_application_attributes(): conn = boto.connect_sns() conn.get_platform_application_attributes.when.called_with("a-fake-arn").should.throw(BotoServerError) -@mock_sns +@mock_sns_deprecated def test_set_platform_application_attributes(): conn = boto.connect_sns() platform_application = conn.create_platform_application( @@ -68,7 +68,7 @@ def test_set_platform_application_attributes(): }) -@mock_sns +@mock_sns_deprecated def test_list_platform_applications(): conn = boto.connect_sns() conn.create_platform_application( @@ -85,7 +85,7 @@ def test_list_platform_applications(): applications.should.have.length_of(2) -@mock_sns +@mock_sns_deprecated def test_delete_platform_application(): conn = boto.connect_sns() conn.create_platform_application( @@ -109,7 +109,7 @@ def test_delete_platform_application(): applications.should.have.length_of(1) -@mock_sns +@mock_sns_deprecated def test_create_platform_endpoint(): conn = boto.connect_sns() platform_application = conn.create_platform_application( @@ -131,7 +131,7 @@ def test_create_platform_endpoint(): endpoint_arn.should.contain("arn:aws:sns:us-east-1:123456789012:endpoint/APNS/my-application/") -@mock_sns +@mock_sns_deprecated def test_get_list_endpoints_by_platform_application(): conn = boto.connect_sns() platform_application = conn.create_platform_application( @@ -159,7 +159,7 @@ def test_get_list_endpoints_by_platform_application(): endpoint_list[0]['EndpointArn'].should.equal(endpoint_arn) -@mock_sns +@mock_sns_deprecated def test_get_endpoint_attributes(): conn = boto.connect_sns() platform_application = conn.create_platform_application( @@ -187,13 +187,13 @@ def test_get_endpoint_attributes(): }) -@mock_sns +@mock_sns_deprecated def test_get_missing_endpoint_attributes(): conn = boto.connect_sns() conn.get_endpoint_attributes.when.called_with("a-fake-arn").should.throw(BotoServerError) -@mock_sns +@mock_sns_deprecated def test_set_endpoint_attributes(): conn = boto.connect_sns() platform_application = conn.create_platform_application( @@ -224,7 +224,7 @@ def test_set_endpoint_attributes(): }) -@mock_sns +@mock_sns_deprecated def test_delete_endpoint(): conn = boto.connect_sns() platform_application = conn.create_platform_application( @@ -258,7 +258,7 @@ def test_delete_endpoint(): endpoint_list.should.have.length_of(0) -@mock_sns +@mock_sns_deprecated def test_publish_to_platform_endpoint(): conn = boto.connect_sns() platform_application = conn.create_platform_application( diff --git a/tests/test_sns/test_publishing.py b/tests/test_sns/test_publishing.py index 3805d9e5e..8f8bfb0a1 100644 --- a/tests/test_sns/test_publishing.py +++ b/tests/test_sns/test_publishing.py @@ -3,14 +3,14 @@ from six.moves.urllib.parse import parse_qs import boto from freezegun import freeze_time -import httpretty import sure # noqa -from moto import mock_sns, mock_sqs +from moto.packages.responses import responses +from moto import mock_sns, mock_sns_deprecated, mock_sqs_deprecated -@mock_sqs -@mock_sns +@mock_sqs_deprecated +@mock_sns_deprecated def test_publish_to_sqs(): conn = boto.connect_sns() conn.create_topic("some-topic") @@ -29,8 +29,8 @@ def test_publish_to_sqs(): message.get_body().should.equal('my message') -@mock_sqs -@mock_sns +@mock_sqs_deprecated +@mock_sns_deprecated def test_publish_to_sqs_in_different_region(): conn = boto.sns.connect_to_region("us-west-1") conn.create_topic("some-topic") @@ -51,10 +51,11 @@ def test_publish_to_sqs_in_different_region(): @freeze_time("2013-01-01") @mock_sns +@mock_sns_deprecated def test_publish_to_http(): - httpretty.HTTPretty.register_uri( + responses.add( method="POST", - uri="http://example.com/foobar", + url="http://example.com/foobar", ) conn = boto.connect_sns() @@ -67,7 +68,7 @@ def test_publish_to_http(): response = conn.publish(topic=topic_arn, message="my message", subject="my subject") message_id = response['PublishResponse']['PublishResult']['MessageId'] - last_request = httpretty.last_request() + last_request = responses.calls[-1].request last_request.method.should.equal("POST") parse_qs(last_request.body.decode('utf-8')).should.equal({ "Type": ["Notification"], @@ -81,3 +82,5 @@ def test_publish_to_http(): "SigningCertURL": ["https://sns.us-east-1.amazonaws.com/SimpleNotificationService-f3ecfb7224c7233fe7bb5f59f96de52f.pem"], "UnsubscribeURL": ["https://sns.us-east-1.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:us-east-1:123456789012:some-topic:2bcfbf39-05c3-41de-beaa-fcfcc21c8f55"], }) + + diff --git a/tests/test_sns/test_publishing_boto3.py b/tests/test_sns/test_publishing_boto3.py index 90d063971..b37522641 100644 --- a/tests/test_sns/test_publishing_boto3.py +++ b/tests/test_sns/test_publishing_boto3.py @@ -3,9 +3,9 @@ from six.moves.urllib.parse import parse_qs import boto3 from freezegun import freeze_time -import httpretty import sure # noqa +from moto.packages.responses import responses from moto import mock_sns, mock_sqs @@ -56,9 +56,9 @@ def test_publish_to_sqs_in_different_region(): @freeze_time("2013-01-01") @mock_sns def test_publish_to_http(): - httpretty.HTTPretty.register_uri( + responses.add( method="POST", - uri="http://example.com/foobar", + url="http://example.com/foobar", ) conn = boto3.client('sns', region_name='us-east-1') @@ -73,7 +73,7 @@ def test_publish_to_http(): response = conn.publish(TopicArn=topic_arn, Message="my message", Subject="my subject") message_id = response['MessageId'] - last_request = httpretty.last_request() + last_request = responses.calls[-2].request last_request.method.should.equal("POST") parse_qs(last_request.body.decode('utf-8')).should.equal({ "Type": ["Notification"], diff --git a/tests/test_sns/test_subscriptions.py b/tests/test_sns/test_subscriptions.py index a202edf36..e141c503a 100644 --- a/tests/test_sns/test_subscriptions.py +++ b/tests/test_sns/test_subscriptions.py @@ -3,11 +3,11 @@ import boto import sure # noqa -from moto import mock_sns +from moto import mock_sns_deprecated from moto.sns.models import DEFAULT_PAGE_SIZE -@mock_sns +@mock_sns_deprecated def test_creating_subscription(): conn = boto.connect_sns() conn.create_topic("some-topic") @@ -32,7 +32,7 @@ def test_creating_subscription(): subscriptions.should.have.length_of(0) -@mock_sns +@mock_sns_deprecated def test_getting_subscriptions_by_topic(): conn = boto.connect_sns() conn.create_topic("topic1") @@ -51,7 +51,7 @@ def test_getting_subscriptions_by_topic(): topic1_subscriptions[0]['Endpoint'].should.equal("http://example1.com/") -@mock_sns +@mock_sns_deprecated def test_subscription_paging(): conn = boto.connect_sns() conn.create_topic("topic1") diff --git a/tests/test_sns/test_topics.py b/tests/test_sns/test_topics.py index a2a8092ee..ab2f06382 100644 --- a/tests/test_sns/test_topics.py +++ b/tests/test_sns/test_topics.py @@ -5,11 +5,11 @@ import six import sure # noqa from boto.exception import BotoServerError -from moto import mock_sns +from moto import mock_sns_deprecated from moto.sns.models import DEFAULT_TOPIC_POLICY, DEFAULT_EFFECTIVE_DELIVERY_POLICY, DEFAULT_PAGE_SIZE -@mock_sns +@mock_sns_deprecated def test_create_and_delete_topic(): conn = boto.connect_sns() conn.create_topic("some-topic") @@ -31,20 +31,20 @@ def test_create_and_delete_topic(): topics.should.have.length_of(0) -@mock_sns +@mock_sns_deprecated def test_get_missing_topic(): conn = boto.connect_sns() conn.get_topic_attributes.when.called_with("a-fake-arn").should.throw(BotoServerError) -@mock_sns +@mock_sns_deprecated def test_create_topic_in_multiple_regions(): for region in ['us-west-1', 'us-west-2']: conn = boto.sns.connect_to_region(region) conn.create_topic("some-topic") list(conn.get_all_topics()["ListTopicsResponse"]["ListTopicsResult"]["Topics"]).should.have.length_of(1) -@mock_sns +@mock_sns_deprecated def test_topic_corresponds_to_region(): for region in ['us-east-1', 'us-west-2']: conn = boto.sns.connect_to_region(region) @@ -53,7 +53,7 @@ def test_topic_corresponds_to_region(): topic_arn = topics_json["ListTopicsResponse"]["ListTopicsResult"]["Topics"][0]['TopicArn'] topic_arn.should.equal("arn:aws:sns:{0}:123456789012:some-topic".format(region)) -@mock_sns +@mock_sns_deprecated def test_topic_attributes(): conn = boto.connect_sns() conn.create_topic("some-topic") @@ -95,7 +95,7 @@ def test_topic_attributes(): attributes["DisplayName"].should.equal("My display name") attributes["DeliveryPolicy"].should.equal("{'http': {'defaultHealthyRetryPolicy': {'numRetries': 5}}}") -@mock_sns +@mock_sns_deprecated def test_topic_paging(): conn = boto.connect_sns() for index in range(DEFAULT_PAGE_SIZE + int(DEFAULT_PAGE_SIZE / 2)): diff --git a/tests/test_sqs/test_sqs.py b/tests/test_sqs/test_sqs.py index 32b026a46..b3eaaab75 100644 --- a/tests/test_sqs/test_sqs.py +++ b/tests/test_sqs/test_sqs.py @@ -10,16 +10,15 @@ import requests import sure # noqa import time -from moto import mock_sqs +from moto import mock_sqs, mock_sqs_deprecated from tests.helpers import requires_boto_gte import tests.backport_assert_raises # noqa from nose.tools import assert_raises -sqs = boto3.resource('sqs', region_name='us-east-1') - @mock_sqs def test_create_queue(): + sqs = boto3.resource('sqs', region_name='us-east-1') new_queue = sqs.create_queue(QueueName='test-queue') new_queue.should_not.be.none new_queue.should.have.property('url').should.contain('test-queue') @@ -34,11 +33,13 @@ def test_create_queue(): @mock_sqs def test_get_inexistent_queue(): + sqs = boto3.resource('sqs', region_name='us-east-1') sqs.get_queue_by_name.when.called_with(QueueName='nonexisting-queue').should.throw(botocore.exceptions.ClientError) @mock_sqs def test_message_send(): + sqs = boto3.resource('sqs', region_name='us-east-1') queue = sqs.create_queue(QueueName="blah") msg = queue.send_message(MessageBody="derp") @@ -52,6 +53,8 @@ def test_message_send(): @mock_sqs def test_set_queue_attributes(): + sqs = boto3.resource('sqs', region_name='us-east-1') + conn = boto3.client('sqs', region_name='us-west-1') queue = sqs.create_queue(QueueName="blah") queue.attributes['VisibilityTimeout'].should.equal("30") @@ -90,6 +93,7 @@ def test_get_queue_with_prefix(): @mock_sqs def test_delete_queue(): + sqs = boto3.resource('sqs', region_name='us-east-1') conn = boto3.client("sqs", region_name='us-east-1') conn.create_queue(QueueName="test-queue", Attributes={"VisibilityTimeout": "60"}) queue = sqs.Queue('test-queue') @@ -105,6 +109,7 @@ def test_delete_queue(): @mock_sqs def test_set_queue_attribute(): + sqs = boto3.resource('sqs', region_name='us-east-1') conn = boto3.client("sqs", region_name='us-east-1') conn.create_queue(QueueName="test-queue", Attributes={"VisibilityTimeout": '60'}) @@ -118,6 +123,7 @@ def test_set_queue_attribute(): @mock_sqs def test_send_message(): + sqs = boto3.resource('sqs', region_name='us-east-1') conn = boto3.client("sqs", region_name='us-east-1') conn.create_queue(QueueName="test-queue") queue = sqs.Queue("test-queue") @@ -134,7 +140,7 @@ def test_send_message(): messages[1]['Body'].should.equal(body_two) -@mock_sqs +@mock_sqs_deprecated def test_send_message_with_xml_characters(): conn = boto.connect_sqs('the_key', 'the_secret') queue = conn.create_queue("test-queue", visibility_timeout=60) @@ -150,7 +156,7 @@ def test_send_message_with_xml_characters(): @requires_boto_gte("2.28") -@mock_sqs +@mock_sqs_deprecated def test_send_message_with_attributes(): conn = boto.connect_sqs('the_key', 'the_secret') queue = conn.create_queue("test-queue", visibility_timeout=60) @@ -175,7 +181,7 @@ def test_send_message_with_attributes(): dict(messages[0].message_attributes[name]).should.equal(value) -@mock_sqs +@mock_sqs_deprecated def test_send_message_with_delay(): conn = boto.connect_sqs('the_key', 'the_secret') queue = conn.create_queue("test-queue", visibility_timeout=60) @@ -196,7 +202,7 @@ def test_send_message_with_delay(): queue.count().should.equal(0) -@mock_sqs +@mock_sqs_deprecated def test_send_large_message_fails(): conn = boto.connect_sqs('the_key', 'the_secret') queue = conn.create_queue("test-queue", visibility_timeout=60) @@ -208,7 +214,7 @@ def test_send_large_message_fails(): queue.write.when.called_with(huge_message).should.throw(SQSError) -@mock_sqs +@mock_sqs_deprecated def test_message_becomes_inflight_when_received(): conn = boto.connect_sqs('the_key', 'the_secret') queue = conn.create_queue("test-queue", visibility_timeout=2) @@ -229,7 +235,7 @@ def test_message_becomes_inflight_when_received(): queue.count().should.equal(1) -@mock_sqs +@mock_sqs_deprecated def test_receive_message_with_explicit_visibility_timeout(): conn = boto.connect_sqs('the_key', 'the_secret') queue = conn.create_queue("test-queue", visibility_timeout=60) @@ -246,7 +252,7 @@ def test_receive_message_with_explicit_visibility_timeout(): # Message should remain visible queue.count().should.equal(1) -@mock_sqs +@mock_sqs_deprecated def test_change_message_visibility(): conn = boto.connect_sqs('the_key', 'the_secret') queue = conn.create_queue("test-queue", visibility_timeout=2) @@ -280,7 +286,7 @@ def test_change_message_visibility(): queue.count().should.equal(0) -@mock_sqs +@mock_sqs_deprecated def test_message_attributes(): conn = boto.connect_sqs('the_key', 'the_secret') queue = conn.create_queue("test-queue", visibility_timeout=2) @@ -304,7 +310,7 @@ def test_message_attributes(): assert message_attributes.get('SenderId') -@mock_sqs +@mock_sqs_deprecated def test_read_message_from_queue(): conn = boto.connect_sqs() queue = conn.create_queue('testqueue') @@ -316,7 +322,7 @@ def test_read_message_from_queue(): message.get_body().should.equal(body) -@mock_sqs +@mock_sqs_deprecated def test_queue_length(): conn = boto.connect_sqs('the_key', 'the_secret') queue = conn.create_queue("test-queue", visibility_timeout=60) @@ -327,7 +333,7 @@ def test_queue_length(): queue.count().should.equal(2) -@mock_sqs +@mock_sqs_deprecated def test_delete_message(): conn = boto.connect_sqs('the_key', 'the_secret') queue = conn.create_queue("test-queue", visibility_timeout=60) @@ -348,7 +354,7 @@ def test_delete_message(): queue.count().should.equal(0) -@mock_sqs +@mock_sqs_deprecated def test_send_batch_operation(): conn = boto.connect_sqs('the_key', 'the_secret') queue = conn.create_queue("test-queue", visibility_timeout=60) @@ -370,7 +376,7 @@ def test_send_batch_operation(): @requires_boto_gte("2.28") -@mock_sqs +@mock_sqs_deprecated def test_send_batch_operation_with_message_attributes(): conn = boto.connect_sqs('the_key', 'the_secret') queue = conn.create_queue("test-queue", visibility_timeout=60) @@ -386,7 +392,7 @@ def test_send_batch_operation_with_message_attributes(): dict(messages[0].message_attributes[name]).should.equal(value) -@mock_sqs +@mock_sqs_deprecated def test_delete_batch_operation(): conn = boto.connect_sqs('the_key', 'the_secret') queue = conn.create_queue("test-queue", visibility_timeout=60) @@ -408,7 +414,7 @@ def test_sqs_method_not_implemented(): requests.post.when.called_with("https://sqs.amazonaws.com/?Action=[foobar]").should.throw(NotImplementedError) -@mock_sqs +@mock_sqs_deprecated def test_queue_attributes(): conn = boto.connect_sqs('the_key', 'the_secret') @@ -438,7 +444,7 @@ def test_queue_attributes(): attribute_names.should.contain('QueueArn') -@mock_sqs +@mock_sqs_deprecated def test_change_message_visibility_on_invalid_receipt(): conn = boto.connect_sqs('the_key', 'the_secret') queue = conn.create_queue("test-queue", visibility_timeout=1) @@ -465,7 +471,7 @@ def test_change_message_visibility_on_invalid_receipt(): original_message.change_visibility.when.called_with(100).should.throw(SQSError) -@mock_sqs +@mock_sqs_deprecated def test_change_message_visibility_on_visible_message(): conn = boto.connect_sqs('the_key', 'the_secret') queue = conn.create_queue("test-queue", visibility_timeout=1) @@ -488,7 +494,7 @@ def test_change_message_visibility_on_visible_message(): original_message.change_visibility.when.called_with(100).should.throw(SQSError) -@mock_sqs +@mock_sqs_deprecated def test_purge_action(): conn = boto.sqs.connect_to_region("us-east-1") @@ -501,7 +507,7 @@ def test_purge_action(): queue.count().should.equal(0) -@mock_sqs +@mock_sqs_deprecated def test_delete_message_after_visibility_timeout(): VISIBILITY_TIMEOUT = 1 conn = boto.sqs.connect_to_region("us-east-1") diff --git a/tests/test_sts/test_sts.py b/tests/test_sts/test_sts.py index 9bd02ce12..870f14860 100644 --- a/tests/test_sts/test_sts.py +++ b/tests/test_sts/test_sts.py @@ -6,11 +6,11 @@ import boto3 from freezegun import freeze_time import sure # noqa -from moto import mock_sts +from moto import mock_sts, mock_sts_deprecated @freeze_time("2012-01-01 12:00:00") -@mock_sts +@mock_sts_deprecated def test_get_session_token(): conn = boto.connect_sts() token = conn.get_session_token(duration=123) @@ -22,7 +22,7 @@ def test_get_session_token(): @freeze_time("2012-01-01 12:00:00") -@mock_sts +@mock_sts_deprecated def test_get_federation_token(): conn = boto.connect_sts() token = conn.get_federation_token(duration=123, name="Bob") @@ -36,7 +36,7 @@ def test_get_federation_token(): @freeze_time("2012-01-01 12:00:00") -@mock_sts +@mock_sts_deprecated def test_assume_role(): conn = boto.connect_sts() diff --git a/tests/test_swf/responses/test_activity_tasks.py b/tests/test_swf/responses/test_activity_tasks.py index 31eaeeddd..e6671e9e9 100644 --- a/tests/test_swf/responses/test_activity_tasks.py +++ b/tests/test_swf/responses/test_activity_tasks.py @@ -1,14 +1,14 @@ from boto.swf.exceptions import SWFResponseError from freezegun import freeze_time -from moto import mock_swf +from moto import mock_swf_deprecated from moto.swf import swf_backend from ..utils import setup_workflow, SCHEDULE_ACTIVITY_TASK_DECISION # PollForActivityTask endpoint -@mock_swf +@mock_swf_deprecated def test_poll_for_activity_task_when_one(): conn = setup_workflow() decision_token = conn.poll_for_decision_task("test-domain", "queue")["taskToken"] @@ -26,14 +26,14 @@ def test_poll_for_activity_task_when_one(): ) -@mock_swf +@mock_swf_deprecated def test_poll_for_activity_task_when_none(): conn = setup_workflow() resp = conn.poll_for_activity_task("test-domain", "activity-task-list") resp.should.equal({"startedEventId": 0}) -@mock_swf +@mock_swf_deprecated def test_poll_for_activity_task_on_non_existent_queue(): conn = setup_workflow() resp = conn.poll_for_activity_task("test-domain", "non-existent-queue") @@ -41,7 +41,7 @@ def test_poll_for_activity_task_on_non_existent_queue(): # CountPendingActivityTasks endpoint -@mock_swf +@mock_swf_deprecated def test_count_pending_activity_tasks(): conn = setup_workflow() decision_token = conn.poll_for_decision_task("test-domain", "queue")["taskToken"] @@ -53,7 +53,7 @@ def test_count_pending_activity_tasks(): resp.should.equal({"count": 1, "truncated": False}) -@mock_swf +@mock_swf_deprecated def test_count_pending_decision_tasks_on_non_existent_task_list(): conn = setup_workflow() resp = conn.count_pending_activity_tasks("test-domain", "non-existent") @@ -61,7 +61,7 @@ def test_count_pending_decision_tasks_on_non_existent_task_list(): # RespondActivityTaskCompleted endpoint -@mock_swf +@mock_swf_deprecated def test_respond_activity_task_completed(): conn = setup_workflow() decision_token = conn.poll_for_decision_task("test-domain", "queue")["taskToken"] @@ -80,7 +80,7 @@ def test_respond_activity_task_completed(): ) -@mock_swf +@mock_swf_deprecated def test_respond_activity_task_completed_on_closed_workflow_execution(): conn = setup_workflow() decision_token = conn.poll_for_decision_task("test-domain", "queue")["taskToken"] @@ -99,7 +99,7 @@ def test_respond_activity_task_completed_on_closed_workflow_execution(): ).should.throw(SWFResponseError, "WorkflowExecution=") -@mock_swf +@mock_swf_deprecated def test_respond_activity_task_completed_with_task_already_completed(): conn = setup_workflow() decision_token = conn.poll_for_decision_task("test-domain", "queue")["taskToken"] @@ -116,7 +116,7 @@ def test_respond_activity_task_completed_with_task_already_completed(): # RespondActivityTaskFailed endpoint -@mock_swf +@mock_swf_deprecated def test_respond_activity_task_failed(): conn = setup_workflow() decision_token = conn.poll_for_decision_task("test-domain", "queue")["taskToken"] @@ -138,7 +138,7 @@ def test_respond_activity_task_failed(): ) -@mock_swf +@mock_swf_deprecated def test_respond_activity_task_completed_with_wrong_token(): # NB: we just test ONE failure case for RespondActivityTaskFailed # because the safeguards are shared with RespondActivityTaskCompleted, so @@ -155,7 +155,7 @@ def test_respond_activity_task_completed_with_wrong_token(): # RecordActivityTaskHeartbeat endpoint -@mock_swf +@mock_swf_deprecated def test_record_activity_task_heartbeat(): conn = setup_workflow() decision_token = conn.poll_for_decision_task("test-domain", "queue")["taskToken"] @@ -168,7 +168,7 @@ def test_record_activity_task_heartbeat(): resp.should.equal({"cancelRequested": False}) -@mock_swf +@mock_swf_deprecated def test_record_activity_task_heartbeat_with_wrong_token(): conn = setup_workflow() decision_token = conn.poll_for_decision_task("test-domain", "queue")["taskToken"] @@ -182,7 +182,7 @@ def test_record_activity_task_heartbeat_with_wrong_token(): ).should.throw(SWFResponseError) -@mock_swf +@mock_swf_deprecated def test_record_activity_task_heartbeat_sets_details_in_case_of_timeout(): conn = setup_workflow() decision_token = conn.poll_for_decision_task("test-domain", "queue")["taskToken"] diff --git a/tests/test_swf/responses/test_activity_types.py b/tests/test_swf/responses/test_activity_types.py index 872cd7f64..20c44dc5f 100644 --- a/tests/test_swf/responses/test_activity_types.py +++ b/tests/test_swf/responses/test_activity_types.py @@ -1,11 +1,11 @@ import boto from boto.swf.exceptions import SWFResponseError -from moto import mock_swf +from moto import mock_swf_deprecated # RegisterActivityType endpoint -@mock_swf +@mock_swf_deprecated def test_register_activity_type(): conn = boto.connect_swf("the_key", "the_secret") conn.register_domain("test-domain", "60") @@ -17,7 +17,7 @@ def test_register_activity_type(): actype["activityType"]["version"].should.equal("v1.0") -@mock_swf +@mock_swf_deprecated def test_register_already_existing_activity_type(): conn = boto.connect_swf("the_key", "the_secret") conn.register_domain("test-domain", "60") @@ -28,7 +28,7 @@ def test_register_already_existing_activity_type(): ).should.throw(SWFResponseError) -@mock_swf +@mock_swf_deprecated def test_register_with_wrong_parameter_type(): conn = boto.connect_swf("the_key", "the_secret") conn.register_domain("test-domain", "60") @@ -39,7 +39,7 @@ def test_register_with_wrong_parameter_type(): # ListActivityTypes endpoint -@mock_swf +@mock_swf_deprecated def test_list_activity_types(): conn = boto.connect_swf("the_key", "the_secret") conn.register_domain("test-domain", "60") @@ -52,7 +52,7 @@ def test_list_activity_types(): names.should.equal(["a-test-activity", "b-test-activity", "c-test-activity"]) -@mock_swf +@mock_swf_deprecated def test_list_activity_types_reverse_order(): conn = boto.connect_swf("the_key", "the_secret") conn.register_domain("test-domain", "60") @@ -67,7 +67,7 @@ def test_list_activity_types_reverse_order(): # DeprecateActivityType endpoint -@mock_swf +@mock_swf_deprecated def test_deprecate_activity_type(): conn = boto.connect_swf("the_key", "the_secret") conn.register_domain("test-domain", "60") @@ -80,7 +80,7 @@ def test_deprecate_activity_type(): actype["activityType"]["version"].should.equal("v1.0") -@mock_swf +@mock_swf_deprecated def test_deprecate_already_deprecated_activity_type(): conn = boto.connect_swf("the_key", "the_secret") conn.register_domain("test-domain", "60") @@ -92,7 +92,7 @@ def test_deprecate_already_deprecated_activity_type(): ).should.throw(SWFResponseError) -@mock_swf +@mock_swf_deprecated def test_deprecate_non_existent_activity_type(): conn = boto.connect_swf("the_key", "the_secret") conn.register_domain("test-domain", "60") @@ -103,7 +103,7 @@ def test_deprecate_non_existent_activity_type(): # DescribeActivityType endpoint -@mock_swf +@mock_swf_deprecated def test_describe_activity_type(): conn = boto.connect_swf("the_key", "the_secret") conn.register_domain("test-domain", "60") @@ -118,7 +118,7 @@ def test_describe_activity_type(): infos["status"].should.equal("REGISTERED") -@mock_swf +@mock_swf_deprecated def test_describe_non_existent_activity_type(): conn = boto.connect_swf("the_key", "the_secret") conn.register_domain("test-domain", "60") diff --git a/tests/test_swf/responses/test_decision_tasks.py b/tests/test_swf/responses/test_decision_tasks.py index b16a6441a..b552723cb 100644 --- a/tests/test_swf/responses/test_decision_tasks.py +++ b/tests/test_swf/responses/test_decision_tasks.py @@ -1,14 +1,14 @@ from boto.swf.exceptions import SWFResponseError from freezegun import freeze_time -from moto import mock_swf +from moto import mock_swf_deprecated from moto.swf import swf_backend from ..utils import setup_workflow # PollForDecisionTask endpoint -@mock_swf +@mock_swf_deprecated def test_poll_for_decision_task_when_one(): conn = setup_workflow() @@ -23,7 +23,7 @@ def test_poll_for_decision_task_when_one(): resp["events"][-1]["decisionTaskStartedEventAttributes"]["identity"].should.equal("srv01") -@mock_swf +@mock_swf_deprecated def test_poll_for_decision_task_when_none(): conn = setup_workflow() conn.poll_for_decision_task("test-domain", "queue") @@ -34,14 +34,14 @@ def test_poll_for_decision_task_when_none(): resp.should.equal({"previousStartedEventId": 0, "startedEventId": 0}) -@mock_swf +@mock_swf_deprecated def test_poll_for_decision_task_on_non_existent_queue(): conn = setup_workflow() resp = conn.poll_for_decision_task("test-domain", "non-existent-queue") resp.should.equal({"previousStartedEventId": 0, "startedEventId": 0}) -@mock_swf +@mock_swf_deprecated def test_poll_for_decision_task_with_reverse_order(): conn = setup_workflow() resp = conn.poll_for_decision_task("test-domain", "queue", reverse_order=True) @@ -50,7 +50,7 @@ def test_poll_for_decision_task_with_reverse_order(): # CountPendingDecisionTasks endpoint -@mock_swf +@mock_swf_deprecated def test_count_pending_decision_tasks(): conn = setup_workflow() conn.poll_for_decision_task("test-domain", "queue") @@ -58,14 +58,14 @@ def test_count_pending_decision_tasks(): resp.should.equal({"count": 1, "truncated": False}) -@mock_swf +@mock_swf_deprecated def test_count_pending_decision_tasks_on_non_existent_task_list(): conn = setup_workflow() resp = conn.count_pending_decision_tasks("test-domain", "non-existent") resp.should.equal({"count": 0, "truncated": False}) -@mock_swf +@mock_swf_deprecated def test_count_pending_decision_tasks_after_decision_completes(): conn = setup_workflow() resp = conn.poll_for_decision_task("test-domain", "queue") @@ -76,7 +76,7 @@ def test_count_pending_decision_tasks_after_decision_completes(): # RespondDecisionTaskCompleted endpoint -@mock_swf +@mock_swf_deprecated def test_respond_decision_task_completed_with_no_decision(): conn = setup_workflow() @@ -108,7 +108,7 @@ def test_respond_decision_task_completed_with_no_decision(): resp["latestExecutionContext"].should.equal("free-form context") -@mock_swf +@mock_swf_deprecated def test_respond_decision_task_completed_with_wrong_token(): conn = setup_workflow() conn.poll_for_decision_task("test-domain", "queue") @@ -117,7 +117,7 @@ def test_respond_decision_task_completed_with_wrong_token(): ).should.throw(SWFResponseError) -@mock_swf +@mock_swf_deprecated def test_respond_decision_task_completed_on_close_workflow_execution(): conn = setup_workflow() resp = conn.poll_for_decision_task("test-domain", "queue") @@ -133,7 +133,7 @@ def test_respond_decision_task_completed_on_close_workflow_execution(): ).should.throw(SWFResponseError) -@mock_swf +@mock_swf_deprecated def test_respond_decision_task_completed_with_task_already_completed(): conn = setup_workflow() resp = conn.poll_for_decision_task("test-domain", "queue") @@ -145,7 +145,7 @@ def test_respond_decision_task_completed_with_task_already_completed(): ).should.throw(SWFResponseError) -@mock_swf +@mock_swf_deprecated def test_respond_decision_task_completed_with_complete_workflow_execution(): conn = setup_workflow() resp = conn.poll_for_decision_task("test-domain", "queue") @@ -170,7 +170,7 @@ def test_respond_decision_task_completed_with_complete_workflow_execution(): resp["events"][-1]["workflowExecutionCompletedEventAttributes"]["result"].should.equal("foo bar") -@mock_swf +@mock_swf_deprecated def test_respond_decision_task_completed_with_close_decision_not_last(): conn = setup_workflow() resp = conn.poll_for_decision_task("test-domain", "queue") @@ -186,7 +186,7 @@ def test_respond_decision_task_completed_with_close_decision_not_last(): ).should.throw(SWFResponseError, r"Close must be last decision in list") -@mock_swf +@mock_swf_deprecated def test_respond_decision_task_completed_with_invalid_decision_type(): conn = setup_workflow() resp = conn.poll_for_decision_task("test-domain", "queue") @@ -204,7 +204,7 @@ def test_respond_decision_task_completed_with_invalid_decision_type(): ) -@mock_swf +@mock_swf_deprecated def test_respond_decision_task_completed_with_missing_attributes(): conn = setup_workflow() resp = conn.poll_for_decision_task("test-domain", "queue") @@ -226,7 +226,7 @@ def test_respond_decision_task_completed_with_missing_attributes(): ) -@mock_swf +@mock_swf_deprecated def test_respond_decision_task_completed_with_missing_attributes_totally(): conn = setup_workflow() resp = conn.poll_for_decision_task("test-domain", "queue") @@ -245,7 +245,7 @@ def test_respond_decision_task_completed_with_missing_attributes_totally(): ) -@mock_swf +@mock_swf_deprecated def test_respond_decision_task_completed_with_fail_workflow_execution(): conn = setup_workflow() resp = conn.poll_for_decision_task("test-domain", "queue") @@ -272,7 +272,7 @@ def test_respond_decision_task_completed_with_fail_workflow_execution(): attrs["details"].should.equal("foo") -@mock_swf +@mock_swf_deprecated @freeze_time("2015-01-01 12:00:00") def test_respond_decision_task_completed_with_schedule_activity_task(): conn = setup_workflow() diff --git a/tests/test_swf/responses/test_domains.py b/tests/test_swf/responses/test_domains.py index fc89ea752..1f785095c 100644 --- a/tests/test_swf/responses/test_domains.py +++ b/tests/test_swf/responses/test_domains.py @@ -1,11 +1,11 @@ import boto from boto.swf.exceptions import SWFResponseError -from moto import mock_swf +from moto import mock_swf_deprecated # RegisterDomain endpoint -@mock_swf +@mock_swf_deprecated def test_register_domain(): conn = boto.connect_swf("the_key", "the_secret") conn.register_domain("test-domain", "60", description="A test domain") @@ -18,7 +18,7 @@ def test_register_domain(): domain["description"].should.equal("A test domain") -@mock_swf +@mock_swf_deprecated def test_register_already_existing_domain(): conn = boto.connect_swf("the_key", "the_secret") conn.register_domain("test-domain", "60", description="A test domain") @@ -28,7 +28,7 @@ def test_register_already_existing_domain(): ).should.throw(SWFResponseError) -@mock_swf +@mock_swf_deprecated def test_register_with_wrong_parameter_type(): conn = boto.connect_swf("the_key", "the_secret") @@ -38,7 +38,7 @@ def test_register_with_wrong_parameter_type(): # ListDomains endpoint -@mock_swf +@mock_swf_deprecated def test_list_domains_order(): conn = boto.connect_swf("the_key", "the_secret") conn.register_domain("b-test-domain", "60") @@ -50,7 +50,7 @@ def test_list_domains_order(): names.should.equal(["a-test-domain", "b-test-domain", "c-test-domain"]) -@mock_swf +@mock_swf_deprecated def test_list_domains_reverse_order(): conn = boto.connect_swf("the_key", "the_secret") conn.register_domain("b-test-domain", "60") @@ -63,7 +63,7 @@ def test_list_domains_reverse_order(): # DeprecateDomain endpoint -@mock_swf +@mock_swf_deprecated def test_deprecate_domain(): conn = boto.connect_swf("the_key", "the_secret") conn.register_domain("test-domain", "60", description="A test domain") @@ -75,7 +75,7 @@ def test_deprecate_domain(): domain["name"].should.equal("test-domain") -@mock_swf +@mock_swf_deprecated def test_deprecate_already_deprecated_domain(): conn = boto.connect_swf("the_key", "the_secret") conn.register_domain("test-domain", "60", description="A test domain") @@ -86,7 +86,7 @@ def test_deprecate_already_deprecated_domain(): ).should.throw(SWFResponseError) -@mock_swf +@mock_swf_deprecated def test_deprecate_non_existent_domain(): conn = boto.connect_swf("the_key", "the_secret") @@ -96,7 +96,7 @@ def test_deprecate_non_existent_domain(): # DescribeDomain endpoint -@mock_swf +@mock_swf_deprecated def test_describe_domain(): conn = boto.connect_swf("the_key", "the_secret") conn.register_domain("test-domain", "60", description="A test domain") @@ -108,7 +108,7 @@ def test_describe_domain(): domain["domainInfo"]["status"].should.equal("REGISTERED") -@mock_swf +@mock_swf_deprecated def test_describe_non_existent_domain(): conn = boto.connect_swf("the_key", "the_secret") diff --git a/tests/test_swf/responses/test_timeouts.py b/tests/test_swf/responses/test_timeouts.py index afa130c21..726410e76 100644 --- a/tests/test_swf/responses/test_timeouts.py +++ b/tests/test_swf/responses/test_timeouts.py @@ -1,13 +1,13 @@ from freezegun import freeze_time -from moto import mock_swf +from moto import mock_swf_deprecated from ..utils import setup_workflow, SCHEDULE_ACTIVITY_TASK_DECISION # Activity Task Heartbeat timeout # Default value in workflow helpers: 5 mins -@mock_swf +@mock_swf_deprecated def test_activity_task_heartbeat_timeout(): with freeze_time("2015-01-01 12:00:00"): conn = setup_workflow() @@ -36,7 +36,7 @@ def test_activity_task_heartbeat_timeout(): # Decision Task Start to Close timeout # Default value in workflow helpers: 5 mins -@mock_swf +@mock_swf_deprecated def test_decision_task_start_to_close_timeout(): pass with freeze_time("2015-01-01 12:00:00"): @@ -70,7 +70,7 @@ def test_decision_task_start_to_close_timeout(): # Workflow Execution Start to Close timeout # Default value in workflow helpers: 2 hours -@mock_swf +@mock_swf_deprecated def test_workflow_execution_start_to_close_timeout(): pass with freeze_time("2015-01-01 12:00:00"): diff --git a/tests/test_swf/responses/test_workflow_executions.py b/tests/test_swf/responses/test_workflow_executions.py index f4a949687..d5dc44a38 100644 --- a/tests/test_swf/responses/test_workflow_executions.py +++ b/tests/test_swf/responses/test_workflow_executions.py @@ -6,12 +6,12 @@ import sure # noqa # Ensure 'assert_raises' context manager support for Python 2.6 import tests.backport_assert_raises # noqa -from moto import mock_swf +from moto import mock_swf_deprecated from moto.core.utils import unix_time # Utils -@mock_swf +@mock_swf_deprecated def setup_swf_environment(): conn = boto.connect_swf("the_key", "the_secret") conn.register_domain("test-domain", "60", description="A test domain") @@ -26,7 +26,7 @@ def setup_swf_environment(): # StartWorkflowExecution endpoint -@mock_swf +@mock_swf_deprecated def test_start_workflow_execution(): conn = setup_swf_environment() @@ -34,7 +34,7 @@ def test_start_workflow_execution(): wf.should.contain("runId") -@mock_swf +@mock_swf_deprecated def test_start_already_started_workflow_execution(): conn = setup_swf_environment() conn.start_workflow_execution("test-domain", "uid-abcd1234", "test-workflow", "v1.0") @@ -44,7 +44,7 @@ def test_start_already_started_workflow_execution(): ).should.throw(SWFResponseError) -@mock_swf +@mock_swf_deprecated def test_start_workflow_execution_on_deprecated_type(): conn = setup_swf_environment() conn.deprecate_workflow_type("test-domain", "test-workflow", "v1.0") @@ -55,7 +55,7 @@ def test_start_workflow_execution_on_deprecated_type(): # DescribeWorkflowExecution endpoint -@mock_swf +@mock_swf_deprecated def test_describe_workflow_execution(): conn = setup_swf_environment() hsh = conn.start_workflow_execution("test-domain", "uid-abcd1234", "test-workflow", "v1.0") @@ -66,7 +66,7 @@ def test_describe_workflow_execution(): wfe["executionInfo"]["executionStatus"].should.equal("OPEN") -@mock_swf +@mock_swf_deprecated def test_describe_non_existent_workflow_execution(): conn = setup_swf_environment() @@ -76,7 +76,7 @@ def test_describe_non_existent_workflow_execution(): # GetWorkflowExecutionHistory endpoint -@mock_swf +@mock_swf_deprecated def test_get_workflow_execution_history(): conn = setup_swf_environment() hsh = conn.start_workflow_execution("test-domain", "uid-abcd1234", "test-workflow", "v1.0") @@ -87,7 +87,7 @@ def test_get_workflow_execution_history(): types.should.equal(["WorkflowExecutionStarted", "DecisionTaskScheduled"]) -@mock_swf +@mock_swf_deprecated def test_get_workflow_execution_history_with_reverse_order(): conn = setup_swf_environment() hsh = conn.start_workflow_execution("test-domain", "uid-abcd1234", "test-workflow", "v1.0") @@ -99,7 +99,7 @@ def test_get_workflow_execution_history_with_reverse_order(): types.should.equal(["DecisionTaskScheduled", "WorkflowExecutionStarted"]) -@mock_swf +@mock_swf_deprecated def test_get_workflow_execution_history_on_non_existent_workflow_execution(): conn = setup_swf_environment() @@ -109,7 +109,7 @@ def test_get_workflow_execution_history_on_non_existent_workflow_execution(): # ListOpenWorkflowExecutions endpoint -@mock_swf +@mock_swf_deprecated def test_list_open_workflow_executions(): conn = setup_swf_environment() # One open workflow execution @@ -143,7 +143,7 @@ def test_list_open_workflow_executions(): # ListClosedWorkflowExecutions endpoint -@mock_swf +@mock_swf_deprecated def test_list_closed_workflow_executions(): conn = setup_swf_environment() # Leave one workflow execution open to make sure it isn't displayed @@ -178,7 +178,7 @@ def test_list_closed_workflow_executions(): # TerminateWorkflowExecution endpoint -@mock_swf +@mock_swf_deprecated def test_terminate_workflow_execution(): conn = setup_swf_environment() run_id = conn.start_workflow_execution( @@ -200,7 +200,7 @@ def test_terminate_workflow_execution(): attrs["cause"].should.equal("OPERATOR_INITIATED") -@mock_swf +@mock_swf_deprecated def test_terminate_workflow_execution_with_wrong_workflow_or_run_id(): conn = setup_swf_environment() run_id = conn.start_workflow_execution( diff --git a/tests/test_swf/responses/test_workflow_types.py b/tests/test_swf/responses/test_workflow_types.py index 04521ff6e..1e838c2ee 100644 --- a/tests/test_swf/responses/test_workflow_types.py +++ b/tests/test_swf/responses/test_workflow_types.py @@ -1,11 +1,12 @@ +import sure import boto -from moto import mock_swf +from moto import mock_swf_deprecated from boto.swf.exceptions import SWFResponseError # RegisterWorkflowType endpoint -@mock_swf +@mock_swf_deprecated def test_register_workflow_type(): conn = boto.connect_swf("the_key", "the_secret") conn.register_domain("test-domain", "60") @@ -17,7 +18,7 @@ def test_register_workflow_type(): actype["workflowType"]["version"].should.equal("v1.0") -@mock_swf +@mock_swf_deprecated def test_register_already_existing_workflow_type(): conn = boto.connect_swf("the_key", "the_secret") conn.register_domain("test-domain", "60") @@ -28,7 +29,7 @@ def test_register_already_existing_workflow_type(): ).should.throw(SWFResponseError) -@mock_swf +@mock_swf_deprecated def test_register_with_wrong_parameter_type(): conn = boto.connect_swf("the_key", "the_secret") conn.register_domain("test-domain", "60") @@ -39,7 +40,7 @@ def test_register_with_wrong_parameter_type(): # ListWorkflowTypes endpoint -@mock_swf +@mock_swf_deprecated def test_list_workflow_types(): conn = boto.connect_swf("the_key", "the_secret") conn.register_domain("test-domain", "60") @@ -52,7 +53,7 @@ def test_list_workflow_types(): names.should.equal(["a-test-workflow", "b-test-workflow", "c-test-workflow"]) -@mock_swf +@mock_swf_deprecated def test_list_workflow_types_reverse_order(): conn = boto.connect_swf("the_key", "the_secret") conn.register_domain("test-domain", "60") @@ -67,7 +68,7 @@ def test_list_workflow_types_reverse_order(): # DeprecateWorkflowType endpoint -@mock_swf +@mock_swf_deprecated def test_deprecate_workflow_type(): conn = boto.connect_swf("the_key", "the_secret") conn.register_domain("test-domain", "60") @@ -80,7 +81,7 @@ def test_deprecate_workflow_type(): actype["workflowType"]["version"].should.equal("v1.0") -@mock_swf +@mock_swf_deprecated def test_deprecate_already_deprecated_workflow_type(): conn = boto.connect_swf("the_key", "the_secret") conn.register_domain("test-domain", "60") @@ -92,7 +93,7 @@ def test_deprecate_already_deprecated_workflow_type(): ).should.throw(SWFResponseError) -@mock_swf +@mock_swf_deprecated def test_deprecate_non_existent_workflow_type(): conn = boto.connect_swf("the_key", "the_secret") conn.register_domain("test-domain", "60") @@ -103,7 +104,7 @@ def test_deprecate_non_existent_workflow_type(): # DescribeWorkflowType endpoint -@mock_swf +@mock_swf_deprecated def test_describe_workflow_type(): conn = boto.connect_swf("the_key", "the_secret") conn.register_domain("test-domain", "60") @@ -120,7 +121,7 @@ def test_describe_workflow_type(): infos["status"].should.equal("REGISTERED") -@mock_swf +@mock_swf_deprecated def test_describe_non_existent_workflow_type(): conn = boto.connect_swf("the_key", "the_secret") conn.register_domain("test-domain", "60")