Exemple #1
0
    def cookie(self, key, value, encrypt=True,
               http_only="HttpOnly;", path='/', expires=''):
        """Set a cookie in the browser.

        Arguments:
            key {string} -- Name of the cookie you want set.
            value {string} -- Value of the cookie you want set.

        Keyword Arguments:
            encrypt {bool} -- Whether or not you want to encrypt the cookie (default: {True})
            http_only {str} -- If the cookie is HttpOnly or not (default: {"HttpOnly;"})
            path {str} -- The path of the cookie to be set to. (default: {'/'})
            expires {string} -- When the cookie expires (5 minutes, 1 minute, 10 hours, etc) (default: {''})

        Returns:
            self
        """
        if encrypt:
            value = Sign(self.encryption_key).sign(value)
        else:
            value = value

        if expires:
            expires = "Expires={0};".format(cookie_expire_time(expires))

        if not http_only:
            http_only = ""

        self.cookies.append(
            ('Set-Cookie', '{0}={1};{2} {3}Path={4}'.format(
                key, value, expires, http_only, path)))
        self.append_cookie(key, value)
        return self
Exemple #2
0
    def cookie(self,
               key,
               value,
               encrypt=True,
               http_only="HttpOnly;",
               path='/',
               expires=''):
        """
        Sets a cookie in the browser
        """

        if encrypt:
            value = Sign(self.encryption_key).sign(value)
        else:
            value = value

        if expires:
            expires = "Expires={0};".format(cookie_expire_time(expires))

        if not http_only:
            http_only = ""

        self.cookies.append(
            ('Set-Cookie',
             '{0}={1};{2} {3}Path={4}'.format(key, value, expires, http_only,
                                              path)))
        self.append_cookie(key, value)
        return self
def test_request_sets_expiration_cookie_2_months():
    REQUEST.cookies = []
    REQUEST.cookie('setcookie_expiration', 'value', expires='2 months')

    time = cookie_expire_time('2 months')

    assert REQUEST.get_cookie('setcookie_expiration') == 'value'
    assert 'Expires={0}'.format(time) in REQUEST.cookies[0][1]
Exemple #4
0
    def test_request_sets_expiration_cookie_2_months(self):
        self.request.cookies = []
        self.request.cookie('setcookie_expiration', 'value', expires='2 months')

        time = cookie_expire_time('2 months')

        assert self.request.get_cookie('setcookie_expiration') == 'value'
        assert 'Expires={0}'.format(time) in self.request.cookies[0][1]
    def test_request_sets_expiration_cookie_2_months(self):
        self.request.cookies = []
        self.request.cookie('setcookie_expiration',
                            'value',
                            expires='2 months')

        time = cookie_expire_time('2 months')

        self.assertEqual(self.request.get_cookie('setcookie_expiration'),
                         'value')
        self.assertEqual(
            self.request.get_raw_cookie('setcookie_expiration')['expires'],
            time)