Mikhail Korobov committed 2b23311

Support auto-following of GET requests. This can be useful if e.g url scheme for site is migrated to new one using redirects.

  • Participants
  • Parent commits dd3cd53

Comments (0)

Files changed (2)


         return response
     def get(self, url, params=None, headers=None, extra_environ=None,
-            status=None, expect_errors=False, user=None):
+            status=None, expect_errors=False, user=None, auto_follow=False):
         extra_environ = self._update_environ(extra_environ, user)
-        return super(DjangoTestApp, self).get(
+        response = super(DjangoTestApp, self).get(
                   url, params, headers, extra_environ, status, expect_errors)
+        is_redirect = lambda r: r.status_int >= 300 and r.status_int < 400
+        while auto_follow and is_redirect(response):
+            response = response.follow()
+        return response
     def post(self, url, params='', headers=None, extra_environ=None,
              status=None, upload_files=None, expect_errors=False,


     if form.is_valid():
         return HttpResponseRedirect('/')
     return direct_to_template(request, 'form.html', {'form': form})