def assert_redirect ( self , response , expected_url = None ) : self . assertIn ( response . status_code , self . redirect_codes , self . _get_redirect_assertion_message ( response ) , ) if expected_url : location_header = response . _headers . get ( 'location' , None ) self . assertEqual ( location_header , ( 'Location' , str ( expected_url ) ) , 'Response should redirect to {0}, but it redirects to {1} instead' . format ( expected_url , location_header [ 1 ] , ) )
python unittest redirect assert failure
assertRedirects from Django TestCase follows the redirects chains this assertion does not - which is more like real unit testing
def assert_redirect(self, response, expected_url=None):
        """
        assertRedirects from Django TestCase follows the redirects chains,
        this assertion does not - which is more like real unit testing
        """
        self.assertIn(
            response.status_code,
            self.redirect_codes,
            self._get_redirect_assertion_message(response),
        )
        if expected_url:
            location_header = response._headers.get('location', None)
            self.assertEqual(
                location_header,
                ('Location', str(expected_url)),
                'Response should redirect to {0}, but it redirects to {1} instead'.format(
                    expected_url,
                    location_header[1],
                )
            )