title: flask unit test: how to test request from logged in user
body: <p>I'm writing some unit tests for my Flask web application and I'm trying to test the differences in the response between a request made by an anonymous user and a logged in user.</p>
  
  <p>I'm using the <code>Flask-Login</code> extension to implement the user login/logout.</p>
  
  <p>Obviously I'm able to perform an anonymous request, but how do I simulate a request from a logged in user?</p>
  
  <p>I thought it was enough to send in the headers the <code>session</code> cookie, but it's not working.</p>
  
  <pre><code>headers = Headers({'Cookie':['WEBSITE_ID=%s; Domain=adsabs.harvard.edu; expires=Thu, 25-Apr-2213 16:53:22 GMT; Path=/' % cookie_value, 
                               'WEBSITE_ID=%s; Domain=.adsabs.harvard.edu; expires=Thu, 25-Apr-2213 16:53:22 GMT; Path=/' % cookie_value,
                               'session="A VERY LONG STRING"; Path=/; HttpOnly',
                   ]})
  rv = app.test_client().get('/', headers=headers)
  </code></pre>
  
  <p>Where the session cookie value is a value I got from a real login in my browser.</p>
  
  <p>What am I missing?</p>