# module name.
TESTFN = "{}_{}_tmp".format(TESTFN, os.getpid())
+# Define the URL of a dedicated HTTP server for the network tests.
+# The URL must use clear-text HTTP: no redirection to encrypted HTTPS.
+TEST_HTTP_URL = "http://www.pythontest.net"
+
# FS_NONASCII: non-ASCII character encodable by os.fsencode(),
# or None if there is no such character.
FS_NONASCII = None
with self.assertRaises(urllib.error.ContentTooShortError):
try:
- urllib.request.urlretrieve('http://example.com/',
+ urllib.request.urlretrieve(support.TEST_HTTP_URL,
reporthook=_reporthook)
finally:
self.unfakehttp()
''')
with self.assertRaises(urllib.error.ContentTooShortError):
try:
- urllib.request.urlretrieve('http://example.com/')
+ urllib.request.urlretrieve(support.TEST_HTTP_URL)
finally:
self.unfakehttp()
def test_close(self):
# calling .close() on urllib2's response objects should close the
# underlying socket
- url = "http://www.example.com/"
+ url = support.TEST_HTTP_URL
with support.transient_internet(url):
response = _urlopen_with_retry(url)
sock = response.fp
"http://www.pythontest.net/elsewhere/#frag")
def test_custom_headers(self):
- url = "http://www.example.com"
+ url = support.TEST_HTTP_URL
with support.transient_internet(url):
opener = urllib.request.build_opener()
request = urllib.request.Request(url)
class TimeoutTest(unittest.TestCase):
def test_http_basic(self):
self.assertIsNone(socket.getdefaulttimeout())
- url = "http://www.example.com"
+ url = support.TEST_HTTP_URL
with support.transient_internet(url, timeout=None):
u = _urlopen_with_retry(url)
self.addCleanup(u.close)
def test_http_default_timeout(self):
self.assertIsNone(socket.getdefaulttimeout())
- url = "http://www.example.com"
+ url = support.TEST_HTTP_URL
with support.transient_internet(url):
socket.setdefaulttimeout(60)
try:
def test_http_no_timeout(self):
self.assertIsNone(socket.getdefaulttimeout())
- url = "http://www.example.com"
+ url = support.TEST_HTTP_URL
with support.transient_internet(url):
socket.setdefaulttimeout(60)
try:
self.assertIsNone(u.fp.raw._sock.gettimeout())
def test_http_timeout(self):
- url = "http://www.example.com"
+ url = support.TEST_HTTP_URL
with support.transient_internet(url):
u = _urlopen_with_retry(url, timeout=120)
self.addCleanup(u.close)