Hi Matt,

Use:

from django.test import Client
csrf_client = Client(enforce_csrf_checks=True)

https://docs.djangoproject.com/en/dev/ref/contrib/csrf/#testing

10.06.2011, 08:48, "Matteius" <matte...@gmail.com>:
> Greetings,
>
> I am writing unit tests for my application, and I want to leave CSRF
> checks enabled in testing.  This means on my POST I am getting 403
> because I have not figured out how to add csrf to my context when
> using the test client.  Please advise on how to most easily do this:
>
>         # Issue a POST request.
>         response = self.client.post('/student/open_enrollments/',
> {'course': 3})
>         # Check that the response is 200 OK.
>         self.assertEqual(response.status_code, 200)
>         # Verify template is the expected one.
>         self.assertTemplateUsed(response, 'student_portal/
> open_enrollments.html')
>         # Check that the rendered context contains now 0 Courses.
>         self.assertEqual(len(response.context['courses']), 0)
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to