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

Method test_netscape_example_2

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

Source from the content-addressed store, hash-verified

1529 self.assertStartsWith(h, "SHIPPING=FEDEX;")
1530
1531 def test_netscape_example_2(self):
1532 # Second Example transaction sequence:
1533 #
1534 # Assume all mappings from above have been cleared.
1535 #
1536 # Client receives:
1537 #
1538 # Set-Cookie: PART_NUMBER=ROCKET_LAUNCHER_0001; path=/
1539 #
1540 # When client requests a URL in path "/" on this server, it sends:
1541 #
1542 # Cookie: PART_NUMBER=ROCKET_LAUNCHER_0001
1543 #
1544 # Client receives:
1545 #
1546 # Set-Cookie: PART_NUMBER=RIDING_ROCKET_0023; path=/ammo
1547 #
1548 # When client requests a URL in path "/ammo" on this server, it sends:
1549 #
1550 # Cookie: PART_NUMBER=RIDING_ROCKET_0023; PART_NUMBER=ROCKET_LAUNCHER_0001
1551 #
1552 # NOTE: There are two name/value pairs named "PART_NUMBER" due to
1553 # the inheritance of the "/" mapping in addition to the "/ammo" mapping.
1554
1555 c = CookieJar()
1556 headers = []
1557
1558 req = urllib.request.Request("http://www.acme.com/")
1559 headers.append("Set-Cookie: PART_NUMBER=ROCKET_LAUNCHER_0001; path=/")
1560 res = FakeResponse(headers, "http://www.acme.com/")
1561
1562 c.extract_cookies(res, req)
1563
1564 req = urllib.request.Request("http://www.acme.com/")
1565 c.add_cookie_header(req)
1566
1567 self.assertEqual(req.get_header("Cookie"),
1568 "PART_NUMBER=ROCKET_LAUNCHER_0001")
1569
1570 headers.append(
1571 "Set-Cookie: PART_NUMBER=RIDING_ROCKET_0023; path=/ammo")
1572 res = FakeResponse(headers, "http://www.acme.com/")
1573 c.extract_cookies(res, req)
1574
1575 req = urllib.request.Request("http://www.acme.com/ammo")
1576 c.add_cookie_header(req)
1577
1578 self.assertRegex(req.get_header("Cookie"),
1579 r"PART_NUMBER=RIDING_ROCKET_0023;\s*"
1580 "PART_NUMBER=ROCKET_LAUNCHER_0001")
1581
1582 def test_ietf_example_1(self):
1583 #-------------------------------------------------------------------

Callers

nothing calls this directly

Calls 8

extract_cookiesMethod · 0.95
add_cookie_headerMethod · 0.95
get_headerMethod · 0.95
CookieJarClass · 0.90
FakeResponseClass · 0.85
assertRegexMethod · 0.80
appendMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected