Merge pull request #240 from sartography/weird-email-error

The email script was failing validation because of missing parameters…
This commit is contained in:
Dan Funk 2021-02-12 09:31:52 -05:00 committed by GitHub
commit 35773ebc29
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 1 deletions

View File

@ -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)

View File

@ -172,6 +172,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:

View File

@ -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))