mirror of
https://github.com/ansible/awx.git
synced 2026-05-22 08:17:39 -02:30
Fixing test fallout from InventorySource model change
This commit is contained in:
@@ -4,17 +4,19 @@ from awx.api.versioning import reverse
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_inventory_source_notification_on_cloud_only(get, post, group_factory, user, notification_template):
|
||||
def test_inventory_source_notification_on_cloud_only(get, post, inventory_source_factory, user, notification_template):
|
||||
u = user('admin', True)
|
||||
g_cloud = group_factory('cloud')
|
||||
g_not = group_factory('not_cloud')
|
||||
cloud_is = g_cloud.inventory_source
|
||||
not_is = g_not.inventory_source
|
||||
cloud_is.source = 'ec2'
|
||||
|
||||
cloud_is = inventory_source_factory("ec2")
|
||||
cloud_is.source = "ec2"
|
||||
cloud_is.save()
|
||||
|
||||
not_is = inventory_source_factory("not_ec2")
|
||||
|
||||
url = reverse('api:inventory_source_notification_templates_any_list', kwargs={'pk': cloud_is.id})
|
||||
response = post(url, dict(id=notification_template.id), u)
|
||||
assert response.status_code == 204
|
||||
|
||||
url = reverse('api:inventory_source_notification_templates_success_list', kwargs={'pk': not_is.id})
|
||||
response = post(url, dict(id=notification_template.id), u)
|
||||
assert response.status_code == 400
|
||||
@@ -178,5 +180,5 @@ def test_delete_inventory_host(delete, host, alice, role_field, expected_status_
|
||||
@pytest.mark.django_db
|
||||
def test_inventory_source_update(post, inventory_source, alice, role_field, expected_status_code):
|
||||
if role_field:
|
||||
getattr(inventory_source.group.inventory, role_field).members.add(alice)
|
||||
getattr(inventory_source.inventory, role_field).members.add(alice)
|
||||
post(reverse('api:inventory_source_update_view', kwargs={'pk': inventory_source.id}), {}, alice, expect=expected_status_code)
|
||||
|
||||
@@ -346,7 +346,7 @@ def test_group_update_capabilities_possible(group, inventory_source, admin_user)
|
||||
group.inventory_source = inventory_source
|
||||
group.save()
|
||||
|
||||
capabilities = get_user_capabilities(admin_user, group, method_list=['start'])
|
||||
capabilities = get_user_capabilities(admin_user, group.inventory, method_list=['start'])
|
||||
assert capabilities['start']
|
||||
|
||||
|
||||
|
||||
@@ -342,12 +342,25 @@ def group(inventory):
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def inventory_source(group, inventory):
|
||||
group.inventory = inventory
|
||||
return InventorySource.objects.create(name=group.name,
|
||||
def inventory_source(inventory):
|
||||
return InventorySource.objects.create(name='single-inv-src',
|
||||
inventory=inventory, source='gce')
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def inventory_source_factory(inventory_factory):
|
||||
def invsrc(name, source=None, inventory=None):
|
||||
if inventory is None:
|
||||
inventory = inventory_factory("inv-is-%s" % name)
|
||||
if source is None:
|
||||
source = 'file'
|
||||
try:
|
||||
return inventory.inventory_sources.get(name=name)
|
||||
except:
|
||||
return inventory.inventory_sources.create(name=name, source=source)
|
||||
return invsrc
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def inventory_update(inventory_source):
|
||||
return InventoryUpdate.objects.create(inventory_source=inventory_source)
|
||||
|
||||
@@ -73,9 +73,8 @@ class TestInventoryUpdateDict():
|
||||
@pytest.fixture
|
||||
def waiting_inventory_update(self, org):
|
||||
i = Inventory.objects.create(name='inv1', organization=org)
|
||||
g = Group.objects.create(name='group1', inventory=i)
|
||||
#Inventory.groups.add(g)
|
||||
inv_src = InventorySource.objects.create(group=g)
|
||||
Group.objects.create(name='group1', inventory=i)
|
||||
inv_src = InventorySource.objects.create(inventory=i)
|
||||
iu = InventoryUpdate.objects.create(inventory_source=inv_src, status='waiting')
|
||||
return iu
|
||||
|
||||
@@ -96,13 +95,13 @@ class TestInventoryUpdateLatestDict():
|
||||
|
||||
@pytest.fixture
|
||||
def inventory_updates(self, inventory):
|
||||
g1 = Group.objects.create(name='group1', inventory=inventory)
|
||||
g2 = Group.objects.create(name='group2', inventory=inventory)
|
||||
g3 = Group.objects.create(name='group3', inventory=inventory)
|
||||
Group.objects.create(name='group1', inventory=inventory)
|
||||
Group.objects.create(name='group2', inventory=inventory)
|
||||
Group.objects.create(name='group3', inventory=inventory)
|
||||
|
||||
inv_src1 = InventorySource.objects.create(group=g1, update_on_launch=True, inventory=inventory)
|
||||
inv_src2 = InventorySource.objects.create(group=g2, update_on_launch=False, inventory=inventory)
|
||||
inv_src3 = InventorySource.objects.create(group=g3, update_on_launch=True, inventory=inventory)
|
||||
inv_src1 = InventorySource.objects.create(update_on_launch=True, inventory=inventory)
|
||||
inv_src2 = InventorySource.objects.create(update_on_launch=False, inventory=inventory)
|
||||
inv_src3 = InventorySource.objects.create(update_on_launch=True, inventory=inventory)
|
||||
|
||||
import time
|
||||
iu1 = InventoryUpdate.objects.create(inventory_source=inv_src1, status='successful')
|
||||
|
||||
@@ -276,7 +276,7 @@ def test_host_access(organization, inventory, group, user, group_factory):
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_inventory_source_credential_check(rando, inventory_source, credential):
|
||||
inventory_source.group.inventory.admin_role.members.add(rando)
|
||||
inventory_source.inventory.admin_role.members.add(rando)
|
||||
access = InventorySourceAccess(rando)
|
||||
assert not access.can_change(inventory_source, {'credential': credential})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user