Skip to content

Commit

Permalink
Enable sending query parameters for selecting and ordering
Browse files Browse the repository at this point in the history
closes pulp#542
  • Loading branch information
lubosmj committed Sep 26, 2022
1 parent 8aaa087 commit 488e89e
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
23 changes: 23 additions & 0 deletions pulpcore/cli/common/generic.py
Expand Up @@ -533,6 +533,26 @@ def _type_callback(ctx: click.Context, param: click.Parameter, value: Optional[s
help=_("Skip a number of {entities} to show."),
)

ordering_option = pulp_option(
"--ordering",
required=False,
help=_("A field that will be used to order the results."),
)
field_option = pulp_option(
"--field",
"fields",
multiple=True,
required=False,
help=_("A list of fields that are to be selected from a result."),
)
exclude_field_option = pulp_option(
"--exclude-field",
"exclude_fields",
multiple=True,
required=False,
help=_("A list of fields that are to be excluded from a result."),
)

href_option = pulp_option(
"--href",
help=_("HREF of the {entity}"),
Expand Down Expand Up @@ -790,6 +810,9 @@ def list_command(**kwargs: Any) -> click.Command:
@pulp_command(**kwargs)
@limit_option
@offset_option
@ordering_option
@field_option
@exclude_field_option
@pass_entity_context
@pass_pulp_context
def callback(
Expand Down
43 changes: 43 additions & 0 deletions tests/scripts/pulp_file/test_query_params.sh
@@ -0,0 +1,43 @@
#!/bin/bash

# shellcheck source=tests/scripts/config.source
. "$(dirname "$(dirname "$(realpath "$0")")")"/config.source

cleanup() {
pulp file repository destroy --name aaaaaaaaaa || true
pulp file repository destroy --name bbbbbbbbbb || true
pulp file repository destroy --name cccccccccc || true
}
trap cleanup EXIT

expect_succ pulp file repository create --name aaaaaaaaaa
expect_succ pulp file repository create --name bbbbbbbbbb
expect_succ pulp file repository create --name cccccccccc

expect_succ pulp file repository list --ordering -name
ORDERED_RESULTS=$(echo "$OUTPUT" | jq -r .[].name | tr "\n" " " | xargs)
EXPECTED_RESULTS="cccccccccc bbbbbbbbbb aaaaaaaaaa"
if [[ "$ORDERED_RESULTS" != "$EXPECTED_RESULTS" ]]; then
echo "Ordered results do not match: {$ORDERED_RESULTS} != {$EXPECTED_RESULTS}"
exit 1
fi

expect_succ pulp file repository list --field name --field remote
SELECTED_FIELDS=$(echo "$OUTPUT" | jq -r ".[] | keys[]" | sort| tr "\n" " " | xargs)
EXPECTED_FIELDS="name name name remote remote remote"
if [[ "$SELECTED_FIELDS" != "$EXPECTED_FIELDS" ]]; then
echo "Selected fields do not match: {$SELECTED_FIELDS} != {$EXPECTED_FIELDS}"
exit 1
fi

expect_succ pulp file repository list --exclude-field name --exclude-field remote
EXCLUDED_FIELDS=$(echo "$OUTPUT" | jq -r ".[] | keys[]" | tr "\n" " " )

if [[ "$EXCLUDED_FIELDS" == *"name"* ]]; then
echo "The name field was not excluded from {$EXCLUDED_FIELDS}"
exit 1
fi
if [[ "$EXCLUDED_FIELDS" == *"remote"* ]]; then
echo "The name field was not excluded from {$EXCLUDED_FIELDS}"
exit 1
fi

0 comments on commit 488e89e

Please sign in to comment.