Assure that if a form has an enumeration it errors out if that enumeration is empty.
This commit is contained in:
parent
8ed520c6f1
commit
1b9743a4d1
|
@ -281,7 +281,12 @@ class WorkflowProcessor(object):
|
|||
form_data = {}
|
||||
for field in task.task_spec.form.fields:
|
||||
if field.type == "enum":
|
||||
form_data[field.id] = random.choice(field.options)
|
||||
if len(field.options) > 0:
|
||||
form_data[field.id] = random.choice(field.options)
|
||||
else:
|
||||
raise ApiError.from_task("invalid_enum", "You specified an enumeration field (%s),"
|
||||
" with no options" % field.id,
|
||||
task)
|
||||
elif field.type == "long":
|
||||
form_data[field.id] = random.randint(1, 1000)
|
||||
elif field.type == 'boolean':
|
||||
|
|
|
@ -4,7 +4,10 @@ import string
|
|||
import random
|
||||
from unittest.mock import patch
|
||||
|
||||
from SpiffWorkflow import Task as SpiffTask
|
||||
from SpiffWorkflow.bpmn.specs.EndEvent import EndEvent
|
||||
from SpiffWorkflow.camunda.specs.UserTask import Form, FormField
|
||||
from SpiffWorkflow.specs import TaskSpec
|
||||
|
||||
from crc import session, db, app
|
||||
from crc.api.common import ApiError
|
||||
|
@ -378,3 +381,21 @@ class TestWorkflowProcessor(BaseTest):
|
|||
self.assertTrue("sponsor_funding_source" in data)
|
||||
self.assertEqual("disabled", data["sponsor_funding_source"])
|
||||
|
||||
def test_enum_with_no_choices_raises_api_error(self):
|
||||
self.load_example_data()
|
||||
workflow_spec_model = self.load_test_spec("random_fact")
|
||||
study = session.query(StudyModel).first()
|
||||
processor = self.get_processor(study, workflow_spec_model)
|
||||
processor.do_engine_steps()
|
||||
tasks = processor.next_user_tasks()
|
||||
task = tasks[0]
|
||||
|
||||
|
||||
field = FormField()
|
||||
field.id = "test_enum_field"
|
||||
field.type = "enum"
|
||||
field.options = []
|
||||
task.task_spec.form.fields.append(field)
|
||||
|
||||
with self.assertRaises(ApiError):
|
||||
processor.populate_form_with_random_data(task)
|
Loading…
Reference in New Issue