def test_to_string(self): cookie = Cookie('foo', 'bar', 1, '/', 'example.com', True) self.assertEquals( 'foo=bar; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/; domain=example.com; secure; httponly', str(cookie)) cookie = Cookie('foo', '', 1, '/admin/', 'example.com') self.assertEqual( 'foo=deleted; expires=Thu, 01-Jan-1970 00:00:00 GMT; path=/admin/; domain=example.com; httponly', str(cookie)) cookie = Cookie('foo', 'bar', 0, '/', '') self.assertEqual('foo=bar; path=/; httponly', str(cookie))
def test_cookie_is_cleared(self): cookie = Cookie('foo', 'bar', int(round(time.time())) - 20) self.assertTrue(cookie.is_cleared())
def test_is_http_only(self): cookie = Cookie('foo', 'bar', 3600, '/', 'example.com', False, True) self.assertTrue(cookie.is_http_only())
def test_cookie_is_not_cleared(self): cookie = Cookie('foo', 'bar', int(round(time.time())) + 3600 * 24) self.assertFalse(cookie.is_cleared())
def test_is_secure(self): cookie = Cookie('foo', 'bar', 3600, '/', 'example.com', True) self.assertTrue(cookie.is_secure())
def test_get_domain(self): cookie = Cookie('foo', 'bar', 3600, '/', 'example.com') self.assertEqual('example.com', cookie.get_domain())
def test_get_expires_time(self): cookie = Cookie('foo', 'bar', 3600) self.assertEqual(3600, cookie.get_expires_time())
def test_get_path(self): cookie = Cookie('foo', 'bar') self.assertEqual('/', cookie.get_path())
def test_get_value(self): value = 'MyValue' cookie = Cookie('MyCookie', value) self.assertEqual(value, cookie.get_value())