summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2008-01-20 11:43:03 (GMT)
committerGeorg Brandl <georg@python.org>2008-01-20 11:43:03 (GMT)
commit9b0d46db115c10767b240a0a64286214b50fe6ad (patch)
tree7ecec7b9261dfc50941932036aaec79af5a0a1ce /Lib/test
parentdcd6b522060d9b14e26046519770e718e65802cd (diff)
downloadcpython-9b0d46db115c10767b240a0a64286214b50fe6ad.zip
cpython-9b0d46db115c10767b240a0a64286214b50fe6ad.tar.gz
cpython-9b0d46db115c10767b240a0a64286214b50fe6ad.tar.bz2
#1178141: add addinfourl.code to get http status code from urllib.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_urllib.py7
-rw-r--r--Lib/test/test_urllibnet.py10
2 files changed, 16 insertions, 1 deletions
diff --git a/Lib/test/test_urllib.py b/Lib/test/test_urllib.py
index ed7f6ce..455e7fc 100644
--- a/Lib/test/test_urllib.py
+++ b/Lib/test/test_urllib.py
@@ -47,7 +47,7 @@ class urlopen_FileTests(unittest.TestCase):
def test_interface(self):
# Make sure object returned by urlopen() has the specified methods
for attr in ("read", "readline", "readlines", "fileno",
- "close", "info", "geturl", "__iter__"):
+ "close", "info", "geturl", "getcode", "__iter__"):
self.assert_(hasattr(self.returned_obj, attr),
"object returned by urlopen() lacks %s attribute" %
attr)
@@ -87,6 +87,9 @@ class urlopen_FileTests(unittest.TestCase):
def test_geturl(self):
self.assertEqual(self.returned_obj.geturl(), self.pathname)
+ def test_getcode(self):
+ self.assertEqual(self.returned_obj.getcode(), None)
+
def test_iter(self):
# Test iterator
# Don't need to count number of iterations since test would fail the
@@ -123,6 +126,8 @@ class urlopen_HttpTests(unittest.TestCase):
fp = urllib.urlopen("http://python.org/")
self.assertEqual(fp.readline(), 'Hello!')
self.assertEqual(fp.readline(), '')
+ self.assertEqual(fp.geturl(), 'http://python.org/')
+ self.assertEqual(fp.getcode(), 200)
finally:
self.unfakehttp()
diff --git a/Lib/test/test_urllibnet.py b/Lib/test/test_urllibnet.py
index 9105afe..a28c081 100644
--- a/Lib/test/test_urllibnet.py
+++ b/Lib/test/test_urllibnet.py
@@ -83,6 +83,16 @@ class urlopenNetworkTests(unittest.TestCase):
open_url.close()
self.assertEqual(gotten_url, URL)
+ def test_getcode(self):
+ # test getcode() with the fancy opener to get 404 error codes
+ URL = "http://www.python.org/XXXinvalidXXX"
+ open_url = urllib.FancyURLopener().open(URL)
+ try:
+ code = open_url.getcode()
+ finally:
+ open_url.close()
+ self.assertEqual(code, 404)
+
def test_fileno(self):
if (sys.platform in ('win32',) or
not hasattr(os, 'fdopen')):