Fixed #23682 -- Enhanced circular redirects detection in tests.

Please see [#23682](https://code.djangoproject.com/ticket/23682).
It's usually best to do cleanup changes in a separate commit or pull request. I recommend only touching the imports you need to for now.