Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

requests-like wrapper for flask's test_client

I'm trying to make a usable tests for my package, but using Flask.test_client is so different from the requests API that I found it hard to use.

I have tried to make requests.adapters.HTTPAdapter wrap the response, but it looks like werkzeug doesn't use httplib (or urllib for that matter) to build it own Response object.

Any idea how it can be done? Reference to existing code will be the best (googling werkzeug + requests doesn't give any useful results)

Many thanks!!

like image 356
eplaut Avatar asked Dec 12 '16 19:12

eplaut


People also ask

What is Flask request?

When the Flask application handles a request, it creates a Request object based on the environment it received from the WSGI server. Because a worker (thread, process, or coroutine depending on the server) handles only one request at a time, the request data can be considered global to that worker during that request.

What is Mimetype in Flask?

Flask-Mime is Flask extension that enables applications to dispatch requests based on Accept header of it.

What is payload in Flask?

This payload can be in the shape of query strings, form data, and JSON objects. Flask, like any other web framework, allows you to access the request data. In this tutorial, you will build a Flask application with three routes that accept either query strings, form data, or JSON objects.

What is a Flask object?

The flask object implements a WSGI application and acts as the central object. It is passed the name of the module or package of the application. Once it is created it will act as a central registry for the view functions, the URL rules, template configuration and much more.


1 Answers

A PyPI package now exists for this so you can use pip install requests-flask-adapter.

like image 69
Adam Dangoor Avatar answered Sep 28 '22 18:09

Adam Dangoor