Merge branch 'dev' into test-protocol-builder-519

This commit is contained in:
mike cullerton 2021-11-05 10:29:20 -04:00
commit 271d4da5ff
6 changed files with 107 additions and 30 deletions

View File

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

View File

@ -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 = "<!DOCTYPE html><html><head></head><body><div><h2>Hello</h2></div></body></html>"
email_model = EmailModel(subject=subject,
recipients=recipients,
content=content,

View File

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

View File

@ -1,43 +1,67 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" id="Definitions_0szq8v9" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="4.2.0">
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" id="Definitions_0szq8v9" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="4.2.0">
<bpmn:process id="Process_1dxw783" name="Get Localtime" isExecutable="true">
<bpmn:startEvent id="StartEvent_1">
<bpmn:outgoing>Flow_0lnc9x0</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:sequenceFlow id="Flow_0lnc9x0" sourceRef="StartEvent_1" targetRef="Activity_0aq21yg" />
<bpmn:sequenceFlow id="Flow_0gtgzcf" sourceRef="Activity_0aq21yg" targetRef="Activity_1by2ose" />
<bpmn:sequenceFlow id="Flow_0k1hbif" sourceRef="Activity_1by2ose" targetRef="Activity_0d5fjpa" />
<bpmn:sequenceFlow id="Flow_0lnc9x0" sourceRef="StartEvent_1" targetRef="Activity_GetData" />
<bpmn:sequenceFlow id="Flow_0gtgzcf" sourceRef="Activity_GetData" targetRef="Activity_GetLocaltime" />
<bpmn:sequenceFlow id="Flow_0k1hbif" sourceRef="Activity_GetLocaltime" targetRef="Activity_0d5fjpa" />
<bpmn:endEvent id="Event_1vxo45i">
<bpmn:incoming>Flow_0kgtoh1</bpmn:incoming>
</bpmn:endEvent>
<bpmn:sequenceFlow id="Flow_0kgtoh1" sourceRef="Activity_0d5fjpa" targetRef="Event_1vxo45i" />
<bpmn:scriptTask id="Activity_0aq21yg" name="Send Email">
<bpmn:documentation>This is my email</bpmn:documentation>
<bpmn:incoming>Flow_0lnc9x0</bpmn:incoming>
<bpmn:outgoing>Flow_0gtgzcf</bpmn:outgoing>
<bpmn:script>email_model = email(subject='My Email Subject', recipients='user@example.com')
email_data = get_email_data(email_id=email_model['id'])
</bpmn:script>
</bpmn:scriptTask>
<bpmn:scriptTask id="Activity_1by2ose" name="Get Localtime">
<bpmn:scriptTask id="Activity_GetLocaltime" name="Get Localtime">
<bpmn:documentation>timestamp = email_model.timestamp
localtime = get_localtime(str(timestamp))</bpmn:documentation>
<bpmn:incoming>Flow_0gtgzcf</bpmn:incoming>
<bpmn:outgoing>Flow_0k1hbif</bpmn:outgoing>
<bpmn:script>timestamp=email_model.timestamp
localtime = get_localtime(timestamp=timestamp)
</bpmn:script>
<bpmn:script>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()</bpmn:script>
</bpmn:scriptTask>
<bpmn:manualTask id="Activity_0d5fjpa" name="Display Times">
<bpmn:documentation># Timestamp
{{ timestamp }}
# Timezone
{{ timezone }}
# Localtime
{{ localtime }}</bpmn:documentation>
# Localtime With
{{ localtime_with }}
# Localtime Without
{{ localtime_without }}</bpmn:documentation>
<bpmn:incoming>Flow_0k1hbif</bpmn:incoming>
<bpmn:outgoing>Flow_0kgtoh1</bpmn:outgoing>
</bpmn:manualTask>
<bpmn:userTask id="Activity_GetData" name="Get Data" camunda:formKey="DataForm">
<bpmn:documentation>This is my email</bpmn:documentation>
<bpmn:extensionElements>
<camunda:formData>
<camunda:formField id="with_timestamp" label="With Timestamp" type="boolean" defaultValue="False">
<camunda:validation>
<camunda:constraint name="required" config="True" />
</camunda:validation>
</camunda:formField>
<camunda:formField id="with_timezone" label="With Timezone" type="boolean" defaultValue="False">
<camunda:validation>
<camunda:constraint name="required" config="True" />
</camunda:validation>
</camunda:formField>
<camunda:formField id="timestamp" label="Timestamp" type="string" />
<camunda:formField id="timezone" label="Timezone" type="string" />
</camunda:formData>
</bpmn:extensionElements>
<bpmn:incoming>Flow_0lnc9x0</bpmn:incoming>
<bpmn:outgoing>Flow_0gtgzcf</bpmn:outgoing>
</bpmn:userTask>
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1dxw783">
@ -63,15 +87,15 @@ localtime = get_localtime(timestamp=timestamp)
<bpmndi:BPMNShape id="Event_1vxo45i_di" bpmnElement="Event_1vxo45i">
<dc:Bounds x="752" y="99" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_01qg6wo_di" bpmnElement="Activity_0aq21yg">
<dc:Bounds x="270" y="77" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0q4ycxr_di" bpmnElement="Activity_1by2ose">
<bpmndi:BPMNShape id="Activity_0q4ycxr_di" bpmnElement="Activity_GetLocaltime">
<dc:Bounds x="430" y="77" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_178gn50_di" bpmnElement="Activity_0d5fjpa">
<dc:Bounds x="590" y="77" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0jhiwc1_di" bpmnElement="Activity_GetData">
<dc:Bounds x="270" y="77" width="100" height="80" />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>

View File

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

View File

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