Exemple #1
0
    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)
Exemple #2
0
 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)
Exemple #3
0
 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)
Exemple #4
0
 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)
Exemple #5
0
 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)
Exemple #6
0
 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)