Clean up querystring logic.
This commit is contained in:
parent
ffcbaf366e
commit
8b278eb05d
@ -26,7 +26,7 @@ class BaseResponse(object):
|
||||
for key, value in request.form.iteritems():
|
||||
querystring[key] = [value, ]
|
||||
|
||||
if querystring is None:
|
||||
if not querystring:
|
||||
querystring.update(parse_qs(urlparse(full_url).query))
|
||||
if not querystring:
|
||||
querystring.update(parse_qs(self.body))
|
||||
|
@ -20,12 +20,16 @@ class DomainDispatcherApplication(object):
|
||||
value. We'll match the host header value with the url_bases of each backend.
|
||||
"""
|
||||
|
||||
def __init__(self, create_app):
|
||||
def __init__(self, create_app, service=None):
|
||||
self.create_app = create_app
|
||||
self.lock = Lock()
|
||||
self.app_instances = {}
|
||||
self.service = service
|
||||
|
||||
def get_backend_for_host(self, host):
|
||||
if self.service:
|
||||
return BACKENDS[self.service]
|
||||
|
||||
for backend in BACKENDS.itervalues():
|
||||
for url_base in backend.url_bases:
|
||||
if re.match(url_base, 'http://%s' % host):
|
||||
@ -55,7 +59,7 @@ class RegexConverter(BaseConverter):
|
||||
self.regex = items[0]
|
||||
|
||||
|
||||
def create_backend_app(backend):
|
||||
def create_backend_app(service):
|
||||
from werkzeug.routing import Map
|
||||
|
||||
# Create the backend_app
|
||||
@ -66,6 +70,8 @@ def create_backend_app(backend):
|
||||
backend_app.view_functions = {}
|
||||
backend_app.url_map = Map()
|
||||
backend_app.url_map.converters['regex'] = RegexConverter
|
||||
|
||||
backend = BACKENDS[service]
|
||||
for url_path, handler in backend.flask_paths.iteritems():
|
||||
backend_app.route(url_path, methods=HTTP_METHODS)(convert_flask_to_httpretty_response(handler))
|
||||
|
||||
@ -74,6 +80,9 @@ def create_backend_app(backend):
|
||||
|
||||
def main(argv=sys.argv[1:]):
|
||||
parser = argparse.ArgumentParser()
|
||||
|
||||
# Keep this for backwards compat
|
||||
parser.add_argument("service", type=str)
|
||||
parser.add_argument(
|
||||
'-H', '--host', type=str,
|
||||
help='Which host to bind',
|
||||
@ -86,7 +95,7 @@ def main(argv=sys.argv[1:]):
|
||||
args = parser.parse_args(argv)
|
||||
|
||||
# Wrap the main application
|
||||
main_app = DomainDispatcherApplication(create_backend_app)
|
||||
main_app = DomainDispatcherApplication(create_backend_app, service=args.service)
|
||||
main_app.debug = True
|
||||
|
||||
run_simple(args.host, args.port, main_app)
|
||||
|
@ -1,7 +1,7 @@
|
||||
from .responses import QueueResponse, QueuesResponse
|
||||
|
||||
url_bases = [
|
||||
"https?://queue(.*).amazonaws.com"
|
||||
"https?://(.*?)(queue|sqs)(.*?).amazonaws.com"
|
||||
]
|
||||
|
||||
url_paths = {
|
||||
|
@ -5,11 +5,12 @@ import moto.server as server
|
||||
'''
|
||||
Test the different server responses
|
||||
'''
|
||||
server.configure_urls("autoscaling")
|
||||
|
||||
|
||||
def test_describe_autoscaling_groups():
|
||||
test_client = server.app.test_client()
|
||||
backend = server.create_backend_app("autoscaling")
|
||||
test_client = backend.test_client()
|
||||
|
||||
res = test_client.get('/?Action=DescribeLaunchConfigurations')
|
||||
|
||||
res.data.should.contain('<DescribeLaunchConfigurationsResponse')
|
||||
|
@ -13,13 +13,17 @@ def test_wrong_arguments():
|
||||
pass
|
||||
|
||||
|
||||
@patch('moto.server.app.run')
|
||||
def test_right_arguments(app_run):
|
||||
@patch('moto.server.run_simple')
|
||||
def test_right_arguments(run_simple):
|
||||
main(["s3"])
|
||||
app_run.assert_called_once_with(host='0.0.0.0', port=5000)
|
||||
func_call = run_simple.call_args[0]
|
||||
func_call[0].should.equal("0.0.0.0")
|
||||
func_call[1].should.equal(5000)
|
||||
|
||||
|
||||
@patch('moto.server.app.run')
|
||||
def test_port_argument(app_run):
|
||||
@patch('moto.server.run_simple')
|
||||
def test_port_argument(run_simple):
|
||||
main(["s3", "--port", "8080"])
|
||||
app_run.assert_called_once_with(host='0.0.0.0', port=8080)
|
||||
func_call = run_simple.call_args[0]
|
||||
func_call[0].should.equal("0.0.0.0")
|
||||
func_call[1].should.equal(8080)
|
||||
|
@ -5,11 +5,12 @@ import moto.server as server
|
||||
'''
|
||||
Test the different server responses
|
||||
'''
|
||||
server.configure_urls("dynamodb")
|
||||
|
||||
|
||||
def test_table_list():
|
||||
test_client = server.app.test_client()
|
||||
backend = server.create_backend_app("dynamodb")
|
||||
test_client = backend.test_client()
|
||||
|
||||
res = test_client.get('/')
|
||||
res.status_code.should.equal(404)
|
||||
|
||||
|
@ -6,11 +6,12 @@ import moto.server as server
|
||||
'''
|
||||
Test the different server responses
|
||||
'''
|
||||
server.configure_urls("ec2")
|
||||
|
||||
|
||||
def test_ec2_server_get():
|
||||
test_client = server.app.test_client()
|
||||
backend = server.create_backend_app("ec2")
|
||||
test_client = backend.test_client()
|
||||
|
||||
res = test_client.get('/?Action=RunInstances&ImageId=ami-60a54009')
|
||||
|
||||
groups = re.search("<instanceId>(.*)</instanceId>", res.data)
|
||||
|
@ -5,11 +5,12 @@ import moto.server as server
|
||||
'''
|
||||
Test the different server responses
|
||||
'''
|
||||
server.configure_urls("elb")
|
||||
|
||||
|
||||
def test_elb_describe_instances():
|
||||
test_client = server.app.test_client()
|
||||
backend = server.create_backend_app("elb")
|
||||
test_client = backend.test_client()
|
||||
|
||||
res = test_client.get('/?Action=DescribeLoadBalancers')
|
||||
|
||||
res.data.should.contain('DescribeLoadBalancersResponse')
|
||||
|
@ -5,11 +5,12 @@ import moto.server as server
|
||||
'''
|
||||
Test the different server responses
|
||||
'''
|
||||
server.configure_urls("emr")
|
||||
|
||||
|
||||
def test_describe_jobflows():
|
||||
test_client = server.app.test_client()
|
||||
backend = server.create_backend_app("emr")
|
||||
test_client = backend.test_client()
|
||||
|
||||
res = test_client.get('/?Action=DescribeJobFlows')
|
||||
|
||||
res.data.should.contain('<DescribeJobFlowsResult>')
|
||||
|
@ -5,18 +5,21 @@ import moto.server as server
|
||||
'''
|
||||
Test the different server responses
|
||||
'''
|
||||
server.configure_urls("s3")
|
||||
|
||||
|
||||
def test_s3_server_get():
|
||||
test_client = server.app.test_client()
|
||||
backend = server.create_backend_app("s3")
|
||||
test_client = backend.test_client()
|
||||
|
||||
res = test_client.get('/')
|
||||
|
||||
res.data.should.contain('ListAllMyBucketsResult')
|
||||
|
||||
|
||||
def test_s3_server_bucket_create():
|
||||
test_client = server.app.test_client()
|
||||
backend = server.create_backend_app("s3")
|
||||
test_client = backend.test_client()
|
||||
|
||||
res = test_client.put('/', 'http://foobar.localhost:5000/')
|
||||
res.status_code.should.equal(200)
|
||||
|
||||
@ -36,7 +39,9 @@ def test_s3_server_bucket_create():
|
||||
|
||||
|
||||
def test_s3_server_post_to_bucket():
|
||||
test_client = server.app.test_client()
|
||||
backend = server.create_backend_app("s3")
|
||||
test_client = backend.test_client()
|
||||
|
||||
res = test_client.put('/', 'http://foobar.localhost:5000/')
|
||||
res.status_code.should.equal(200)
|
||||
|
||||
|
@ -5,18 +5,21 @@ import moto.server as server
|
||||
'''
|
||||
Test the different server responses
|
||||
'''
|
||||
server.configure_urls("s3bucket_path")
|
||||
|
||||
|
||||
def test_s3_server_get():
|
||||
test_client = server.app.test_client()
|
||||
backend = server.create_backend_app("s3bucket_path")
|
||||
test_client = backend.test_client()
|
||||
|
||||
res = test_client.get('/')
|
||||
|
||||
res.data.should.contain('ListAllMyBucketsResult')
|
||||
|
||||
|
||||
def test_s3_server_bucket_create():
|
||||
test_client = server.app.test_client()
|
||||
backend = server.create_backend_app("s3bucket_path")
|
||||
test_client = backend.test_client()
|
||||
|
||||
res = test_client.put('/foobar', 'http://localhost:5000')
|
||||
res.status_code.should.equal(200)
|
||||
|
||||
@ -36,7 +39,9 @@ def test_s3_server_bucket_create():
|
||||
|
||||
|
||||
def test_s3_server_post_to_bucket():
|
||||
test_client = server.app.test_client()
|
||||
backend = server.create_backend_app("s3bucket_path")
|
||||
test_client = backend.test_client()
|
||||
|
||||
res = test_client.put('/foobar', 'http://localhost:5000/')
|
||||
res.status_code.should.equal(200)
|
||||
|
||||
|
@ -5,10 +5,11 @@ import moto.server as server
|
||||
'''
|
||||
Test the different server responses
|
||||
'''
|
||||
server.configure_urls("ses")
|
||||
|
||||
|
||||
def test_ses_list_identities():
|
||||
test_client = server.app.test_client()
|
||||
backend = server.create_backend_app("ses")
|
||||
test_client = backend.test_client()
|
||||
|
||||
res = test_client.get('/?Action=ListIdentities')
|
||||
res.data.should.contain("ListIdentitiesResponse")
|
||||
|
@ -6,11 +6,12 @@ import moto.server as server
|
||||
'''
|
||||
Test the different server responses
|
||||
'''
|
||||
server.configure_urls("sqs")
|
||||
|
||||
|
||||
def test_sqs_list_identities():
|
||||
test_client = server.app.test_client()
|
||||
backend = server.create_backend_app("sqs")
|
||||
test_client = backend.test_client()
|
||||
|
||||
res = test_client.get('/?Action=ListQueues')
|
||||
res.data.should.contain("ListQueuesResponse")
|
||||
|
||||
|
@ -5,11 +5,12 @@ import moto.server as server
|
||||
'''
|
||||
Test the different server responses
|
||||
'''
|
||||
server.configure_urls("sts")
|
||||
|
||||
|
||||
def test_sts_get_session_token():
|
||||
test_client = server.app.test_client()
|
||||
backend = server.create_backend_app("sts")
|
||||
test_client = backend.test_client()
|
||||
|
||||
res = test_client.get('/?Action=GetSessionToken')
|
||||
res.status_code.should.equal(200)
|
||||
res.data.should.contain("SessionToken")
|
||||
|
Loading…
x
Reference in New Issue
Block a user