|
32 | 32 | def stub_response(): |
33 | 33 | """Mock successful upload of a package.""" |
34 | 34 | return pretend.stub( |
35 | | - is_redirect=False, status_code=201, raise_for_status=lambda: None |
| 35 | + is_redirect=False, |
| 36 | + url="https://test.pypi.org/legacy/", |
| 37 | + status_code=200, |
| 38 | + reason="OK", |
| 39 | + text=None, |
| 40 | + raise_for_status=lambda: None, |
36 | 41 | ) |
37 | 42 |
|
38 | 43 |
|
@@ -138,6 +143,25 @@ def test_print_packages_if_verbose(upload_settings, capsys): |
138 | 143 | assert captured.out.count(f"{filename} ({size})") == 1 |
139 | 144 |
|
140 | 145 |
|
| 146 | +def test_print_response_if_verbose(upload_settings, stub_response, capsys): |
| 147 | + """Print details about the response from the repostiry.""" |
| 148 | + upload_settings.verbose = True |
| 149 | + |
| 150 | + result = upload.upload( |
| 151 | + upload_settings, |
| 152 | + [helpers.WHEEL_FIXTURE, helpers.SDIST_FIXTURE], |
| 153 | + ) |
| 154 | + assert result is None |
| 155 | + |
| 156 | + captured = capsys.readouterr() |
| 157 | + response_log = ( |
| 158 | + f"Response from {stub_response.url}:\n" |
| 159 | + f"{stub_response.status_code} {stub_response.reason}" |
| 160 | + ) |
| 161 | + |
| 162 | + assert captured.out.count(response_log) == 2 |
| 163 | + |
| 164 | + |
141 | 165 | def test_success_with_pre_signed_distribution(upload_settings, stub_repository): |
142 | 166 | """Add GPG signature provided by user to uploaded package.""" |
143 | 167 | # Upload a pre-signed distribution |
@@ -186,7 +210,8 @@ def test_exception_for_http_status(verbose, upload_settings, stub_response, caps |
186 | 210 |
|
187 | 211 | stub_response.is_redirect = False |
188 | 212 | stub_response.status_code = 403 |
189 | | - stub_response.text = "Invalid or non-existent authentication information" |
| 213 | + stub_response.reason = "Invalid or non-existent authentication information" |
| 214 | + stub_response.text = stub_response.reason |
190 | 215 | stub_response.raise_for_status = pretend.raiser(requests.HTTPError) |
191 | 216 |
|
192 | 217 | with pytest.raises(requests.HTTPError): |
@@ -288,8 +313,11 @@ def test_exception_for_redirect( |
288 | 313 |
|
289 | 314 | stub_response = pretend.stub( |
290 | 315 | is_redirect=True, |
| 316 | + url=redirect_url, |
291 | 317 | status_code=301, |
292 | 318 | headers={"location": redirect_url}, |
| 319 | + reason="Redirect", |
| 320 | + text="", |
293 | 321 | ) |
294 | 322 |
|
295 | 323 | stub_repository = pretend.stub( |
@@ -323,7 +351,9 @@ def test_prints_skip_message_for_response( |
323 | 351 | ): |
324 | 352 | upload_settings.skip_existing = True |
325 | 353 |
|
326 | | - stub_response.status_code = 409 |
| 354 | + stub_response.status_code = 400 |
| 355 | + stub_response.reason = "File already exists" |
| 356 | + stub_response.text = stub_response.reason |
327 | 357 |
|
328 | 358 | # Do the upload, triggering the error response |
329 | 359 | stub_repository.package_is_uploaded = lambda package: False |
|
0 commit comments