Skip to content

Commit

Permalink
Renamed get_or_create_with_default_galaxy_cred to get_or_create_org_...
Browse files Browse the repository at this point in the history
  • Loading branch information
john-westcott-iv committed Jan 26, 2023
1 parent 2743bc4 commit 82650d3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions awx/sso/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,10 @@ def create_org_and_teams(org_list, team_map, adapter, can_create=True):
if org_name and org_name not in existing_orgs:
logger.info("{} adapter is creating org {}".format(adapter, org_name))
try:
new_org = get_or_create_with_default_galaxy_cred(name=org_name)
new_org = get_or_create_org_with_default_galaxy_cred(name=org_name)
except IntegrityError:
# Another thread must have created this org before we did so now we need to get it
new_org = get_or_create_with_default_galaxy_cred(name=org_name)
new_org = get_or_create_org_with_default_galaxy_cred(name=org_name)
# Add the org name to the existing orgs since we created it and we may need it to build the teams below
existing_orgs[org_name] = new_org.id

Expand All @@ -156,7 +156,7 @@ def create_org_and_teams(org_list, team_map, adapter, can_create=True):
# ==============================================================================================================


def get_or_create_with_default_galaxy_cred(**kwargs):
def get_or_create_org_with_default_galaxy_cred(**kwargs):
from awx.main.models import Organization, Credential

(org, org_created) = Organization.objects.get_or_create(**kwargs)
Expand Down
6 changes: 3 additions & 3 deletions awx/sso/social_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import re
import logging

from awx.sso.common import get_or_create_with_default_galaxy_cred
from awx.sso.common import get_or_create_org_with_default_galaxy_cred

logger = logging.getLogger('awx.sso.social_pipeline')

Expand Down Expand Up @@ -53,7 +53,7 @@ def update_user_orgs(backend, details, user=None, *args, **kwargs):
organization_name = organization_alias
else:
organization_name = org_name
org = get_or_create_with_default_galaxy_cred(name=organization_name)
org = get_or_create_org_with_default_galaxy_cred(name=organization_name)

# Update org admins from expression(s).
remove = bool(org_opts.get('remove', True))
Expand Down Expand Up @@ -81,7 +81,7 @@ def update_user_teams(backend, details, user=None, *args, **kwargs):
# Get or create the org to update.
if 'organization' not in team_opts:
continue
org = get_or_create_with_default_galaxy_cred(name=team_opts['organization'])
org = get_or_create_org_with_default_galaxy_cred(name=team_opts['organization'])

# Update team members from expression(s).
team = Team.objects.get_or_create(name=team_name, organization=org)[0]
Expand Down
10 changes: 5 additions & 5 deletions awx/sso/tests/functional/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from django.utils.timezone import now

from awx.main.models import Credential, CredentialType, Organization, Team, User
from awx.sso.common import get_orgs_by_ids, reconcile_users_org_team_mappings, create_org_and_teams, get_or_create_with_default_galaxy_cred
from awx.sso.common import get_orgs_by_ids, reconcile_users_org_team_mappings, create_org_and_teams, get_or_create_org_with_default_galaxy_cred


@pytest.mark.django_db
Expand Down Expand Up @@ -255,24 +255,24 @@ def test_create_org_and_teams(self, galaxy_credential, org_list, team_map, can_c
assert Organization.objects.count() == org_count
assert Team.objects.count() == team_count

def test_get_or_create_with_default_galaxy_cred_add_galaxy_cred(self, galaxy_credential):
def test_get_or_create_org_with_default_galaxy_cred_add_galaxy_cred(self, galaxy_credential):
# If this method creates the org it should get the default galaxy credential
num_orgs = 4
for number in range(1, (num_orgs + 1)):
get_or_create_with_default_galaxy_cred(name=f"Default {number}")
get_or_create_org_with_default_galaxy_cred(name=f"Default {number}")

assert Organization.objects.count() == 4

for o in Organization.objects.all():
assert o.galaxy_credentials.count() == 1
assert o.galaxy_credentials.first().name == 'Ansible Galaxy'

def test_get_or_create_with_default_galaxy_cred_no_galaxy_cred(self, galaxy_credential):
def test_get_or_create_org_with_default_galaxy_cred_no_galaxy_cred(self, galaxy_credential):
# If the org is pre-created, we should not add the galaxy_credential
num_orgs = 4
for number in range(1, (num_orgs + 1)):
Organization.objects.create(name=f"Default {number}")
get_or_create_with_default_galaxy_cred(name=f"Default {number}")
get_or_create_org_with_default_galaxy_cred(name=f"Default {number}")

assert Organization.objects.count() == 4

Expand Down

0 comments on commit 82650d3

Please sign in to comment.