mirror of
https://github.com/ansible/awx.git
synced 2026-01-19 21:51:26 -03:30
Merge pull request #6240 from wwitzel3/issue-6233
Add test to verify no duplicate results in DynamicFilter
This commit is contained in:
commit
8b0735a910
@ -41,7 +41,8 @@ class HostManager(models.Manager):
|
||||
# If we don't disable this, a filter of {'inventory': self.instance} gets automatically
|
||||
# injected by the related object mapper.
|
||||
self.core_filters = {}
|
||||
return qs & q
|
||||
qs = qs & q
|
||||
return qs.distinct()
|
||||
return qs
|
||||
|
||||
|
||||
|
||||
@ -3,6 +3,7 @@ import mock
|
||||
|
||||
# AWX
|
||||
from awx.main.models import (
|
||||
Host,
|
||||
Inventory,
|
||||
InventorySource,
|
||||
InventoryUpdate,
|
||||
@ -48,8 +49,7 @@ class TestSCMUpdateFeatures:
|
||||
|
||||
@pytest.fixture
|
||||
def setup_ec2_gce(organization):
|
||||
ec2_inv = Inventory(name='test_ec2', organization=organization)
|
||||
ec2_inv.save()
|
||||
ec2_inv = Inventory.objects.create(name='test_ec2', organization=organization)
|
||||
|
||||
ec2_source = ec2_inv.inventory_sources.create(name='test_ec2_source', source='ec2')
|
||||
for i in range(2):
|
||||
@ -57,8 +57,7 @@ def setup_ec2_gce(organization):
|
||||
ec2_host.inventory_sources.add(ec2_source)
|
||||
ec2_inv.save()
|
||||
|
||||
gce_inv = Inventory(name='test_gce', organization=organization)
|
||||
gce_inv.save()
|
||||
gce_inv = Inventory.objects.create(name='test_gce', organization=organization)
|
||||
|
||||
gce_source = gce_inv.inventory_sources.create(name='test_gce_source', source='gce')
|
||||
gce_host = gce_inv.hosts.create(name='test_gce_host')
|
||||
@ -66,6 +65,21 @@ def setup_ec2_gce(organization):
|
||||
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
|
||||
class TestHostManager:
|
||||
def test_host_filter_change(self, setup_ec2_gce, organization):
|
||||
@ -97,3 +111,11 @@ class TestHostManager:
|
||||
assert len(hosts) == 2
|
||||
assert hosts[0].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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user