mirror of
https://github.com/ZwareBear/awx.git
synced 2026-04-20 23:11:48 -05:00
Merge pull request #363 from AlanCoding/org_smart_inv
backend of org-scoped smart inventories
This commit is contained in:
@@ -10,6 +10,7 @@ from awx.main.models import (
|
||||
InventorySource,
|
||||
InventoryUpdate,
|
||||
)
|
||||
from awx.main.utils.filters import SmartFilter
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
@@ -109,3 +110,17 @@ class TestHostManager:
|
||||
organization=organization,
|
||||
host_filter='inventory_sources__source=ec2')
|
||||
assert len(smart_inventory.hosts.all()) == 0
|
||||
|
||||
def test_host_distinctness(self, setup_inventory_groups, organization):
|
||||
"""
|
||||
two criteria would both yield the same host, check that we only get 1 copy here
|
||||
"""
|
||||
assert (
|
||||
list(SmartFilter.query_from_string('name=single_host or name__startswith=single_')) ==
|
||||
[Host.objects.get(name='single_host')]
|
||||
)
|
||||
|
||||
# Things we can not easily test due to SQLite backend:
|
||||
# 2 organizations with host of same name only has 1 entry in smart inventory
|
||||
# smart inventory in 1 organization does not include host from another
|
||||
# smart inventory correctly returns hosts in filter in same organization
|
||||
|
||||
@@ -174,3 +174,17 @@ def test_inventory_source_org_admin_schedule_access(org_admin, inventory_source)
|
||||
assert access.get_queryset()
|
||||
assert access.can_read(schedule)
|
||||
assert access.can_change(schedule, {'rrule': 'DTSTART:20151117T050000Z RRULE:FREQ=DAILY;INTERVAL=1;COUNT=2'})
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def smart_inventory(organization):
|
||||
return organization.inventories.create(name="smart-inv", kind="smart")
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
class TestSmartInventory:
|
||||
|
||||
def test_host_filter_edit(self, smart_inventory, rando, org_admin):
|
||||
assert InventoryAccess(org_admin).can_admin(smart_inventory, {'host_filter': 'search=foo'})
|
||||
smart_inventory.admin_role.members.add(rando)
|
||||
assert not InventoryAccess(rando).can_admin(smart_inventory, {'host_filter': 'search=foo'})
|
||||
|
||||
@@ -220,8 +220,8 @@ class TestHostInsights():
|
||||
class TestInventoryHostsList(object):
|
||||
|
||||
def test_host_list_smart_inventory(self, mocker):
|
||||
Inventory = namedtuple('Inventory', ['kind', 'host_filter', 'hosts'])
|
||||
obj = Inventory(kind='smart', host_filter='localhost', hosts=HostManager())
|
||||
Inventory = namedtuple('Inventory', ['kind', 'host_filter', 'hosts', 'organization_id'])
|
||||
obj = Inventory(kind='smart', host_filter='localhost', hosts=HostManager(), organization_id=None)
|
||||
obj.hosts.instance = obj
|
||||
|
||||
with mock.patch.object(InventoryHostsList, 'get_parent_object', return_value=obj):
|
||||
|
||||
Reference in New Issue
Block a user