Dynamic -> Smart Inventory

This commit is contained in:
Wayne Witzel III
2017-05-17 16:25:40 -04:00
parent a539a820a7
commit d652ed16d0
9 changed files with 67 additions and 67 deletions

View File

@@ -83,39 +83,39 @@ def setup_inventory_groups(inventory, group_factory):
@pytest.mark.django_db
class TestHostManager:
def test_host_filter_change(self, setup_ec2_gce, organization):
dynamic_inventory = Inventory(name='dynamic',
kind='dynamic',
organization=organization,
host_filter='inventory_sources__source=ec2')
dynamic_inventory.save()
assert len(dynamic_inventory.hosts.all()) == 2
smart_inventory = Inventory(name='smart',
kind='smart',
organization=organization,
host_filter='inventory_sources__source=ec2')
smart_inventory.save()
assert len(smart_inventory.hosts.all()) == 2
dynamic_inventory.host_filter = 'inventory_sources__source=gce'
dynamic_inventory.save()
assert len(dynamic_inventory.hosts.all()) == 1
smart_inventory.host_filter = 'inventory_sources__source=gce'
smart_inventory.save()
assert len(smart_inventory.hosts.all()) == 1
def test_host_filter_not_dynamic(self, setup_ec2_gce, organization):
dynamic_inventory = Inventory(name='dynamic',
organization=organization,
host_filter='inventory_sources__source=ec2')
assert len(dynamic_inventory.hosts.all()) == 0
def test_host_filter_not_smart(self, setup_ec2_gce, organization):
smart_inventory = Inventory(name='smart',
organization=organization,
host_filter='inventory_sources__source=ec2')
assert len(smart_inventory.hosts.all()) == 0
def test_host_objects_manager(self, setup_ec2_gce, organization):
dynamic_inventory = Inventory(kind='dynamic',
name='dynamic',
organization=organization,
host_filter='inventory_sources__source=ec2')
dynamic_inventory.save()
smart_inventory = Inventory(kind='smart',
name='smart',
organization=organization,
host_filter='inventory_sources__source=ec2')
smart_inventory.save()
hosts = dynamic_inventory.hosts.all()
hosts = smart_inventory.hosts.all()
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
smart_inventory = Inventory(name='smart',
kind='smart',
organization=organization,
host_filter='groups__name=test_groupA or groups__name=test_groupB')
smart_inventory.save()
assert len(smart_inventory.hosts.all()) == 1

View File

@@ -4,7 +4,7 @@ import pytest
import mock
# AWX
from awx.main.utils.filters import DynamicFilter
from awx.main.utils.filters import SmartFilter
# Django
from django.db.models import Q
@@ -22,7 +22,7 @@ class mockHost:
@mock.patch('awx.main.utils.filters.get_host_model', return_value=mockHost())
class TestDynamicFilterQueryFromString():
class TestSmartFilterQueryFromString():
@pytest.mark.parametrize("filter_string,q_expected", [
('facts__facts__blank=""', Q(**{u"facts__facts__blank": u""})),
('"facts__facts__ space "="f"', Q(**{u"facts__facts__ space ": u"f"})),
@@ -36,7 +36,7 @@ class TestDynamicFilterQueryFromString():
#('a__b\"__c="true"', Q(**{u"a__b\"__c": "true"})),
])
def test_query_generated(self, mock_get_host_model, filter_string, q_expected):
q = DynamicFilter.query_from_string(filter_string)
q = SmartFilter.query_from_string(filter_string)
assert unicode(q) == unicode(q_expected)
@pytest.mark.parametrize("filter_string", [
@@ -45,7 +45,7 @@ class TestDynamicFilterQueryFromString():
])
def test_invalid_filter_strings(self, mock_get_host_model, filter_string):
with pytest.raises(RuntimeError) as e:
DynamicFilter.query_from_string(filter_string)
SmartFilter.query_from_string(filter_string)
assert e.value.message == u"Invalid query " + filter_string
@pytest.mark.parametrize("filter_string,q_expected", [
@@ -53,7 +53,7 @@ class TestDynamicFilterQueryFromString():
(u'(ansible_facts__a=abc\u1F5E3def)', Q(**{u"ansible_facts__contains": {u"a": u"abc\u1F5E3def"}})),
])
def test_unicode(self, mock_get_host_model, filter_string, q_expected):
q = DynamicFilter.query_from_string(filter_string)
q = SmartFilter.query_from_string(filter_string)
assert unicode(q) == unicode(q_expected)
@pytest.mark.parametrize("filter_string,q_expected", [
@@ -67,7 +67,7 @@ class TestDynamicFilterQueryFromString():
('a=b or a=d or a=e or a=z and b=h and b=i and b=j and b=k', Q(**{u"a": u"b"}) | Q(**{u"a": u"d"}) | Q(**{u"a": u"e"}) | Q(**{u"a": u"z"}) & Q(**{u"b": u"h"}) & Q(**{u"b": u"i"}) & Q(**{u"b": u"j"}) & Q(**{u"b": u"k"}))
])
def test_boolean_parenthesis(self, mock_get_host_model, filter_string, q_expected):
q = DynamicFilter.query_from_string(filter_string)
q = SmartFilter.query_from_string(filter_string)
assert unicode(q) == unicode(q_expected)
@pytest.mark.parametrize("filter_string,q_expected", [
@@ -87,7 +87,7 @@ class TestDynamicFilterQueryFromString():
#('a__b\"__c="true"', Q(**{u"a__b\"__c": "true"})),
])
def test_contains_query_generated(self, mock_get_host_model, filter_string, q_expected):
q = DynamicFilter.query_from_string(filter_string)
q = SmartFilter.query_from_string(filter_string)
assert unicode(q) == unicode(q_expected)
@pytest.mark.parametrize("filter_string,q_expected", [
@@ -97,7 +97,7 @@ class TestDynamicFilterQueryFromString():
#('a__b\"__c="true"', Q(**{u"a__b\"__c": "true"})),
])
def test_contains_query_generated_unicode(self, mock_get_host_model, filter_string, q_expected):
q = DynamicFilter.query_from_string(filter_string)
q = SmartFilter.query_from_string(filter_string)
assert unicode(q) == unicode(q_expected)
@pytest.mark.parametrize("filter_string,q_expected", [
@@ -105,7 +105,7 @@ class TestDynamicFilterQueryFromString():
('ansible_facts__c="null"', Q(**{u"ansible_facts__contains": {u"c": u"\"null\""}})),
])
def test_contains_query_generated_null(self, mock_get_host_model, filter_string, q_expected):
q = DynamicFilter.query_from_string(filter_string)
q = SmartFilter.query_from_string(filter_string)
assert unicode(q) == unicode(q_expected)