This commit is contained in:
Steve Pulec 2017-02-23 21:37:43 -05:00
commit f37bad0e00
260 changed files with 6363 additions and 3766 deletions

View file

@ -59,11 +59,13 @@ def test_decorater_wrapped_gets_set():
"""
Moto decorator's __wrapped__ should get set to the tests function
"""
test_decorater_wrapped_gets_set.__wrapped__.__name__.should.equal('test_decorater_wrapped_gets_set')
test_decorater_wrapped_gets_set.__wrapped__.__name__.should.equal(
'test_decorater_wrapped_gets_set')
@mock_ec2_deprecated
class Tester(object):
def test_the_class(self):
conn = boto.connect_ec2()
list(conn.get_all_instances()).should.have.length_of(0)
@ -75,6 +77,7 @@ class Tester(object):
@mock_s3_deprecated
class TesterWithSetup(unittest.TestCase):
def setUp(self):
self.conn = boto.connect_s3()
self.conn.create_bucket('mybucket')

View file

@ -30,13 +30,15 @@ def test_meta_data_iam():
@mock_ec2
def test_meta_data_security_credentials():
res = requests.get("{0}/latest/meta-data/iam/security-credentials/".format(BASE_URL))
res = requests.get(
"{0}/latest/meta-data/iam/security-credentials/".format(BASE_URL))
res.content.should.equal(b"default-role")
@mock_ec2
def test_meta_data_default_role():
res = requests.get("{0}/latest/meta-data/iam/security-credentials/default-role".format(BASE_URL))
res = requests.get(
"{0}/latest/meta-data/iam/security-credentials/default-role".format(BASE_URL))
json_response = res.json()
json_response.should.contain('AccessKeyId')
json_response.should.contain('SecretAccessKey')

View file

@ -7,7 +7,8 @@ from moto.core.responses import flatten_json_request_body
def test_flatten_json_request_body():
spec = AWSServiceSpec('data/emr/2009-03-31/service-2.json').input_spec('RunJobFlow')
spec = AWSServiceSpec(
'data/emr/2009-03-31/service-2.json').input_spec('RunJobFlow')
body = {
'Name': 'cluster',
@ -42,25 +43,32 @@ def test_flatten_json_request_body():
flat['Name'].should.equal(body['Name'])
flat['Instances.Ec2KeyName'].should.equal(body['Instances']['Ec2KeyName'])
for idx in range(2):
flat['Instances.InstanceGroups.member.' + str(idx + 1) + '.InstanceRole'].should.equal(body['Instances']['InstanceGroups'][idx]['InstanceRole'])
flat['Instances.InstanceGroups.member.' + str(idx + 1) + '.InstanceType'].should.equal(body['Instances']['InstanceGroups'][idx]['InstanceType'])
flat['Instances.Placement.AvailabilityZone'].should.equal(body['Instances']['Placement']['AvailabilityZone'])
flat['Instances.InstanceGroups.member.' + str(idx + 1) + '.InstanceRole'].should.equal(
body['Instances']['InstanceGroups'][idx]['InstanceRole'])
flat['Instances.InstanceGroups.member.' + str(idx + 1) + '.InstanceType'].should.equal(
body['Instances']['InstanceGroups'][idx]['InstanceType'])
flat['Instances.Placement.AvailabilityZone'].should.equal(
body['Instances']['Placement']['AvailabilityZone'])
for idx in range(1):
prefix = 'Steps.member.' + str(idx + 1) + '.HadoopJarStep'
step = body['Steps'][idx]['HadoopJarStep']
i = 0
while prefix + '.Properties.member.' + str(i + 1) + '.Key' in flat:
flat[prefix + '.Properties.member.' + str(i + 1) + '.Key'].should.equal(step['Properties'][i]['Key'])
flat[prefix + '.Properties.member.' + str(i + 1) + '.Value'].should.equal(step['Properties'][i]['Value'])
flat[prefix + '.Properties.member.' +
str(i + 1) + '.Key'].should.equal(step['Properties'][i]['Key'])
flat[prefix + '.Properties.member.' +
str(i + 1) + '.Value'].should.equal(step['Properties'][i]['Value'])
i += 1
i = 0
while prefix + '.Args.member.' + str(i + 1) in flat:
flat[prefix + '.Args.member.' + str(i + 1)].should.equal(step['Args'][i])
flat[prefix + '.Args.member.' +
str(i + 1)].should.equal(step['Args'][i])
i += 1
for idx in range(2):
flat['Configurations.member.' + str(idx + 1) + '.Classification'].should.equal(body['Configurations'][idx]['Classification'])
flat['Configurations.member.' + str(idx + 1) + '.Classification'].should.equal(
body['Configurations'][idx]['Classification'])
props = {}
i = 1

View file

@ -32,19 +32,22 @@ def test_port_argument(run_simple):
def test_domain_dispatched():
dispatcher = DomainDispatcherApplication(create_backend_app)
backend_app = dispatcher.get_application({"HTTP_HOST": "email.us-east1.amazonaws.com"})
backend_app = dispatcher.get_application(
{"HTTP_HOST": "email.us-east1.amazonaws.com"})
keys = list(backend_app.view_functions.keys())
keys[0].should.equal('EmailResponse.dispatch')
def test_domain_without_matches():
dispatcher = DomainDispatcherApplication(create_backend_app)
dispatcher.get_application.when.called_with({"HTTP_HOST": "not-matching-anything.com"}).should.throw(RuntimeError)
dispatcher.get_application.when.called_with(
{"HTTP_HOST": "not-matching-anything.com"}).should.throw(RuntimeError)
def test_domain_dispatched_with_service():
# If we pass a particular service, always return that.
dispatcher = DomainDispatcherApplication(create_backend_app, service="s3")
backend_app = dispatcher.get_application({"HTTP_HOST": "s3.us-east1.amazonaws.com"})
backend_app = dispatcher.get_application(
{"HTTP_HOST": "s3.us-east1.amazonaws.com"})
keys = set(backend_app.view_functions.keys())
keys.should.contain('ResponseObject.key_response')

View file

@ -14,7 +14,8 @@ def test_flask_path_converting_simple():
def test_flask_path_converting_regex():
convert_regex_to_flask_path("/(?P<key_name>[a-zA-Z0-9\-_]+)").should.equal('/<regex("[a-zA-Z0-9\-_]+"):key_name>')
convert_regex_to_flask_path(
"/(?P<key_name>[a-zA-Z0-9\-_]+)").should.equal('/<regex("[a-zA-Z0-9\-_]+"):key_name>')
convert_regex_to_flask_path("(?P<account_id>\d+)/(?P<queue_name>.*)$").should.equal(
'<regex("\d+"):account_id>/<regex(".*"):queue_name>'