From 47ead5ab4524b55f650262001dd16bf041889456 Mon Sep 17 00:00:00 2001 From: mike cullerton Date: Tue, 2 Nov 2021 10:00:41 -0400 Subject: [PATCH 1/3] Fixed validation bug. There is no element documentation available in the task, so we mock up the email content. --- crc/scripts/get_email_data.py | 3 ++- tests/scripts/test_get_email_data.py | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/crc/scripts/get_email_data.py b/crc/scripts/get_email_data.py index ba6c2a39..4f787ddb 100644 --- a/crc/scripts/get_email_data.py +++ b/crc/scripts/get_email_data.py @@ -16,7 +16,8 @@ class EmailData(Script): if 'email_id' in kwargs or 'workflow_spec_id' in kwargs: subject = 'My Test Email' recipients = 'user@example.com' - content, content_html = EmailService().get_rendered_content(task.task_spec.documentation, task.data) + content = "Hello" + content_html = "

Hello

" email_model = EmailModel(subject=subject, recipients=recipients, content=content, diff --git a/tests/scripts/test_get_email_data.py b/tests/scripts/test_get_email_data.py index 8b847b90..b9e45a37 100644 --- a/tests/scripts/test_get_email_data.py +++ b/tests/scripts/test_get_email_data.py @@ -6,6 +6,12 @@ from crc.services.email_service import EmailService class TestGetEmailData(BaseTest): + def test_email_data_validation(self): + self.load_example_data() + spec_model = self.load_test_spec('get_email_data') + rv = self.app.get('/v1.0/workflow-specification/%s/validate' % spec_model.id, headers=self.logged_in_headers()) + self.assertEqual([], rv.json) + def test_get_email_data_by_email_id(self): self.load_example_data() workflow = self.create_workflow('get_email_data') From 1f9c80d70d15f064a3d802f1a3870fac9c232af5 Mon Sep 17 00:00:00 2001 From: mike cullerton Date: Wed, 3 Nov 2021 08:36:24 -0400 Subject: [PATCH 2/3] Added ordered arguments to the get_localtime script Modified the workflow so the first task is a form with booleans that allows me to test all the permutations. Modified tests to cover all the permutations for calling the script --- crc/scripts/get_localtime.py | 11 +++- tests/data/get_localtime/get_localtime.bpmn | 68 ++++++++++++++------- tests/scripts/test_get_localtime.py | 47 +++++++++++++- 3 files changed, 98 insertions(+), 28 deletions(-) diff --git a/crc/scripts/get_localtime.py b/crc/scripts/get_localtime.py index c6d120bf..edc912e0 100644 --- a/crc/scripts/get_localtime.py +++ b/crc/scripts/get_localtime.py @@ -12,16 +12,21 @@ class GetLocaltime(Script): Defaults to US/Eastern""" def do_task_validate_only(self, task, study_id, workflow_id, *args, **kwargs): - if 'timestamp' in kwargs: + if len(args) > 0 or 'timestamp' in kwargs: return self.do_task(task, study_id, workflow_id, *args, **kwargs) raise ApiError(code='missing_timestamp', message='You must include a timestamp to convert.') def do_task(self, task, study_id, workflow_id, *args, **kwargs): - if 'timestamp' in kwargs: - timestamp = kwargs['timestamp'] + if len(args) > 0 or 'timestamp' in kwargs: + if 'timestamp' in kwargs: + timestamp = kwargs['timestamp'] + else: + timestamp = args[0] if 'timezone' in kwargs: timezone = kwargs['timezone'] + elif len(args) > 1: + timezone = args[1] else: timezone = 'US/Eastern' parsed_timestamp = dateparser.parse(timestamp) diff --git a/tests/data/get_localtime/get_localtime.bpmn b/tests/data/get_localtime/get_localtime.bpmn index 23ef708f..e8d91c63 100644 --- a/tests/data/get_localtime/get_localtime.bpmn +++ b/tests/data/get_localtime/get_localtime.bpmn @@ -1,43 +1,67 @@ - + Flow_0lnc9x0 - - - + + + Flow_0kgtoh1 - - This is my email - Flow_0lnc9x0 - Flow_0gtgzcf - 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 localtime = get_localtime(str(timestamp)) Flow_0gtgzcf Flow_0k1hbif - timestamp=email_model.timestamp -localtime = get_localtime(timestamp=timestamp) - + if with_timestamp: + if with_timezone: + localtime_with = get_localtime(timestamp=timestamp, timezone=timezone) + localtime_without = get_localtime(timestamp, timezone) + else: + localtime_with = get_localtime(timestamp=timestamp) + localtime_without = get_localtime(timestamp) +else: + localtime = get_localtime() # Timestamp {{ timestamp }} +# Timezone +{{ timezone }} -# Localtime -{{ localtime }} +# Localtime With +{{ localtime_with }} + +# Localtime Without +{{ localtime_without }} Flow_0k1hbif Flow_0kgtoh1 + + This is my email + + + + + + + + + + + + + + + + + Flow_0lnc9x0 + Flow_0gtgzcf + @@ -63,15 +87,15 @@ localtime = get_localtime(timestamp=timestamp) - - - - + + + + diff --git a/tests/scripts/test_get_localtime.py b/tests/scripts/test_get_localtime.py index 4abac7ea..de54a982 100644 --- a/tests/scripts/test_get_localtime.py +++ b/tests/scripts/test_get_localtime.py @@ -1,6 +1,7 @@ from tests.base_test import BaseTest from crc.scripts.get_localtime import GetLocaltime import dateparser +import datetime class TestGetLocaltime(BaseTest): @@ -8,11 +9,51 @@ class TestGetLocaltime(BaseTest): def test_get_localtime(self): self.load_example_data() + timestamp = datetime.datetime.utcnow() workflow = self.create_workflow('get_localtime') + workflow_api = self.get_workflow_api(workflow) task = workflow_api.next_task - timestamp = task.data['timestamp'] - localtime = task.data['localtime'] + workflow_api = self.complete_form(workflow, task, {'with_timestamp': True, + 'with_timezone': False, + 'timestamp': str(timestamp)}) + task = workflow_api.next_task - self.assertEqual(dateparser.parse(localtime), GetLocaltime().do_task(None, None, None, timestamp=timestamp)) + # The workflow calls get_localtime twice, once with named arguments and once without + localtime_with = task.data['localtime_with'] + localtime_without = task.data['localtime_without'] + + self.assertEqual(dateparser.parse(localtime_with), GetLocaltime().do_task(None, None, None, timestamp=str(timestamp))) + self.assertEqual(dateparser.parse(localtime_without), GetLocaltime().do_task(None, None, None, str(timestamp))) + + def test_get_localtime_with_timezone(self): + self.load_example_data() + + timestamp = datetime.datetime.utcnow() + workflow = self.create_workflow('get_localtime') + + workflow_api = self.get_workflow_api(workflow) + task = workflow_api.next_task + + workflow_api = self.complete_form(workflow, task, {'with_timestamp': True, + 'with_timezone': True, + 'timestamp': str(timestamp), + 'timezone': 'US/Eastern'}) + task = workflow_api.next_task + + # The workflow calls get_localtime twice, once with named arguments and once without + localtime_with = task.data['localtime_with'] + localtime_without = task.data['localtime_without'] + + self.assertEqual(dateparser.parse(localtime_with), GetLocaltime().do_task(None, None, None, timestamp=str(timestamp), timezone='US/Eastern')) + self.assertEqual(dateparser.parse(localtime_without), GetLocaltime().do_task(None, None, None, str(timestamp), 'US/Eastern')) + + def test_get_localtime_no_timestamp(self): + workflow = self.create_workflow('get_localtime') + + workflow_api = self.get_workflow_api(workflow) + task = workflow_api.next_task + + with self.assertRaises(AssertionError): + self.complete_form(workflow, task, {'with_timestamp': False, 'with_timezone': False}) From 9376d3deaf35a43a6f1bbd8aa59a893c7f0644b5 Mon Sep 17 00:00:00 2001 From: Dan Date: Thu, 4 Nov 2021 13:32:57 -0400 Subject: [PATCH 3/3] Don't error out trying to send an error about invalid review types. --- crc/api/study.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crc/api/study.py b/crc/api/study.py index bbdcad01..593895a1 100644 --- a/crc/api/study.py +++ b/crc/api/study.py @@ -102,7 +102,7 @@ def user_studies(): if len(studies) == 0: studies = StudyService().get_studies_for_user(user, include_invalid=True) if len(studies) > 0: - message = f"All studies associated with User: {user.display_name} failed study validation" + message = f"All studies associated with User: {user.uid} failed study validation" raise ApiError(code="study_integrity_error", message=message) results = StudySchema(many=True).dump(studies)