1
0
mirror of https://github.com/ansible/awx.git synced 2024-10-30 22:21:13 +03:00

Fix issue where unified_job method overrode the SurveyMixin methods

This commit is contained in:
AlanCoding 2016-11-08 09:19:29 -05:00
parent 76eb0bb866
commit a1c17a7243
3 changed files with 26 additions and 9 deletions

View File

@ -292,12 +292,6 @@ class UnifiedJobTemplate(PolymorphicModel, CommonModelNameNotUnique, Notificatio
'''
raise NotImplementedError # Implement in subclass.
def _update_unified_job_kwargs(self, **kwargs):
'''
Hook for subclasses to update kwargs.
'''
return kwargs # Override if needed in subclass.
@property
def notification_templates(self):
'''
@ -346,7 +340,10 @@ class UnifiedJobTemplate(PolymorphicModel, CommonModelNameNotUnique, Notificatio
m2m_fields[field_name] = getattr(self, field_name)
else:
create_kwargs[field_name] = getattr(self, field_name)
new_kwargs = self._update_unified_job_kwargs(**create_kwargs)
if hasattr(self, '_update_unified_job_kwargs'):
new_kwargs = self._update_unified_job_kwargs(**create_kwargs)
else:
new_kwargs = create_kwargs
unified_job = unified_job_class(**new_kwargs)
# For JobTemplate-based jobs with surveys, add passwords to list for perma-redaction
if hasattr(self, 'survey_spec') and getattr(self, 'survey_enabled', False):

View File

@ -345,7 +345,7 @@ class WorkflowJobTemplate(UnifiedJobTemplate, WorkflowJobOptions, SurveyJobTempl
def can_start_without_user_input(self):
'''Return whether WFJT can be launched without survey passwords.'''
return bool(self.variables_needed_to_start)
return not bool(self.variables_needed_to_start)
def get_warnings(self):
warning_data = {}

View File

@ -75,9 +75,29 @@ class TestWorkflowSurveys:
"Assure that the survey default over-rides a JT variable"
spec = survey_spec_factory('var1')
spec['spec'][0]['default'] = 3
spec['spec'][0]['required'] = False
wfjt = WorkflowJobTemplate(
name="test-wfjt",
survey_spec=spec,
survey_enabled=True,
extra_vars="var1: 5"
)
assert json.loads(wfjt._update_unified_job_kwargs()['extra_vars'])['var1'] == 3
updated_extra_vars = wfjt._update_unified_job_kwargs()
assert 'extra_vars' in updated_extra_vars
assert json.loads(updated_extra_vars['extra_vars'])['var1'] == 3
assert wfjt.can_start_without_user_input()
def test_variables_needed_to_start(self, survey_spec_factory):
"Assure that variables_needed_to_start output contains mandatory vars"
spec = survey_spec_factory(['question1', 'question2', 'question3'])
spec['spec'][0]['required'] = False
spec['spec'][1]['required'] = True
spec['spec'][2]['required'] = False
wfjt = WorkflowJobTemplate(
name="test-wfjt",
survey_spec=spec,
survey_enabled=True,
extra_vars="question2: hiworld"
)
assert wfjt.variables_needed_to_start == ['question2']
assert not wfjt.can_start_without_user_input()