From 054a720c1b7c63f306ae36d7c4a1bd3d2296ef11 Mon Sep 17 00:00:00 2001 From: jctanner Date: Thu, 9 Nov 2023 06:34:53 -0500 Subject: [PATCH] Use the correct property for the github id. (#1971) No-Issue --- galaxy_ng/app/api/v1/serializers.py | 2 +- .../community/test_v1_user_github_ids.py | 61 +++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 galaxy_ng/tests/integration/community/test_v1_user_github_ids.py diff --git a/galaxy_ng/app/api/v1/serializers.py b/galaxy_ng/app/api/v1/serializers.py index c948e8e9f0..7e0424b7d9 100644 --- a/galaxy_ng/app/api/v1/serializers.py +++ b/galaxy_ng/app/api/v1/serializers.py @@ -190,7 +190,7 @@ def get_github_id(self, obj): social_user = UserSocialAuth.objects.filter(user=obj).first() if not social_user: return None - return social_user.id + return int(social_user.uid) except Exception: return None diff --git a/galaxy_ng/tests/integration/community/test_v1_user_github_ids.py b/galaxy_ng/tests/integration/community/test_v1_user_github_ids.py new file mode 100644 index 0000000000..1a1ebae93a --- /dev/null +++ b/galaxy_ng/tests/integration/community/test_v1_user_github_ids.py @@ -0,0 +1,61 @@ +"""test_community.py - Tests related to the community featureset. +""" + +import pytest + +from ..utils import ( + SocialGithubClient, + GithubAdminClient, +) +from ..utils.legacy import ( + cleanup_social_user, +) + +pytestmark = pytest.mark.qa # noqa: F821 + + +def extract_default_config(ansible_config): + base_cfg = ansible_config('github_user_1') + cfg = {} + cfg['token'] = None + cfg['url'] = base_cfg.get('url') + cfg['auth_url'] = base_cfg.get('auth_url') + cfg['github_url'] = base_cfg.get('github_url') + cfg['github_api_url'] = base_cfg.get('github_api_url') + return cfg + + +@pytest.mark.deployment_community +def test_v1_user_github_ids(ansible_config): + """" The github_id should show up in the v1 user serializer """ + + for x in range(0, 10): + + github_user = 'deleteme' + str(x) + cleanup_social_user(github_user, ansible_config) + + user_cfg = extract_default_config(ansible_config) + user_cfg['username'] = github_user + user_cfg['password'] = 'redhat' + + # delete and recreate the github user ... + ga = GithubAdminClient() + try: + ga.delete_user(login=github_user) + except Exception: + pass + gdata = ga.create_user( + login=github_user, + password='redhat', + email=f'{github_user}@bar.com' + ) + + # Login with the user first to create the v1+v3 namespaces + with SocialGithubClient(config=user_cfg) as client: + me = client.get('_ui/v1/me/') + assert me.json()['username'] == github_user + uid = me.json()['id'] + + urr = client.get(f'v1/users/{uid}/') + udata = urr.json() + assert udata['github_id'] == gdata['id']