mirror of
https://github.com/ansible/awx.git
synced 2026-05-07 17:37:37 -02:30
Test that the DynamicFilter does not return duplicates.
This commit is contained in:
@@ -3,6 +3,7 @@ import mock
|
|||||||
|
|
||||||
# AWX
|
# AWX
|
||||||
from awx.main.models import (
|
from awx.main.models import (
|
||||||
|
Host,
|
||||||
Inventory,
|
Inventory,
|
||||||
InventorySource,
|
InventorySource,
|
||||||
InventoryUpdate,
|
InventoryUpdate,
|
||||||
@@ -48,8 +49,7 @@ class TestSCMUpdateFeatures:
|
|||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def setup_ec2_gce(organization):
|
def setup_ec2_gce(organization):
|
||||||
ec2_inv = Inventory(name='test_ec2', organization=organization)
|
ec2_inv = Inventory.objects.create(name='test_ec2', organization=organization)
|
||||||
ec2_inv.save()
|
|
||||||
|
|
||||||
ec2_source = ec2_inv.inventory_sources.create(name='test_ec2_source', source='ec2')
|
ec2_source = ec2_inv.inventory_sources.create(name='test_ec2_source', source='ec2')
|
||||||
for i in range(2):
|
for i in range(2):
|
||||||
@@ -57,8 +57,7 @@ def setup_ec2_gce(organization):
|
|||||||
ec2_host.inventory_sources.add(ec2_source)
|
ec2_host.inventory_sources.add(ec2_source)
|
||||||
ec2_inv.save()
|
ec2_inv.save()
|
||||||
|
|
||||||
gce_inv = Inventory(name='test_gce', organization=organization)
|
gce_inv = Inventory.objects.create(name='test_gce', organization=organization)
|
||||||
gce_inv.save()
|
|
||||||
|
|
||||||
gce_source = gce_inv.inventory_sources.create(name='test_gce_source', source='gce')
|
gce_source = gce_inv.inventory_sources.create(name='test_gce_source', source='gce')
|
||||||
gce_host = gce_inv.hosts.create(name='test_gce_host')
|
gce_host = gce_inv.hosts.create(name='test_gce_host')
|
||||||
@@ -66,6 +65,21 @@ def setup_ec2_gce(organization):
|
|||||||
gce_inv.save()
|
gce_inv.save()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def setup_inventory_groups(inventory, group_factory):
|
||||||
|
|
||||||
|
groupA = group_factory('test_groupA')
|
||||||
|
groupB = group_factory('test_groupB')
|
||||||
|
|
||||||
|
host = Host.objects.create(name='single_host', inventory=inventory)
|
||||||
|
|
||||||
|
groupA.hosts.add(host)
|
||||||
|
groupA.save()
|
||||||
|
|
||||||
|
groupB.hosts.add(host)
|
||||||
|
groupB.save()
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
class TestHostManager:
|
class TestHostManager:
|
||||||
def test_host_filter_change(self, setup_ec2_gce, organization):
|
def test_host_filter_change(self, setup_ec2_gce, organization):
|
||||||
@@ -97,3 +111,11 @@ class TestHostManager:
|
|||||||
assert len(hosts) == 2
|
assert len(hosts) == 2
|
||||||
assert hosts[0].inventory_sources.first().source == 'ec2'
|
assert hosts[0].inventory_sources.first().source == 'ec2'
|
||||||
assert hosts[1].inventory_sources.first().source == 'ec2'
|
assert hosts[1].inventory_sources.first().source == 'ec2'
|
||||||
|
|
||||||
|
def test_host_objects_no_dupes(self, setup_inventory_groups, organization):
|
||||||
|
dynamic_inventory = Inventory(name='dynamic',
|
||||||
|
kind='dynamic',
|
||||||
|
organization=organization,
|
||||||
|
host_filter='groups__name=test_groupA or groups__name=test_groupB')
|
||||||
|
dynamic_inventory.save()
|
||||||
|
assert len(dynamic_inventory.hosts.all()) == 1
|
||||||
|
|||||||
Reference in New Issue
Block a user