Changeset 391 for python/trunk/Lib/test/test_cookielib.py
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Lib/test/test_cookielib.py
r2 r391 2 2 """Tests for cookielib.py.""" 3 3 4 import re, os, time 4 import cookielib 5 import os 6 import re 7 import time 8 5 9 from unittest import TestCase 6 10 7 11 from test import test_support 12 8 13 9 14 class DateTimeTests(TestCase): … … 14 19 base = 1019227000 15 20 day = 24*3600 16 self.assertEqual s(time2isoz(base), "2002-04-19 14:36:40Z")17 self.assertEqual s(time2isoz(base+day), "2002-04-20 14:36:40Z")18 self.assertEqual s(time2isoz(base+2*day), "2002-04-21 14:36:40Z")19 self.assertEqual s(time2isoz(base+3*day), "2002-04-22 14:36:40Z")21 self.assertEqual(time2isoz(base), "2002-04-19 14:36:40Z") 22 self.assertEqual(time2isoz(base+day), "2002-04-20 14:36:40Z") 23 self.assertEqual(time2isoz(base+2*day), "2002-04-21 14:36:40Z") 24 self.assertEqual(time2isoz(base+3*day), "2002-04-22 14:36:40Z") 20 25 21 26 az = time2isoz() 22 27 bz = time2isoz(500000) 23 28 for text in (az, bz): 24 self.assert _(re.search(r"^\d{4}-\d\d-\d\d \d\d:\d\d:\d\dZ$", text),29 self.assertTrue(re.search(r"^\d{4}-\d\d-\d\d \d\d:\d\d:\d\dZ$", text), 25 30 "bad time2isoz format: %s %s" % (az, bz)) 26 31 … … 31 36 return time.gmtime(http2time(text))[:6] 32 37 33 self.assertEqual s(parse_date("01 Jan 2001"), (2001, 1, 1, 0, 0, 0.0))38 self.assertEqual(parse_date("01 Jan 2001"), (2001, 1, 1, 0, 0, 0.0)) 34 39 35 40 # this test will break around year 2070 36 self.assertEqual s(parse_date("03-Feb-20"), (2020, 2, 3, 0, 0, 0.0))41 self.assertEqual(parse_date("03-Feb-20"), (2020, 2, 3, 0, 0, 0.0)) 37 42 38 43 # this test will break around year 2048 39 self.assertEqual s(parse_date("03-Feb-98"), (1998, 2, 3, 0, 0, 0.0))44 self.assertEqual(parse_date("03-Feb-98"), (1998, 2, 3, 0, 0, 0.0)) 40 45 41 46 def test_http2time_formats(self): … … 67 72 result = time2isoz(test_t) 68 73 expected = "1994-02-03 00:00:00Z" 69 self.assertEqual s(result, expected,70 74 self.assertEqual(result, expected, 75 "%s => '%s' (%s)" % (test_t, result, expected)) 71 76 72 77 for s in tests: … … 75 80 t3 = http2time(s.upper()) 76 81 77 self.assert _(t == t2 == t3 == test_t,82 self.assertTrue(t == t2 == t3 == test_t, 78 83 "'%s' => %s, %s, %s (%s)" % (s, t, t2, t3, test_t)) 79 84 … … 93 98 '01-01-1980 00:00:62', 94 99 ]: 95 self.assert _(http2time(test) is None,100 self.assertTrue(http2time(test) is None, 96 101 "http2time(%s) is not None\n" 97 102 "http2time(test) %s" % (test, http2time(test)) … … 100 105 101 106 class HeaderTests(TestCase): 102 def test_parse_ns_headers(self): 107 108 def test_parse_ns_headers_expires(self): 103 109 from cookielib import parse_ns_headers 104 110 … … 109 115 'foo=bar; expires="01 Jan 2040 22:23:32 GMT"', 110 116 ]: 111 self.assertEquals(parse_ns_headers([hdr]), expected) 117 self.assertEqual(parse_ns_headers([hdr]), expected) 118 119 def test_parse_ns_headers_version(self): 120 from cookielib import parse_ns_headers 121 122 # quotes should be stripped 123 expected = [[('foo', 'bar'), ('version', '1')]] 124 for hdr in [ 125 'foo=bar; version="1"', 126 'foo=bar; Version="1"', 127 ]: 128 self.assertEqual(parse_ns_headers([hdr]), expected) 112 129 113 130 def test_parse_ns_headers_special_names(self): … … 119 136 hdr = 'expires=01 Jan 2040 22:23:32 GMT' 120 137 expected = [[("expires", "01 Jan 2040 22:23:32 GMT"), ("version", "0")]] 121 self.assertEqual s(parse_ns_headers([hdr]), expected)138 self.assertEqual(parse_ns_headers([hdr]), expected) 122 139 123 140 def test_join_header_words(self): … … 125 142 126 143 joined = join_header_words([[("foo", None), ("bar", "baz")]]) 127 self.assertEqual s(joined, "foo; bar=baz")128 129 self.assertEqual s(join_header_words([[]]), "")144 self.assertEqual(joined, "foo; bar=baz") 145 146 self.assertEqual(join_header_words([[]]), "") 130 147 131 148 def test_split_header_words(self): … … 159 176 traceback.print_exc(None, f) 160 177 result = "(error -- traceback follows)\n\n%s" % f.getvalue() 161 self.assertEqual s(result, expect, """178 self.assertEqual(result, expect, """ 162 179 When parsing: '%s' 163 180 Expected: '%s' … … 193 210 input = split_header_words([arg]) 194 211 res = join_header_words(input) 195 self.assertEqual s(res, expect, """212 self.assertEqual(res, expect, """ 196 213 When parsing: '%s' 197 214 Expected: '%s' … … 313 330 ## means that if you fold multiple Set-Cookie header fields into one, 314 331 ## comma-separated list, it'll be a headache to parse (at least my head 315 ## starts hurting every time I think of that code).332 ## starts hurting every time I think of that code). 316 333 ## - Expires: You'll get all sorts of date formats in the expires, 317 334 ## including emtpy expires attributes ("expires="). Be as flexible as you … … 350 367 request = urllib2.Request(url) 351 368 r = pol.domain_return_ok(domain, request) 352 if ok: self.assert _(r)353 else: self.assert _(not r)369 if ok: self.assertTrue(r) 370 else: self.assertTrue(not r) 354 371 355 372 def test_missing_value(self): … … 363 380 interact_netscape(c, "http://www.acme.com/", '"spam"; path=/foo/') 364 381 cookie = c._cookies["www.acme.com"]["/"]["eggs"] 365 self.assert _(cookie.value is None)366 self.assertEqual s(cookie.name, "eggs")382 self.assertTrue(cookie.value is None) 383 self.assertEqual(cookie.name, "eggs") 367 384 cookie = c._cookies["www.acme.com"]['/foo/']['"spam"'] 368 self.assert _(cookie.value is None)369 self.assertEqual s(cookie.name, '"spam"')370 self.assertEqual s(lwp_cookie_str(cookie), (385 self.assertTrue(cookie.value is None) 386 self.assertEqual(cookie.name, '"spam"') 387 self.assertEqual(lwp_cookie_str(cookie), ( 371 388 r'"spam"; path="/foo/"; domain="www.acme.com"; ' 372 389 'path_spec; discard; version=0')) … … 379 396 os.unlink(c.filename) 380 397 # cookies unchanged apart from lost info re. whether path was specified 381 self.assertEqual s(398 self.assertEqual( 382 399 repr(c), 383 400 re.sub("path_specified=%s" % True, "path_specified=%s" % False, 384 401 old_str) 385 402 ) 386 self.assertEqual s(interact_netscape(c, "http://www.acme.com/foo/"),387 403 self.assertEqual(interact_netscape(c, "http://www.acme.com/foo/"), 404 '"spam"; eggs') 388 405 389 406 def test_rfc2109_handling(self): … … 410 427 cookie = c._cookies["www.example.com"]["/"]["ni"] 411 428 except KeyError: 412 self.assert _(version is None) # didn't expect a stored cookie429 self.assertTrue(version is None) # didn't expect a stored cookie 413 430 else: 414 431 self.assertEqual(cookie.version, version) … … 433 450 434 451 cookie = c._cookies[".acme.com"]["/"]["spam"] 435 self.assertEqual s(cookie.domain, ".acme.com")436 self.assert _(cookie.domain_specified)437 self.assertEqual s(cookie.port, DEFAULT_HTTP_PORT)438 self.assert _(not cookie.port_specified)452 self.assertEqual(cookie.domain, ".acme.com") 453 self.assertTrue(cookie.domain_specified) 454 self.assertEqual(cookie.port, DEFAULT_HTTP_PORT) 455 self.assertTrue(not cookie.port_specified) 439 456 # case is preserved 440 self.assert _(cookie.has_nonstandard_attr("blArgh") and457 self.assertTrue(cookie.has_nonstandard_attr("blArgh") and 441 458 not cookie.has_nonstandard_attr("blargh")) 442 459 443 460 cookie = c._cookies["www.acme.com"]["/"]["ni"] 444 self.assertEqual s(cookie.domain, "www.acme.com")445 self.assert _(not cookie.domain_specified)446 self.assertEqual s(cookie.port, "80,8080")447 self.assert _(cookie.port_specified)461 self.assertEqual(cookie.domain, "www.acme.com") 462 self.assertTrue(not cookie.domain_specified) 463 self.assertEqual(cookie.port, "80,8080") 464 self.assertTrue(cookie.port_specified) 448 465 449 466 cookie = c._cookies["www.acme.com"]["/"]["nini"] 450 self.assert _(cookie.port is None)451 self.assert _(not cookie.port_specified)467 self.assertTrue(cookie.port is None) 468 self.assertTrue(not cookie.port_specified) 452 469 453 470 # invalid expires should not cause cookie to be dropped 454 471 foo = c._cookies["www.acme.com"]["/"]["foo"] 455 472 spam = c._cookies["www.acme.com"]["/"]["foo"] 456 self.assert _(foo.expires is None)457 self.assert _(spam.expires is None)473 self.assertTrue(foo.expires is None) 474 self.assertTrue(spam.expires is None) 458 475 459 476 def test_ns_parser_special_names(self): … … 467 484 468 485 cookies = c._cookies["www.acme.com"]["/"] 469 self.assert _('expires' in cookies)470 self.assert _('version' in cookies)486 self.assertTrue('expires' in cookies) 487 self.assertTrue('version' in cookies) 471 488 472 489 def test_expires(self): … … 478 495 interact_netscape(c, "http://www.acme.com/", 'spam="bar"; expires=%s' % 479 496 future) 480 self.assertEqual s(len(c), 1)497 self.assertEqual(len(c), 1) 481 498 now = time2netscape(time.time()-1) 482 499 # ... and if in past or present, discard it … … 484 501 now) 485 502 h = interact_netscape(c, "http://www.acme.com/") 486 self.assertEqual s(len(c), 1)487 self.assert _('spam="bar"' in h and "foo" not in h)503 self.assertEqual(len(c), 1) 504 self.assertTrue('spam="bar"' in h and "foo" not in h) 488 505 489 506 # max-age takes precedence over expires, and zero max-age is request to … … 493 510 interact_netscape(c, "http://www.acme.com/", 'bar="bar"; expires=%s' % 494 511 future) 495 self.assertEqual s(len(c), 3)512 self.assertEqual(len(c), 3) 496 513 interact_netscape(c, "http://www.acme.com/", 'eggs="bar"; ' 497 514 'expires=%s; max-age=0' % future) … … 499 516 'max-age=0; expires=%s' % future) 500 517 h = interact_netscape(c, "http://www.acme.com/") 501 self.assertEqual s(len(c), 1)518 self.assertEqual(len(c), 1) 502 519 503 520 # test expiry at end of session for cookies with no expires attribute 504 521 interact_netscape(c, "http://www.rhubarb.net/", 'whum="fizz"') 505 self.assertEqual s(len(c), 2)522 self.assertEqual(len(c), 2) 506 523 c.clear_session_cookies() 507 self.assertEqual s(len(c), 1)508 self.assert _('spam="bar"' inh)524 self.assertEqual(len(c), 1) 525 self.assertIn('spam="bar"', h) 509 526 510 527 # XXX RFC 2965 expiry rules (some apply to V0 too) … … 518 535 c = CookieJar(pol) 519 536 interact_2965(c, "http://www.acme.com/", 'spam="bar"; Version="1"') 520 self.assert _("/" inc._cookies["www.acme.com"])537 self.assertIn("/", c._cookies["www.acme.com"]) 521 538 522 539 c = CookieJar(pol) 523 540 interact_2965(c, "http://www.acme.com/blah", 'eggs="bar"; Version="1"') 524 self.assert _("/" inc._cookies["www.acme.com"])541 self.assertIn("/", c._cookies["www.acme.com"]) 525 542 526 543 c = CookieJar(pol) 527 544 interact_2965(c, "http://www.acme.com/blah/rhubarb", 528 545 'eggs="bar"; Version="1"') 529 self.assert _("/blah/" inc._cookies["www.acme.com"])546 self.assertIn("/blah/", c._cookies["www.acme.com"]) 530 547 531 548 c = CookieJar(pol) 532 549 interact_2965(c, "http://www.acme.com/blah/rhubarb/", 533 550 'eggs="bar"; Version="1"') 534 self.assert _("/blah/rhubarb/" inc._cookies["www.acme.com"])551 self.assertIn("/blah/rhubarb/", c._cookies["www.acme.com"]) 535 552 536 553 # Netscape … … 538 555 c = CookieJar() 539 556 interact_netscape(c, "http://www.acme.com/", 'spam="bar"') 540 self.assert _("/" inc._cookies["www.acme.com"])557 self.assertIn("/", c._cookies["www.acme.com"]) 541 558 542 559 c = CookieJar() 543 560 interact_netscape(c, "http://www.acme.com/blah", 'eggs="bar"') 544 self.assert _("/" inc._cookies["www.acme.com"])561 self.assertIn("/", c._cookies["www.acme.com"]) 545 562 546 563 c = CookieJar() 547 564 interact_netscape(c, "http://www.acme.com/blah/rhubarb", 'eggs="bar"') 548 self.assert _("/blah" inc._cookies["www.acme.com"])565 self.assertIn("/blah", c._cookies["www.acme.com"]) 549 566 550 567 c = CookieJar() 551 568 interact_netscape(c, "http://www.acme.com/blah/rhubarb/", 'eggs="bar"') 552 self.assert_("/blah/rhubarb" in c._cookies["www.acme.com"]) 569 self.assertIn("/blah/rhubarb", c._cookies["www.acme.com"]) 570 571 def test_default_path_with_query(self): 572 cj = cookielib.CookieJar() 573 uri = "http://example.com/?spam/eggs" 574 value = 'eggs="bar"' 575 interact_netscape(cj, uri, value) 576 # default path does not include query, so is "/", not "/?spam" 577 self.assertIn("/", cj._cookies["example.com"]) 578 # cookie is sent back to the same URI 579 self.assertEqual(interact_netscape(cj, uri), value) 553 580 554 581 def test_escape_path(self): … … 574 601 ] 575 602 for arg, result in cases: 576 self.assertEqual s(escape_path(arg), result)603 self.assertEqual(escape_path(arg), result) 577 604 578 605 def test_request_path(self): … … 580 607 from cookielib import request_path 581 608 # with parameters 582 req = Request("http://www.example.com/rheum/rhapon icum;"609 req = Request("http://www.example.com/rheum/rhaponticum;" 583 610 "foo=bar;sing=song?apples=pears&spam=eggs#ni") 584 self.assertEqual s(request_path(req), "/rheum/rhaponicum;"585 "foo=bar;sing=song?apples=pears&spam=eggs#ni")611 self.assertEqual(request_path(req), 612 "/rheum/rhaponticum;foo=bar;sing=song") 586 613 # without parameters 587 req = Request("http://www.example.com/rheum/rhapon icum?"614 req = Request("http://www.example.com/rheum/rhaponticum?" 588 615 "apples=pears&spam=eggs#ni") 589 self.assertEquals(request_path(req), "/rheum/rhaponicum?" 590 "apples=pears&spam=eggs#ni") 616 self.assertEqual(request_path(req), "/rheum/rhaponticum") 591 617 # missing final slash 592 618 req = Request("http://www.example.com") 593 self.assertEqual s(request_path(req), "/")619 self.assertEqual(request_path(req), "/") 594 620 595 621 def test_request_port(self): … … 598 624 req = Request("http://www.acme.com:1234/", 599 625 headers={"Host": "www.acme.com:4321"}) 600 self.assertEqual s(request_port(req), "1234")626 self.assertEqual(request_port(req), "1234") 601 627 req = Request("http://www.acme.com/", 602 628 headers={"Host": "www.acme.com:4321"}) 603 self.assertEqual s(request_port(req), DEFAULT_HTTP_PORT)629 self.assertEqual(request_port(req), DEFAULT_HTTP_PORT) 604 630 605 631 def test_request_host(self): … … 611 637 # libwww-perl wants this response, but that seems wrong (RFC 2616, 612 638 # section 5.2, point 1., and RFC 2965 section 1, paragraph 3) 613 #self.assertEqual s(request_host(req), "www.acme.com")614 self.assertEqual s(request_host(req), "1.1.1.1")639 #self.assertEqual(request_host(req), "www.acme.com") 640 self.assertEqual(request_host(req), "1.1.1.1") 615 641 req = Request("http://www.acme.com/", 616 642 headers={"Host": "irrelevant.com"}) 617 self.assertEqual s(request_host(req), "www.acme.com")643 self.assertEqual(request_host(req), "www.acme.com") 618 644 # not actually sure this one is valid Request object, so maybe should 619 645 # remove test for no host in url in request_host function? 620 646 req = Request("/resource.html", 621 647 headers={"Host": "www.acme.com"}) 622 self.assertEqual s(request_host(req), "www.acme.com")648 self.assertEqual(request_host(req), "www.acme.com") 623 649 # port shouldn't be in request-host 624 650 req = Request("http://www.acme.com:2345/resource.html", 625 651 headers={"Host": "www.acme.com:5432"}) 626 self.assertEqual s(request_host(req), "www.acme.com")652 self.assertEqual(request_host(req), "www.acme.com") 627 653 628 654 def test_is_HDN(self): 629 655 from cookielib import is_HDN 630 self.assert _(is_HDN("foo.bar.com"))631 self.assert _(is_HDN("1foo2.3bar4.5com"))632 self.assert _(not is_HDN("192.168.1.1"))633 self.assert _(not is_HDN(""))634 self.assert _(not is_HDN("."))635 self.assert _(not is_HDN(".foo.bar.com"))636 self.assert _(not is_HDN("..foo"))637 self.assert _(not is_HDN("foo."))656 self.assertTrue(is_HDN("foo.bar.com")) 657 self.assertTrue(is_HDN("1foo2.3bar4.5com")) 658 self.assertTrue(not is_HDN("192.168.1.1")) 659 self.assertTrue(not is_HDN("")) 660 self.assertTrue(not is_HDN(".")) 661 self.assertTrue(not is_HDN(".foo.bar.com")) 662 self.assertTrue(not is_HDN("..foo")) 663 self.assertTrue(not is_HDN("foo.")) 638 664 639 665 def test_reach(self): 640 666 from cookielib import reach 641 self.assertEqual s(reach("www.acme.com"), ".acme.com")642 self.assertEqual s(reach("acme.com"), "acme.com")643 self.assertEqual s(reach("acme.local"), ".local")644 self.assertEqual s(reach(".local"), ".local")645 self.assertEqual s(reach(".com"), ".com")646 self.assertEqual s(reach("."), ".")647 self.assertEqual s(reach(""), "")648 self.assertEqual s(reach("192.168.0.1"), "192.168.0.1")667 self.assertEqual(reach("www.acme.com"), ".acme.com") 668 self.assertEqual(reach("acme.com"), "acme.com") 669 self.assertEqual(reach("acme.local"), ".local") 670 self.assertEqual(reach(".local"), ".local") 671 self.assertEqual(reach(".com"), ".com") 672 self.assertEqual(reach("."), ".") 673 self.assertEqual(reach(""), "") 674 self.assertEqual(reach("192.168.0.1"), "192.168.0.1") 649 675 650 676 def test_domain_match(self): 651 677 from cookielib import domain_match, user_domain_match 652 self.assert _(domain_match("192.168.1.1", "192.168.1.1"))653 self.assert _(not domain_match("192.168.1.1", ".168.1.1"))654 self.assert _(domain_match("x.y.com", "x.Y.com"))655 self.assert _(domain_match("x.y.com", ".Y.com"))656 self.assert _(not domain_match("x.y.com", "Y.com"))657 self.assert _(domain_match("a.b.c.com", ".c.com"))658 self.assert _(not domain_match(".c.com", "a.b.c.com"))659 self.assert _(domain_match("example.local", ".local"))660 self.assert _(not domain_match("blah.blah", ""))661 self.assert _(not domain_match("", ".rhubarb.rhubarb"))662 self.assert _(domain_match("", ""))663 664 self.assert _(user_domain_match("acme.com", "acme.com"))665 self.assert _(not user_domain_match("acme.com", ".acme.com"))666 self.assert _(user_domain_match("rhubarb.acme.com", ".acme.com"))667 self.assert _(user_domain_match("www.rhubarb.acme.com", ".acme.com"))668 self.assert _(user_domain_match("x.y.com", "x.Y.com"))669 self.assert _(user_domain_match("x.y.com", ".Y.com"))670 self.assert _(not user_domain_match("x.y.com", "Y.com"))671 self.assert _(user_domain_match("y.com", "Y.com"))672 self.assert _(not user_domain_match(".y.com", "Y.com"))673 self.assert _(user_domain_match(".y.com", ".Y.com"))674 self.assert _(user_domain_match("x.y.com", ".com"))675 self.assert _(not user_domain_match("x.y.com", "com"))676 self.assert _(not user_domain_match("x.y.com", "m"))677 self.assert _(not user_domain_match("x.y.com", ".m"))678 self.assert _(not user_domain_match("x.y.com", ""))679 self.assert _(not user_domain_match("x.y.com", "."))680 self.assert _(user_domain_match("192.168.1.1", "192.168.1.1"))678 self.assertTrue(domain_match("192.168.1.1", "192.168.1.1")) 679 self.assertTrue(not domain_match("192.168.1.1", ".168.1.1")) 680 self.assertTrue(domain_match("x.y.com", "x.Y.com")) 681 self.assertTrue(domain_match("x.y.com", ".Y.com")) 682 self.assertTrue(not domain_match("x.y.com", "Y.com")) 683 self.assertTrue(domain_match("a.b.c.com", ".c.com")) 684 self.assertTrue(not domain_match(".c.com", "a.b.c.com")) 685 self.assertTrue(domain_match("example.local", ".local")) 686 self.assertTrue(not domain_match("blah.blah", "")) 687 self.assertTrue(not domain_match("", ".rhubarb.rhubarb")) 688 self.assertTrue(domain_match("", "")) 689 690 self.assertTrue(user_domain_match("acme.com", "acme.com")) 691 self.assertTrue(not user_domain_match("acme.com", ".acme.com")) 692 self.assertTrue(user_domain_match("rhubarb.acme.com", ".acme.com")) 693 self.assertTrue(user_domain_match("www.rhubarb.acme.com", ".acme.com")) 694 self.assertTrue(user_domain_match("x.y.com", "x.Y.com")) 695 self.assertTrue(user_domain_match("x.y.com", ".Y.com")) 696 self.assertTrue(not user_domain_match("x.y.com", "Y.com")) 697 self.assertTrue(user_domain_match("y.com", "Y.com")) 698 self.assertTrue(not user_domain_match(".y.com", "Y.com")) 699 self.assertTrue(user_domain_match(".y.com", ".Y.com")) 700 self.assertTrue(user_domain_match("x.y.com", ".com")) 701 self.assertTrue(not user_domain_match("x.y.com", "com")) 702 self.assertTrue(not user_domain_match("x.y.com", "m")) 703 self.assertTrue(not user_domain_match("x.y.com", ".m")) 704 self.assertTrue(not user_domain_match("x.y.com", "")) 705 self.assertTrue(not user_domain_match("x.y.com", ".")) 706 self.assertTrue(user_domain_match("192.168.1.1", "192.168.1.1")) 681 707 # not both HDNs, so must string-compare equal to match 682 self.assert _(not user_domain_match("192.168.1.1", ".168.1.1"))683 self.assert _(not user_domain_match("192.168.1.1", "."))708 self.assertTrue(not user_domain_match("192.168.1.1", ".168.1.1")) 709 self.assertTrue(not user_domain_match("192.168.1.1", ".")) 684 710 # empty string is a special case 685 self.assert _(not user_domain_match("192.168.1.1", ""))711 self.assertTrue(not user_domain_match("192.168.1.1", "")) 686 712 687 713 def test_wrong_domain(self): … … 694 720 interact_2965(c, "http://www.nasty.com/", 695 721 'foo=bar; domain=friendly.org; Version="1"') 696 self.assertEqual s(len(c), 0)722 self.assertEqual(len(c), 0) 697 723 698 724 def test_strict_domain(self): … … 706 732 interact_netscape(cj, "http://example.co.uk/", 707 733 'okey=dokey; Domain=.example.co.uk') 708 self.assertEqual s(len(cj), 2)734 self.assertEqual(len(cj), 2) 709 735 for pseudo_tld in [".co.uk", ".org.za", ".tx.us", ".name.us"]: 710 736 interact_netscape(cj, "http://example.%s/" % pseudo_tld, 711 737 'spam=eggs; Domain=.co.uk') 712 self.assertEqual s(len(cj), 2)738 self.assertEqual(len(cj), 2) 713 739 714 740 def test_two_component_domain_ns(self): … … 722 748 # two-component V0 domain is OK 723 749 interact_netscape(c, "http://foo.net/", 'ns=bar') 724 self.assertEqual s(len(c), 1)725 self.assertEqual s(c._cookies["foo.net"]["/"]["ns"].value, "bar")726 self.assertEqual s(interact_netscape(c, "http://foo.net/"), "ns=bar")750 self.assertEqual(len(c), 1) 751 self.assertEqual(c._cookies["foo.net"]["/"]["ns"].value, "bar") 752 self.assertEqual(interact_netscape(c, "http://foo.net/"), "ns=bar") 727 753 # *will* be returned to any other domain (unlike RFC 2965)... 728 self.assertEqual s(interact_netscape(c, "http://www.foo.net/"),729 754 self.assertEqual(interact_netscape(c, "http://www.foo.net/"), 755 "ns=bar") 730 756 # ...unless requested otherwise 731 757 pol = DefaultCookiePolicy( 732 758 strict_ns_domain=DefaultCookiePolicy.DomainStrictNonDomain) 733 759 c.set_policy(pol) 734 self.assertEqual s(interact_netscape(c, "http://www.foo.net/"), "")760 self.assertEqual(interact_netscape(c, "http://www.foo.net/"), "") 735 761 736 762 # unlike RFC 2965, even explicit two-component domain is OK, … … 741 767 interact_netscape(c, "http://foo.net/foo/bar/", 742 768 'spam2=eggs; domain=.foo.net') 743 self.assertEqual s(len(c), 3)744 self.assertEqual s(c._cookies[".foo.net"]["/foo"]["spam1"].value,745 746 self.assertEqual s(c._cookies[".foo.net"]["/foo/bar"]["spam2"].value,747 748 self.assertEqual s(interact_netscape(c, "http://foo.net/foo/bar/"),749 769 self.assertEqual(len(c), 3) 770 self.assertEqual(c._cookies[".foo.net"]["/foo"]["spam1"].value, 771 "eggs") 772 self.assertEqual(c._cookies[".foo.net"]["/foo/bar"]["spam2"].value, 773 "eggs") 774 self.assertEqual(interact_netscape(c, "http://foo.net/foo/bar/"), 775 "spam2=eggs; spam1=eggs; ns=bar") 750 776 751 777 # top-level domain is too general 752 778 interact_netscape(c, "http://foo.net/", 'nini="ni"; domain=.net') 753 self.assertEqual s(len(c), 3)779 self.assertEqual(len(c), 3) 754 780 755 781 ## # Netscape protocol doesn't allow non-special top level domains (such … … 759 785 # cookies (of course) rely on that behaviour. 760 786 interact_netscape(c, "http://foo.co.uk", 'nasty=trick; domain=.co.uk') 761 ## self.assertEqual s(len(c), 2)762 self.assertEqual s(len(c), 4)787 ## self.assertEqual(len(c), 2) 788 self.assertEqual(len(c), 4) 763 789 764 790 def test_two_component_domain_rfc2965(self): … … 770 796 # two-component V1 domain is OK 771 797 interact_2965(c, "http://foo.net/", 'foo=bar; Version="1"') 772 self.assertEqual s(len(c), 1)773 self.assertEqual s(c._cookies["foo.net"]["/"]["foo"].value, "bar")774 self.assertEqual s(interact_2965(c, "http://foo.net/"),775 798 self.assertEqual(len(c), 1) 799 self.assertEqual(c._cookies["foo.net"]["/"]["foo"].value, "bar") 800 self.assertEqual(interact_2965(c, "http://foo.net/"), 801 "$Version=1; foo=bar") 776 802 # won't be returned to any other domain (because domain was implied) 777 self.assertEqual s(interact_2965(c, "http://www.foo.net/"), "")803 self.assertEqual(interact_2965(c, "http://www.foo.net/"), "") 778 804 779 805 # unless domain is given explicitly, because then it must be … … 782 808 interact_2965(c, "http://foo.net/foo", 783 809 'spam=eggs; domain=foo.net; path=/foo; Version="1"') 784 self.assertEqual s(len(c), 1)785 self.assertEqual s(interact_2965(c, "http://foo.net/foo"),786 810 self.assertEqual(len(c), 1) 811 self.assertEqual(interact_2965(c, "http://foo.net/foo"), 812 "$Version=1; foo=bar") 787 813 788 814 # explicit foo.net from three-component domain www.foo.net *does* get … … 790 816 interact_2965(c, "http://www.foo.net/foo/", 791 817 'spam=eggs; domain=foo.net; Version="1"') 792 self.assertEqual s(c._cookies[".foo.net"]["/foo/"]["spam"].value,793 794 self.assertEqual s(len(c), 2)795 self.assertEqual s(interact_2965(c, "http://foo.net/foo/"),796 797 self.assertEqual s(interact_2965(c, "http://www.foo.net/foo/"),798 818 self.assertEqual(c._cookies[".foo.net"]["/foo/"]["spam"].value, 819 "eggs") 820 self.assertEqual(len(c), 2) 821 self.assertEqual(interact_2965(c, "http://foo.net/foo/"), 822 "$Version=1; foo=bar") 823 self.assertEqual(interact_2965(c, "http://www.foo.net/foo/"), 824 '$Version=1; spam=eggs; $Domain="foo.net"') 799 825 800 826 # top-level domain is too general 801 827 interact_2965(c, "http://foo.net/", 802 828 'ni="ni"; domain=".net"; Version="1"') 803 self.assertEqual s(len(c), 2)829 self.assertEqual(len(c), 2) 804 830 805 831 # RFC 2965 doesn't require blocking this 806 832 interact_2965(c, "http://foo.co.uk/", 807 833 'nasty=trick; domain=.co.uk; Version="1"') 808 self.assertEqual s(len(c), 3)834 self.assertEqual(len(c), 3) 809 835 810 836 def test_domain_allow(self): … … 820 846 res = FakeResponse(headers, "http://acme.com/") 821 847 c.extract_cookies(res, req) 822 self.assertEqual s(len(c), 0)848 self.assertEqual(len(c), 0) 823 849 824 850 req = Request("http://www.acme.com/") 825 851 res = FakeResponse(headers, "http://www.acme.com/") 826 852 c.extract_cookies(res, req) 827 self.assertEqual s(len(c), 1)853 self.assertEqual(len(c), 1) 828 854 829 855 req = Request("http://www.coyote.com/") 830 856 res = FakeResponse(headers, "http://www.coyote.com/") 831 857 c.extract_cookies(res, req) 832 self.assertEqual s(len(c), 1)858 self.assertEqual(len(c), 1) 833 859 834 860 # set a cookie with non-allowed domain... … … 837 863 cookies = c.make_cookies(res, req) 838 864 c.set_cookie(cookies[0]) 839 self.assertEqual s(len(c), 2)865 self.assertEqual(len(c), 2) 840 866 # ... and check is doesn't get returned 841 867 c.add_cookie_header(req) 842 self.assert _(not req.has_header("Cookie"))868 self.assertTrue(not req.has_header("Cookie")) 843 869 844 870 def test_domain_block(self): … … 854 880 res = FakeResponse(headers, "http://www.acme.com/") 855 881 c.extract_cookies(res, req) 856 self.assertEqual s(len(c), 0)882 self.assertEqual(len(c), 0) 857 883 858 884 p = pol.set_blocked_domains(["acme.com"]) 859 885 c.extract_cookies(res, req) 860 self.assertEqual s(len(c), 1)886 self.assertEqual(len(c), 1) 861 887 862 888 c.clear() … … 864 890 res = FakeResponse(headers, "http://www.roadrunner.net/") 865 891 c.extract_cookies(res, req) 866 self.assertEqual s(len(c), 1)892 self.assertEqual(len(c), 1) 867 893 req = Request("http://www.roadrunner.net/") 868 894 c.add_cookie_header(req) 869 self.assert _((req.has_header("Cookie") and895 self.assertTrue((req.has_header("Cookie") and 870 896 req.has_header("Cookie2"))) 871 897 … … 873 899 pol.set_blocked_domains([".acme.com"]) 874 900 c.extract_cookies(res, req) 875 self.assertEqual s(len(c), 1)901 self.assertEqual(len(c), 1) 876 902 877 903 # set a cookie with blocked domain... … … 880 906 cookies = c.make_cookies(res, req) 881 907 c.set_cookie(cookies[0]) 882 self.assertEqual s(len(c), 2)908 self.assertEqual(len(c), 2) 883 909 # ... and check is doesn't get returned 884 910 c.add_cookie_header(req) 885 self.assert _(not req.has_header("Cookie"))911 self.assertTrue(not req.has_header("Cookie")) 886 912 887 913 def test_secure(self): … … 903 929 int(c, url, "foo1=bar%s%s" % (vs, whitespace)) 904 930 int(c, url, "foo2=bar%s; secure%s" % (vs, whitespace)) 905 self.assert _(931 self.assertTrue( 906 932 not c._cookies["www.acme.com"]["/"]["foo1"].secure, 907 933 "non-secure cookie registered secure") 908 self.assert _(934 self.assertTrue( 909 935 c._cookies["www.acme.com"]["/"]["foo2"].secure, 910 936 "secure cookie registered non-secure") … … 915 941 interact_2965(c, "http://www.acme.com/", r'foo=\b"a"r; Version=1') 916 942 h = interact_2965(c, "http://www.acme.com/") 917 self.assertEqual s(h, r'$Version=1; foo=\\b\"a\"r')943 self.assertEqual(h, r'$Version=1; foo=\\b\"a\"r') 918 944 919 945 def test_missing_final_slash(self): … … 925 951 interact_2965(c, url, "foo=bar; Version=1") 926 952 req = Request(url) 927 self.assertEqual s(len(c), 1)953 self.assertEqual(len(c), 1) 928 954 c.add_cookie_header(req) 929 self.assert _(req.has_header("Cookie"))955 self.assertTrue(req.has_header("Cookie")) 930 956 931 957 def test_domain_mirror(self): … … 938 964 interact_2965(c, url, "spam=eggs; Version=1") 939 965 h = interact_2965(c, url) 940 self.assert _("Domain" not inh,941 "absent domain returned with domain present")966 self.assertNotIn("Domain", h, 967 "absent domain returned with domain present") 942 968 943 969 c = CookieJar(pol) … … 945 971 interact_2965(c, url, 'spam=eggs; Version=1; Domain=.bar.com') 946 972 h = interact_2965(c, url) 947 self.assert _('$Domain=".bar.com"' inh, "domain not returned")973 self.assertIn('$Domain=".bar.com"', h, "domain not returned") 948 974 949 975 c = CookieJar(pol) … … 952 978 interact_2965(c, url, 'spam=eggs; Version=1; Domain=bar.com') 953 979 h = interact_2965(c, url) 954 self.assert _('$Domain="bar.com"' inh, "domain not returned")980 self.assertIn('$Domain="bar.com"', h, "domain not returned") 955 981 956 982 def test_path_mirror(self): … … 963 989 interact_2965(c, url, "spam=eggs; Version=1") 964 990 h = interact_2965(c, url) 965 self.assert_("Path" not in h, 966 "absent path returned with path present") 991 self.assertNotIn("Path", h, "absent path returned with path present") 967 992 968 993 c = CookieJar(pol) … … 970 995 interact_2965(c, url, 'spam=eggs; Version=1; Path=/') 971 996 h = interact_2965(c, url) 972 self.assert _('$Path="/"' inh, "path not returned")997 self.assertIn('$Path="/"', h, "path not returned") 973 998 974 999 def test_port_mirror(self): … … 981 1006 interact_2965(c, url, "spam=eggs; Version=1") 982 1007 h = interact_2965(c, url) 983 self.assert_("Port" not in h, 984 "absent port returned with port present") 1008 self.assertNotIn("Port", h, "absent port returned with port present") 985 1009 986 1010 c = CookieJar(pol) … … 988 1012 interact_2965(c, url, "spam=eggs; Version=1; Port") 989 1013 h = interact_2965(c, url) 990 self.assert _(re.search("\$Port([^=]|$)", h),1014 self.assertTrue(re.search("\$Port([^=]|$)", h), 991 1015 "port with no value not returned with no value") 992 1016 … … 995 1019 interact_2965(c, url, 'spam=eggs; Version=1; Port="80"') 996 1020 h = interact_2965(c, url) 997 self.assert _('$Port="80"' inh,998 "port with single value not returned with single value")1021 self.assertIn('$Port="80"', h, 1022 "port with single value not returned with single value") 999 1023 1000 1024 c = CookieJar(pol) … … 1002 1026 interact_2965(c, url, 'spam=eggs; Version=1; Port="80,8080"') 1003 1027 h = interact_2965(c, url) 1004 self.assert _('$Port="80,8080"' inh,1005 "port with multiple values not returned with multiple "1006 "values")1028 self.assertIn('$Port="80,8080"', h, 1029 "port with multiple values not returned with multiple " 1030 "values") 1007 1031 1008 1032 def test_no_return_comment(self): … … 1015 1039 'CommentURL="http://foo.bar.net/comment.html"') 1016 1040 h = interact_2965(c, url) 1017 self.assert _(1041 self.assertTrue( 1018 1042 "Comment" not in h, 1019 1043 "Comment or CommentURL cookie-attributes returned to server") … … 1046 1070 i = 0 1047 1071 for c in cs: 1048 self.assert _(isinstance(c, Cookie))1049 self.assertEqual s(c.version, versions[i])1050 self.assertEqual s(c.name, names[i])1051 self.assertEqual s(c.domain, domains[i])1052 self.assertEqual s(c.path, paths[i])1072 self.assertIsInstance(c, Cookie) 1073 self.assertEqual(c.version, versions[i]) 1074 self.assertEqual(c.name, names[i]) 1075 self.assertEqual(c.domain, domains[i]) 1076 self.assertEqual(c.path, paths[i]) 1053 1077 i = i + 1 1054 1078 … … 1057 1081 1058 1082 # missing domain value (invalid cookie) 1059 self.assertEqual s(1083 self.assertEqual( 1060 1084 parse_ns_headers(["foo=bar; path=/; domain"]), 1061 1085 [[("foo", "bar"), … … 1063 1087 ) 1064 1088 # invalid expires value 1065 self.assertEqual s(1089 self.assertEqual( 1066 1090 parse_ns_headers(["foo=bar; expires=Foo Bar 12 33:22:11 2000"]), 1067 1091 [[("foo", "bar"), ("expires", None), ("version", "0")]] 1068 1092 ) 1069 1093 # missing cookie value (valid cookie) 1070 self.assertEqual s(1094 self.assertEqual( 1071 1095 parse_ns_headers(["foo"]), 1072 1096 [[("foo", None), ("version", "0")]] 1073 1097 ) 1074 1098 # shouldn't add version if header is empty 1075 self.assertEqual s(parse_ns_headers([""]), [])1099 self.assertEqual(parse_ns_headers([""]), []) 1076 1100 1077 1101 def test_bad_cookie_header(self): … … 1094 1118 # bad max-age 1095 1119 ["Set-Cookie: b=foo; max-age=oops"], 1120 # bad version 1121 ["Set-Cookie: b=foo; version=spam"], 1096 1122 ]: 1097 1123 c = cookiejar_from_cookie_headers(headers) 1098 1124 # these bad cookies shouldn't be set 1099 self.assertEqual s(len(c), 0)1125 self.assertEqual(len(c), 0) 1100 1126 1101 1127 # cookie with invalid expires is treated as session cookie … … 1103 1129 c = cookiejar_from_cookie_headers(headers) 1104 1130 cookie = c._cookies["www.example.com"]["/"]["c"] 1105 self.assert _(cookie.expires is None)1131 self.assertTrue(cookie.expires is None) 1106 1132 1107 1133 … … 1180 1206 1181 1207 h = req.get_header("Cookie") 1182 self.assert _("PART_NUMBER=ROCKET_LAUNCHER_0001" in h and1183 "CUSTOMER=WILE_E_COYOTE" inh)1208 self.assertIn("PART_NUMBER=ROCKET_LAUNCHER_0001", h) 1209 self.assertIn("CUSTOMER=WILE_E_COYOTE", h) 1184 1210 1185 1211 headers.append('Set-Cookie: SHIPPING=FEDEX; path=/foo') … … 1191 1217 1192 1218 h = req.get_header("Cookie") 1193 self.assert _("PART_NUMBER=ROCKET_LAUNCHER_0001" in h and1194 "CUSTOMER=WILE_E_COYOTE" in h and1195 "SHIPPING=FEDEX" not inh)1219 self.assertIn("PART_NUMBER=ROCKET_LAUNCHER_0001", h) 1220 self.assertIn("CUSTOMER=WILE_E_COYOTE", h) 1221 self.assertNotIn("SHIPPING=FEDEX", h) 1196 1222 1197 1223 req = Request("http://www.acme.com/foo/") … … 1199 1225 1200 1226 h = req.get_header("Cookie") 1201 self.assert _(("PART_NUMBER=ROCKET_LAUNCHER_0001" in h and1202 "CUSTOMER=WILE_E_COYOTE" in h and1203 h.startswith("SHIPPING=FEDEX;")))1227 self.assertIn("PART_NUMBER=ROCKET_LAUNCHER_0001", h) 1228 self.assertIn("CUSTOMER=WILE_E_COYOTE", h) 1229 self.assertTrue(h.startswith("SHIPPING=FEDEX;")) 1204 1230 1205 1231 def test_netscape_example_2(self): … … 1242 1268 c.add_cookie_header(req) 1243 1269 1244 self.assertEqual s(req.get_header("Cookie"),1270 self.assertEqual(req.get_header("Cookie"), 1245 1271 "PART_NUMBER=ROCKET_LAUNCHER_0001") 1246 1272 … … 1253 1279 c.add_cookie_header(req) 1254 1280 1255 self.assert _(re.search(r"PART_NUMBER=RIDING_ROCKET_0023;\s*"1281 self.assertTrue(re.search(r"PART_NUMBER=RIDING_ROCKET_0023;\s*" 1256 1282 "PART_NUMBER=ROCKET_LAUNCHER_0001", 1257 1283 req.get_header("Cookie"))) … … 1289 1315 c, 'http://www.acme.com/acme/login', 1290 1316 'Customer="WILE_E_COYOTE"; Version="1"; Path="/acme"') 1291 self.assert _(not cookie)1317 self.assertTrue(not cookie) 1292 1318 1293 1319 # … … 1311 1337 'Part_Number="Rocket_Launcher_0001"; ' 1312 1338 'Version="1"; Path="/acme"'); 1313 self.assert _(re.search(1339 self.assertTrue(re.search( 1314 1340 r'^\$Version="?1"?; Customer="?WILE_E_COYOTE"?; \$Path="/acme"$', 1315 1341 cookie)) … … 1336 1362 'Shipping="FedEx"; Version="1"; Path="/acme"') 1337 1363 1338 self.assert _(re.search(r'^\$Version="?1"?;', cookie))1339 self.assert _(re.search(r'Part_Number="?Rocket_Launcher_0001"?;'1364 self.assertTrue(re.search(r'^\$Version="?1"?;', cookie)) 1365 self.assertTrue(re.search(r'Part_Number="?Rocket_Launcher_0001"?;' 1340 1366 '\s*\$Path="\/acme"', cookie)) 1341 self.assert _(re.search(r'Customer="?WILE_E_COYOTE"?;\s*\$Path="\/acme"',1367 self.assertTrue(re.search(r'Customer="?WILE_E_COYOTE"?;\s*\$Path="\/acme"', 1342 1368 cookie)) 1343 1369 … … 1361 1387 1362 1388 cookie = interact_2965(c, "http://www.acme.com/acme/process") 1363 self.assert _(1389 self.assertTrue( 1364 1390 re.search(r'Shipping="?FedEx"?;\s*\$Path="\/acme"', cookie) and 1365 1391 "WILE_E_COYOTE" in cookie) … … 1412 1438 1413 1439 cookie = interact_2965(c, "http://www.acme.com/acme/ammo/...") 1414 self.assert _(1440 self.assertTrue( 1415 1441 re.search(r"Riding_Rocket_0023.*Rocket_Launcher_0001", cookie)) 1416 1442 … … 1425 1451 1426 1452 cookie = interact_2965(c, "http://www.acme.com/acme/parts/") 1427 self.assert _("Rocket_Launcher_0001" in cookie and1428 "Riding_Rocket_0023" not incookie)1453 self.assertIn("Rocket_Launcher_0001", cookie) 1454 self.assertNotIn("Riding_Rocket_0023", cookie) 1429 1455 1430 1456 def test_rejection(self): … … 1441 1467 cookie = interact_2965(c, "http://www.acme.com", 1442 1468 'foo=bar; domain=".com"; version=1') 1443 self.assert _(not c)1469 self.assertTrue(not c) 1444 1470 1445 1471 # legal domain 1446 1472 cookie = interact_2965(c, "http://www.acme.com", 1447 1473 'ping=pong; domain="acme.com"; version=1') 1448 self.assertEqual s(len(c), 1)1474 self.assertEqual(len(c), 1) 1449 1475 1450 1476 # illegal domain (host prefix "www.a" contains a dot) 1451 1477 cookie = interact_2965(c, "http://www.a.acme.com", 1452 1478 'whiz=bang; domain="acme.com"; version=1') 1453 self.assertEqual s(len(c), 1)1479 self.assertEqual(len(c), 1) 1454 1480 1455 1481 # legal domain 1456 1482 cookie = interact_2965(c, "http://www.a.acme.com", 1457 1483 'wow=flutter; domain=".a.acme.com"; version=1') 1458 self.assertEqual s(len(c), 2)1484 self.assertEqual(len(c), 2) 1459 1485 1460 1486 # can't partially match an IP-address 1461 1487 cookie = interact_2965(c, "http://125.125.125.125", 1462 1488 'zzzz=ping; domain="125.125.125"; version=1') 1463 self.assertEqual s(len(c), 2)1489 self.assertEqual(len(c), 2) 1464 1490 1465 1491 # illegal path (must be prefix of request path) … … 1467 1493 'blah=rhubarb; domain=".sol.no"; path="/foo"; ' 1468 1494 'version=1') 1469 self.assertEqual s(len(c), 2)1495 self.assertEqual(len(c), 2) 1470 1496 1471 1497 # legal path … … 1473 1499 'bing=bong; domain=".sol.no"; path="/foo"; ' 1474 1500 'version=1') 1475 self.assertEqual s(len(c), 3)1501 self.assertEqual(len(c), 3) 1476 1502 1477 1503 # illegal port (request-port not in list) … … 1479 1505 'whiz=ffft; domain=".sol.no"; port="90,100"; ' 1480 1506 'version=1') 1481 self.assertEqual s(len(c), 3)1507 self.assertEqual(len(c), 3) 1482 1508 1483 1509 # legal port … … 1487 1513 r'port="90,100, 80,8080"; ' 1488 1514 r'max-age=100; Comment = "Just kidding! (\"|\\\\) "') 1489 self.assertEqual s(len(c), 4)1515 self.assertEqual(len(c), 4) 1490 1516 1491 1517 # port attribute without any value (current port) … … 1493 1519 'foo9=bar; version=1; domain=".sol.no"; port; ' 1494 1520 'max-age=100;') 1495 self.assertEqual s(len(c), 5)1521 self.assertEqual(len(c), 5) 1496 1522 1497 1523 # encoded path … … 1504 1530 cookie = interact_2965(c, "http://www.sol.no/<oo/", 1505 1531 r'foo8=bar; version=1; path="/%3coo"') 1506 self.assertEqual s(len(c), 6)1532 self.assertEqual(len(c), 6) 1507 1533 1508 1534 # save and restore … … 1519 1545 except OSError: pass 1520 1546 1521 self.assertEqual s(old, repr(c))1547 self.assertEqual(old, repr(c)) 1522 1548 1523 1549 def test_url_encoding(self): … … 1534 1560 'bar=baz; path="/foo/"; version=1'); 1535 1561 version_re = re.compile(r'^\$version=\"?1\"?', re.I) 1536 self.assert _("foo=bar" in cookie and version_re.search(cookie))1562 self.assertTrue("foo=bar" in cookie and version_re.search(cookie)) 1537 1563 1538 1564 cookie = interact_2965( 1539 1565 c, "http://www.acme.com/foo/%25/<<%0anewå/æøå") 1540 self.assert _(not cookie)1566 self.assertTrue(not cookie) 1541 1567 1542 1568 # unicode URL doesn't raise exception … … 1579 1605 1580 1606 new_c = save_and_restore(c, True) 1581 self.assertEqual s(len(new_c), 6) # none discarded1582 self.assert _("name='foo1', value='bar'" inrepr(new_c))1607 self.assertEqual(len(new_c), 6) # none discarded 1608 self.assertIn("name='foo1', value='bar'", repr(new_c)) 1583 1609 1584 1610 new_c = save_and_restore(c, False) 1585 self.assertEqual s(len(new_c), 4) # 2 of them discarded on save1586 self.assert _("name='foo1', value='bar'" inrepr(new_c))1611 self.assertEqual(len(new_c), 4) # 2 of them discarded on save 1612 self.assertIn("name='foo1', value='bar'", repr(new_c)) 1587 1613 1588 1614 def test_netscape_misc(self): … … 1609 1635 req = Request("http://foo.bar.acme.com/foo") 1610 1636 c.add_cookie_header(req) 1611 self.assert _(1637 self.assertTrue( 1612 1638 "PART_NUMBER=3,4" in req.get_header("Cookie") and 1613 1639 "Customer=WILE_E_COYOTE" in req.get_header("Cookie")) … … 1622 1648 cookie = interact_2965(c, "http://example/", 1623 1649 'foo2=bar; domain=".local"; Version=1') 1624 self.assert _("foo1=bar" incookie)1650 self.assertIn("foo1=bar", cookie) 1625 1651 1626 1652 interact_2965(c, "http://example/", 'foo3=bar; Version=1') 1627 1653 cookie = interact_2965(c, "http://example/") 1628 self.assert_("foo2=bar" in cookie and len(c) == 3) 1654 self.assertIn("foo2=bar", cookie) 1655 self.assertEqual(len(c), 3) 1629 1656 1630 1657 def test_intranet_domains_ns(self): … … 1635 1662 cookie = interact_netscape(c, "http://example/", 1636 1663 'foo2=bar; domain=.local') 1637 self.assertEqual s(len(c), 2)1638 self.assert _("foo1=bar" incookie)1664 self.assertEqual(len(c), 2) 1665 self.assertIn("foo1=bar", cookie) 1639 1666 1640 1667 cookie = interact_netscape(c, "http://example/") 1641 self.assert _("foo2=bar" incookie)1642 self.assertEqual s(len(c), 2)1668 self.assertIn("foo2=bar", cookie) 1669 self.assertEqual(len(c), 2) 1643 1670 1644 1671 def test_empty_path(self): … … 1664 1691 c.add_cookie_header(req) 1665 1692 1666 self.assertEqual s(req.get_header("Cookie"),1667 1668 self.assertEqual s(req.get_header("Cookie2"), '$Version="1"')1693 self.assertEqual(req.get_header("Cookie"), 1694 "JSESSIONID=ABCDERANDOM123") 1695 self.assertEqual(req.get_header("Cookie2"), '$Version="1"') 1669 1696 1670 1697 # missing path in the request URI … … 1672 1699 c.add_cookie_header(req) 1673 1700 1674 self.assertEqual s(req.get_header("Cookie"),1675 1676 self.assertEqual s(req.get_header("Cookie2"), '$Version="1"')1701 self.assertEqual(req.get_header("Cookie"), 1702 "JSESSIONID=ABCDERANDOM123") 1703 self.assertEqual(req.get_header("Cookie2"), '$Version="1"') 1677 1704 1678 1705 def test_session_cookies(self): … … 1714 1741 counter[key] = counter[key] + 1 1715 1742 1716 self.assert _(not (1743 self.assertTrue(not ( 1717 1744 # a permanent cookie got lost accidentally 1718 1745 counter["perm_after"] != counter["perm_before"] or … … 1724 1751 1725 1752 def test_main(verbose=None): 1726 from test import test_sets1727 1753 test_support.run_unittest( 1728 1754 DateTimeTests,
Note:
See TracChangeset
for help on using the changeset viewer.