Skip to content

Commit

Permalink
fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
AlanCoding committed Aug 6, 2019
1 parent cf9656f commit f112cf3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 19 deletions.
17 changes: 14 additions & 3 deletions awx/api/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3090,6 +3090,17 @@ def get(self, request, *args, **kwargs):
data.update(messages)
return Response(data)

def _build_create_dict(self, obj):
"""Special processing of fields managed by char_prompts
"""
r = super(WorkflowJobTemplateCopy, self)._build_create_dict(obj)
field_names = set(f.name for f in obj._meta.get_fields())
for field_name, ask_field_name in obj.get_ask_mapping().items():
if field_name in r and field_name not in field_names:
r.setdefault('char_prompts', {})
r['char_prompts'][field_name] = r.pop(field_name)
return r

@staticmethod
def deep_copy_permission_check_func(user, new_objs):
for obj in new_objs:
Expand Down Expand Up @@ -3140,10 +3151,10 @@ def update_raw_data(self, data):
for field_name, ask_field_name in obj.get_ask_mapping().items():
if not getattr(obj, ask_field_name):
data.pop(field_name, None)
elif field == 'inventory':
data[field] = getattrd(obj, "%s.%s" % (field, 'id'), None)
elif field_name == 'inventory':
data[field_name] = getattrd(obj, "%s.%s" % (field_name, 'id'), None)
else:
data[field] = getattr(obj, field)
data[field_name] = getattr(obj, field_name)
return data

def post(self, request, *args, **kwargs):
Expand Down
1 change: 1 addition & 0 deletions awx/main/models/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,7 @@ class Meta:
null=True,
default=None,
on_delete=models.SET_NULL,
help_text=_('Inventory applied as a prompt, assuming job template prompts for inventory')
)
# All standard fields are stored in this dictionary field
# This is a solution to the nullable CharField problem, specific to prompting
Expand Down
12 changes: 1 addition & 11 deletions awx/main/models/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
NotificationTemplate,
JobNotificationMixin
)
from awx.main.models.base import BaseModel, CreatedModifiedModel, VarsDictProperty
from awx.main.models.base import CreatedModifiedModel, VarsDictProperty
from awx.main.models.rbac import (
ROLE_SINGLETON_SYSTEM_ADMINISTRATOR,
ROLE_SINGLETON_SYSTEM_AUDITOR
Expand Down Expand Up @@ -361,16 +361,6 @@ class Meta:
on_delete=models.SET_NULL,
related_name='workflows',
)
# declared here for help_text
inventory = models.ForeignKey(
'Inventory',
related_name='%(class)ss',
blank=True,
null=True,
default=None,
on_delete=models.SET_NULL,
help_text=_('Inventory applied to all job templates in workflow that prompt for inventory.'),
)
ask_inventory_on_launch = AskForField(
blank=True,
default=False,
Expand Down
10 changes: 5 additions & 5 deletions awx/main/tests/unit/models/test_workflow_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from awx.main.models.jobs import JobTemplate
from awx.main.models import Inventory, CredentialType, Credential, Project
from awx.main.models.workflow import (
WorkflowJobTemplate, WorkflowJobTemplateNode, WorkflowJobOptions,
WorkflowJobTemplate, WorkflowJobTemplateNode,
WorkflowJob, WorkflowJobNode
)
from unittest import mock
Expand Down Expand Up @@ -33,11 +33,11 @@ def job_template_nodes(self, job_templates):
def test__create_workflow_job_nodes(self, mocker, job_template_nodes):
workflow_job_node_create = mocker.patch('awx.main.models.WorkflowJobTemplateNode.create_workflow_job_node')

mixin = WorkflowJobOptions()
mixin._create_workflow_nodes(job_template_nodes)
workflow_job = WorkflowJob()
workflow_job._create_workflow_nodes(job_template_nodes)

for job_template_node in job_template_nodes:
workflow_job_node_create.assert_any_call(workflow_job=mixin)
workflow_job_node_create.assert_any_call(workflow_job=workflow_job)

class TestMapWorkflowJobNodes():
@pytest.fixture
Expand Down Expand Up @@ -236,4 +236,4 @@ def test_no_accepted_project_node_prompts(self, job_node_no_prompts, project_uni


def test_get_ask_mapping_integrity():
assert list(WorkflowJobTemplate.get_ask_mapping().keys()) == ['extra_vars', 'inventory']
assert list(WorkflowJobTemplate.get_ask_mapping().keys()) == ['extra_vars', 'inventory', 'limit']

0 comments on commit f112cf3

Please sign in to comment.