[Answer]-Django: Is there an attribute to Client() get/post response that indicates final URL

1👍

Just to highlight the solution a bit, you can get the final url with r.request['PATH_INFO']. r.wsgi_request.META['PATH_INFO'] works as well.

0👍

I’m sure there are other ways of doing this, but would a simple in check suffice?

def test_final_url(self):

    final_url = reverse('your_url_name')

    found = False
    for item in r.redirect_chain:
        if final_url in item[0]:
            found = True
            break

    self.assertTrue(found)

Since Python lists don’t have a guaranteed order, I’m not sure it’s 100% safe to look at r.redirect_chain[-1][0] but it might be the fastest solution.

Leave a comment