def test_caching(self):
     CookieGroup.objects.create(
         varname="foo",
         name="Foo",
     )
     with self.assertNumQueries(2):
         cookie_group = get_cookie_group("optional")
         get_cookie_group("foo")
         get_cookie(cookie_group, "foo", "")
 def test_caching(self):
     CookieGroup.objects.create(
         varname="foo",
         name="Foo",
     )
     with self.assertNumQueries(2):
         cookie_group = get_cookie_group("optional")
         get_cookie_group("foo")
         get_cookie(cookie_group, "foo", "")
    def test_caching_expire(self):
        with self.assertNumQueries(2):
            cookie_group = get_cookie_group("optional")

        self.cookie_group.name = "Bar"
        self.cookie_group.save()

        with self.assertNumQueries(2):
            cookie_group = get_cookie_group("optional")
        self.assertEqual(cookie_group.name, "Bar")
    def test_caching_expire(self):
        with self.assertNumQueries(2):
            cookie_group = get_cookie_group("optional")

        self.cookie_group.name = "Bar"
        self.cookie_group.save()

        with self.assertNumQueries(2):
            cookie_group = get_cookie_group("optional")
        self.assertEqual(cookie_group.name, "Bar")
Exemplo n.º 5
0
    def test_can_override_cache_settings(self):
        """
        Assert that the cache backend/settings can be swapped out in tests.

        Regression test for #41
        """
        CookieGroup.objects.create(
            varname="foo",
            name="Foo",
        )
        # expect multiple calls to not be cached because of the no-op cache
        with self.assertNumQueries(2 + 2):
            get_cookie_group("optional")
            get_cookie_group("foo")
Exemplo n.º 6
0
def get_cookie_value_from_request(request, varname, cookie=None):
    """
    Returns if cookie group or its specific cookie has been accepted.

    Returns True or False when cookie is accepted or declined or None
    if cookie is not set.
    """
    cookie_dic = get_cookie_dict_from_request(request)
    if not cookie_dic:
        return None

    cookie_group = get_cookie_group(varname=varname)
    if not cookie_group:
        return None
    if cookie:
        name, domain = cookie.split(":")
        cookie = get_cookie(cookie_group, name, domain)
    else:
        cookie = None

    version = cookie_dic.get(varname, None)

    if version == settings.COOKIE_CONSENT_DECLINE:
        return False
    if version is None:
        return None
    if not cookie:
        v = cookie_group.get_version()
    else:
        v = cookie.get_version()
    if version >= v:
        return True
    return None
Exemplo n.º 7
0
def get_cookie_value_from_request(request, varname, cookie=None):
    """
    Returns if cookie group or its specific cookie has been accepted.

    Returns True or False when cookie is accepted or declined or None
    if cookie is not set.
    """
    cookie_dic = get_cookie_dict_from_request(request)
    if not cookie_dic:
        return None

    cookie_group = get_cookie_group(varname=varname)
    if not cookie_group:
        return None
    if cookie:
        name, domain = cookie.split(":")
        cookie = get_cookie(cookie_group, name, domain)
    else:
        cookie = None

    version = cookie_dic.get(varname, None)

    if version == settings.COOKIE_CONSENT_DECLINE:
        return False
    if version is None:
        return None
    if not cookie:
        v = cookie_group.get_version()
    else:
        v = cookie.get_version()
    if version >= v:
        return True
    return None
 def test_get_cookie(self):
     cookie_group = get_cookie_group("optional")
     self.assertEqual(get_cookie(cookie_group, "foo", ""), self.cookie)
 def test_get_cookie_group(self):
     self.assertEqual(get_cookie_group("optional"), self.cookie_group)
Exemplo n.º 10
0
 def test_get_cookie(self):
     cookie_group = get_cookie_group("optional")
     self.assertEqual(get_cookie(cookie_group, "foo", ""), self.cookie)
Exemplo n.º 11
0
 def test_get_cookie_group(self):
     self.assertEqual(get_cookie_group("optional"), self.cookie_group)