From f88aba1db0836d0daeced8de41b25310303d5a9c Mon Sep 17 00:00:00 2001 From: mike cullerton Date: Tue, 26 Oct 2021 14:29:38 -0400 Subject: [PATCH] Cleanup validation for get_locatime. Make sure we send the same type of values back for validation. --- crc/scripts/email.py | 5 +++- crc/scripts/get_email_data.py | 23 ++++++++++++++---- crc/scripts/get_localtime.py | 4 +-- tests/data/get_localtime/get_localtime.bpmn | 27 ++++++++++++--------- 4 files changed, 38 insertions(+), 21 deletions(-) diff --git a/crc/scripts/email.py b/crc/scripts/email.py index 1520308d..5c35b46b 100644 --- a/crc/scripts/email.py +++ b/crc/scripts/email.py @@ -1,5 +1,6 @@ import sys import traceback +import datetime from crc import app, session from crc.api.common import ApiError @@ -43,7 +44,9 @@ email(subject="My Subject", recipients="user@example.com", attachments=['Study_A subject = self.get_subject(kwargs['subject']) recipients = self.get_email_addresses(kwargs['recipients'], study_id) content, content_html = EmailService().get_rendered_content(task.task_spec.documentation, task.data) - return EmailModel(subject=subject, recipients=recipients, content=content, content_html=content_html) + + email_model = EmailModel(subject=subject, recipients=recipients, content=content, content_html=content_html, timestamp=datetime.datetime.utcnow()) + return EmailModelSchema().dump(email_model) def do_task(self, task, study_id, workflow_id, *args, **kwargs): diff --git a/crc/scripts/get_email_data.py b/crc/scripts/get_email_data.py index c3539823..ba6c2a39 100644 --- a/crc/scripts/get_email_data.py +++ b/crc/scripts/get_email_data.py @@ -2,7 +2,9 @@ from crc.scripts.script import Script from crc.api.common import ApiError from crc import session from crc.models.email import EmailModel, EmailModelSchema -import json +from crc.services.email_service import EmailService + +import datetime class EmailData(Script): @@ -12,11 +14,22 @@ class EmailData(Script): def do_task_validate_only(self, task, study_id, workflow_id, *args, **kwargs): if 'email_id' in kwargs or 'workflow_spec_id' in kwargs: - return True - else: - return False + subject = 'My Test Email' + recipients = 'user@example.com' + content, content_html = EmailService().get_rendered_content(task.task_spec.documentation, task.data) + email_model = EmailModel(subject=subject, + recipients=recipients, + content=content, + content_html=content_html, + timestamp=datetime.datetime.utcnow()) + return EmailModelSchema(many=True).dump([email_model]) - def do_task(self, task, study_id, workflow_id, **kwargs): + else: + raise ApiError.from_task(code='missing_email_id', + message='You must include an email_id or workflow_spec_id with the get_email_data script.', + task=task) + + def do_task(self, task, study_id, workflow_id, *args, **kwargs): email_models = None email_data = None if 'email_id' in kwargs: diff --git a/crc/scripts/get_localtime.py b/crc/scripts/get_localtime.py index c3add55e..c6d120bf 100644 --- a/crc/scripts/get_localtime.py +++ b/crc/scripts/get_localtime.py @@ -1,5 +1,3 @@ -import datetime - from crc.api.common import ApiError from crc.scripts.script import Script @@ -15,7 +13,7 @@ class GetLocaltime(Script): def do_task_validate_only(self, task, study_id, workflow_id, *args, **kwargs): if 'timestamp' in kwargs: - return datetime.datetime.now() + return self.do_task(task, study_id, workflow_id, *args, **kwargs) raise ApiError(code='missing_timestamp', message='You must include a timestamp to convert.') diff --git a/tests/data/get_localtime/get_localtime.bpmn b/tests/data/get_localtime/get_localtime.bpmn index 43a136d5..23ef708f 100644 --- a/tests/data/get_localtime/get_localtime.bpmn +++ b/tests/data/get_localtime/get_localtime.bpmn @@ -15,7 +15,9 @@ This is my email Flow_0lnc9x0 Flow_0gtgzcf - email_model = email(subject='My Email Subject', recipients='user@example.com') + email_model = email(subject='My Email Subject', recipients='user@example.com') +email_data = get_email_data(email_id=email_model['id']) + timestamp = email_model.timestamp @@ -23,7 +25,8 @@ localtime = get_localtime(str(timestamp)) Flow_0gtgzcf Flow_0k1hbif timestamp=email_model.timestamp -localtime = get_localtime(timestamp=timestamp) +localtime = get_localtime(timestamp=timestamp) + # Timestamp @@ -38,21 +41,21 @@ localtime = get_localtime(timestamp=timestamp) - - - - - - - + + + - - - + + + + + + +