daphne/channels/tests/test_http.py
Drew French f4c9b02ae3 Valid cookie serialization for the test HTTPClient (#453)
* valid cookie serialization

* Added set cookie test

* delimiter fix

* more cases

* quote fix

* cleanup

* fix

* lint cleanup

* more lint clean up
2016-12-22 22:46:09 +00:00

26 lines
816 B
Python

from __future__ import unicode_literals
from django.http.cookie import parse_cookie
from channels.tests import ChannelTestCase
from channels.tests.http import HttpClient
class HttpClientTests(ChannelTestCase):
def test_cookies(self):
client = HttpClient()
client.set_cookie('foo', 'not-bar')
client.set_cookie('foo', 'bar')
client.set_cookie('qux', 'qu;x')
# Django's interpretation of the serialized cookie.
cookie_dict = parse_cookie(client.headers['cookie'].decode('ascii'))
self.assertEqual(client.get_cookies(),
cookie_dict)
self.assertEqual({'foo': 'bar',
'qux': 'qu;x',
'sessionid': client.get_cookies()['sessionid']},
cookie_dict)