Skip to content

Commit

Permalink
Make v1 filter for owner__username case insensitive (#1878)
Browse files Browse the repository at this point in the history
* Make the v1 owner__username filter case insensitive per CLI requirements.

No-Issue

Signed-off-by: James Tanner <[email protected]>

* Lint fixes.

No-Issue

Signed-off-by: James Tanner <[email protected]>

---------

Signed-off-by: James Tanner <[email protected]>
  • Loading branch information
jctanner authored Sep 11, 2023
1 parent 0b2fd75 commit 637a583
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 1 deletion.
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)

0 comments on commit 637a583

Please sign in to comment.