Make org an optional parameter for both inv source and inv source update modules

This commit is contained in:
beeankha
2020-09-04 18:40:18 -04:00
parent 4133ec974b
commit a0b8f6a25d
6 changed files with 40 additions and 37 deletions

View File

@@ -24,12 +24,11 @@ def project(base_inventory):
@pytest.mark.django_db
def test_inventory_source_create(run_module, admin_user, base_inventory, project, organization):
def test_inventory_source_create(run_module, admin_user, base_inventory, project):
source_path = '/var/lib/awx/example_source_path/'
result = run_module('tower_inventory_source', dict(
name='foo',
inventory=base_inventory.name,
organization='test-org',
state='present',
source='scm',
source_path=source_path,
@@ -46,6 +45,30 @@ def test_inventory_source_create(run_module, admin_user, base_inventory, project
}
@pytest.mark.django_db
def test_create_inventory_source_implied_org(run_module, admin_user):
org = Organization.objects.create(name='test-org')
inv = Inventory.objects.create(name='test-inv', organization=org)
# Credential is not required for ec2 source, because of IAM roles
result = run_module('tower_inventory_source', dict(
name='Test Inventory Source',
inventory='test-inv',
source='ec2',
state='present'
), admin_user)
assert result.pop('changed', None), result
inv_src = InventorySource.objects.get(name='Test Inventory Source')
assert inv_src.inventory == inv
result.pop('invocation')
assert result == {
"name": "Test Inventory Source",
"id": inv_src.id,
}
@pytest.mark.django_db
def test_create_inventory_source_multiple_orgs(run_module, admin_user):
org = Organization.objects.create(name='test-org')
@@ -82,7 +105,6 @@ def test_create_inventory_source_with_venv(run_module, admin_user, base_inventor
result = run_module('tower_inventory_source', dict(
name='foo',
inventory=base_inventory.name,
organization='test-org',
state='present',
source='scm',
source_project=project.name,
@@ -99,7 +121,7 @@ def test_create_inventory_source_with_venv(run_module, admin_user, base_inventor
@pytest.mark.django_db
def test_custom_venv_no_op(run_module, admin_user, base_inventory, mocker, project, organization):
def test_custom_venv_no_op(run_module, admin_user, base_inventory, mocker, project):
"""If the inventory source is modified, then it should not blank fields
unrelated to the params that the user passed.
This enforces assumptions about the behavior of the AnsibleModule
@@ -119,7 +141,6 @@ def test_custom_venv_no_op(run_module, admin_user, base_inventory, mocker, proje
name='foo',
description='this is the changed description',
inventory=base_inventory.name,
organization='test-org',
source='scm', # is required, but behavior is arguable
state='present',
source_project=project.name,
@@ -136,7 +157,6 @@ def test_falsy_value(run_module, admin_user, base_inventory):
result = run_module('tower_inventory_source', dict(
name='falsy-test',
inventory=base_inventory.name,
organization='test-org',
source='ec2',
update_on_launch=True
), admin_user)
@@ -149,7 +169,6 @@ def test_falsy_value(run_module, admin_user, base_inventory):
result = run_module('tower_inventory_source', dict(
name='falsy-test',
inventory=base_inventory.name,
organization='test-org',
# source='ec2',
update_on_launch=False
), admin_user)
@@ -185,7 +204,6 @@ def test_missing_required_credential(run_module, admin_user, base_inventory):
result = run_module('tower_inventory_source', dict(
name='Test Azure Source',
inventory=base_inventory.name,
organization='test-org',
source='azure_rm',
state='present'
), admin_user)
@@ -199,7 +217,6 @@ def test_source_project_not_for_cloud(run_module, admin_user, base_inventory, pr
result = run_module('tower_inventory_source', dict(
name='Test ec2 Inventory Source',
inventory=base_inventory.name,
organization='test-org',
source='ec2',
state='present',
source_project=project.name
@@ -214,7 +231,6 @@ def test_source_path_not_for_cloud(run_module, admin_user, base_inventory):
result = run_module('tower_inventory_source', dict(
name='Test ec2 Inventory Source',
inventory=base_inventory.name,
organization='test-org',
source='ec2',
state='present',
source_path='where/am/I'
@@ -228,7 +244,6 @@ def test_source_path_not_for_cloud(run_module, admin_user, base_inventory):
def test_scm_source_needs_project(run_module, admin_user, base_inventory):
result = run_module('tower_inventory_source', dict(
name='SCM inventory without project',
organization='test-org',
inventory=base_inventory.name,
state='present',
source='scm',