coverage back at 100%
This commit is contained in:
parent
0fc2a638dd
commit
4345077173
@ -3,7 +3,7 @@ import json
|
||||
|
||||
from urlparse import parse_qs, urlparse
|
||||
|
||||
from moto.core.utils import headers_to_dict, camelcase_to_underscores, method_names_from_class
|
||||
from moto.core.utils import camelcase_to_underscores, method_names_from_class
|
||||
|
||||
|
||||
class BaseResponse(object):
|
||||
@ -20,7 +20,7 @@ class BaseResponse(object):
|
||||
if not querystring:
|
||||
querystring = parse_qs(self.body)
|
||||
if not querystring:
|
||||
querystring = headers_to_dict(headers)
|
||||
querystring = headers
|
||||
|
||||
self.uri = full_url
|
||||
self.path = urlparse(full_url).path
|
||||
@ -59,11 +59,7 @@ def metadata_response(request, full_url, headers):
|
||||
parsed_url = urlparse(full_url)
|
||||
tomorrow = datetime.datetime.now() + datetime.timedelta(days=1)
|
||||
path = parsed_url.path.lstrip("/latest/meta-data/")
|
||||
if path == '':
|
||||
result = "iam/"
|
||||
elif path == 'iam/':
|
||||
result = 'security-credentials/'
|
||||
elif path == 'iam/security-credentials/':
|
||||
if path == 'iam/security-credentials/':
|
||||
result = 'default-role'
|
||||
elif path == 'iam/security-credentials/default-role':
|
||||
result = json.dumps(dict(
|
||||
|
@ -1,36 +1,10 @@
|
||||
import inspect
|
||||
import random
|
||||
import re
|
||||
from urlparse import parse_qs
|
||||
|
||||
from flask import request
|
||||
|
||||
|
||||
def headers_to_dict(headers):
|
||||
if isinstance(headers, dict):
|
||||
# If already dict, return
|
||||
return headers
|
||||
|
||||
result = {}
|
||||
for index, header in enumerate(headers.split("\r\n")):
|
||||
if not header:
|
||||
continue
|
||||
if index:
|
||||
# Parsing headers
|
||||
key, value = header.split(":", 1)
|
||||
result[key.strip()] = value.strip()
|
||||
else:
|
||||
# Parsing method and path
|
||||
path_and_querystring = header.split(" /")[1]
|
||||
if '?' in path_and_querystring:
|
||||
querystring = path_and_querystring.split("?")[1]
|
||||
else:
|
||||
querystring = path_and_querystring
|
||||
queryset_dict = parse_qs(querystring)
|
||||
result.update(queryset_dict)
|
||||
return result
|
||||
|
||||
|
||||
def camelcase_to_underscores(argument):
|
||||
''' Converts a camelcase param like theNewAttribute to the equivalent
|
||||
python underscore variable like the_new_attribute'''
|
||||
@ -92,10 +66,6 @@ class convert_flask_to_httpretty_response(object):
|
||||
def __call__(self, args=None, **kwargs):
|
||||
headers = dict(request.headers)
|
||||
result = self.callback(request, request.url, headers)
|
||||
if isinstance(result, basestring):
|
||||
# result is just the response
|
||||
return result
|
||||
else:
|
||||
# result is a status, headers, response tuple
|
||||
status, headers, response = result
|
||||
return response, status, headers
|
||||
# result is a status, headers, response tuple
|
||||
status, headers, response = result
|
||||
return response, status, headers
|
||||
|
@ -3,7 +3,6 @@ from urlparse import parse_qs, urlparse
|
||||
from jinja2 import Template
|
||||
|
||||
from .models import s3_backend
|
||||
from moto.core.utils import headers_to_dict
|
||||
from .utils import bucket_name_from_url
|
||||
|
||||
|
||||
@ -15,7 +14,6 @@ def all_buckets():
|
||||
|
||||
|
||||
def bucket_response(request, full_url, headers):
|
||||
headers = headers_to_dict(headers)
|
||||
response = _bucket_response(request, full_url, headers)
|
||||
if isinstance(response, basestring):
|
||||
return 200, headers, response
|
||||
@ -74,8 +72,6 @@ def _bucket_response(request, full_url, headers):
|
||||
|
||||
|
||||
def key_response(request, full_url, headers):
|
||||
headers = headers_to_dict(headers)
|
||||
|
||||
response = _key_response(request, full_url, headers)
|
||||
if isinstance(response, basestring):
|
||||
return 200, headers, response
|
||||
@ -110,22 +106,10 @@ def _key_response(request, full_url, headers):
|
||||
s3_backend.copy_key(src_bucket, src_key, bucket_name, key_name)
|
||||
template = Template(S3_OBJECT_COPY_RESPONSE)
|
||||
return template.render(key=src_key)
|
||||
content_length = int(headers.get('Content-Length', 0))
|
||||
if body or (body == '' and content_length == 0):
|
||||
# We want to write the key in once of two circumstances.
|
||||
# - Anytime we are given a truthy body value
|
||||
# - We are given an empty body value and the content length is zero.
|
||||
# The reason we do not set the key to an empty string if the
|
||||
# content length is not zero is because we are sometimes sent an
|
||||
# empty string as part of closing the connection.
|
||||
new_key = s3_backend.set_key(bucket_name, key_name, body)
|
||||
template = Template(S3_OBJECT_RESPONSE)
|
||||
headers.update(new_key.response_dict)
|
||||
return 200, headers, template.render(key=new_key)
|
||||
key = s3_backend.get_key(bucket_name, key_name)
|
||||
if key:
|
||||
headers.update(key.response_dict)
|
||||
return 200, headers, ""
|
||||
new_key = s3_backend.set_key(bucket_name, key_name, body)
|
||||
template = Template(S3_OBJECT_RESPONSE)
|
||||
headers.update(new_key.response_dict)
|
||||
return 200, headers, template.render(key=new_key)
|
||||
elif method == 'HEAD':
|
||||
key = s3_backend.get_key(bucket_name, key_name)
|
||||
if key:
|
||||
|
Loading…
Reference in New Issue
Block a user