Skip to content

Commit 9a3c082

Browse files
authored
Merge pull request #8182 from deveshks/no-input-tests
Enable --no-input option by adding docs and tests
2 parents 4abb40e + 4ecd7ec commit 9a3c082

File tree

4 files changed

+84
-2
lines changed

4 files changed

+84
-2
lines changed

news/7688.doc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add ``--no-input`` option to pip docs

src/pip/_internal/cli/cmdoptions.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ class PipOption(Option):
243243
dest='no_input',
244244
action='store_true',
245245
default=False,
246-
help=SUPPRESS_HELP
246+
help="Disable prompting for input."
247247
) # type: Callable[..., Option]
248248

249249
proxy = partial(

tests/functional/test_install_config.py

+66-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
import os
2+
import ssl
23
import tempfile
34
import textwrap
45

56
import pytest
67

7-
from tests.lib.server import file_response, package_page
8+
from tests.lib.server import (
9+
authorization_response,
10+
file_response,
11+
make_mock_server,
12+
package_page,
13+
server_running,
14+
)
815

916

1017
def test_options_from_env_vars(script):
@@ -209,3 +216,61 @@ def test_install_no_binary_via_config_disables_cached_wheels(
209216
assert "Building wheel for upper" not in str(res), str(res)
210217
# Must have used source, not a cached wheel to install upper.
211218
assert "Running setup.py install for upper" in str(res), str(res)
219+
220+
221+
def test_prompt_for_authentication(script, data, cert_factory):
222+
"""Test behaviour while installing from a index url
223+
requiring authentication
224+
"""
225+
cert_path = cert_factory()
226+
ctx = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
227+
ctx.load_cert_chain(cert_path, cert_path)
228+
ctx.load_verify_locations(cafile=cert_path)
229+
ctx.verify_mode = ssl.CERT_REQUIRED
230+
231+
server = make_mock_server(ssl_context=ctx)
232+
server.mock.side_effect = [
233+
package_page({
234+
"simple-3.0.tar.gz": "/files/simple-3.0.tar.gz",
235+
}),
236+
authorization_response(str(data.packages / "simple-3.0.tar.gz")),
237+
]
238+
239+
url = "https://{}:{}/simple".format(server.host, server.port)
240+
241+
with server_running(server):
242+
result = script.pip('install', "--index-url", url,
243+
"--cert", cert_path, "--client-cert", cert_path,
244+
'simple', expect_error=True)
245+
246+
assert 'User for {}:{}'.format(server.host, server.port) in \
247+
result.stdout, str(result)
248+
249+
250+
def test_do_not_prompt_for_authentication(script, data, cert_factory):
251+
"""Test behaviour if --no-input option is given while installing
252+
from a index url requiring authentication
253+
"""
254+
cert_path = cert_factory()
255+
ctx = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
256+
ctx.load_cert_chain(cert_path, cert_path)
257+
ctx.load_verify_locations(cafile=cert_path)
258+
ctx.verify_mode = ssl.CERT_REQUIRED
259+
260+
server = make_mock_server(ssl_context=ctx)
261+
262+
server.mock.side_effect = [
263+
package_page({
264+
"simple-3.0.tar.gz": "/files/simple-3.0.tar.gz",
265+
}),
266+
authorization_response(str(data.packages / "simple-3.0.tar.gz")),
267+
]
268+
269+
url = "https://{}:{}/simple".format(server.host, server.port)
270+
271+
with server_running(server):
272+
result = script.pip('install', "--index-url", url,
273+
"--cert", cert_path, "--client-cert", cert_path,
274+
'--no-input', 'simple', expect_error=True)
275+
276+
assert "ERROR: HTTP error 401" in result.stderr

tests/lib/server.py

+16
Original file line numberDiff line numberDiff line change
@@ -210,3 +210,19 @@ def responder(environ, start_response):
210210
return [f.read()]
211211

212212
return responder
213+
214+
215+
def authorization_response(path):
216+
def responder(environ, start_response):
217+
# type: (Environ, StartResponse) -> Body
218+
219+
start_response(
220+
"401 Unauthorized", [
221+
("WWW-Authenticate", "Basic"),
222+
],
223+
)
224+
225+
with open(path, 'rb') as f:
226+
return [f.read()]
227+
228+
return responder

0 commit comments

Comments
 (0)