MCPcopy Index your code
hub / github.com/python/cpython / test_expires

Method test_expires

Lib/test/test_http_cookiejar.py:664–719  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

662 self.assertIn('version', cookies)
663
664 def test_expires(self):
665 # if expires is in future, keep cookie...
666 c = CookieJar()
667 future = time2netscape(time.time()+3600)
668
669 with warnings_helper.check_no_warnings(self):
670 headers = [f"Set-Cookie: FOO=BAR; path=/; expires={future}"]
671 req = urllib.request.Request("http://www.coyote.com/")
672 res = FakeResponse(headers, "http://www.coyote.com/")
673 cookies = c.make_cookies(res, req)
674 self.assertEqual(len(cookies), 1)
675 self.assertEqual(time2netscape(cookies[0].expires), future)
676
677 interact_netscape(c, "http://www.acme.com/", 'spam="bar"; expires=%s' %
678 future)
679 self.assertEqual(len(c), 1)
680 now = time2netscape(time.time()-1)
681 # ... and if in past or present, discard it
682 interact_netscape(c, "http://www.acme.com/", 'foo="eggs"; expires=%s' %
683 now)
684 h = interact_netscape(c, "http://www.acme.com/")
685 self.assertEqual(len(c), 1)
686 self.assertIn('spam="bar"', h)
687 self.assertNotIn("foo", h)
688
689 # max-age takes precedence over expires, and zero max-age is request to
690 # delete both new cookie and any old matching cookie
691 interact_netscape(c, "http://www.acme.com/", 'eggs="bar"; expires=%s' %
692 future)
693 interact_netscape(c, "http://www.acme.com/", 'bar="bar"; expires=%s' %
694 future)
695 self.assertEqual(len(c), 3)
696 interact_netscape(c, "http://www.acme.com/", 'eggs="bar"; '
697 'expires=%s; max-age=0' % future)
698 interact_netscape(c, "http://www.acme.com/", 'bar="bar"; '
699 'max-age=0; expires=%s' % future)
700 h = interact_netscape(c, "http://www.acme.com/")
701 self.assertEqual(len(c), 1)
702
703 # test expiry at end of session for cookies with no expires attribute
704 interact_netscape(c, "http://www.rhubarb.net/", 'whum="fizz"')
705 self.assertEqual(len(c), 2)
706 c.clear_session_cookies()
707 self.assertEqual(len(c), 1)
708 self.assertIn('spam="bar"', h)
709
710 # test if fractional expiry is accepted
711 cookie = Cookie(0, "name", "value",
712 None, False, "www.python.org",
713 True, False, "/",
714 False, False, "1444312383.018307",
715 False, None, None,
716 {})
717 self.assertEqual(cookie.expires, 1444312383)
718
719 # XXX RFC 2965 expiry rules (some apply to V0 too)
720
721 def test_default_path(self):

Callers

nothing calls this directly

Calls 11

make_cookiesMethod · 0.95
clear_session_cookiesMethod · 0.95
CookieJarClass · 0.90
time2netscapeFunction · 0.90
CookieClass · 0.90
FakeResponseClass · 0.85
interact_netscapeFunction · 0.85
assertInMethod · 0.80
assertNotInMethod · 0.80
timeMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected