Django: get cookie inside test case

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

According to docs , the cookie should be available in the client object, but it client.cookies.itemsreturns an empty list. The cookie is set correctly in the browser.

Any ideas?

EDIT: Adding a Test Case

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

The last statement returns an empty list.

+5
source share
1 answer

You need to use the response client instance:

response = self.client.get(url)
response.client.cookies.items()
+7
source

All Articles