From 68f884825538acfe8b863a6ba77e8f5dca1c66e1 Mon Sep 17 00:00:00 2001 From: James Tanner Date: Mon, 11 Sep 2023 12:48:34 -0400 Subject: [PATCH 1/2] Make the v1 owner__username filter case insensitive per CLI requirements. No-Issue Signed-off-by: James Tanner --- galaxy_ng/app/api/v1/filtersets.py | 7 +- .../tests/integration/community/__init__.py | 0 .../integration/community/test_v1_api.py | 74 +++++++++++++++++++ 3 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 galaxy_ng/tests/integration/community/__init__.py create mode 100644 galaxy_ng/tests/integration/community/test_v1_api.py diff --git a/galaxy_ng/app/api/v1/filtersets.py b/galaxy_ng/app/api/v1/filtersets.py index a2197bae96..76d9bc0222 100644 --- a/galaxy_ng/app/api/v1/filtersets.py +++ b/galaxy_ng/app/api/v1/filtersets.py @@ -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): diff --git a/galaxy_ng/tests/integration/community/__init__.py b/galaxy_ng/tests/integration/community/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/galaxy_ng/tests/integration/community/test_v1_api.py b/galaxy_ng/tests/integration/community/test_v1_api.py new file mode 100644 index 0000000000..c2ea45ade7 --- /dev/null +++ b/galaxy_ng/tests/integration/community/test_v1_api.py @@ -0,0 +1,74 @@ +"""test_community.py - Tests related to the community featureset. +""" + +import json +import pytest + +from urllib.parse import urlparse + +from ..utils import ( + ansible_galaxy, + build_collection, + get_client, + SocialGithubClient, + create_user, +) +from ..utils.legacy import ( + clean_all_roles, + cleanup_social_user, + wait_for_v1_task, +) + +from jsonschema import validate as validate_json + +from ..schemas import ( + schema_objectlist, +) + + +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) From 810e21480c916041d408db21db460942f27472a0 Mon Sep 17 00:00:00 2001 From: James Tanner Date: Mon, 11 Sep 2023 12:54:56 -0400 Subject: [PATCH 2/2] Lint fixes. No-Issue Signed-off-by: James Tanner --- .../tests/integration/community/test_v1_api.py | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/galaxy_ng/tests/integration/community/test_v1_api.py b/galaxy_ng/tests/integration/community/test_v1_api.py index c2ea45ade7..6b70e2f6ff 100644 --- a/galaxy_ng/tests/integration/community/test_v1_api.py +++ b/galaxy_ng/tests/integration/community/test_v1_api.py @@ -1,28 +1,14 @@ """test_community.py - Tests related to the community featureset. """ -import json import pytest -from urllib.parse import urlparse - from ..utils import ( ansible_galaxy, - build_collection, get_client, - SocialGithubClient, - create_user, ) from ..utils.legacy import ( - clean_all_roles, cleanup_social_user, - wait_for_v1_task, -) - -from jsonschema import validate as validate_json - -from ..schemas import ( - schema_objectlist, )