Fix tests for py3.

This commit is contained in:
Steve Pulec 2017-02-23 22:28:09 -05:00
parent 0dda687762
commit 3c0c4c2996
10 changed files with 16 additions and 20 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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',

View File

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

View File

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

View File

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