From d8bd20313932e5a20949747ba6de09c2203114e6 Mon Sep 17 00:00:00 2001 From: mike cullerton Date: Thu, 11 Feb 2021 15:36:12 -0500 Subject: [PATCH] The email script was failing validation because of missing parameters in scripts.email.do_task_validate_only. I added a test in tests.test_email_script to make sure we get the default email_address. I also found and fixed a bug in workflow_service.populate_form_with_random_data where we would overwrite default_values with random text because of a missing continue. (We don't want to continue if we have repeating fields though.) --- crc/scripts/email.py | 2 +- crc/services/workflow_service.py | 2 ++ tests/test_email_script.py | 11 +++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/crc/scripts/email.py b/crc/scripts/email.py index 3160dc22..dcef5e8e 100644 --- a/crc/scripts/email.py +++ b/crc/scripts/email.py @@ -26,7 +26,7 @@ Example: email ("My Subject", "dhf8r@virginia.edu", pi.email) """ - def do_task_validate_only(self, task, *args, **kwargs): + def do_task_validate_only(self, task, study_id, workflow_id, *args, **kwargs): self.get_subject(args) self.get_email_recipients(task, args) self.get_content(task) diff --git a/crc/services/workflow_service.py b/crc/services/workflow_service.py index 74d070c0..894bac4f 100644 --- a/crc/services/workflow_service.py +++ b/crc/services/workflow_service.py @@ -166,6 +166,8 @@ class WorkflowService(object): # If we have a default_value or value_expression, try to set the default if field.has_property(Task.FIELD_PROP_VALUE_EXPRESSION) or (hasattr(field, 'default_value') and field.default_value): form_data[field.id] = WorkflowService.get_default_value(field, task) + if not field.has_property(Task.FIELD_PROP_REPEAT): + continue # If we are only populating required fields, and this isn't required. stop here. if required_only: diff --git a/tests/test_email_script.py b/tests/test_email_script.py index ee3d7219..d1520314 100644 --- a/tests/test_email_script.py +++ b/tests/test_email_script.py @@ -1,9 +1,19 @@ from tests.base_test import BaseTest from crc import mail +import json class TestEmailScript(BaseTest): + def test_email_script_validation(self): + # This validates scripts.email.do_task_validate_only + # It also tests that we don't overwrite the default email_address with random text during validation + # Otherwise json would have an error about parsing the email address + self.load_example_data() + spec_model = self.load_test_spec('email_script') + rv = self.app.get('/v1.0/workflow-specification/%s/validate' % spec_model.id, headers=self.logged_in_headers()) + self.assertEqual([], rv.json) + def test_email_script(self): with mail.record_messages() as outbox: @@ -12,6 +22,7 @@ class TestEmailScript(BaseTest): first_task = self.get_workflow_api(workflow).next_task workflow = self.get_workflow_api(workflow) + self.assertEqual('dan@sartography.com', workflow.next_task.data['email_address']) self.complete_form(workflow, first_task, {'email_address': 'test@example.com'}) self.assertEqual(1, len(outbox))