'Tests middleware conditional redirection.
middleware.ExceptionMiddleware makes sure the user ends up in the right
place when they cancel authentication via the provider\'s UX.'

def assert_exception_redirect_looks_correct(self, expected_uri, auth_entry=None):

    exception_middleware = middleware.ExceptionMiddleware()
    (request, _) = self.get_request_and_strategy(auth_entry=auth_entry)
    response = exception_middleware.process_exception(request, exceptions.AuthCanceled(request.backend))
    location = response.get('Location')
    self.assertEqual(302, response.status_code)
    self.assertIn('canceled', location)
    self.assertIn(self.backend_name, location)
    self.assertTrue(location.startswith((expected_uri + '?')))
