Fix tests for py3.
This commit is contained in:
parent
0dda687762
commit
3c0c4c2996
@ -57,7 +57,7 @@ class LambdaResponse(BaseResponse):
|
|||||||
|
|
||||||
def _create_function(self, request, full_url, headers):
|
def _create_function(self, request, full_url, headers):
|
||||||
lambda_backend = self.get_lambda_backend(full_url)
|
lambda_backend = self.get_lambda_backend(full_url)
|
||||||
spec = json.loads(self.body.decode('utf-8'))
|
spec = json.loads(self.body)
|
||||||
try:
|
try:
|
||||||
fn = lambda_backend.create_function(spec)
|
fn = lambda_backend.create_function(spec)
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
|
@ -62,10 +62,10 @@ BACKENDS = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def get_model(name, region):
|
def get_model(name, region_name):
|
||||||
for backends in BACKENDS.values():
|
for backends in BACKENDS.values():
|
||||||
for region, backend in backends.items():
|
for region, backend in backends.items():
|
||||||
if region == region:
|
if region == region_name:
|
||||||
models = getattr(backend.__class__, '__models__', {})
|
models = getattr(backend.__class__, '__models__', {})
|
||||||
if name in models:
|
if name in models:
|
||||||
return list(getattr(backend, models[name])())
|
return list(getattr(backend, models[name])())
|
||||||
|
@ -21,9 +21,8 @@ from moto.s3 import models as s3_models
|
|||||||
from moto.sns import models as sns_models
|
from moto.sns import models as sns_models
|
||||||
from moto.sqs import models as sqs_models
|
from moto.sqs import models as sqs_models
|
||||||
from .utils import random_suffix
|
from .utils import random_suffix
|
||||||
from .exceptions import MissingParameterError, UnformattedGetAttTemplateException
|
from .exceptions import MissingParameterError, UnformattedGetAttTemplateException, ValidationError
|
||||||
from boto.cloudformation.stack import Output
|
from boto.cloudformation.stack import Output
|
||||||
from boto.exception import BotoServerError
|
|
||||||
|
|
||||||
MODEL_MAP = {
|
MODEL_MAP = {
|
||||||
"AWS::AutoScaling::AutoScalingGroup": autoscaling_models.FakeAutoScalingGroup,
|
"AWS::AutoScaling::AutoScalingGroup": autoscaling_models.FakeAutoScalingGroup,
|
||||||
@ -137,8 +136,7 @@ def clean_json(resource_json, resources_map):
|
|||||||
logger.warning(n.message.format(
|
logger.warning(n.message.format(
|
||||||
resource_json['Fn::GetAtt'][0]))
|
resource_json['Fn::GetAtt'][0]))
|
||||||
except UnformattedGetAttTemplateException:
|
except UnformattedGetAttTemplateException:
|
||||||
raise BotoServerError(
|
raise ValidationError(
|
||||||
UnformattedGetAttTemplateException.status_code,
|
|
||||||
'Bad Request',
|
'Bad Request',
|
||||||
UnformattedGetAttTemplateException.description.format(
|
UnformattedGetAttTemplateException.description.format(
|
||||||
resource_json['Fn::GetAtt'][0], resource_json['Fn::GetAtt'][1]))
|
resource_json['Fn::GetAtt'][0], resource_json['Fn::GetAtt'][1]))
|
||||||
|
@ -259,7 +259,7 @@ class ElasticMapReduceResponse(BaseResponse):
|
|||||||
'Provided AMI: {0}, release label: {1}.').format(
|
'Provided AMI: {0}, release label: {1}.').format(
|
||||||
ami_version, release_label)
|
ami_version, release_label)
|
||||||
raise EmrError(error_type="ValidationException",
|
raise EmrError(error_type="ValidationException",
|
||||||
message=message, template='single_error')
|
message=message, template='error_json')
|
||||||
else:
|
else:
|
||||||
if ami_version:
|
if ami_version:
|
||||||
kwargs['requested_ami_version'] = ami_version
|
kwargs['requested_ami_version'] = ami_version
|
||||||
|
@ -39,7 +39,7 @@ class DomainDispatcherApplication(object):
|
|||||||
return host
|
return host
|
||||||
|
|
||||||
for backend_name, backend in BACKENDS.items():
|
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):
|
if re.match(url_base, 'http://%s' % host):
|
||||||
return backend_name
|
return backend_name
|
||||||
|
|
||||||
@ -118,7 +118,7 @@ def create_backend_app(service):
|
|||||||
backend_app.view_functions = {}
|
backend_app.view_functions = {}
|
||||||
backend_app.url_map = Map()
|
backend_app.url_map = Map()
|
||||||
backend_app.url_map.converters['regex'] = RegexConverter
|
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():
|
for url_path, handler in backend.flask_paths.items():
|
||||||
if handler.__name__ == 'dispatch':
|
if handler.__name__ == 'dispatch':
|
||||||
endpoint = '{0}.dispatch'.format(handler.__self__.__name__)
|
endpoint = '{0}.dispatch'.format(handler.__self__.__name__)
|
||||||
|
@ -4,12 +4,12 @@ import json
|
|||||||
from mock import patch
|
from mock import patch
|
||||||
import sure # noqa
|
import sure # noqa
|
||||||
|
|
||||||
|
from moto.cloudformation.exceptions import ValidationError
|
||||||
from moto.cloudformation.models import FakeStack
|
from moto.cloudformation.models import FakeStack
|
||||||
from moto.cloudformation.parsing import resource_class_from_type, parse_condition
|
from moto.cloudformation.parsing import resource_class_from_type, parse_condition
|
||||||
from moto.sqs.models import Queue
|
from moto.sqs.models import Queue
|
||||||
from moto.s3.models import FakeBucket
|
from moto.s3.models import FakeBucket
|
||||||
from boto.cloudformation.stack import Output
|
from boto.cloudformation.stack import Output
|
||||||
from boto.exception import BotoServerError
|
|
||||||
|
|
||||||
dummy_template = {
|
dummy_template = {
|
||||||
"AWSTemplateFormatVersion": "2010-09-09",
|
"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():
|
def test_parse_stack_with_bad_get_attribute_outputs():
|
||||||
FakeStack.when.called_with(
|
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():
|
def test_parse_equals_condition():
|
||||||
|
@ -39,7 +39,7 @@ def test_request_spot_instances():
|
|||||||
"ImageId": 'ami-abcd1234',
|
"ImageId": 'ami-abcd1234',
|
||||||
"KeyName": "test",
|
"KeyName": "test",
|
||||||
"SecurityGroups": ['group1', 'group2'],
|
"SecurityGroups": ['group1', 'group2'],
|
||||||
"UserData": b"some test data",
|
"UserData": "some test data",
|
||||||
"InstanceType": 'm1.small',
|
"InstanceType": 'm1.small',
|
||||||
"Placement": {
|
"Placement": {
|
||||||
"AvailabilityZone": 'us-east-1c',
|
"AvailabilityZone": 'us-east-1c',
|
||||||
@ -67,7 +67,7 @@ def test_request_spot_instances():
|
|||||||
"ImageId": 'ami-abcd1234',
|
"ImageId": 'ami-abcd1234',
|
||||||
"KeyName": "test",
|
"KeyName": "test",
|
||||||
"SecurityGroups": ['group1', 'group2'],
|
"SecurityGroups": ['group1', 'group2'],
|
||||||
"UserData": b"some test data",
|
"UserData": "some test data",
|
||||||
"InstanceType": 'm1.small',
|
"InstanceType": 'm1.small',
|
||||||
"Placement": {
|
"Placement": {
|
||||||
"AvailabilityZone": 'us-east-1c',
|
"AvailabilityZone": 'us-east-1c',
|
||||||
|
@ -347,8 +347,7 @@ def test_run_job_flow_with_invalid_params():
|
|||||||
args['AmiVersion'] = '2.4'
|
args['AmiVersion'] = '2.4'
|
||||||
args['ReleaseLabel'] = 'emr-5.0.0'
|
args['ReleaseLabel'] = 'emr-5.0.0'
|
||||||
client.run_job_flow(**args)
|
client.run_job_flow(**args)
|
||||||
ex.exception.response['Error'][
|
ex.exception.response['Error']['Code'].should.equal('ValidationException')
|
||||||
'Message'].should.contain('ValidationException')
|
|
||||||
|
|
||||||
|
|
||||||
@mock_emr
|
@mock_emr
|
||||||
|
@ -49,7 +49,6 @@ def get_random_rule():
|
|||||||
return RULES[random.randint(0, len(RULES) - 1)]
|
return RULES[random.randint(0, len(RULES) - 1)]
|
||||||
|
|
||||||
|
|
||||||
@mock_events
|
|
||||||
def generate_environment():
|
def generate_environment():
|
||||||
client = boto3.client('events', 'us-west-2')
|
client = boto3.client('events', 'us-west-2')
|
||||||
|
|
||||||
@ -115,12 +114,12 @@ def test_list_rule_names_by_target():
|
|||||||
client = generate_environment()
|
client = generate_environment()
|
||||||
|
|
||||||
rules = client.list_rule_names_by_target(TargetArn=test_1_target['Arn'])
|
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']:
|
for rule in rules['RuleNames']:
|
||||||
assert(rule in test_1_target['Rules'])
|
assert(rule in test_1_target['Rules'])
|
||||||
|
|
||||||
rules = client.list_rule_names_by_target(TargetArn=test_2_target['Arn'])
|
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']:
|
for rule in rules['RuleNames']:
|
||||||
assert(rule in test_2_target['Rules'])
|
assert(rule in test_2_target['Rules'])
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ def test_my_model_save():
|
|||||||
body = conn.Object('mybucket', 'steve').get()[
|
body = conn.Object('mybucket', 'steve').get()[
|
||||||
'Body'].read().decode("utf-8")
|
'Body'].read().decode("utf-8")
|
||||||
|
|
||||||
assert body == b'is awesome'
|
assert body == 'is awesome'
|
||||||
|
|
||||||
|
|
||||||
@mock_s3
|
@mock_s3
|
||||||
|
Loading…
x
Reference in New Issue
Block a user