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

Method test_netscape_example_1

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

Source from the content-addressed store, hash-verified

1438 # Tests taken from libwww-perl, with a few modifications and additions.
1439
1440 def test_netscape_example_1(self):
1441 #-------------------------------------------------------------------
1442 # First we check that it works for the original example at
1443 # http://www.netscape.com/newsref/std/cookie_spec.html
1444
1445 # Client requests a document, and receives in the response:
1446 #
1447 # Set-Cookie: CUSTOMER=WILE_E_COYOTE; path=/; expires=Wednesday, 09-Nov-99 23:12:40 GMT
1448 #
1449 # When client requests a URL in path "/" on this server, it sends:
1450 #
1451 # Cookie: CUSTOMER=WILE_E_COYOTE
1452 #
1453 # Client requests a document, and receives in the response:
1454 #
1455 # Set-Cookie: PART_NUMBER=ROCKET_LAUNCHER_0001; path=/
1456 #
1457 # When client requests a URL in path "/" on this server, it sends:
1458 #
1459 # Cookie: CUSTOMER=WILE_E_COYOTE; PART_NUMBER=ROCKET_LAUNCHER_0001
1460 #
1461 # Client receives:
1462 #
1463 # Set-Cookie: SHIPPING=FEDEX; path=/fo
1464 #
1465 # When client requests a URL in path "/" on this server, it sends:
1466 #
1467 # Cookie: CUSTOMER=WILE_E_COYOTE; PART_NUMBER=ROCKET_LAUNCHER_0001
1468 #
1469 # When client requests a URL in path "/foo" on this server, it sends:
1470 #
1471 # Cookie: CUSTOMER=WILE_E_COYOTE; PART_NUMBER=ROCKET_LAUNCHER_0001; SHIPPING=FEDEX
1472 #
1473 # The last Cookie is buggy, because both specifications say that the
1474 # most specific cookie must be sent first. SHIPPING=FEDEX is the
1475 # most specific and should thus be first.
1476
1477 year_plus_one = time.localtime()[0] + 1
1478
1479 headers = []
1480
1481 c = CookieJar(DefaultCookiePolicy(rfc2965 = True))
1482
1483 #req = urllib.request.Request("http://1.1.1.1/",
1484 # headers={"Host": "www.acme.com:80"})
1485 req = urllib.request.Request("http://www.acme.com:80/",
1486 headers={"Host": "www.acme.com:80"})
1487
1488 headers.append(
1489 "Set-Cookie: CUSTOMER=WILE_E_COYOTE; path=/ ; "
1490 "expires=Wednesday, 09-Nov-%d 23:12:40 GMT" % year_plus_one)
1491 res = FakeResponse(headers, "http://www.acme.com/")
1492 c.extract_cookies(res, req)
1493
1494 req = urllib.request.Request("http://www.acme.com/")
1495 c.add_cookie_header(req)
1496
1497 self.assertEqual(req.get_header("Cookie"), "CUSTOMER=WILE_E_COYOTE")

Callers

nothing calls this directly

Calls 11

extract_cookiesMethod · 0.95
add_cookie_headerMethod · 0.95
get_headerMethod · 0.95
CookieJarClass · 0.90
DefaultCookiePolicyClass · 0.90
FakeResponseClass · 0.85
assertInMethod · 0.80
assertNotInMethod · 0.80
assertStartsWithMethod · 0.80
appendMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected