def test_process_404(self): """A 404 should not trigger anything""" request = RequestFactory().get("dummy_url") response = RedirectUnenrolledMiddleware().process_exception( request, Http404() ) self.assertIsNone(response)
def check_user_not_enrolled_redirect(self): """A UserNotEnrolled exception should trigger a redirect""" request = RequestFactory().get("dummy_url") response = RedirectUnenrolledMiddleware().process_exception( request, courses.UserNotEnrolled(self.course.id)) self.assertEqual(response.status_code, 302) # make sure we redirect to the course about page expected_url = reverse("about_course", args=[self.course.id.to_deprecated_string()]) target_url = response._headers['location'][1] self.assertTrue(target_url.endswith(expected_url))