def test_http_response_to_dict(body, headers, status_code): r = Response(body=body, headers=headers, status_code=status_code) serialized = r.to_dict() assert 'headers' in serialized assert 'statusCode' in serialized assert 'body' in serialized assert isinstance(serialized['body'], six.string_types)
def test_http_response_to_dict(body, headers, status_code): r = Response(body=body, headers=headers, status_code=status_code) serialized = r.to_dict() assert 'headers' in serialized assert 'statusCode' in serialized assert 'body' in serialized assert isinstance(serialized['body'], six.string_types)
def test_handles_binary_responses(body, content_type): r = Response(body=body, headers={'Content-Type': content_type}) serialized = r.to_dict(BINARY_TYPES) # A binary response should always result in the # response being base64 encoded. assert serialized['isBase64Encoded'] assert isinstance(serialized['body'], six.string_types) assert isinstance(base64.b64decode(serialized['body']), bytes)
def test_handles_binary_responses(body, content_type): r = Response(body=body, headers={'Content-Type': content_type}) serialized = r.to_dict(BINARY_TYPES) # A binary response should always result in the # response being base64 encoded. assert serialized['isBase64Encoded'] assert isinstance(serialized['body'], six.string_types) assert isinstance(base64.b64decode(serialized['body']), bytes)
def error_response(message, error_code, http_status_code, headers=None): body = {'Code': error_code, 'Message': message} response = Response(body=body, status_code=http_status_code, headers=headers) return response.to_dict()