"""Test for the flask plugin.""" import flask from requests.structures import CaseInsensitiveDict from owsrequest import context from owsrequest import flask_request from owsrequest.constants import headers def test_request_context_setup(): """Test that a RequestContext is auto added to flask.g.""" environment = 'test' path = '/' application_name = 'app_name' application = flask.Flask(application_name) flask_request.setup(application, environment, True) request_headers = { headers.GRASS_ACCOUNT_TYPE: 'vendor', headers.GRASS_ACCOUNT_ID: '7123', headers.ORCHARD_USER_ID: 'alw:777', headers.ORCHARD_ROLES: 'catalog,analytics', headers.ORCHARD_IDENTITY_ID: 'u1234a', headers.ORCHARD_IDENTITY_UUID: 'UUID', } expected_request_context = context.RequestContext( CaseInsensitiveDict(request_headers)) with application.test_request_context(path, headers=request_headers): application.preprocess_request() assert vars(flask.g.request_context) == vars(expected_request_context)