0

When I create a Google Cloud function through Cloud Console, there is a default function:

def hello_world(request):
    """Responds to any HTTP request.
    Args:
        request (flask.Request): HTTP request object.
    Returns:
        The response text or any set of values that can be turned into a
        Response object using
        `make_response <http://flask.pocoo.org/docs/1.0/api/#flask.Flask.make_response>`.
    """
    request_json = request.get_json()
    if request.args and 'message' in request.args:
        return request.args.get('message')
    elif request_json and 'message' in request_json:
        return request_json['message']
    else:
        return f'Hello World!'

I would like to test this locally. When I deploy it, I will write this to my browser:

https://region-project.cloudfunctions.net/function-1?message={"a"=1,"b"=2}

To test hello_world, I need to pass it the dict I am passing to my function in the HTTP request above in some form. What is processing, if I expect hello_world(processing({"a"=1,"b"=2})) to output the same thing as a deployed Cloud Function would output to browser as a response to the request https://region-project.cloudfunctions.net/function-1?message={"a"=1,"b"=2}?

zabop
  • 6,750
  • 3
  • 39
  • 84

1 Answers1

1

The function body in Python for Cloud Functions is passed a Flask Request object (see here). If you pass in an object that has a similar signature to the Request object you should be able to work. There appears to be some documentation on testing flask apps found by a search on testing flask. Examples include:

Kolban
  • 13,794
  • 3
  • 38
  • 60