Skip to content
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

Make v1 filter for owner__username case insensitive #1878

Merged
merged 2 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion galaxy_ng/app/api/v1/filtersets.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,12 @@ def github_user_filter(self, queryset, name, value):
return queryset.filter(namespace__name=value)

def owner__username_filter(self, queryset, name, value):
return queryset.filter(namespace__name=value)
"""
The cli uses this filter to find a role by the namespace.
It should be case insenstive such that Foo and foo find
the same content... hence the __iexact
"""
return queryset.filter(namespace__name__iexact=value)

def tags_filter(self, queryset, name, value):

Expand Down
Empty file.
60 changes: 60 additions & 0 deletions galaxy_ng/tests/integration/community/test_v1_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
"""test_community.py - Tests related to the community featureset.
"""

import pytest

from ..utils import (
ansible_galaxy,
get_client,
)
from ..utils.legacy import (
cleanup_social_user,
)


pytestmark = pytest.mark.qa # noqa: F821


@pytest.mark.deployment_community
def test_v1_owner_username_filter_is_case_insensitive(ansible_config):
"""" Tests if v1 sync accepts a user&limit arg """

config = ansible_config("admin")
api_client = get_client(
config=config,
request_token=False,
require_auth=True
)

github_user = 'jctannerTEST'
github_repo = 'role1'
cleanup_social_user(github_user, ansible_config)

# Run the import
import_pid = ansible_galaxy(
f"role import {github_user} {github_repo}",
ansible_config=config,
token=None,
force_token=False,
cleanup=False,
check_retcode=False
)
assert import_pid.returncode == 0

# verify filtering in the way that the CLI does it
resp = api_client(f'/api/v1/roles/?owner__username={github_user}')
assert resp['count'] == 1
assert resp['results'][0]['username'] == github_user
roleid = resp['results'][0]['id']

# verify filtering with the username as lowercase ...
resp2 = api_client(f'/api/v1/roles/?owner__username={github_user.lower()}')
assert resp2['count'] == 1
assert resp2['results'][0]['username'] == github_user
roleid2 = resp2['results'][0]['id']

# roleids should match
assert roleid == roleid2

# cleanup
cleanup_social_user(github_user, ansible_config)
Loading