mirror of
https://github.com/f-droid/fdroidserver.git
synced 2025-09-13 14:32:28 +03:00
net: ignore proxy env vars, tests only use localhost
Proxy settings via environment variables can interfere with this test. The requests library will automatically pick up proxy settings from environment variables. Proxy settings can force the local connection over the proxy, which might not support that, then this fails with an error like 405 or others.
This commit is contained in:
parent
05e091804d
commit
90eeb63809
1 changed files with 12 additions and 2 deletions
|
@ -25,7 +25,15 @@ from pathlib import Path
|
|||
|
||||
|
||||
class RetryServer:
|
||||
"""A stupid simple HTTP server that can fail to connect"""
|
||||
"""A stupid simple HTTP server that can fail to connect.
|
||||
|
||||
Proxy settings via environment variables can interfere with this
|
||||
test. The requests library will automatically pick up proxy
|
||||
settings from environment variables. Proxy settings can force the
|
||||
local connection over the proxy, which might not support that,
|
||||
then this fails with an error like 405 or others.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, port=None, failures=3):
|
||||
self.port = port
|
||||
|
@ -123,6 +131,7 @@ class NetTest(unittest.TestCase):
|
|||
net.download_file('http://localhost:%d/f.txt' % server.port)
|
||||
server.stop()
|
||||
|
||||
@patch.dict(os.environ, clear=True)
|
||||
def test_download_using_mirrors_retries(self):
|
||||
server = RetryServer()
|
||||
f = net.download_using_mirrors(
|
||||
|
@ -131,13 +140,14 @@ class NetTest(unittest.TestCase):
|
|||
'https://httpbin.org/status/403',
|
||||
'https://httpbin.org/status/500',
|
||||
'http://localhost:1/f.txt', # ConnectionError
|
||||
'http://localhost:%d/' % server.port,
|
||||
'http://localhost:%d/should-succeed' % server.port,
|
||||
],
|
||||
)
|
||||
# strip the HTTP headers and compare the reply
|
||||
self.assertEqual(server.reply.split(b'\n\n')[1], Path(f).read_bytes())
|
||||
server.stop()
|
||||
|
||||
@patch.dict(os.environ, clear=True)
|
||||
def test_download_using_mirrors_retries_not_forever(self):
|
||||
"""The retry logic should eventually exit with an error."""
|
||||
server = RetryServer(failures=5)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue