Skip to content

Commit

Permalink
Attempt to update fixtures and begin fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
djyasin committed Oct 11, 2024
1 parent 9a8a34b commit 19c8fea
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 19 deletions.
19 changes: 3 additions & 16 deletions awx/main/tests/functional/api/test_inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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={
Expand All @@ -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()
Expand Down
32 changes: 29 additions & 3 deletions awx/main/tests/functional/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__ = {}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 19c8fea

Please sign in to comment.