def test_get_cookie_value_from_request_specific_cookie(self): cookie_str = dict_to_cookie_str( {"optional": self.cookie_group.get_version()}) self.request.COOKIES[settings.COOKIE_CONSENT_NAME] = cookie_str res = get_cookie_value_from_request(self.request, 'optional', "foo:") self.assertTrue(res) Cookie.objects.create( cookiegroup=self.cookie_group, name="bar", domain=".example.com", ) res = get_cookie_value_from_request(self.request, 'optional', "bar:.example.com") self.assertFalse(res) res = get_cookie_value_from_request(self.request, 'optional', "foo:") self.assertTrue(res) cookie_str = dict_to_cookie_str( {"optional": self.cookie_group.get_version()}) self.request.COOKIES[settings.COOKIE_CONSENT_NAME] = cookie_str res = get_cookie_value_from_request(self.request, 'optional', "bar:.example.com") self.assertTrue(res)
def test_dict_to_cookie_str(self): cookie_str = "|" dic = { 'foo': "2013-06-04T01:08:58.262162", 'bar': "2013-06-04T01:08:58", } cookie_str = dict_to_cookie_str(dic) self.assertEqual(parse_cookie_str(cookie_str), dic)
def test_get_cookie_value_from_request_added_cookies(self): cookie_str = dict_to_cookie_str({ "optional": self.cookie_group.get_version(), }) Cookie.objects.create( cookiegroup=self.cookie_group, name="bar", domain=".example.com", ) self.request.COOKIES[settings.COOKIE_CONSENT_NAME] = cookie_str res = get_cookie_value_from_request(self.request, 'optional') self.assertIsNone(res)
def test_get_cookie_value_from_request_declined(self): cookie_str = dict_to_cookie_str( {"optional": datetime(1999, 1, 1).isoformat()}) self.request.COOKIES[settings.COOKIE_CONSENT_NAME] = cookie_str res = get_cookie_value_from_request(self.request, 'optional') self.assertFalse(res)
def test_get_cookie_value_from_request(self): cookie_str = dict_to_cookie_str( {"optional": self.cookie_group.get_version()}) self.request.COOKIES[settings.COOKIE_CONSENT_NAME] = cookie_str res = get_cookie_value_from_request(self.request, 'optional') self.assertTrue(res)
def test_get_accepted_cookies(self): cookie_str = dict_to_cookie_str( {"optional": self.cookie_group.get_version()}) self.request.COOKIES[settings.COOKIE_CONSENT_NAME] = cookie_str cookies = get_accepted_cookies(self.request) self.assertIn(self.cookie, cookies)