coverage back at 100%
This commit is contained in:
parent
0fc2a638dd
commit
4345077173
3 changed files with 10 additions and 60 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue