diff --git a/awx/main/tests/functional/conftest.py b/awx/main/tests/functional/conftest.py index 4f8b6bc83c..e1284ce87c 100644 --- a/awx/main/tests/functional/conftest.py +++ b/awx/main/tests/functional/conftest.py @@ -511,6 +511,14 @@ def group(inventory): return inventory.groups.create(name='single-group') +@pytest.fixture +def constructed_inventory(organization): + """ + creates a new constructed inventory source + """ + 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 diff --git a/awx/main/tests/functional/test_inventory_input_constructed.py b/awx/main/tests/functional/test_inventory_input_constructed.py index ea1efb7d64..2602cf2947 100644 --- a/awx/main/tests/functional/test_inventory_input_constructed.py +++ b/awx/main/tests/functional/test_inventory_input_constructed.py @@ -3,26 +3,10 @@ from awx.main.models import Inventory from awx.api.versioning import reverse -@pytest.fixture -def constructed_inventory(organization): - """ - creates a new constructed inventory source - """ - - def factory(name, org=organization): - try: - inv = Inventory.objects.get(name=name, organization=org, kind='constructed') - except Inventory.DoesNotExist: - inv = Inventory.objects.create(name=name, organization=org, kind='constructed') - return inv - - return factory - - @pytest.mark.django_db -def test_constructed_inventory_post(post, admin_user, constructed_inventory): - inv1 = constructed_inventory(name='dummy1') - inv2 = constructed_inventory(name='dummy2') +def test_constructed_inventory_post(post, admin_user, organization): + inv1 = Inventory.objects.create(name='dummy1', kind='constructed', organization=organization) + inv2 = Inventory.objects.create(name='dummy2', kind='constructed', organization=organization) resp = post( url=reverse('api:inventory_input_inventories', kwargs={'pk': inv1.pk}), data={'id': inv2.pk}, @@ -34,9 +18,8 @@ def test_constructed_inventory_post(post, admin_user, constructed_inventory): @pytest.mark.django_db def test_add_constructed_inventory_source(post, admin_user, constructed_inventory): - inv1 = constructed_inventory(name='dummy1') resp = post( - url=reverse('api:inventory_inventory_sources_list', kwargs={'pk': inv1.pk}), + url=reverse('api:inventory_inventory_sources_list', kwargs={'pk': constructed_inventory.pk}), data={'name': 'dummy1', 'source': 'constructed'}, user=admin_user, expect=400, @@ -46,9 +29,8 @@ def test_add_constructed_inventory_source(post, admin_user, constructed_inventor @pytest.mark.django_db def test_add_constructed_inventory_host(post, admin_user, constructed_inventory): - inv1 = constructed_inventory(name='dummy1') resp = post( - url=reverse('api:inventory_hosts_list', kwargs={'pk': inv1.pk}), + url=reverse('api:inventory_hosts_list', kwargs={'pk': constructed_inventory.pk}), data={'name': 'dummy1'}, user=admin_user, expect=400, @@ -58,9 +40,8 @@ def test_add_constructed_inventory_host(post, admin_user, constructed_inventory) @pytest.mark.django_db def test_add_constructed_inventory_group(post, admin_user, constructed_inventory): - inv1 = constructed_inventory(name='dummy1') resp = post( - reverse('api:inventory_groups_list', kwargs={'pk': inv1.pk}), + reverse('api:inventory_groups_list', kwargs={'pk': constructed_inventory.pk}), data={'name': 'group-test'}, user=admin_user, expect=400, @@ -72,7 +53,7 @@ def test_add_constructed_inventory_group(post, admin_user, constructed_inventory def test_edit_constructed_inventory_source(patch, admin_user, inventory_source_factory): inv_src = inventory_source_factory(name='dummy1', source='constructed') resp = patch( - reverse('api:inventory_source_detail', kwargs={'pk': inv_src.id}), + reverse('api:inventory_source_detail', kwargs={'pk': inv_src.pk}), data={'description': inv_src.name}, user=admin_user, expect=400,