Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django: Get cookie inside test case

I have a view that sets a cookie using response.set_cookie method. I would like to test if the cookie is being set in a TestCase.

According to docs, the cookie should be accessible in the client object, but client.cookies.items returns an empty list. The cookie is being correctly set in the browser.

Any ideas?

EDIT: adding test case

>>> response = self.client.get(url)
>>> self.client.cookies.items()
[]

The last statement returns an empty list.

like image 202
Marco Lima Avatar asked May 24 '12 13:05

Marco Lima


1 Answers

You need to use the response's client instance:

response = self.client.get(url)
response.client.cookies.items()
like image 177
Bernhard Avatar answered Nov 06 '22 15:11

Bernhard