Merge pull request #406 from sartography/convert-timestamp-499

Convert timestamp #499
This commit is contained in:
Dan Funk 2021-10-21 14:12:59 -04:00 committed by GitHub
commit 2ef03b0c79
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 8 deletions

View File

@ -3,7 +3,7 @@ import traceback
from crc import app, session from crc import app, session
from crc.api.common import ApiError from crc.api.common import ApiError
from crc.models.email import EmailModelSchema from crc.models.email import EmailModel, EmailModelSchema
from crc.models.file import FileModel, CONTENT_TYPES from crc.models.file import FileModel, CONTENT_TYPES
from crc.models.workflow import WorkflowModel from crc.models.workflow import WorkflowModel
from crc.services.document_service import DocumentService from crc.services.document_service import DocumentService
@ -40,9 +40,10 @@ email(subject="My Subject", recipients="user@example.com", attachments=['Study_A
""" """
def do_task_validate_only(self, task, study_id, workflow_id, *args, **kwargs): def do_task_validate_only(self, task, study_id, workflow_id, *args, **kwargs):
self.get_subject(kwargs['subject']) subject = self.get_subject(kwargs['subject'])
self.get_email_addresses(kwargs['recipients'], study_id) recipients = self.get_email_addresses(kwargs['recipients'], study_id)
EmailService().get_rendered_content(task.task_spec.documentation, task.data) 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)
def do_task(self, task, study_id, workflow_id, *args, **kwargs): def do_task(self, task, study_id, workflow_id, *args, **kwargs):
@ -136,7 +137,7 @@ email(subject="My Subject", recipients="user@example.com", attachments=['Study_A
if not subject or not isinstance(subject, str): if not subject or not isinstance(subject, str):
raise ApiError(code="invalid_argument", raise ApiError(code="invalid_argument",
message="The subject you provided could not be parsed. " message="The subject you provided could not be parsed. "
"The value is \"%s\" " % subject) "The value is \"%s\" " % subject)
return subject return subject
@staticmethod @staticmethod

View File

@ -1,3 +1,5 @@
import datetime
from crc.api.common import ApiError from crc.api.common import ApiError
from crc.scripts.script import Script from crc.scripts.script import Script
@ -13,7 +15,7 @@ class GetLocaltime(Script):
def do_task_validate_only(self, task, study_id, workflow_id, *args, **kwargs): def do_task_validate_only(self, task, study_id, workflow_id, *args, **kwargs):
if 'timestamp' in kwargs: if 'timestamp' in kwargs:
return True return datetime.datetime.now()
raise ApiError(code='missing_timestamp', raise ApiError(code='missing_timestamp',
message='You must include a timestamp to convert.') message='You must include a timestamp to convert.')
@ -26,7 +28,7 @@ class GetLocaltime(Script):
timezone = 'US/Eastern' timezone = 'US/Eastern'
parsed_timestamp = dateparser.parse(timestamp) parsed_timestamp = dateparser.parse(timestamp)
localtime = parsed_timestamp.astimezone(pytz.timezone(timezone)) localtime = parsed_timestamp.astimezone(pytz.timezone(timezone))
return str(localtime) return localtime
else: else:
raise ApiError(code='missing_timestamp', raise ApiError(code='missing_timestamp',

View File

@ -1,5 +1,6 @@
from tests.base_test import BaseTest from tests.base_test import BaseTest
from crc.scripts.get_localtime import GetLocaltime from crc.scripts.get_localtime import GetLocaltime
import dateparser
class TestGetLocaltime(BaseTest): class TestGetLocaltime(BaseTest):
@ -14,4 +15,4 @@ class TestGetLocaltime(BaseTest):
timestamp = task.data['timestamp'] timestamp = task.data['timestamp']
localtime = task.data['localtime'] localtime = task.data['localtime']
self.assertEqual(localtime, GetLocaltime().do_task(None, None, None, timestamp=timestamp)) self.assertEqual(dateparser.parse(localtime), GetLocaltime().do_task(None, None, None, timestamp=timestamp))