mirror of
https://github.com/ansible/awx.git
synced 2026-01-28 00:51:27 -03:30
fix bug processing survey spec
This commit is contained in:
parent
5e595caf5e
commit
795c989a49
@ -215,13 +215,15 @@ def main():
|
||||
new_fields['extra_vars'] = json.dumps(new_fields['extra_vars'])
|
||||
|
||||
on_change = None
|
||||
existing_spec = None
|
||||
if existing_item:
|
||||
existing_spec = module.get_endpoint('spec_endpoint')
|
||||
new_spec = module.params.get('survey')
|
||||
if new_spec and (new_spec != existing_spec):
|
||||
module.json_output['changed'] = True
|
||||
on_change = update_survey
|
||||
if new_spec:
|
||||
existing_spec = None
|
||||
if existing_item:
|
||||
spec_endpoint = existing_item.get('related', {}).get('survey_spec')
|
||||
existing_spec = module.get_endpoint(spec_endpoint)
|
||||
if new_spec != existing_spec:
|
||||
module.json_output['changed'] = True
|
||||
on_change = update_survey
|
||||
|
||||
if state == 'absent':
|
||||
# If the state was absent we can let the module delete it if needed, the module will handle exiting from this
|
||||
|
||||
@ -165,6 +165,15 @@ EXAMPLES = '''
|
||||
organization: Default # organization of workflow job template
|
||||
extra_data:
|
||||
foo_key: bar_value
|
||||
|
||||
- name: Create parent node for prior node
|
||||
tower_workflow_job_template_node:
|
||||
identifier: my-root-node
|
||||
workflow: example-workflow
|
||||
unified_job_template: jt-for-node-use
|
||||
organization: Default
|
||||
success_nodes:
|
||||
- my-first-node
|
||||
'''
|
||||
|
||||
from ..module_utils.tower_api import TowerModule
|
||||
|
||||
@ -22,16 +22,35 @@ def test_create_workflow_job_template(run_module, admin_user, organization, surv
|
||||
assert wfjt.extra_vars == '{"foo": "bar", "another-foo": {"barz": "bar2"}}'
|
||||
|
||||
result.pop('invocation', None)
|
||||
assert result == {
|
||||
"name": "foo-workflow",
|
||||
"id": wfjt.id,
|
||||
"changed": True
|
||||
}
|
||||
assert result == {"name": "foo-workflow", "id": wfjt.id, "changed": True}
|
||||
|
||||
assert wfjt.organization_id == organization.id
|
||||
assert wfjt.survey_spec == survey_spec
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_create_modify_no_survey(run_module, admin_user, organization, survey_spec):
|
||||
result = run_module('tower_workflow_job_template', {
|
||||
'name': 'foo-workflow',
|
||||
'organization': organization.name
|
||||
}, admin_user)
|
||||
assert not result.get('failed', False), result.get('msg', result)
|
||||
assert result.get('changed', False), result
|
||||
|
||||
wfjt = WorkflowJobTemplate.objects.get(name='foo-workflow')
|
||||
assert wfjt.organization_id == organization.id
|
||||
assert wfjt.survey_spec == {}
|
||||
result.pop('invocation', None)
|
||||
assert result == {"name": "foo-workflow", "id": wfjt.id, "changed": True}
|
||||
|
||||
result = run_module('tower_workflow_job_template', {
|
||||
'name': 'foo-workflow',
|
||||
'organization': organization.name
|
||||
}, admin_user)
|
||||
assert not result.get('failed', False), result.get('msg', result)
|
||||
assert not result.get('changed', True), result
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_survey_spec_only_changed(run_module, admin_user, organization, survey_spec):
|
||||
wfjt = WorkflowJobTemplate.objects.create(
|
||||
@ -60,3 +79,21 @@ def test_survey_spec_only_changed(run_module, admin_user, organization, survey_s
|
||||
assert result.get('changed', True), result
|
||||
wfjt.refresh_from_db()
|
||||
assert wfjt.survey_spec == survey_spec
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_delete_with_spec(run_module, admin_user, organization, survey_spec):
|
||||
WorkflowJobTemplate.objects.create(
|
||||
organization=organization, name='foo-workflow',
|
||||
survey_enabled=True, survey_spec=survey_spec
|
||||
)
|
||||
result = run_module('tower_workflow_job_template', {
|
||||
'name': 'foo-workflow',
|
||||
'organization': organization.name,
|
||||
'state': 'absent'
|
||||
}, admin_user)
|
||||
assert not result.get('failed', False), result.get('msg', result)
|
||||
assert result.get('changed', True), result
|
||||
|
||||
assert WorkflowJobTemplate.objects.filter(
|
||||
name='foo-workflow', organization=organization).count() == 0
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user