Skip to content

Commit

Permalink
Fix unit test failures and add missing links for WFJ nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
AlanCoding committed Sep 14, 2023
1 parent c8d0cca commit 2bb167b
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 13 deletions.
8 changes: 8 additions & 0 deletions awx/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4108,6 +4108,14 @@ class WorkflowJobNodeSerializer(LaunchConfigurationBaseSerializer):
success_nodes = serializers.PrimaryKeyRelatedField(many=True, read_only=True)
failure_nodes = serializers.PrimaryKeyRelatedField(many=True, read_only=True)
always_nodes = serializers.PrimaryKeyRelatedField(many=True, read_only=True)
sublists = (
('success_nodes', 'workflow_job_node_success_nodes_list'),
('failure_nodes', 'workflow_job_node_failure_nodes_list'),
('always_nodes', 'workflow_job_node_always_nodes_list'),
('labels', 'workflow_job_node_labels_list'),
('credentials', 'workflow_job_node_credentials_list'),
('instance_groups', 'workflow_job_node_instance_groups_list'),
)

class Meta:
model = WorkflowJobNode
Expand Down
16 changes: 12 additions & 4 deletions awx/main/tests/unit/api/serializers/test_inventory_serializers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Python
import pytest
from unittest import mock

# AWX
from awx.api.serializers import (
Expand All @@ -12,13 +11,22 @@
@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
pk=22,
id=22,
inventory=mocker.MagicMock(pk=23),
update=mocker.MagicMock(),
source_project_id=None,
current_update=None,
last_update=None,
spec=InventorySource,
created_by=mocker.MagicMock(pk=442),
modified_by=mocker.MagicMock(pk=552),
credential=89,
execution_environment_id=99,
)
return obj


@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',
Expand Down
15 changes: 12 additions & 3 deletions awx/main/tests/unit/api/serializers/test_job_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,18 @@ def project_update(mocker):

@pytest.fixture
def job(mocker, job_template, project_update):
return mocker.MagicMock(pk=5, job_template=job_template, project_update=project_update, workflow_job_id=None, execution_environment_id=None)
return mocker.MagicMock(
pk=5,
job_template=job_template,
project_update=project_update,
workflow_job_id=None,
execution_environment_id=None,
created_by=mocker.MagicMock(pk=42),
modified_by=mocker.MagicMock(pk=43),
inventory=mocker.MagicMock(pk=44),
project=mocker.MagicMock(pk=45),
organization_id=46,
)


@pytest.fixture
Expand All @@ -46,8 +57,6 @@ def jobs(mocker):
return [Job(id=x, name='job-%d' % x) for x in range(0, 25)]


@mock.patch('awx.api.serializers.UnifiedJobTemplateSerializer.get_related', lambda x, y: {})
@mock.patch('awx.api.serializers.JobOptionsSerializer.get_related', lambda x, y: {})
class TestJobSerializerGetRelated:
@pytest.mark.parametrize(
"related_resource_name",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ def job_template(mocker):
mock_jt.webhook_service = ''
mock_jt.organization_id = None
mock_jt.webhook_credential_id = None
mock_jt.created_by = mocker.MagicMock(pk=98)
mock_jt.modified_by = mocker.MagicMock(pk=99)
mock_jt.inventory = mocker.MagicMock(pk=100)
mock_jt.project = mocker.MagicMock(pk=101)
mock_jt.execution_environment_id = 102
return mock_jt


Expand All @@ -45,8 +50,6 @@ def jobs(mocker):
return [Job(id=x, name='job-%d' % x) for x in range(0, 25)]


@mock.patch('awx.api.serializers.UnifiedJobTemplateSerializer.get_related', lambda x, y: {})
@mock.patch('awx.api.serializers.JobOptionsSerializer.get_related', lambda x, y: {})
class TestJobTemplateSerializerGetRelated:
@pytest.mark.parametrize(
"related_resource_name",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@


@pytest.mark.django_db
@mock.patch('awx.api.serializers.UnifiedJobTemplateSerializer.get_related', lambda x, y: {})
class TestWorkflowJobTemplateSerializerGetRelated:
@pytest.fixture
def workflow_job_template(self, workflow_job_template_factory):
Expand All @@ -34,7 +33,6 @@ def test_get_related(self, mocker, test_get_related, workflow_job_template, rela
test_get_related(WorkflowJobTemplateSerializer, workflow_job_template, 'workflow_job_templates', related_resource_name)


@mock.patch('awx.api.serializers.BaseSerializer.get_related', lambda x, y: {})
class TestWorkflowNodeBaseSerializerGetRelated:
@pytest.fixture
def job_template(self, job_template_factory):
Expand All @@ -61,7 +59,6 @@ def test_workflow_unified_job_template_absent(self, workflow_job_template_node):


@pytest.mark.django_db
@mock.patch('awx.api.serializers.BaseSerializer.get_related', lambda x, y: {})
class TestWorkflowJobTemplateNodeSerializerGetRelated:
@pytest.fixture
def workflow_job_template_node(self):
Expand Down Expand Up @@ -210,7 +207,6 @@ def test_accept_password_default(self, jt, mocker):
assert attrs['extra_data'] == {}


@mock.patch('awx.api.serializers.WorkflowJobTemplateNodeSerializer.get_related', lambda x, y: {})
class TestWorkflowJobNodeSerializerGetRelated:
@pytest.fixture
def workflow_job_node(self):
Expand Down

0 comments on commit 2bb167b

Please sign in to comment.