Example #1
0
    def test_attributes(self):
        cookie = Cookie('color', 'blue')
        assert cookie.key == 'color'
        assert cookie.value == 'blue'
        assert cookie.domain is None
        assert cookie.path is None
        assert cookie.max_age is None
        assert cookie.expires is None
        assert cookie.secure is None
        assert cookie.httponly is None

        cookie.domain = 'example.com'
        assert cookie.domain == 'example.com'
        cookie.domain = None
        assert cookie.domain is None

        cookie.path = '/toplevel'
        assert cookie.path == '/toplevel'
        cookie.path = None
        assert cookie.path is None

        cookie.max_age = 400
        assert cookie.max_age == 400
        cookie.max_age = None
        assert cookie.max_age is None

        cookie.expires = 'Sun, 06 Nov 1994 08:49:37 GMT'
        assert cookie.expires == datetime.datetime(
            1994, 11, 6, 8, 49, 37, tzinfo=datetime.timezone.utc)
        cookie.expires = None
        assert cookie.expires is None

        cookie.secure = True
        assert cookie.secure is True
        assert str(cookie) == "color=blue; Secure"
        cookie.secure = False
        assert cookie.secure is False
        assert str(cookie) == "color=blue"
        cookie.secure = None
        assert cookie.secure is None
        assert str(cookie) == "color=blue"

        cookie.httponly = True
        assert cookie.httponly is True
        assert str(cookie) == "color=blue; HttpOnly"
        cookie.httponly = False
        assert cookie.httponly is False
        assert str(cookie) == "color=blue"
        cookie.httponly = None
        assert cookie.httponly is None
        assert str(cookie) == "color=blue"
Example #2
0
    def test_attributes(self):
        cookie = Cookie('color', 'blue')
        self.assertEqual(cookie.key, 'color')
        self.assertEqual(cookie.value, 'blue')
        self.assertEqual(cookie.domain, None)
        self.assertEqual(cookie.path, None)
        self.assertEqual(cookie.max_age, None)
        self.assertEqual(cookie.expires, None)
        self.assertEqual(cookie.secure, None)
        self.assertEqual(cookie.httponly, None)

        cookie.domain = 'example.com'
        self.assertEqual(cookie.domain, 'example.com')
        cookie.domain = None
        self.assertEqual(cookie.domain, None)

        cookie.path = '/toplevel'
        self.assertEqual(cookie.path, '/toplevel')
        cookie.path = None
        self.assertEqual(cookie.path, None)

        cookie.max_age = 400
        self.assertEqual(cookie.max_age, 400)
        cookie.max_age = None
        self.assertEqual(cookie.max_age, None)

        cookie.expires = 'Sun, 06 Nov 1994 08:49:37 GMT'
        self.assertEqual(cookie.expires,
                         datetime.datetime(1994, 11, 6, 8, 49, 37))
        cookie.expires = None
        self.assertEqual(cookie.expires, None)

        cookie.secure = True
        self.assertEqual(cookie.secure, True)
        self.assertEqual(str(cookie), "color=blue; Secure")
        cookie.secure = False
        self.assertEqual(cookie.secure, False)
        self.assertEqual(str(cookie), "color=blue")
        cookie.secure = None
        self.assertEqual(cookie.secure, None)
        self.assertEqual(str(cookie), "color=blue")

        cookie.httponly = True
        self.assertEqual(cookie.httponly, True)
        self.assertEqual(str(cookie), "color=blue; HttpOnly")
        cookie.httponly = False
        self.assertEqual(cookie.httponly, False)
        self.assertEqual(str(cookie), "color=blue")
        cookie.httponly = None
        self.assertEqual(cookie.httponly, None)
        self.assertEqual(str(cookie), "color=blue")
