(self)
| 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): |
nothing calls this directly
no test coverage detected