Files
awx/awx_collection/test/awx/test_organization.py
Jake Jackson 03cd450669 [AAP-47877] Backport collection updates (#6992)
* Update collection args (#16025)

* update collection arguments

* Add integration testing for new param

* fix: sanity check failures

---------

Co-authored-by: Sean Sullivan <ssulliva@redhat.com>
Co-authored-by: Alan Rominger <arominge@redhat.com>

* update formatting for sanity testing

* fixing indentation for sanity suite

* adjust tests to use new token name

* update tests to use aap_token instead of controller_oauthtoken

* add back aliases for backward compat

* we have integration tests that still leverage the old token name
* while we can rename these, this tells me that customers might still
  have them in the wild and breaking them in a z stream is no bueno

* revert alias changes

---------

Co-authored-by: Peter Braun <pbraun@redhat.com>
Co-authored-by: Sean Sullivan <ssulliva@redhat.com>
Co-authored-by: Alan Rominger <arominge@redhat.com>
2025-07-10 10:14:40 -04:00

94 lines
2.6 KiB
Python

from __future__ import absolute_import, division, print_function
__metaclass__ = type
import pytest
import random
from awx.main.models import Organization, Credential, CredentialType
@pytest.mark.django_db
def test_create_organization(run_module, admin_user):
module_args = {
'name': 'foo',
'description': 'barfoo',
'state': 'present',
'max_hosts': '0',
'controller_host': None,
'controller_username': None,
'controller_password': None,
'validate_certs': None,
'aap_token': None,
'controller_config_file': None,
}
result = run_module('organization', module_args, admin_user)
assert result.get('changed'), result
org = Organization.objects.get(name='foo')
assert result == {"name": "foo", "changed": True, "id": org.id, "invocation": {"module_args": module_args}}
assert org.description == 'barfoo'
@pytest.mark.django_db
def test_galaxy_credential_order(run_module, admin_user):
org = Organization.objects.create(name='foo')
cred_type = CredentialType.defaults['galaxy_api_token']()
cred_type.save()
cred_ids = []
for number in range(1, 10):
new_cred = Credential.objects.create(name=f"Galaxy Credential {number}", credential_type=cred_type, organization=org, inputs={'url': 'www.redhat.com'})
cred_ids.append(new_cred.id)
random.shuffle(cred_ids)
module_args = {
'name': 'foo',
'state': 'present',
'controller_host': None,
'controller_username': None,
'controller_password': None,
'validate_certs': None,
'aap_token': None,
'controller_config_file': None,
'galaxy_credentials': cred_ids,
}
result = run_module('organization', module_args, admin_user)
print(result)
assert result['changed'] is True
cred_order_in_org = []
for a_cred in org.galaxy_credentials.all():
cred_order_in_org.append(a_cred.id)
assert cred_order_in_org == cred_ids
# Shuffle them up and try again to make sure a new order is honored
random.shuffle(cred_ids)
module_args = {
'name': 'foo',
'state': 'present',
'controller_host': None,
'controller_username': None,
'controller_password': None,
'validate_certs': None,
'aap_token': None,
'controller_config_file': None,
'galaxy_credentials': cred_ids,
}
result = run_module('organization', module_args, admin_user)
assert result['changed'] is True
cred_order_in_org = []
for a_cred in org.galaxy_credentials.all():
cred_order_in_org.append(a_cred.id)
assert cred_order_in_org == cred_ids