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
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)

View File

@ -186,7 +186,7 @@ class TestAccessListCapabilities:
"Establish that exactly 1 type of access exists so we know the entry is the right one"
assert len(data['results']) == 1
assert len(data['results'][0]['summary_fields'][sublist]) == 1
def test_access_list_direct_access_capability(
self, inventory, rando, get, mocker, mock_access_method):
inventory.admin_role.members.add(rando)
@ -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']

View File

@ -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)

View File

@ -33,7 +33,7 @@ class TestProjectUpdateLatestDictDict():
pu = ProjectUpdate.objects.create(project=p, status='successful', finished=tz_now() - timedelta(seconds=20))
return (p, pu)
# Failed project updates newer than successful ones
@pytest.fixture
def multiple_project_updates(self):
@ -42,9 +42,9 @@ class TestProjectUpdateLatestDictDict():
epoch = tz_now()
successful_pus = [ProjectUpdate.objects.create(project=p,
status='successful',
status='successful',
finished=epoch - timedelta(seconds=100 + i)) for i in xrange(0, 5)]
failed_pus = [ProjectUpdate.objects.create(project=p,
failed_pus = [ProjectUpdate.objects.create(project=p,
status='failed',
finished=epoch - timedelta(seconds=100 - len(successful_pus) + i)) for i in xrange(0, 5)]
return (p, failed_pus, successful_pus)
@ -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')
@ -114,7 +113,7 @@ class TestInventoryUpdateLatestDict():
@pytest.mark.django_db
def test_filter_partial(self, inventory, inventory_updates):
tasks = InventoryUpdateLatestDict.filter_partial([inventory.id])
inventory_updates_expected = [inventory_updates[0], inventory_updates[2]]
@ -123,4 +122,4 @@ class TestInventoryUpdateLatestDict():
task_ids = [task['id'] for task in tasks]
for inventory_update in inventory_updates_expected:
inventory_update.id in task_ids

View File

@ -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})