Skip to content

Commit

Permalink
Repository version user-entered options order fix
Browse files Browse the repository at this point in the history
The order in which the user enters options (--version, --repository, ..) no longer matters for
'pulp <plugin> repository version' commands, since all API calls are now deferred to after the
options' callbacks are processed.

closes pulp#650
  • Loading branch information
MichalPysik committed Feb 15, 2024
1 parent 6bfb7e3 commit 6cc4258
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGES/650.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
User-entered order of parameters no longer matters for repository version commands.
12 changes: 6 additions & 6 deletions pulpcore/cli/common/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,14 +414,14 @@ def _href_callback(
def _version_callback(
ctx: click.Context, param: click.Parameter, value: t.Optional[int]
) -> t.Optional[int]:
entity_ctx = ctx.find_object(PulpEntityContext)
assert entity_ctx is not None
repository_ctx = ctx.find_object(PulpRepositoryContext)
assert repository_ctx is not None
repository_version_ctx = ctx.find_object(PulpRepositoryVersionContext)
assert repository_version_ctx is not None
if value is not None:
entity_ctx.pulp_href = f"{repository_ctx.entity['versions_href']}{value}/"
repository_version_ctx.entity = {"number": value}
else:
entity_ctx.pulp_href = repository_ctx.entity["latest_version_href"]
repository_ctx = ctx.find_object(PulpRepositoryContext)
assert repository_ctx is not None
repository_version_ctx.pulp_href = repository_ctx.entity["latest_version_href"]
return value


Expand Down
2 changes: 1 addition & 1 deletion tests/scripts/pulp_container/test_copy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ expect_succ pulp container repository content -t "manifest" list --repository "c
test "$(echo "$OUTPUT" | jq -r 'length')" -eq 1
test "$(echo "$OUTPUT" | jq -r '.[0].digest')" = "$DIGEST"

expect_succ pulp container repository copy-manifest --repository "cli_test_dest_container_repository" --source "cli_test_source_container_repository" --version "1" --media-type "application/vnd.docker.distribution.manifest.v2+json"
expect_succ pulp container repository copy-manifest --version "1" --repository "cli_test_dest_container_repository" --source "cli_test_source_container_repository" --media-type "application/vnd.docker.distribution.manifest.v2+json"
expect_succ pulp container repository content -t "manifest" list --repository "cli_test_dest_container_repository" --version "2"
COPIED="$(echo "$OUTPUT" | jq -r 'length')"
test "$COPIED" -gt 1
Expand Down
2 changes: 1 addition & 1 deletion tests/scripts/pulp_file/test_sync.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ expect_succ pulp file repository version repair --repository "cli_test_file_repo
test "$(echo "$OUTPUT" | jq -r '.state')" = "completed"

# Delete version again
expect_succ pulp file repository version destroy --repository "cli_test_file_repository" --version 1
expect_succ pulp file repository version destroy --version 1 --repository "cli_test_file_repository"

# Test autopublish
expect_succ pulp file repository create --name "$autopublish_repo" --remote "cli_test_file_remote" --autopublish
Expand Down
2 changes: 1 addition & 1 deletion tests/scripts/pulp_rpm/test_rpm_sync_publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ then
fi

expect_succ pulp rpm repository version list --repository "cli_test_rpm_repository"
expect_succ pulp rpm repository version repair --repository "cli_test_rpm_repository" --version 1
expect_succ pulp rpm repository version repair --version 1 --repository "cli_test_rpm_repository"

expect_succ pulp rpm repository update --name "cli_test_rpm_repository" --retain-package-versions 2
expect_succ pulp rpm repository show --name "cli_test_rpm_repository"
Expand Down
43 changes: 43 additions & 0 deletions tests/test_help_pages.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import typing as t

from functools import reduce

import click
import pytest
from click.testing import CliRunner
Expand Down Expand Up @@ -57,3 +59,44 @@ def test_access_help(no_api: None, subtests: SubTests) -> None:
assert result.stdout.startswith("Usage:") or result.stdout.startswith(
"DeprecationWarning:"
)


@pytest.mark.parametrize(
"command,options",
[
(
[
"file",
"repository",
"show",
],
[
"--repository",
"dummy",
],
),
pytest.param(
[
"file",
"repository",
"version",
"show",
],
[
"--repository",
"dummy",
"--version",
"42",
],
),
],
)
def test_deferred_context(monkeypatch, no_api, command, options):
monkeypatch.setattr(
reduce(lambda com, sub: com.commands[sub], command, main),
"callback",
lambda: None,
)
runner = CliRunner()
result = runner.invoke(main, command + options)
assert result.exit_code == 0

0 comments on commit 6cc4258

Please sign in to comment.