Files
awx/awx_collection/test/awx/test_organization.py
AlanCoding 55a7591f89 Resolve actions conflicts and delete unwatned files
Bump migrations and delete some files

Resolve remaining conflicts

Fix requirements

Flake8 fixes

Prefer devel changes for schema

Use correct versions

Remove sso connected stuff

Update to modern actions and collection fixes

Remove unwated alias

Version problems in actions

Fix more versioning problems

Update warning string

Messed it up again

Shorten exception

More removals

Remove pbr license

Remove tests deleted in devel

Remove unexpected files

Remove some content missed in the rebase

Use sleep_task from devel

Restore devel live conftest file

Add in settings that got missed

Prefer devel version of collection test

Finish repairing .github path

Remove unintended test file duplication

Undo more unintended file additions
2025-09-17 10:23:19 -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