Ensure test requests operate with an isolated application context
Ensure test requests operate with an isolated application context

Add  a custom Test Client for handling the creation of a dedicated application context on a per request basis.

Flask-SQLAlchemy attaches its db operations to the top application context on the context stack.
Requests use the top application context on the context stack or create a new one if none exists.

Normally this isn't an issue. Each new request in production will use its own thread and
on finding that there is no existing application context will create a new one.

In tests however we require an application context to create/ update the database with the data required for the
test. We can then end up using this polluted application context in the view we're testing if we don't pop it. In
the open method of the new class we create a fresh application context for the request/ view to use and remove it
after so it doesn't leak back to the test.

alphagov/digitalmarketplace-api,alphagov/digitalmarketplace-api,alphagov/digitalmarketplace-api