|
4 | 4 |
|
5 | 5 | import pytest
|
6 | 6 |
|
| 7 | +from tests.lib.server import file_response, package_page |
| 8 | + |
7 | 9 |
|
8 | 10 | def test_options_from_env_vars(script):
|
9 | 11 | """
|
@@ -122,46 +124,55 @@ def test_command_line_appends_correctly(script, data):
|
122 | 124 | ), 'stdout: {}'.format(result.stdout)
|
123 | 125 |
|
124 | 126 |
|
125 |
| -@pytest.mark.network |
126 |
| -def test_config_file_override_stack(script, virtualenv): |
| 127 | +def test_config_file_override_stack( |
| 128 | + script, virtualenv, mock_server, shared_data |
| 129 | +): |
127 | 130 | """
|
128 | 131 | Test config files (global, overriding a global config with a
|
129 | 132 | local, overriding all with a command line flag).
|
130 | 133 | """
|
| 134 | + mock_server.set_responses([ |
| 135 | + package_page({}), |
| 136 | + package_page({}), |
| 137 | + package_page({"INITools-0.2.tar.gz": "/files/INITools-0.2.tar.gz"}), |
| 138 | + file_response(shared_data.packages.joinpath("INITools-0.2.tar.gz")), |
| 139 | + ]) |
| 140 | + mock_server.start() |
| 141 | + base_address = "http://{}:{}".format(mock_server.host, mock_server.port) |
| 142 | + |
131 | 143 | config_file = script.scratch_path / "test-pip.cfg"
|
132 | 144 |
|
133 | 145 | # set this to make pip load it
|
134 | 146 | script.environ['PIP_CONFIG_FILE'] = str(config_file)
|
| 147 | + |
135 | 148 | config_file.write_text(textwrap.dedent("""\
|
136 | 149 | [global]
|
137 |
| - index-url = https://download.zope.org/ppix |
138 |
| - """)) |
139 |
| - result = script.pip('install', '-vvv', 'INITools', expect_error=True) |
140 |
| - assert ( |
141 |
| - "Getting page https://download.zope.org/ppix/initools" in result.stdout |
142 |
| - ) |
| 150 | + index-url = {}/simple1 |
| 151 | + """.format(base_address))) |
| 152 | + script.pip('install', '-vvv', 'INITools', expect_error=True) |
143 | 153 | virtualenv.clear()
|
| 154 | + |
144 | 155 | config_file.write_text(textwrap.dedent("""\
|
145 | 156 | [global]
|
146 |
| - index-url = https://download.zope.org/ppix |
| 157 | + index-url = {address}/simple1 |
147 | 158 | [install]
|
148 |
| - index-url = https://pypi.gocept.com/ |
149 |
| - """)) |
150 |
| - result = script.pip('install', '-vvv', 'INITools', expect_error=True) |
151 |
| - assert "Getting page https://pypi.gocept.com/initools" in result.stdout |
152 |
| - result = script.pip( |
153 |
| - 'install', '-vvv', '--index-url', 'https://pypi.org/simple/', |
154 |
| - 'INITools', |
| 159 | + index-url = {address}/simple2 |
| 160 | + """.format(address=base_address)) |
155 | 161 | )
|
156 |
| - assert ( |
157 |
| - "Getting page http://download.zope.org/ppix/INITools" |
158 |
| - not in result.stdout |
159 |
| - ) |
160 |
| - assert "Getting page https://pypi.gocept.com/INITools" not in result.stdout |
161 |
| - assert ( |
162 |
| - "Getting page https://pypi.org/simple/initools" in result.stdout |
| 162 | + script.pip('install', '-vvv', 'INITools', expect_error=True) |
| 163 | + script.pip( |
| 164 | + 'install', '-vvv', '--index-url', "{}/simple3".format(base_address), |
| 165 | + 'INITools', |
163 | 166 | )
|
164 | 167 |
|
| 168 | + mock_server.stop() |
| 169 | + requests = mock_server.get_requests() |
| 170 | + assert len(requests) == 4 |
| 171 | + assert requests[0]["PATH_INFO"] == "/simple1/initools/" |
| 172 | + assert requests[1]["PATH_INFO"] == "/simple2/initools/" |
| 173 | + assert requests[2]["PATH_INFO"] == "/simple3/initools/" |
| 174 | + assert requests[3]["PATH_INFO"] == "/files/INITools-0.2.tar.gz" |
| 175 | + |
165 | 176 |
|
166 | 177 | def test_options_from_venv_config(script, virtualenv):
|
167 | 178 | """
|
|
0 commit comments