mirror of
https://github.com/ansible/awx.git
synced 2026-03-15 07:57:29 -02:30
unit test inventory source serializer get_related (#6214)
This commit is contained in:
@@ -6,9 +6,11 @@ from mock import PropertyMock
|
|||||||
# AWX
|
# AWX
|
||||||
from awx.api.serializers import (
|
from awx.api.serializers import (
|
||||||
CustomInventoryScriptSerializer,
|
CustomInventoryScriptSerializer,
|
||||||
|
InventorySourceSerializer,
|
||||||
)
|
)
|
||||||
from awx.main.models import (
|
from awx.main.models import (
|
||||||
CustomInventoryScript,
|
CustomInventoryScript,
|
||||||
|
InventorySource,
|
||||||
User,
|
User,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -20,6 +22,20 @@ from rest_framework.test import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def inventory_source(mocker):
|
||||||
|
obj = mocker.MagicMock(
|
||||||
|
pk=22,
|
||||||
|
inventory=mocker.MagicMock(pk=23),
|
||||||
|
update=mocker.MagicMock(),
|
||||||
|
source_project_id=None,
|
||||||
|
current_update=None,
|
||||||
|
last_update=None,
|
||||||
|
spec=InventorySource
|
||||||
|
)
|
||||||
|
return obj
|
||||||
|
|
||||||
|
|
||||||
class TestCustomInventoryScriptSerializer(object):
|
class TestCustomInventoryScriptSerializer(object):
|
||||||
@pytest.mark.parametrize("superuser,sysaudit,admin_role,value",
|
@pytest.mark.parametrize("superuser,sysaudit,admin_role,value",
|
||||||
((True, False, False, '#!/python'),
|
((True, False, False, '#!/python'),
|
||||||
@@ -45,3 +61,25 @@ class TestCustomInventoryScriptSerializer(object):
|
|||||||
|
|
||||||
representation = serializer.to_representation(cis)
|
representation = serializer.to_representation(cis)
|
||||||
assert representation['script'] == value
|
assert representation['script'] == value
|
||||||
|
|
||||||
|
|
||||||
|
@mock.patch('awx.api.serializers.UnifiedJobTemplateSerializer.get_related', lambda x,y: {})
|
||||||
|
@mock.patch('awx.api.serializers.InventorySourceOptionsSerializer.get_related', lambda x,y: {})
|
||||||
|
class TestInventorySourceSerializerGetRelated(object):
|
||||||
|
@pytest.mark.parametrize('related_resource_name', [
|
||||||
|
'activity_stream',
|
||||||
|
'notification_templates_error',
|
||||||
|
'notification_templates_success',
|
||||||
|
'notification_templates_any',
|
||||||
|
'inventory_updates',
|
||||||
|
'update',
|
||||||
|
'hosts',
|
||||||
|
'groups',
|
||||||
|
])
|
||||||
|
def test_get_related(self, test_get_related, inventory_source, related_resource_name):
|
||||||
|
test_get_related(
|
||||||
|
InventorySourceSerializer,
|
||||||
|
inventory_source,
|
||||||
|
'inventory_sources',
|
||||||
|
related_resource_name
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user