Example #3
0
    def test_attributes(self):
        cookie = Cookie('color', 'blue')
        self.assertEqual(cookie.key, 'color')
        self.assertEqual(cookie.value, 'blue')
        self.assertEqual(cookie.domain, None)
        self.assertEqual(cookie.path, None)
        self.assertEqual(cookie.max_age, None)
        self.assertEqual(cookie.expires, None)
        self.assertEqual(cookie.secure, None)
        self.assertEqual(cookie.httponly, None)

        cookie.domain = 'example.com'
        self.assertEqual(cookie.domain, 'example.com')
        cookie.domain = None
        self.assertEqual(cookie.domain, None)

        cookie.path = '/toplevel'
        self.assertEqual(cookie.path, '/toplevel')
        cookie.path = None
        self.assertEqual(cookie.path, None)

        cookie.max_age = 400
        self.assertEqual(cookie.max_age, 400)
        cookie.max_age = None
        self.assertEqual(cookie.max_age, None)

        cookie.expires = 'Sun, 06 Nov 1994 08:49:37 GMT'
        self.assertEqual(cookie.expires, datetime.datetime(1994, 11, 6, 8, 49, 37))
        cookie.expires = None
        self.assertEqual(cookie.expires, None)

        cookie.secure = True
        self.assertEqual(cookie.secure, True)
        self.assertEqual(str(cookie), "color=blue; Secure")
        cookie.secure = False
        self.assertEqual(cookie.secure, False)
        self.assertEqual(str(cookie), "color=blue")
        cookie.secure = None
        self.assertEqual(cookie.secure, None)
        self.assertEqual(str(cookie), "color=blue")

        cookie.httponly = True
        self.assertEqual(cookie.httponly, True)
        self.assertEqual(str(cookie), "color=blue; HttpOnly")
        cookie.httponly = False
        self.assertEqual(cookie.httponly, False)
        self.assertEqual(str(cookie), "color=blue")
        cookie.httponly = None
        self.assertEqual(cookie.httponly, None)
        self.assertEqual(str(cookie), "color=blue")
Example #4
0
    def test_attributes(self):
        cookie = Cookie("color", "blue")
        self.assertEqual(cookie.key, "color")
        self.assertEqual(cookie.value, "blue")
        self.assertEqual(cookie.domain, None)
        self.assertEqual(cookie.path, None)
        self.assertEqual(cookie.max_age, None)
        self.assertEqual(cookie.expires, None)
        self.assertEqual(cookie.secure, None)
        self.assertEqual(cookie.httponly, None)

        cookie.domain = "example.com"
        self.assertEqual(cookie.domain, "example.com")
        cookie.domain = None
        self.assertEqual(cookie.domain, None)

        cookie.path = "/toplevel"
        self.assertEqual(cookie.path, "/toplevel")
        cookie.path = None
        self.assertEqual(cookie.path, None)

        cookie.max_age = 400
        self.assertEqual(cookie.max_age, 400)
        cookie.max_age = None
        self.assertEqual(cookie.max_age, None)

        cookie.expires = "Sun, 06 Nov 1994 08:49:37 GMT"
        self.assertEqual(cookie.expires, datetime.datetime(1994, 11, 6, 8, 49, 37))
        cookie.expires = None
        self.assertEqual(cookie.expires, None)

        cookie.secure = True
        self.assertEqual(cookie.secure, True)
        self.assertEqual(str(cookie), "color=blue; Secure")
        cookie.secure = False
        self.assertEqual(cookie.secure, False)
        self.assertEqual(str(cookie), "color=blue")
        cookie.secure = None
        self.assertEqual(cookie.secure, None)
        self.assertEqual(str(cookie), "color=blue")

        cookie.httponly = True
        self.assertEqual(cookie.httponly, True)
        self.assertEqual(str(cookie), "color=blue; HttpOnly")
        cookie.httponly = False
        self.assertEqual(cookie.httponly, False)
        self.assertEqual(str(cookie), "color=blue")
        cookie.httponly = None
        self.assertEqual(cookie.httponly, None)
        self.assertEqual(str(cookie), "color=blue")