I am deploying a Flask app on IIS and using its Windows Authentication, which sets request.environ['REMOTE_USER'] to your windows username if authenticated successfully. Now when writing test cases, how do I fake request.environ['REMOTE_USER']? The test cases are run independent of the IIS server.
My attempt:
from flask import request
def test_insert_cash_flow_through_post(self):
"""Test that you can insert a cash flow through post."""
request.environ['REMOTE_USER'] = 'foo'
self.client.post("/index?account=main",
data=dict(settlement_date='01/01/2016',
transaction_type='Other',
certainty='Certain',
transaction_amount=1))
assert CashFlow.query.first().user == 'foo'
The part of my view that handles 'REMOTE_USER' is something like:
cf = CashFlow(...,
user=request.environ.get('REMOTE_USER'),
...)
db.session.add(cf)