diff --git a/awx/main/tests/functional/api/test_inventory.py b/awx/main/tests/functional/api/test_inventory.py index 30b92ac8678b..c86515a0ad6b 100644 --- a/awx/main/tests/functional/api/test_inventory.py +++ b/awx/main/tests/functional/api/test_inventory.py @@ -609,23 +609,9 @@ def test_get_constructed_inventory(self, constructed_inventory, admin_user, get) r = get(url=reverse('api:constructed_inventory_detail', kwargs={'pk': constructed_inventory.pk}), user=admin_user, expect=200) assert r.data['update_cache_timeout'] == 53 - def test_patch_constructed_inventory(self, constructed_inventory, admin_user, patch): - inv_src = constructed_inventory.inventory_sources.first() - assert inv_src.update_cache_timeout == 0 - assert inv_src.limit == '' - r = patch( - url=reverse('api:constructed_inventory_detail', kwargs={'pk': constructed_inventory.pk}), - data=dict(update_cache_timeout=54, limit='foobar'), - user=admin_user, - expect=200, - ) - assert r.data['update_cache_timeout'] == 54 - inv_src = constructed_inventory.inventory_sources.first() - assert inv_src.update_cache_timeout == 54 - assert inv_src.limit == 'foobar' - def test_patch_constructed_inventory_generated_source_limits_editable_fields(self, constructed_inventory, admin_user, project, patch, inventory): - inv_src = inventory.first() + queryset, first_inventory_pk = inventory + inv_src = queryset.first() r = patch( url=inv_src.get_absolute_url(), data={ @@ -646,6 +632,7 @@ def test_patch_constructed_inventory_generated_source_limits_editable_fields(sel assert inv_src.source_project == inv_src_after_err.source_project assert inv_src.source_path == inv_src_after_err.source_path assert inv_src.source_vars == inv_src_after_err.source_vars + print(r.data) def test_patch_constructed_inventory_generated_source_allows_source_vars_edit(self, constructed_inventory, admin_user, patch): inv_src = constructed_inventory.inventory_sources.first() diff --git a/awx/main/tests/functional/conftest.py b/awx/main/tests/functional/conftest.py index 8a100b86d078..a3a57bfe4b1d 100644 --- a/awx/main/tests/functional/conftest.py +++ b/awx/main/tests/functional/conftest.py @@ -47,6 +47,7 @@ from awx.main.models.oauth import OAuth2Application as Application from awx.main.models.execution_environments import ExecutionEnvironment from awx.main.utils import is_testing +from awx.main.utils.plugins import compute_cloud_inventory_sources __SWAGGER_REQUESTS__ = {} @@ -351,9 +352,25 @@ def kube_credential(credentialtype_kube): ) +# @pytest.fixture +# def inventory(organization): +# return organization.inventories.create(name="test-inv") + + @pytest.fixture def inventory(organization): - return organization.inventories.create(name="test-inv") + available_providers = compute_cloud_inventory_sources() + + if available_providers: + queryset = organization.inventories.all() + first_inventory = queryset.first() + if first_inventory: + # Return a tuple with the queryset and the pk of the first object + return queryset, first_inventory.pk + else: + raise ValueError("No inventories found in the queryset") + else: + raise ValueError("No available cloud providers found") @pytest.fixture @@ -542,10 +559,19 @@ def constructed_inventory(organization): return Inventory.objects.create(name='dummy1', kind='constructed', organization=organization) +# @pytest.fixture +# def inventory_source(inventory): +# # by making it ec2, the credential is not required +# return InventorySource.objects.create(name='single-inv-src', inventory=inventory, source='ec2') @pytest.fixture def inventory_source(inventory): - # by making it ec2, the credential is not required - return InventorySource.objects.create(name='single-inv-src', inventory=inventory, source='ec2') + + available_providers = compute_cloud_inventory_sources() + + if 'ec2' in available_providers: + return InventorySource.objects.create(name='single-inv-src', inventory=inventory, source='ec2') + else: + raise ValueError("EC2 cloud provider not found") @pytest.fixture