|
7 | 7 |
|
8 | 8 | import keyring |
9 | 9 | import pytest |
| 10 | +import requests |
10 | 11 |
|
11 | 12 | from poetry.core.packages.package import Package |
12 | 13 | from poetry.core.packages.utils.link import Link |
|
21 | 22 | from tests.helpers import flatten_dict |
22 | 23 | from tests.helpers import get_dependency |
23 | 24 | from tests.helpers import get_package |
| 25 | +from tests.helpers import http_setup_redirect |
24 | 26 | from tests.helpers import isolated_environment |
25 | 27 | from tests.helpers import make_entry_point_from_plugin |
26 | 28 | from tests.helpers import mock_clone |
|
35 | 37 | from pathlib import Path |
36 | 38 |
|
37 | 39 | from pytest_mock import MockerFixture |
| 40 | + from responses import RequestsMock |
38 | 41 |
|
39 | 42 |
|
40 | 43 | class TestGetPackage: |
@@ -311,18 +314,35 @@ class FakePlugin: |
311 | 314 | __module__ = "my_plugin.plugin" |
312 | 315 |
|
313 | 316 | ep = make_entry_point_from_plugin("test-plugin", FakePlugin) |
314 | | - assert isinstance(ep, metadata.EntryPoint) |
| 317 | + |
315 | 318 | assert ep.name == "test-plugin" |
316 | 319 | assert ep.group == "poetry.plugin" |
317 | 320 | assert ep.value == "my_plugin.plugin:FakePlugin" |
| 321 | + assert ep.dist is None |
318 | 322 |
|
319 | 323 | def test_creates_entry_point_without_group_attr(self) -> None: |
320 | 324 | class NoGroupPlugin: |
321 | 325 | __module__ = "my_plugin.plugin" |
322 | | - __name__ = "NoGroupPlugin" |
323 | 326 |
|
324 | 327 | ep = make_entry_point_from_plugin("test-plugin", NoGroupPlugin) |
| 328 | + |
| 329 | + assert ep.name == "test-plugin" |
325 | 330 | assert ep.group is None |
| 331 | + assert ep.value == "my_plugin.plugin:NoGroupPlugin" |
| 332 | + |
| 333 | + def test_creates_entry_point_with_dist(self, tmp_path: Path) -> None: |
| 334 | + class FakePlugin: |
| 335 | + group = "poetry.plugin" |
| 336 | + __module__ = "my_plugin.plugin" |
| 337 | + |
| 338 | + dist = metadata.Distribution.at(tmp_path) |
| 339 | + |
| 340 | + ep = make_entry_point_from_plugin("test-plugin", FakePlugin, dist=dist) |
| 341 | + |
| 342 | + assert ep.name == "test-plugin" |
| 343 | + assert ep.group == "poetry.plugin" |
| 344 | + assert ep.value == "my_plugin.plugin:FakePlugin" |
| 345 | + assert ep.dist is dist |
326 | 346 |
|
327 | 347 |
|
328 | 348 | class TestMockMetadataEntryPoints: |
@@ -386,6 +406,39 @@ def test_handles_empty_dict(self) -> None: |
386 | 406 | assert flatten_dict({}) == {} |
387 | 407 |
|
388 | 408 |
|
| 409 | +class TestHttpSetupRedirect: |
| 410 | + def test_redirects_to_original_url(self, http: RequestsMock) -> None: |
| 411 | + http_setup_redirect(http, "GET") |
| 412 | + |
| 413 | + response = requests.get( |
| 414 | + "https://redirect.example.com/files/demo.whl?download=1", |
| 415 | + allow_redirects=False, |
| 416 | + ) |
| 417 | + |
| 418 | + assert response.status_code == 301 |
| 419 | + assert ( |
| 420 | + response.headers["Location"] |
| 421 | + == "https://example.com/files/demo.whl?download=1" |
| 422 | + ) |
| 423 | + |
| 424 | + def test_uses_custom_status_code(self, http: RequestsMock) -> None: |
| 425 | + http_setup_redirect(http, "GET", status_code=307) |
| 426 | + |
| 427 | + response = requests.get( |
| 428 | + "https://redirect.example.com/files/demo.whl", |
| 429 | + allow_redirects=False, |
| 430 | + ) |
| 431 | + |
| 432 | + assert response.status_code == 307 |
| 433 | + assert response.headers["Location"] == "https://example.com/files/demo.whl" |
| 434 | + |
| 435 | + def test_only_registers_requested_methods(self, http: RequestsMock) -> None: |
| 436 | + http_setup_redirect(http, "GET") |
| 437 | + |
| 438 | + with pytest.raises(requests.exceptions.ConnectionError): |
| 439 | + requests.post("https://redirect.example.com/files/demo.whl") |
| 440 | + |
| 441 | + |
389 | 442 | class TestSwitchWorkingDirectory: |
390 | 443 | @pytest.mark.parametrize("remove", [False, True]) |
391 | 444 | @pytest.mark.parametrize("raise_error", [False, True]) |
|
0 commit comments