title: Flask unit testing: Getting the response's redirect location
body: <p>I have a Flask based webapp that occasionally creates new documents with new random keys when posting to their parent document in a certain way. The new key gets in the parent's data structure, the updated parent gets temporarily stored in the session and on successfully saving the child document, the stored parent gets pulled out of the session and stored alongside, in order to link the two together. This is done for certain kinds of relations where one wants to have an inherent order between the keys, so the keys are stored as a list on the parent.</p>
  
  <p>Now, the problem comes in when I want to unit test this using the Werkzeug provided unit test client. Doing a </p>
  
  <pre><code> ret = self.test_client.post(
      request_path,
      data=data,
      follow_redirects=True
  )
  </code></pre>
  
  <p>in the test case object will successfully redirect to the child document with the new key - but I don't know where to retrieve this new key inside the unit tests. I can't find an attribute on top of the return value that would indicate, where it has been redirected to. <code>dir(ret)</code> gives me</p>
  
  <pre><code> ['__call__', '__class__', '__delattr__', '__dict__', '__doc__', '__enter__', '__exit__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_ensure_sequence', '_get_mimetype_params', '_on_close', '_status', '_status_code', 'accept_ranges', 'add_etag', 'age', 'allow', 'autocorrect_location_header', 'automatically_set_content_length', 'cache_control', 'calculate_content_length', 'call_on_close', 'charset', 'close', 'content_encoding', 'content_language', 'content_length', 'content_location', 'content_md5', 'content_range', 'content_type', 'data', 'date', 'default_mimetype', 'default_status', 'delete_cookie', 'direct_passthrough', 'expires', 'force_type', 'freeze', 'from_app', 'get_app_iter', 'get_data', 'get_etag', 'get_wsgi_headers', 'get_wsgi_response', 'headers', 'implicit_sequence_conversion', 'is_sequence', 'is_streamed', 'iter_encoded', 'last_modified', 'location', 'make_conditional', 'make_sequence', 'mimetype', 'mimetype_params', 'response', 'retry_after', 'set_cookie', 'set_data', 'set_etag', 'status', 'status_code', 'stream', 'vary', 'www_authenticate']
  </code></pre>
  
  <p>Of those, <code>headers</code> and <code>location</code> look promising - however location isn't set and headers doesn't contain it either.</p>
  
  <p>How can I get the redirected location from the response? Do I really have to parse the child's key from the response body? Isn't there a better way?</p>