summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_http_cookiejar.py
diff options
context:
space:
mode:
authorEzio Melotti <ezio.melotti@gmail.com>2010-11-20 19:04:17 (GMT)
committerEzio Melotti <ezio.melotti@gmail.com>2010-11-20 19:04:17 (GMT)
commitb3aedd48621ed9d33b5f42f946b256bce4a50673 (patch)
tree2297c8ebce1b09621e1d98096c1603896d9a0f0c /Lib/test/test_http_cookiejar.py
parentb8bc439b2093add9b313bcca2cc507a2d0e87764 (diff)
downloadcpython-b3aedd48621ed9d33b5f42f946b256bce4a50673.zip
cpython-b3aedd48621ed9d33b5f42f946b256bce4a50673.tar.gz
cpython-b3aedd48621ed9d33b5f42f946b256bce4a50673.tar.bz2
#9424: Replace deprecated assert* methods in the Python test suite.
Diffstat (limited to 'Lib/test/test_http_cookiejar.py')
-rw-r--r--Lib/test/test_http_cookiejar.py266
1 files changed, 133 insertions, 133 deletions
diff --git a/Lib/test/test_http_cookiejar.py b/Lib/test/test_http_cookiejar.py
index fca6710..712a4ae 100644
--- a/Lib/test/test_http_cookiejar.py
+++ b/Lib/test/test_http_cookiejar.py
@@ -20,28 +20,28 @@ class DateTimeTests(unittest.TestCase):
def test_time2isoz(self):
base = 1019227000
day = 24*3600
- self.assertEquals(time2isoz(base), "2002-04-19 14:36:40Z")
- self.assertEquals(time2isoz(base+day), "2002-04-20 14:36:40Z")
- self.assertEquals(time2isoz(base+2*day), "2002-04-21 14:36:40Z")
- self.assertEquals(time2isoz(base+3*day), "2002-04-22 14:36:40Z")
+ self.assertEqual(time2isoz(base), "2002-04-19 14:36:40Z")
+ self.assertEqual(time2isoz(base+day), "2002-04-20 14:36:40Z")
+ self.assertEqual(time2isoz(base+2*day), "2002-04-21 14:36:40Z")
+ self.assertEqual(time2isoz(base+3*day), "2002-04-22 14:36:40Z")
az = time2isoz()
bz = time2isoz(500000)
for text in (az, bz):
self.assertTrue(re.search(r"^\d{4}-\d\d-\d\d \d\d:\d\d:\d\dZ$", text),
- "bad time2isoz format: %s %s" % (az, bz))
+ "bad time2isoz format: %s %s" % (az, bz))
def test_http2time(self):
def parse_date(text):
return time.gmtime(http2time(text))[:6]
- self.assertEquals(parse_date("01 Jan 2001"), (2001, 1, 1, 0, 0, 0.0))
+ self.assertEqual(parse_date("01 Jan 2001"), (2001, 1, 1, 0, 0, 0.0))
# this test will break around year 2070
- self.assertEquals(parse_date("03-Feb-20"), (2020, 2, 3, 0, 0, 0.0))
+ self.assertEqual(parse_date("03-Feb-20"), (2020, 2, 3, 0, 0, 0.0))
# this test will break around year 2048
- self.assertEquals(parse_date("03-Feb-98"), (1998, 2, 3, 0, 0, 0.0))
+ self.assertEqual(parse_date("03-Feb-98"), (1998, 2, 3, 0, 0, 0.0))
def test_http2time_formats(self):
# test http2time for supported dates. Test cases with 2 digit year
@@ -69,8 +69,8 @@ class DateTimeTests(unittest.TestCase):
test_t = 760233600 # assume broken POSIX counting of seconds
result = time2isoz(test_t)
expected = "1994-02-03 00:00:00Z"
- self.assertEquals(result, expected,
- "%s => '%s' (%s)" % (test_t, result, expected))
+ self.assertEqual(result, expected,
+ "%s => '%s' (%s)" % (test_t, result, expected))
for s in tests:
t = http2time(s)
@@ -108,7 +108,7 @@ class HeaderTests(unittest.TestCase):
'foo=bar; expires=01 Jan 2040 22:23:32 GMT',
'foo=bar; expires="01 Jan 2040 22:23:32 GMT"',
]:
- self.assertEquals(parse_ns_headers([hdr]), expected)
+ self.assertEqual(parse_ns_headers([hdr]), expected)
def test_parse_ns_headers_version(self):
@@ -118,7 +118,7 @@ class HeaderTests(unittest.TestCase):
'foo=bar; version="1"',
'foo=bar; Version="1"',
]:
- self.assertEquals(parse_ns_headers([hdr]), expected)
+ self.assertEqual(parse_ns_headers([hdr]), expected)
def test_parse_ns_headers_special_names(self):
# names such as 'expires' are not special in first name=value pair
@@ -126,13 +126,13 @@ class HeaderTests(unittest.TestCase):
# Cookie with name 'expires'
hdr = 'expires=01 Jan 2040 22:23:32 GMT'
expected = [[("expires", "01 Jan 2040 22:23:32 GMT"), ("version", "0")]]
- self.assertEquals(parse_ns_headers([hdr]), expected)
+ self.assertEqual(parse_ns_headers([hdr]), expected)
def test_join_header_words(self):
joined = join_header_words([[("foo", None), ("bar", "baz")]])
- self.assertEquals(joined, "foo; bar=baz")
+ self.assertEqual(joined, "foo; bar=baz")
- self.assertEquals(join_header_words([[]]), "")
+ self.assertEqual(join_header_words([[]]), "")
def test_split_header_words(self):
tests = [
@@ -162,7 +162,7 @@ class HeaderTests(unittest.TestCase):
f = io.StringIO()
traceback.print_exc(None, f)
result = "(error -- traceback follows)\n\n%s" % f.getvalue()
- self.assertEquals(result, expect, """
+ self.assertEqual(result, expect, """
When parsing: '%s'
Expected: '%s'
Got: '%s'
@@ -194,7 +194,7 @@ Got: '%s'
for arg, expect in tests:
input = split_header_words([arg])
res = join_header_words(input)
- self.assertEquals(res, expect, """
+ self.assertEqual(res, expect, """
When parsing: '%s'
Expected: '%s'
Got: '%s'
@@ -358,11 +358,11 @@ class CookieTests(unittest.TestCase):
interact_netscape(c, "http://www.acme.com/", '"spam"; path=/foo/')
cookie = c._cookies["www.acme.com"]["/"]["eggs"]
self.assertTrue(cookie.value is None)
- self.assertEquals(cookie.name, "eggs")
+ self.assertEqual(cookie.name, "eggs")
cookie = c._cookies["www.acme.com"]['/foo/']['"spam"']
self.assertTrue(cookie.value is None)
- self.assertEquals(cookie.name, '"spam"')
- self.assertEquals(lwp_cookie_str(cookie), (
+ self.assertEqual(cookie.name, '"spam"')
+ self.assertEqual(lwp_cookie_str(cookie), (
r'"spam"; path="/foo/"; domain="www.acme.com"; '
'path_spec; discard; version=0'))
old_str = repr(c)
@@ -373,13 +373,13 @@ class CookieTests(unittest.TestCase):
finally:
os.unlink(c.filename)
# cookies unchanged apart from lost info re. whether path was specified
- self.assertEquals(
+ self.assertEqual(
repr(c),
re.sub("path_specified=%s" % True, "path_specified=%s" % False,
old_str)
)
- self.assertEquals(interact_netscape(c, "http://www.acme.com/foo/"),
- '"spam"; eggs')
+ self.assertEqual(interact_netscape(c, "http://www.acme.com/foo/"),
+ '"spam"; eggs')
def test_rfc2109_handling(self):
# RFC 2109 cookies are handled as RFC 2965 or Netscape cookies,
@@ -423,18 +423,18 @@ class CookieTests(unittest.TestCase):
'expires="Foo Bar 25 33:22:11 3022"')
cookie = c._cookies[".acme.com"]["/"]["spam"]
- self.assertEquals(cookie.domain, ".acme.com")
+ self.assertEqual(cookie.domain, ".acme.com")
self.assertTrue(cookie.domain_specified)
- self.assertEquals(cookie.port, DEFAULT_HTTP_PORT)
+ self.assertEqual(cookie.port, DEFAULT_HTTP_PORT)
self.assertTrue(not cookie.port_specified)
# case is preserved
self.assertTrue(cookie.has_nonstandard_attr("blArgh") and
not cookie.has_nonstandard_attr("blargh"))
cookie = c._cookies["www.acme.com"]["/"]["ni"]
- self.assertEquals(cookie.domain, "www.acme.com")
+ self.assertEqual(cookie.domain, "www.acme.com")
self.assertTrue(not cookie.domain_specified)
- self.assertEquals(cookie.port, "80,8080")
+ self.assertEqual(cookie.port, "80,8080")
self.assertTrue(cookie.port_specified)
cookie = c._cookies["www.acme.com"]["/"]["nini"]
@@ -464,13 +464,13 @@ class CookieTests(unittest.TestCase):
future = time2netscape(time.time()+3600)
interact_netscape(c, "http://www.acme.com/", 'spam="bar"; expires=%s' %
future)
- self.assertEquals(len(c), 1)
+ self.assertEqual(len(c), 1)
now = time2netscape(time.time()-1)
# ... and if in past or present, discard it
interact_netscape(c, "http://www.acme.com/", 'foo="eggs"; expires=%s' %
now)
h = interact_netscape(c, "http://www.acme.com/")
- self.assertEquals(len(c), 1)
+ self.assertEqual(len(c), 1)
self.assertIn('spam="bar"', h)
self.assertNotIn("foo", h)
@@ -480,19 +480,19 @@ class CookieTests(unittest.TestCase):
future)
interact_netscape(c, "http://www.acme.com/", 'bar="bar"; expires=%s' %
future)
- self.assertEquals(len(c), 3)
+ self.assertEqual(len(c), 3)
interact_netscape(c, "http://www.acme.com/", 'eggs="bar"; '
'expires=%s; max-age=0' % future)
interact_netscape(c, "http://www.acme.com/", 'bar="bar"; '
'max-age=0; expires=%s' % future)
h = interact_netscape(c, "http://www.acme.com/")
- self.assertEquals(len(c), 1)
+ self.assertEqual(len(c), 1)
# test expiry at end of session for cookies with no expires attribute
interact_netscape(c, "http://www.rhubarb.net/", 'whum="fizz"')
- self.assertEquals(len(c), 2)
+ self.assertEqual(len(c), 2)
c.clear_session_cookies()
- self.assertEquals(len(c), 1)
+ self.assertEqual(len(c), 1)
self.assertIn('spam="bar"', h)
# XXX RFC 2965 expiry rules (some apply to V0 too)
@@ -545,7 +545,7 @@ class CookieTests(unittest.TestCase):
# Default path does not include query, so is "/", not "/?spam".
self.assertIn("/", cj._cookies["example.com"])
# Cookie is sent back to the same URI.
- self.assertEquals(interact_netscape(cj, uri), value)
+ self.assertEqual(interact_netscape(cj, uri), value)
def test_escape_path(self):
cases = [
@@ -570,31 +570,31 @@ class CookieTests(unittest.TestCase):
("/foo/bar\uabcd", "/foo/bar%EA%AF%8D"), # UTF-8 encoded
]
for arg, result in cases:
- self.assertEquals(escape_path(arg), result)
+ self.assertEqual(escape_path(arg), result)
def test_request_path(self):
# with parameters
req = urllib.request.Request(
"http://www.example.com/rheum/rhaponticum;"
"foo=bar;sing=song?apples=pears&spam=eggs#ni")
- self.assertEquals(request_path(req),
- "/rheum/rhaponticum;foo=bar;sing=song")
+ self.assertEqual(request_path(req),
+ "/rheum/rhaponticum;foo=bar;sing=song")
# without parameters
req = urllib.request.Request(
"http://www.example.com/rheum/rhaponticum?"
"apples=pears&spam=eggs#ni")
- self.assertEquals(request_path(req), "/rheum/rhaponticum")
+ self.assertEqual(request_path(req), "/rheum/rhaponticum")
# missing final slash
req = urllib.request.Request("http://www.example.com")
- self.assertEquals(request_path(req), "/")
+ self.assertEqual(request_path(req), "/")
def test_request_port(self):
req = urllib.request.Request("http://www.acme.com:1234/",
headers={"Host": "www.acme.com:4321"})
- self.assertEquals(request_port(req), "1234")
+ self.assertEqual(request_port(req), "1234")
req = urllib.request.Request("http://www.acme.com/",
headers={"Host": "www.acme.com:4321"})
- self.assertEquals(request_port(req), DEFAULT_HTTP_PORT)
+ self.assertEqual(request_port(req), DEFAULT_HTTP_PORT)
def test_request_host(self):
# this request is illegal (RFC2616, 14.2.3)
@@ -602,15 +602,15 @@ class CookieTests(unittest.TestCase):
headers={"Host": "www.acme.com:80"})
# libwww-perl wants this response, but that seems wrong (RFC 2616,
# section 5.2, point 1., and RFC 2965 section 1, paragraph 3)
- #self.assertEquals(request_host(req), "www.acme.com")
- self.assertEquals(request_host(req), "1.1.1.1")
+ #self.assertEqual(request_host(req), "www.acme.com")
+ self.assertEqual(request_host(req), "1.1.1.1")
req = urllib.request.Request("http://www.acme.com/",
headers={"Host": "irrelevant.com"})
- self.assertEquals(request_host(req), "www.acme.com")
+ self.assertEqual(request_host(req), "www.acme.com")
# port shouldn't be in request-host
req = urllib.request.Request("http://www.acme.com:2345/resource.html",
headers={"Host": "www.acme.com:5432"})
- self.assertEquals(request_host(req), "www.acme.com")
+ self.assertEqual(request_host(req), "www.acme.com")
def test_is_HDN(self):
self.assertTrue(is_HDN("foo.bar.com"))
@@ -623,14 +623,14 @@ class CookieTests(unittest.TestCase):
self.assertTrue(not is_HDN("foo."))
def test_reach(self):
- self.assertEquals(reach("www.acme.com"), ".acme.com")
- self.assertEquals(reach("acme.com"), "acme.com")
- self.assertEquals(reach("acme.local"), ".local")
- self.assertEquals(reach(".local"), ".local")
- self.assertEquals(reach(".com"), ".com")
- self.assertEquals(reach("."), ".")
- self.assertEquals(reach(""), "")
- self.assertEquals(reach("192.168.0.1"), "192.168.0.1")
+ self.assertEqual(reach("www.acme.com"), ".acme.com")
+ self.assertEqual(reach("acme.com"), "acme.com")
+ self.assertEqual(reach("acme.local"), ".local")
+ self.assertEqual(reach(".local"), ".local")
+ self.assertEqual(reach(".com"), ".com")
+ self.assertEqual(reach("."), ".")
+ self.assertEqual(reach(""), "")
+ self.assertEqual(reach("192.168.0.1"), "192.168.0.1")
def test_domain_match(self):
self.assertTrue(domain_match("192.168.1.1", "192.168.1.1"))
@@ -676,7 +676,7 @@ class CookieTests(unittest.TestCase):
c = CookieJar()
interact_2965(c, "http://www.nasty.com/",
'foo=bar; domain=friendly.org; Version="1"')
- self.assertEquals(len(c), 0)
+ self.assertEqual(len(c), 0)
def test_strict_domain(self):
# Cookies whose domain is a country-code tld like .co.uk should
@@ -686,11 +686,11 @@ class CookieTests(unittest.TestCase):
interact_netscape(cj, "http://example.co.uk/", 'no=problemo')
interact_netscape(cj, "http://example.co.uk/",
'okey=dokey; Domain=.example.co.uk')
- self.assertEquals(len(cj), 2)
+ self.assertEqual(len(cj), 2)
for pseudo_tld in [".co.uk", ".org.za", ".tx.us", ".name.us"]:
interact_netscape(cj, "http://example.%s/" % pseudo_tld,
'spam=eggs; Domain=.co.uk')
- self.assertEquals(len(cj), 2)
+ self.assertEqual(len(cj), 2)
def test_two_component_domain_ns(self):
# Netscape: .www.bar.com, www.bar.com, .bar.com, bar.com, no domain
@@ -700,17 +700,17 @@ class CookieTests(unittest.TestCase):
# two-component V0 domain is OK
interact_netscape(c, "http://foo.net/", 'ns=bar')
- self.assertEquals(len(c), 1)
- self.assertEquals(c._cookies["foo.net"]["/"]["ns"].value, "bar")
- self.assertEquals(interact_netscape(c, "http://foo.net/"), "ns=bar")
+ self.assertEqual(len(c), 1)
+ self.assertEqual(c._cookies["foo.net"]["/"]["ns"].value, "bar")
+ self.assertEqual(interact_netscape(c, "http://foo.net/"), "ns=bar")
# *will* be returned to any other domain (unlike RFC 2965)...
- self.assertEquals(interact_netscape(c, "http://www.foo.net/"),
- "ns=bar")
+ self.assertEqual(interact_netscape(c, "http://www.foo.net/"),
+ "ns=bar")
# ...unless requested otherwise
pol = DefaultCookiePolicy(
strict_ns_domain=DefaultCookiePolicy.DomainStrictNonDomain)
c.set_policy(pol)
- self.assertEquals(interact_netscape(c, "http://www.foo.net/"), "")
+ self.assertEqual(interact_netscape(c, "http://www.foo.net/"), "")
# unlike RFC 2965, even explicit two-component domain is OK,
# because .foo.net matches foo.net
@@ -719,17 +719,17 @@ class CookieTests(unittest.TestCase):
# even if starts with a dot -- in NS rules, .foo.net matches foo.net!
interact_netscape(c, "http://foo.net/foo/bar/",
'spam2=eggs; domain=.foo.net')
- self.assertEquals(len(c), 3)
- self.assertEquals(c._cookies[".foo.net"]["/foo"]["spam1"].value,
- "eggs")
- self.assertEquals(c._cookies[".foo.net"]["/foo/bar"]["spam2"].value,
- "eggs")
- self.assertEquals(interact_netscape(c, "http://foo.net/foo/bar/"),
- "spam2=eggs; spam1=eggs; ns=bar")
+ self.assertEqual(len(c), 3)
+ self.assertEqual(c._cookies[".foo.net"]["/foo"]["spam1"].value,
+ "eggs")
+ self.assertEqual(c._cookies[".foo.net"]["/foo/bar"]["spam2"].value,
+ "eggs")
+ self.assertEqual(interact_netscape(c, "http://foo.net/foo/bar/"),
+ "spam2=eggs; spam1=eggs; ns=bar")
# top-level domain is too general
interact_netscape(c, "http://foo.net/", 'nini="ni"; domain=.net')
- self.assertEquals(len(c), 3)
+ self.assertEqual(len(c), 3)
## # Netscape protocol doesn't allow non-special top level domains (such
## # as co.uk) in the domain attribute unless there are at least three
@@ -737,8 +737,8 @@ class CookieTests(unittest.TestCase):
# Oh yes it does! Real implementations don't check this, and real
# cookies (of course) rely on that behaviour.
interact_netscape(c, "http://foo.co.uk", 'nasty=trick; domain=.co.uk')
-## self.assertEquals(len(c), 2)
- self.assertEquals(len(c), 4)
+## self.assertEqual(len(c), 2)
+ self.assertEqual(len(c), 4)
def test_two_component_domain_rfc2965(self):
pol = DefaultCookiePolicy(rfc2965=True)
@@ -746,43 +746,43 @@ class CookieTests(unittest.TestCase):
# two-component V1 domain is OK
interact_2965(c, "http://foo.net/", 'foo=bar; Version="1"')
- self.assertEquals(len(c), 1)
- self.assertEquals(c._cookies["foo.net"]["/"]["foo"].value, "bar")
- self.assertEquals(interact_2965(c, "http://foo.net/"),
- "$Version=1; foo=bar")
+ self.assertEqual(len(c), 1)
+ self.assertEqual(c._cookies["foo.net"]["/"]["foo"].value, "bar")
+ self.assertEqual(interact_2965(c, "http://foo.net/"),
+ "$Version=1; foo=bar")
# won't be returned to any other domain (because domain was implied)
- self.assertEquals(interact_2965(c, "http://www.foo.net/"), "")
+ self.assertEqual(interact_2965(c, "http://www.foo.net/"), "")
# unless domain is given explicitly, because then it must be
# rewritten to start with a dot: foo.net --> .foo.net, which does
# not domain-match foo.net
interact_2965(c, "http://foo.net/foo",
'spam=eggs; domain=foo.net; path=/foo; Version="1"')
- self.assertEquals(len(c), 1)
- self.assertEquals(interact_2965(c, "http://foo.net/foo"),
- "$Version=1; foo=bar")
+ self.assertEqual(len(c), 1)
+ self.assertEqual(interact_2965(c, "http://foo.net/foo"),
+ "$Version=1; foo=bar")
# explicit foo.net from three-component domain www.foo.net *does* get
# set, because .foo.net domain-matches .foo.net
interact_2965(c, "http://www.foo.net/foo/",
'spam=eggs; domain=foo.net; Version="1"')
- self.assertEquals(c._cookies[".foo.net"]["/foo/"]["spam"].value,
- "eggs")
- self.assertEquals(len(c), 2)
- self.assertEquals(interact_2965(c, "http://foo.net/foo/"),
- "$Version=1; foo=bar")
- self.assertEquals(interact_2965(c, "http://www.foo.net/foo/"),
- '$Version=1; spam=eggs; $Domain="foo.net"')
+ self.assertEqual(c._cookies[".foo.net"]["/foo/"]["spam"].value,
+ "eggs")
+ self.assertEqual(len(c), 2)
+ self.assertEqual(interact_2965(c, "http://foo.net/foo/"),
+ "$Version=1; foo=bar")
+ self.assertEqual(interact_2965(c, "http://www.foo.net/foo/"),
+ '$Version=1; spam=eggs; $Domain="foo.net"')
# top-level domain is too general
interact_2965(c, "http://foo.net/",
'ni="ni"; domain=".net"; Version="1"')
- self.assertEquals(len(c), 2)
+ self.assertEqual(len(c), 2)
# RFC 2965 doesn't require blocking this
interact_2965(c, "http://foo.co.uk/",
'nasty=trick; domain=.co.uk; Version="1"')
- self.assertEquals(len(c), 3)
+ self.assertEqual(len(c), 3)
def test_domain_allow(self):
c = CookieJar(policy=DefaultCookiePolicy(
@@ -793,24 +793,24 @@ class CookieTests(unittest.TestCase):
headers = ["Set-Cookie: CUSTOMER=WILE_E_COYOTE; path=/"]
res = FakeResponse(headers, "http://acme.com/")
c.extract_cookies(res, req)
- self.assertEquals(len(c), 0)
+ self.assertEqual(len(c), 0)
req = urllib.request.Request("http://www.acme.com/")
res = FakeResponse(headers, "http://www.acme.com/")
c.extract_cookies(res, req)
- self.assertEquals(len(c), 1)
+ self.assertEqual(len(c), 1)
req = urllib.request.Request("http://www.coyote.com/")
res = FakeResponse(headers, "http://www.coyote.com/")
c.extract_cookies(res, req)
- self.assertEquals(len(c), 1)
+ self.assertEqual(len(c), 1)
# set a cookie with non-allowed domain...
req = urllib.request.Request("http://www.coyote.com/")
res = FakeResponse(headers, "http://www.coyote.com/")
cookies = c.make_cookies(res, req)
c.set_cookie(cookies[0])
- self.assertEquals(len(c), 2)
+ self.assertEqual(len(c), 2)
# ... and check is doesn't get returned
c.add_cookie_header(req)
self.assertTrue(not req.has_header("Cookie"))
@@ -824,17 +824,17 @@ class CookieTests(unittest.TestCase):
req = urllib.request.Request("http://www.acme.com/")
res = FakeResponse(headers, "http://www.acme.com/")
c.extract_cookies(res, req)
- self.assertEquals(len(c), 0)
+ self.assertEqual(len(c), 0)
p = pol.set_blocked_domains(["acme.com"])
c.extract_cookies(res, req)
- self.assertEquals(len(c), 1)
+ self.assertEqual(len(c), 1)
c.clear()
req = urllib.request.Request("http://www.roadrunner.net/")
res = FakeResponse(headers, "http://www.roadrunner.net/")
c.extract_cookies(res, req)
- self.assertEquals(len(c), 1)
+ self.assertEqual(len(c), 1)
req = urllib.request.Request("http://www.roadrunner.net/")
c.add_cookie_header(req)
self.assertTrue((req.has_header("Cookie") and
@@ -843,14 +843,14 @@ class CookieTests(unittest.TestCase):
c.clear()
pol.set_blocked_domains([".acme.com"])
c.extract_cookies(res, req)
- self.assertEquals(len(c), 1)
+ self.assertEqual(len(c), 1)
# set a cookie with blocked domain...
req = urllib.request.Request("http://www.acme.com/")
res = FakeResponse(headers, "http://www.acme.com/")
cookies = c.make_cookies(res, req)
c.set_cookie(cookies[0])
- self.assertEquals(len(c), 2)
+ self.assertEqual(len(c), 2)
# ... and check is doesn't get returned
c.add_cookie_header(req)
self.assertTrue(not req.has_header("Cookie"))
@@ -882,7 +882,7 @@ class CookieTests(unittest.TestCase):
c = CookieJar(policy=DefaultCookiePolicy(rfc2965=True))
interact_2965(c, "http://www.acme.com/", r'foo=\b"a"r; Version=1')
h = interact_2965(c, "http://www.acme.com/")
- self.assertEquals(h, r'$Version=1; foo=\\b\"a\"r')
+ self.assertEqual(h, r'$Version=1; foo=\\b\"a\"r')
def test_missing_final_slash(self):
# Missing slash from request URL's abs_path should be assumed present.
@@ -890,7 +890,7 @@ class CookieTests(unittest.TestCase):
c = CookieJar(DefaultCookiePolicy(rfc2965=True))
interact_2965(c, url, "foo=bar; Version=1")
req = urllib.request.Request(url)
- self.assertEquals(len(c), 1)
+ self.assertEqual(len(c), 1)
c.add_cookie_header(req)
self.assertTrue(req.has_header("Cookie"))
@@ -1000,31 +1000,31 @@ class CookieTests(unittest.TestCase):
i = 0
for c in cs:
self.assertTrue(isinstance(c, Cookie))
- self.assertEquals(c.version, versions[i])
- self.assertEquals(c.name, names[i])
- self.assertEquals(c.domain, domains[i])
- self.assertEquals(c.path, paths[i])
+ self.assertEqual(c.version, versions[i])
+ self.assertEqual(c.name, names[i])
+ self.assertEqual(c.domain, domains[i])
+ self.assertEqual(c.path, paths[i])
i = i + 1
def test_parse_ns_headers(self):
# missing domain value (invalid cookie)
- self.assertEquals(
+ self.assertEqual(
parse_ns_headers(["foo=bar; path=/; domain"]),
[[("foo", "bar"),
("path", "/"), ("domain", None), ("version", "0")]]
)
# invalid expires value
- self.assertEquals(
+ self.assertEqual(
parse_ns_headers(["foo=bar; expires=Foo Bar 12 33:22:11 2000"]),
[[("foo", "bar"), ("expires", None), ("version", "0")]]
)
# missing cookie value (valid cookie)
- self.assertEquals(
+ self.assertEqual(
parse_ns_headers(["foo"]),
[[("foo", None), ("version", "0")]]
)
# shouldn't add version if header is empty
- self.assertEquals(parse_ns_headers([""]), [])
+ self.assertEqual(parse_ns_headers([""]), [])
def test_bad_cookie_header(self):
@@ -1048,7 +1048,7 @@ class CookieTests(unittest.TestCase):
]:
c = cookiejar_from_cookie_headers(headers)
# these bad cookies shouldn't be set
- self.assertEquals(len(c), 0)
+ self.assertEqual(len(c), 0)
# cookie with invalid expires is treated as session cookie
headers = ["Set-Cookie: c=foo; expires=Foo Bar 12 33:22:11 2000"]
@@ -1187,8 +1187,8 @@ class LWPCookieTests(unittest.TestCase):
req = urllib.request.Request("http://www.acme.com/")
c.add_cookie_header(req)
- self.assertEquals(req.get_header("Cookie"),
- "PART_NUMBER=ROCKET_LAUNCHER_0001")
+ self.assertEqual(req.get_header("Cookie"),
+ "PART_NUMBER=ROCKET_LAUNCHER_0001")
headers.append(
"Set-Cookie: PART_NUMBER=RIDING_ROCKET_0023; path=/ammo")
@@ -1386,40 +1386,40 @@ class LWPCookieTests(unittest.TestCase):
# legal domain
cookie = interact_2965(c, "http://www.acme.com",
'ping=pong; domain="acme.com"; version=1')
- self.assertEquals(len(c), 1)
+ self.assertEqual(len(c), 1)
# illegal domain (host prefix "www.a" contains a dot)
cookie = interact_2965(c, "http://www.a.acme.com",
'whiz=bang; domain="acme.com"; version=1')
- self.assertEquals(len(c), 1)
+ self.assertEqual(len(c), 1)
# legal domain
cookie = interact_2965(c, "http://www.a.acme.com",
'wow=flutter; domain=".a.acme.com"; version=1')
- self.assertEquals(len(c), 2)
+ self.assertEqual(len(c), 2)
# can't partially match an IP-address
cookie = interact_2965(c, "http://125.125.125.125",
'zzzz=ping; domain="125.125.125"; version=1')
- self.assertEquals(len(c), 2)
+ self.assertEqual(len(c), 2)
# illegal path (must be prefix of request path)
cookie = interact_2965(c, "http://www.sol.no",
'blah=rhubarb; domain=".sol.no"; path="/foo"; '
'version=1')
- self.assertEquals(len(c), 2)
+ self.assertEqual(len(c), 2)
# legal path
cookie = interact_2965(c, "http://www.sol.no/foo/bar",
'bing=bong; domain=".sol.no"; path="/foo"; '
'version=1')
- self.assertEquals(len(c), 3)
+ self.assertEqual(len(c), 3)
# illegal port (request-port not in list)
cookie = interact_2965(c, "http://www.sol.no",
'whiz=ffft; domain=".sol.no"; port="90,100"; '
'version=1')
- self.assertEquals(len(c), 3)
+ self.assertEqual(len(c), 3)
# legal port
cookie = interact_2965(
@@ -1427,13 +1427,13 @@ class LWPCookieTests(unittest.TestCase):
r'bang=wallop; version=1; domain=".sol.no"; '
r'port="90,100, 80,8080"; '
r'max-age=100; Comment = "Just kidding! (\"|\\\\) "')
- self.assertEquals(len(c), 4)
+ self.assertEqual(len(c), 4)
# port attribute without any value (current port)
cookie = interact_2965(c, "http://www.sol.no",
'foo9=bar; version=1; domain=".sol.no"; port; '
'max-age=100;')
- self.assertEquals(len(c), 5)
+ self.assertEqual(len(c), 5)
# encoded path
# LWP has this test, but unescaping allowed path characters seems
@@ -1444,7 +1444,7 @@ class LWPCookieTests(unittest.TestCase):
# character:
cookie = interact_2965(c, "http://www.sol.no/<oo/",
r'foo8=bar; version=1; path="/%3coo"')
- self.assertEquals(len(c), 6)
+ self.assertEqual(len(c), 6)
# save and restore
filename = test.support.TESTFN
@@ -1459,7 +1459,7 @@ class LWPCookieTests(unittest.TestCase):
try: os.unlink(filename)
except OSError: pass
- self.assertEquals(old, repr(c))
+ self.assertEqual(old, repr(c))
def test_url_encoding(self):
# Try some URL encodings of the PATHs.
@@ -1517,11 +1517,11 @@ class LWPCookieTests(unittest.TestCase):
return new_c
new_c = save_and_restore(c, True)
- self.assertEquals(len(new_c), 6) # none discarded
+ self.assertEqual(len(new_c), 6) # none discarded
self.assertIn("name='foo1', value='bar'", repr(new_c))
new_c = save_and_restore(c, False)
- self.assertEquals(len(new_c), 4) # 2 of them discarded on save
+ self.assertEqual(len(new_c), 4) # 2 of them discarded on save
self.assertIn("name='foo1', value='bar'", repr(new_c))
def test_netscape_misc(self):
@@ -1559,19 +1559,19 @@ class LWPCookieTests(unittest.TestCase):
interact_2965(c, "http://example/", 'foo3=bar; Version=1')
cookie = interact_2965(c, "http://example/")
self.assertIn("foo2=bar", cookie)
- self.assertEquals(len(c), 3)
+ self.assertEqual(len(c), 3)
def test_intranet_domains_ns(self):
c = CookieJar(DefaultCookiePolicy(rfc2965 = False))
interact_netscape(c, "http://example/", "foo1=bar")
cookie = interact_netscape(c, "http://example/",
'foo2=bar; domain=.local')
- self.assertEquals(len(c), 2)
+ self.assertEqual(len(c), 2)
self.assertIn("foo1=bar", cookie)
cookie = interact_netscape(c, "http://example/")
self.assertIn("foo2=bar", cookie)
- self.assertEquals(len(c), 2)
+ self.assertEqual(len(c), 2)
def test_empty_path(self):
# Test for empty path
@@ -1592,17 +1592,17 @@ class LWPCookieTests(unittest.TestCase):
req = urllib.request.Request("http://www.ants.com/")
c.add_cookie_header(req)
- self.assertEquals(req.get_header("Cookie"),
- "JSESSIONID=ABCDERANDOM123")
- self.assertEquals(req.get_header("Cookie2"), '$Version="1"')
+ self.assertEqual(req.get_header("Cookie"),
+ "JSESSIONID=ABCDERANDOM123")
+ self.assertEqual(req.get_header("Cookie2"), '$Version="1"')
# missing path in the request URI
req = urllib.request.Request("http://www.ants.com:8080")
c.add_cookie_header(req)
- self.assertEquals(req.get_header("Cookie"),
- "JSESSIONID=ABCDERANDOM123")
- self.assertEquals(req.get_header("Cookie2"), '$Version="1"')
+ self.assertEqual(req.get_header("Cookie"),
+ "JSESSIONID=ABCDERANDOM123")
+ self.assertEqual(req.get_header("Cookie2"), '$Version="1"')
def test_session_cookies(self):
year_plus_one = time.localtime()[0] + 1