Fixing test fallout from InventorySource model change

This commit is contained in:
Wayne Witzel III
2017-04-07 00:37:12 -04:00
parent c784c96449
commit 4b5b56c284
5 changed files with 41 additions and 27 deletions

View File

@@ -4,17 +4,19 @@ from awx.api.versioning import reverse
@pytest.mark.django_db @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) u = user('admin', True)
g_cloud = group_factory('cloud')
g_not = group_factory('not_cloud') cloud_is = inventory_source_factory("ec2")
cloud_is = g_cloud.inventory_source cloud_is.source = "ec2"
not_is = g_not.inventory_source
cloud_is.source = 'ec2'
cloud_is.save() cloud_is.save()
not_is = inventory_source_factory("not_ec2")
url = reverse('api:inventory_source_notification_templates_any_list', kwargs={'pk': cloud_is.id}) url = reverse('api:inventory_source_notification_templates_any_list', kwargs={'pk': cloud_is.id})
response = post(url, dict(id=notification_template.id), u) response = post(url, dict(id=notification_template.id), u)
assert response.status_code == 204 assert response.status_code == 204
url = reverse('api:inventory_source_notification_templates_success_list', kwargs={'pk': not_is.id}) url = reverse('api:inventory_source_notification_templates_success_list', kwargs={'pk': not_is.id})
response = post(url, dict(id=notification_template.id), u) response = post(url, dict(id=notification_template.id), u)
assert response.status_code == 400 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 @pytest.mark.django_db
def test_inventory_source_update(post, inventory_source, alice, role_field, expected_status_code): def test_inventory_source_update(post, inventory_source, alice, role_field, expected_status_code):
if role_field: 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) post(reverse('api:inventory_source_update_view', kwargs={'pk': inventory_source.id}), {}, alice, expect=expected_status_code)

View File

@@ -346,7 +346,7 @@ def test_group_update_capabilities_possible(group, inventory_source, admin_user)
group.inventory_source = inventory_source group.inventory_source = inventory_source
group.save() 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'] assert capabilities['start']

View File

@@ -342,12 +342,25 @@ def group(inventory):
@pytest.fixture @pytest.fixture
def inventory_source(group, inventory): def inventory_source(inventory):
group.inventory = inventory return InventorySource.objects.create(name='single-inv-src',
return InventorySource.objects.create(name=group.name,
inventory=inventory, source='gce') 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 @pytest.fixture
def inventory_update(inventory_source): def inventory_update(inventory_source):
return InventoryUpdate.objects.create(inventory_source=inventory_source) return InventoryUpdate.objects.create(inventory_source=inventory_source)

View File

@@ -73,9 +73,8 @@ class TestInventoryUpdateDict():
@pytest.fixture @pytest.fixture
def waiting_inventory_update(self, org): def waiting_inventory_update(self, org):
i = Inventory.objects.create(name='inv1', organization=org) i = Inventory.objects.create(name='inv1', organization=org)
g = Group.objects.create(name='group1', inventory=i) Group.objects.create(name='group1', inventory=i)
#Inventory.groups.add(g) inv_src = InventorySource.objects.create(inventory=i)
inv_src = InventorySource.objects.create(group=g)
iu = InventoryUpdate.objects.create(inventory_source=inv_src, status='waiting') iu = InventoryUpdate.objects.create(inventory_source=inv_src, status='waiting')
return iu return iu
@@ -96,13 +95,13 @@ class TestInventoryUpdateLatestDict():
@pytest.fixture @pytest.fixture
def inventory_updates(self, inventory): def inventory_updates(self, inventory):
g1 = Group.objects.create(name='group1', inventory=inventory) Group.objects.create(name='group1', inventory=inventory)
g2 = Group.objects.create(name='group2', inventory=inventory) Group.objects.create(name='group2', inventory=inventory)
g3 = Group.objects.create(name='group3', inventory=inventory) Group.objects.create(name='group3', inventory=inventory)
inv_src1 = InventorySource.objects.create(group=g1, update_on_launch=True, inventory=inventory) inv_src1 = InventorySource.objects.create(update_on_launch=True, inventory=inventory)
inv_src2 = InventorySource.objects.create(group=g2, update_on_launch=False, inventory=inventory) inv_src2 = InventorySource.objects.create(update_on_launch=False, inventory=inventory)
inv_src3 = InventorySource.objects.create(group=g3, update_on_launch=True, inventory=inventory) inv_src3 = InventorySource.objects.create(update_on_launch=True, inventory=inventory)
import time import time
iu1 = InventoryUpdate.objects.create(inventory_source=inv_src1, status='successful') iu1 = InventoryUpdate.objects.create(inventory_source=inv_src1, status='successful')

View File

@@ -276,7 +276,7 @@ def test_host_access(organization, inventory, group, user, group_factory):
@pytest.mark.django_db @pytest.mark.django_db
def test_inventory_source_credential_check(rando, inventory_source, credential): 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) access = InventorySourceAccess(rando)
assert not access.can_change(inventory_source, {'credential': credential}) assert not access.can_change(inventory_source, {'credential': credential})