Re: How to add CSRF to context when using test client???

2013-10-12 Thread Pratik Mandrekar
I'm getting a 401 (Which is technically an Authorization error) after doing this. c = Client(enforce_csrf_checks=True) response = c.get(a_url_that_requires_login) csrfmiddlewaretoken = '%s' %response.context['csrf_token'] response = c.post(url, data=json.dumps(body),

Re: How to add CSRF to context when using test client???

2011-08-24 Thread Matteius
Thanks for both suggestions, I recently tried this approach and reached success when I ran my tests. So I think this is the correct approach and I'll include this CSRF style testing with my test suite now. -Matteius On Jul 7, 6:02 am, Craig Blaszczyk wrote: > csrf_token

Re: How to add CSRF to context when using test client???

2011-07-07 Thread Craig Blaszczyk
csrf_token is a proxy object not a string. Try doing: csrf_token = '%s' % response.context['csrf_token'] -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit

Re: How to add CSRF to context when using test client???

2011-06-27 Thread andres ledesma
Hi Matteius, I stumbled across the same problem. I wanted to carry out a test case using CSRF, and I failed. I managed to add the csrf_token to my post request, but apparently this is not enough. Here I will show you the code, perhaps you will have better luck then... c =

Re: How to add CSRF to context when using test client???

2011-06-10 Thread Matteius
Yes I Have this in the setUp function which causes my POST request to get a 403 forbidden because I don't actually include the CSRF field in the context as the middleware does on a deployed version of the site. I need a function to call or something to get the CSRF context value, or a function

Re: How to add CSRF to context when using test client???

2011-06-10 Thread Artemenko Alexander
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" : > Greetings, > > I am writing unit tests for my application, and I want to leave CSRF

How to add CSRF to context when using test client???

2011-06-09 Thread Matteius
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: #