diff --git a/moto/awslambda/responses.py b/moto/awslambda/responses.py index b7664c314..d145f4760 100644 --- a/moto/awslambda/responses.py +++ b/moto/awslambda/responses.py @@ -57,7 +57,7 @@ class LambdaResponse(BaseResponse): def _create_function(self, request, full_url, headers): lambda_backend = self.get_lambda_backend(full_url) - spec = json.loads(self.body.decode('utf-8')) + spec = json.loads(self.body) try: fn = lambda_backend.create_function(spec) except ValueError as e: diff --git a/moto/backends.py b/moto/backends.py index 5b1695e3b..94c7f4849 100644 --- a/moto/backends.py +++ b/moto/backends.py @@ -62,10 +62,10 @@ BACKENDS = { } -def get_model(name, region): +def get_model(name, region_name): for backends in BACKENDS.values(): for region, backend in backends.items(): - if region == region: + if region == region_name: models = getattr(backend.__class__, '__models__', {}) if name in models: return list(getattr(backend, models[name])()) diff --git a/moto/cloudformation/parsing.py b/moto/cloudformation/parsing.py index f2ba08522..9dcbdae29 100644 --- a/moto/cloudformation/parsing.py +++ b/moto/cloudformation/parsing.py @@ -21,9 +21,8 @@ from moto.s3 import models as s3_models from moto.sns import models as sns_models from moto.sqs import models as sqs_models from .utils import random_suffix -from .exceptions import MissingParameterError, UnformattedGetAttTemplateException +from .exceptions import MissingParameterError, UnformattedGetAttTemplateException, ValidationError from boto.cloudformation.stack import Output -from boto.exception import BotoServerError MODEL_MAP = { "AWS::AutoScaling::AutoScalingGroup": autoscaling_models.FakeAutoScalingGroup, @@ -137,8 +136,7 @@ def clean_json(resource_json, resources_map): logger.warning(n.message.format( resource_json['Fn::GetAtt'][0])) except UnformattedGetAttTemplateException: - raise BotoServerError( - UnformattedGetAttTemplateException.status_code, + raise ValidationError( 'Bad Request', UnformattedGetAttTemplateException.description.format( resource_json['Fn::GetAtt'][0], resource_json['Fn::GetAtt'][1])) diff --git a/moto/emr/responses.py b/moto/emr/responses.py index 3919d8b3e..8442e4010 100644 --- a/moto/emr/responses.py +++ b/moto/emr/responses.py @@ -259,7 +259,7 @@ class ElasticMapReduceResponse(BaseResponse): 'Provided AMI: {0}, release label: {1}.').format( ami_version, release_label) raise EmrError(error_type="ValidationException", - message=message, template='single_error') + message=message, template='error_json') else: if ami_version: kwargs['requested_ami_version'] = ami_version diff --git a/moto/server.py b/moto/server.py index c7e7f18fb..fcc91ac6c 100644 --- a/moto/server.py +++ b/moto/server.py @@ -39,7 +39,7 @@ class DomainDispatcherApplication(object): return host for backend_name, backend in BACKENDS.items(): - for url_base in backend.values()[0].url_bases: + for url_base in list(backend.values())[0].url_bases: if re.match(url_base, 'http://%s' % host): return backend_name @@ -118,7 +118,7 @@ def create_backend_app(service): backend_app.view_functions = {} backend_app.url_map = Map() backend_app.url_map.converters['regex'] = RegexConverter - backend = BACKENDS[service].values()[0] + backend = list(BACKENDS[service].values())[0] for url_path, handler in backend.flask_paths.items(): if handler.__name__ == 'dispatch': endpoint = '{0}.dispatch'.format(handler.__self__.__name__) diff --git a/tests/test_cloudformation/test_stack_parsing.py b/tests/test_cloudformation/test_stack_parsing.py index be459eff1..c2af6363a 100644 --- a/tests/test_cloudformation/test_stack_parsing.py +++ b/tests/test_cloudformation/test_stack_parsing.py @@ -4,12 +4,12 @@ import json from mock import patch import sure # noqa +from moto.cloudformation.exceptions import ValidationError from moto.cloudformation.models import FakeStack from moto.cloudformation.parsing import resource_class_from_type, parse_condition from moto.sqs.models import Queue from moto.s3.models import FakeBucket from boto.cloudformation.stack import Output -from boto.exception import BotoServerError dummy_template = { "AWSTemplateFormatVersion": "2010-09-09", @@ -158,7 +158,7 @@ def test_parse_stack_with_get_attribute_outputs(): def test_parse_stack_with_bad_get_attribute_outputs(): FakeStack.when.called_with( - "test_id", "test_stack", bad_output_template_json, {}, "us-west-1").should.throw(BotoServerError) + "test_id", "test_stack", bad_output_template_json, {}, "us-west-1").should.throw(ValidationError) def test_parse_equals_condition(): diff --git a/tests/test_ec2/test_spot_instances.py b/tests/test_ec2/test_spot_instances.py index 5c3bdff12..05f8ee88f 100644 --- a/tests/test_ec2/test_spot_instances.py +++ b/tests/test_ec2/test_spot_instances.py @@ -39,7 +39,7 @@ def test_request_spot_instances(): "ImageId": 'ami-abcd1234', "KeyName": "test", "SecurityGroups": ['group1', 'group2'], - "UserData": b"some test data", + "UserData": "some test data", "InstanceType": 'm1.small', "Placement": { "AvailabilityZone": 'us-east-1c', @@ -67,7 +67,7 @@ def test_request_spot_instances(): "ImageId": 'ami-abcd1234', "KeyName": "test", "SecurityGroups": ['group1', 'group2'], - "UserData": b"some test data", + "UserData": "some test data", "InstanceType": 'm1.small', "Placement": { "AvailabilityZone": 'us-east-1c', diff --git a/tests/test_emr/test_emr_boto3.py b/tests/test_emr/test_emr_boto3.py index 4999935c5..b2877c7f5 100644 --- a/tests/test_emr/test_emr_boto3.py +++ b/tests/test_emr/test_emr_boto3.py @@ -347,8 +347,7 @@ def test_run_job_flow_with_invalid_params(): args['AmiVersion'] = '2.4' args['ReleaseLabel'] = 'emr-5.0.0' client.run_job_flow(**args) - ex.exception.response['Error'][ - 'Message'].should.contain('ValidationException') + ex.exception.response['Error']['Code'].should.equal('ValidationException') @mock_emr diff --git a/tests/test_events/test_events.py b/tests/test_events/test_events.py index a2d5a5d47..537b741f2 100644 --- a/tests/test_events/test_events.py +++ b/tests/test_events/test_events.py @@ -49,7 +49,6 @@ def get_random_rule(): return RULES[random.randint(0, len(RULES) - 1)] -@mock_events def generate_environment(): client = boto3.client('events', 'us-west-2') @@ -115,12 +114,12 @@ def test_list_rule_names_by_target(): client = generate_environment() rules = client.list_rule_names_by_target(TargetArn=test_1_target['Arn']) - assert(len(rules) == len(test_1_target['Rules'])) + assert(len(rules['RuleNames']) == len(test_1_target['Rules'])) for rule in rules['RuleNames']: assert(rule in test_1_target['Rules']) rules = client.list_rule_names_by_target(TargetArn=test_2_target['Arn']) - assert(len(rules) == len(test_2_target['Rules'])) + assert(len(rules['RuleNames']) == len(test_2_target['Rules'])) for rule in rules['RuleNames']: assert(rule in test_2_target['Rules']) diff --git a/tests/test_s3/test_s3.py b/tests/test_s3/test_s3.py index 32b772abe..36d4bdbc4 100644 --- a/tests/test_s3/test_s3.py +++ b/tests/test_s3/test_s3.py @@ -71,7 +71,7 @@ def test_my_model_save(): body = conn.Object('mybucket', 'steve').get()[ 'Body'].read().decode("utf-8") - assert body == b'is awesome' + assert body == 'is awesome' @mock_s3