unit test inventory source serializer get_related (#6214)

This commit is contained in:
Jake McDermott 2017-05-09 12:07:39 -04:00 committed by GitHub
parent 55c2f5a2d6
commit be56912dc3

View File

@ -6,9 +6,11 @@ from mock import PropertyMock
# AWX
from awx.api.serializers import (
CustomInventoryScriptSerializer,
InventorySourceSerializer,
)
from awx.main.models import (
CustomInventoryScript,
InventorySource,
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):
@pytest.mark.parametrize("superuser,sysaudit,admin_role,value",
((True, False, False, '#!/python'),
@ -45,3 +61,25 @@ class TestCustomInventoryScriptSerializer(object):
representation = serializer.to_representation(cis)
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
)