mirror of
https://github.com/ansible/awx.git
synced 2026-05-07 17:37:37 -02:30
Merge pull request #152 from wwitzel3/issue-7355
Ensure hosts list properly when given read access to a smart inventory
This commit is contained in:
@@ -1959,6 +1959,10 @@ class InventoryHostsList(SubListCreateAttachDetachAPIView):
|
|||||||
parent_key = 'inventory'
|
parent_key = 'inventory'
|
||||||
capabilities_prefetch = ['inventory.admin']
|
capabilities_prefetch = ['inventory.admin']
|
||||||
|
|
||||||
|
def get_queryset(self):
|
||||||
|
inventory = self.get_parent_object()
|
||||||
|
return getattrd(inventory, self.relationship).all()
|
||||||
|
|
||||||
|
|
||||||
class HostGroupsList(ControlledByScmMixin, SubListCreateAttachDetachAPIView):
|
class HostGroupsList(ControlledByScmMixin, SubListCreateAttachDetachAPIView):
|
||||||
''' the list of groups a host is directly a member of '''
|
''' the list of groups a host is directly a member of '''
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ from awx.api.views import (
|
|||||||
JobTemplateLabelList,
|
JobTemplateLabelList,
|
||||||
JobTemplateSurveySpec,
|
JobTemplateSurveySpec,
|
||||||
InventoryInventorySourcesUpdate,
|
InventoryInventorySourcesUpdate,
|
||||||
|
InventoryHostsList,
|
||||||
HostInsights,
|
HostInsights,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -16,6 +17,8 @@ from awx.main.models import (
|
|||||||
Host,
|
Host,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from awx.main.managers import HostManager
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_response_new(mocker):
|
def mock_response_new(mocker):
|
||||||
@@ -204,3 +207,17 @@ class TestHostInsights():
|
|||||||
|
|
||||||
assert resp.data['error'] == 'The Insights Credential for "inventory_name_here" was not found.'
|
assert resp.data['error'] == 'The Insights Credential for "inventory_name_here" was not found.'
|
||||||
assert resp.status_code == 404
|
assert resp.status_code == 404
|
||||||
|
|
||||||
|
|
||||||
|
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())
|
||||||
|
obj.hosts.instance = obj
|
||||||
|
|
||||||
|
with mock.patch.object(InventoryHostsList, 'get_parent_object', return_value=obj):
|
||||||
|
with mock.patch('awx.main.utils.filters.SmartFilter.query_from_string') as mock_query:
|
||||||
|
view = InventoryHostsList()
|
||||||
|
view.get_queryset()
|
||||||
|
mock_query.assert_called_once_with('localhost')
|
||||||
|
|||||||
Reference in New Issue
Block a user