-
Notifications
You must be signed in to change notification settings - Fork 2.4k
fix(publish): normalize legacy repository URL trailing slash #10732
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -82,6 +82,31 @@ def test_publish_can_publish_to_given_repository( | |
| assert f"Publishing {project_name} ({uploader_version}) to foo" in io.fetch_output() | ||
|
|
||
|
|
||
| def test_publish_normalizes_legacy_repository_url_without_trailing_slash( | ||
| fixture_dir: FixtureDirGetter, mocker: MockerFixture, config: Config | ||
| ) -> None: | ||
| uploader_auth = mocker.patch("poetry.publishing.uploader.Uploader.auth") | ||
| uploader_upload = mocker.patch("poetry.publishing.uploader.Uploader.upload") | ||
|
|
||
| poetry = Factory().create_poetry(fixture_dir("sample_project")) | ||
| poetry._config = config | ||
| poetry.config.merge( | ||
| { | ||
|
Comment on lines
+85
to
+94
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (testing): Add complementary tests to cover non-legacy and already-normalized URLs This test captures the
You can either add two focused tests or parametrize this one over input/expected URLs to more fully exercise the normalization helper and guard against similar regressions. Suggested implementation: @pytest.mark.parametrize(
("configured_url", "expected_url"),
[
("https://test.pypi.org/legacy", "https://test.pypi.org/legacy/"),
("https://test.pypi.org/legacy/", "https://test.pypi.org/legacy/"),
("https://test.pypi.org/simple", "https://test.pypi.org/simple"),
],
)
def test_publish_normalizes_legacy_repository_url_without_trailing_slash(
fixture_dir: FixtureDirGetter,
mocker: MockerFixture,
config: Config,
configured_url: str,
expected_url: str,
) -> None: poetry.config.merge(
{
"repositories": {"testpypi": {"url": configured_url}},
|
||
| "repositories": {"testpypi": {"url": "https://test.pypi.org/legacy"}}, | ||
| "http-basic": {"testpypi": {"username": "foo", "password": "bar"}}, | ||
| } | ||
| ) | ||
|
|
||
| publisher = Publisher(poetry, NullIO()) | ||
| publisher.publish("testpypi", None, None) | ||
|
|
||
| assert uploader_auth.call_args == [("foo", "bar")] | ||
| assert uploader_upload.call_args == [ | ||
|
Comment on lines
+103
to
+104
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue (testing): Use mock's assertion helpers instead of comparing
uploader_auth.assert_called_once_with("foo", "bar")
uploader_upload.assert_called_once_with(
"https://test.pypi.org/legacy/",
cert=True,
client_cert=None,
dry_run=False,
skip_existing=False,
)This makes the expectations explicit and avoids depending on the internal structure of |
||
| ("https://test.pypi.org/legacy/",), | ||
| {"cert": True, "client_cert": None, "dry_run": False, "skip_existing": False}, | ||
| ] | ||
|
|
||
|
|
||
| def test_publish_raises_error_for_undefined_repository( | ||
| fixture_dir: FixtureDirGetter, config: Config | ||
| ) -> None: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't this be good enough?