summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorSenthil Kumaran <senthil@uthcode.com>2012-08-20 20:43:59 (GMT)
committerSenthil Kumaran <senthil@uthcode.com>2012-08-20 20:43:59 (GMT)
commit77ebfccd4d58040bb9a9ea5eba18e895ec201d34 (patch)
tree9b17cdcd95f7265bbb54f2e3d0313b8918701f9a /Lib
parentdf9c945070c3b74438b1141d2fff911a83f6e8fe (diff)
downloadcpython-77ebfccd4d58040bb9a9ea5eba18e895ec201d34.zip
cpython-77ebfccd4d58040bb9a9ea5eba18e895ec201d34.tar.gz
cpython-77ebfccd4d58040bb9a9ea5eba18e895ec201d34.tar.bz2
Fix Issue 15743 - improve urllib tests by removing deprecated method usages. Patch by Jeff Knupp.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_urllib2.py64
1 files changed, 33 insertions, 31 deletions
diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py
index b2cec7e..7ae1553 100644
--- a/Lib/test/test_urllib2.py
+++ b/Lib/test/test_urllib2.py
@@ -622,10 +622,10 @@ class OpenerDirectorTests(unittest.TestCase):
with self.assertWarns(DeprecationWarning):
req.add_data("data")
with self.assertWarns(DeprecationWarning):
- req.has_data()
- with self.assertWarns(DeprecationWarning):
req.get_data()
with self.assertWarns(DeprecationWarning):
+ req.has_data()
+ with self.assertWarns(DeprecationWarning):
req.get_host()
with self.assertWarns(DeprecationWarning):
req.get_selector()
@@ -633,6 +633,8 @@ class OpenerDirectorTests(unittest.TestCase):
req.is_unverifiable()
with self.assertWarns(DeprecationWarning):
req.get_origin_req_host()
+ with self.assertWarns(DeprecationWarning):
+ req.get_type()
def sanepathname2url(path):
@@ -989,8 +991,8 @@ class HandlerTests(unittest.TestCase):
newreq = h.http_request(req)
self.assertIs(cj.ach_req, req)
self.assertIs(cj.ach_req, newreq)
- self.assertEqual(req.get_origin_req_host(), "example.com")
- self.assertFalse(req.is_unverifiable())
+ self.assertEqual(req.origin_req_host, "example.com")
+ self.assertFalse(req.unverifiable)
newr = h.http_response(req, r)
self.assertIs(cj.ec_req, req)
self.assertIs(cj.ec_r, r)
@@ -1022,7 +1024,7 @@ class HandlerTests(unittest.TestCase):
try:
self.assertEqual(o.req.get_method(), "GET")
except AttributeError:
- self.assertFalse(o.req.has_data())
+ self.assertFalse(o.req.data)
# now it's a GET, there should not be headers regarding content
# (possibly dragged from before being a POST)
@@ -1138,9 +1140,9 @@ class HandlerTests(unittest.TestCase):
handlers = add_ordered_mock_handlers(o, meth_spec)
req = Request("http://acme.example.com/")
- self.assertEqual(req.get_host(), "acme.example.com")
+ self.assertEqual(req.host, "acme.example.com")
r = o.open(req)
- self.assertEqual(req.get_host(), "proxy.example.com:3128")
+ self.assertEqual(req.host, "proxy.example.com:3128")
self.assertEqual([(handlers[0], "http_open")],
[tup[0:2] for tup in o.calls])
@@ -1151,13 +1153,13 @@ class HandlerTests(unittest.TestCase):
ph = urllib.request.ProxyHandler(dict(http="proxy.example.com"))
o.add_handler(ph)
req = Request("http://www.perl.org/")
- self.assertEqual(req.get_host(), "www.perl.org")
+ self.assertEqual(req.host, "www.perl.org")
r = o.open(req)
- self.assertEqual(req.get_host(), "proxy.example.com")
+ self.assertEqual(req.host, "proxy.example.com")
req = Request("http://www.python.org")
- self.assertEqual(req.get_host(), "www.python.org")
+ self.assertEqual(req.host, "www.python.org")
r = o.open(req)
- self.assertEqual(req.get_host(), "www.python.org")
+ self.assertEqual(req.host, "www.python.org")
del os.environ['no_proxy']
def test_proxy_no_proxy_all(self):
@@ -1166,9 +1168,9 @@ class HandlerTests(unittest.TestCase):
ph = urllib.request.ProxyHandler(dict(http="proxy.example.com"))
o.add_handler(ph)
req = Request("http://www.python.org")
- self.assertEqual(req.get_host(), "www.python.org")
+ self.assertEqual(req.host, "www.python.org")
r = o.open(req)
- self.assertEqual(req.get_host(), "www.python.org")
+ self.assertEqual(req.host, "www.python.org")
del os.environ['no_proxy']
@@ -1182,9 +1184,9 @@ class HandlerTests(unittest.TestCase):
handlers = add_ordered_mock_handlers(o, meth_spec)
req = Request("https://www.example.com/")
- self.assertEqual(req.get_host(), "www.example.com")
+ self.assertEqual(req.host, "www.example.com")
r = o.open(req)
- self.assertEqual(req.get_host(), "proxy.example.com:3128")
+ self.assertEqual(req.host, "proxy.example.com:3128")
self.assertEqual([(handlers[0], "https_open")],
[tup[0:2] for tup in o.calls])
@@ -1197,7 +1199,7 @@ class HandlerTests(unittest.TestCase):
req = Request("https://www.example.com/")
req.add_header("Proxy-Authorization","FooBar")
req.add_header("User-Agent","Grail")
- self.assertEqual(req.get_host(), "www.example.com")
+ self.assertEqual(req.host, "www.example.com")
self.assertIsNone(req._tunnel_host)
r = o.open(req)
# Verify Proxy-Authorization gets tunneled to request.
@@ -1208,7 +1210,7 @@ class HandlerTests(unittest.TestCase):
self.assertIn(("User-Agent","Grail"),
https_handler.httpconn.req_headers)
self.assertIsNotNone(req._tunnel_host)
- self.assertEqual(req.get_host(), "proxy.example.com:3128")
+ self.assertEqual(req.host, "proxy.example.com:3128")
self.assertEqual(req.get_header("Proxy-authorization"),"FooBar")
# TODO: This should be only for OSX
@@ -1445,11 +1447,11 @@ class RequestTests(unittest.TestCase):
self.assertEqual("POST", self.post.get_method())
self.assertEqual("GET", self.get.get_method())
- def test_add_data(self):
- self.assertFalse(self.get.has_data())
+ def test_data(self):
+ self.assertFalse(self.get.data)
self.assertEqual("GET", self.get.get_method())
- self.get.add_data("spam")
- self.assertTrue(self.get.has_data())
+ self.get.data = "spam"
+ self.assertTrue(self.get.data)
self.assertEqual("POST", self.get.get_method())
def test_get_full_url(self):
@@ -1457,36 +1459,36 @@ class RequestTests(unittest.TestCase):
self.get.get_full_url())
def test_selector(self):
- self.assertEqual("/~jeremy/", self.get.get_selector())
+ self.assertEqual("/~jeremy/", self.get.selector)
req = Request("http://www.python.org/")
- self.assertEqual("/", req.get_selector())
+ self.assertEqual("/", req.selector)
def test_get_type(self):
- self.assertEqual("http", self.get.get_type())
+ self.assertEqual("http", self.get.type)
def test_get_host(self):
- self.assertEqual("www.python.org", self.get.get_host())
+ self.assertEqual("www.python.org", self.get.host)
def test_get_host_unquote(self):
req = Request("http://www.%70ython.org/")
- self.assertEqual("www.python.org", req.get_host())
+ self.assertEqual("www.python.org", req.host)
def test_proxy(self):
self.assertFalse(self.get.has_proxy())
self.get.set_proxy("www.perl.org", "http")
self.assertTrue(self.get.has_proxy())
- self.assertEqual("www.python.org", self.get.get_origin_req_host())
- self.assertEqual("www.perl.org", self.get.get_host())
+ self.assertEqual("www.python.org", self.get.origin_req_host)
+ self.assertEqual("www.perl.org", self.get.host)
def test_wrapped_url(self):
req = Request("<URL:http://www.python.org>")
- self.assertEqual("www.python.org", req.get_host())
+ self.assertEqual("www.python.org", req.host)
def test_url_fragment(self):
req = Request("http://www.python.org/?qs=query#fragment=true")
- self.assertEqual("/?qs=query", req.get_selector())
+ self.assertEqual("/?qs=query", req.selector)
req = Request("http://www.python.org/#fun=true")
- self.assertEqual("/", req.get_selector())
+ self.assertEqual("/", req.selector)
# Issue 11703: geturl() omits fragment in the original URL.
url = 'http://docs.python.org/library/urllib2.html#OK'