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
This commit is contained in:
parent
8a6c1e1b51
commit
1f9c80d70d
|
@ -12,16 +12,21 @@ class GetLocaltime(Script):
|
||||||
Defaults to US/Eastern"""
|
Defaults to US/Eastern"""
|
||||||
|
|
||||||
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 len(args) > 0 or 'timestamp' in kwargs:
|
||||||
return self.do_task(task, study_id, workflow_id, *args, **kwargs)
|
return self.do_task(task, study_id, workflow_id, *args, **kwargs)
|
||||||
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.')
|
||||||
|
|
||||||
def do_task(self, task, study_id, workflow_id, *args, **kwargs):
|
def do_task(self, task, study_id, workflow_id, *args, **kwargs):
|
||||||
if 'timestamp' in kwargs:
|
if len(args) > 0 or 'timestamp' in kwargs:
|
||||||
timestamp = kwargs['timestamp']
|
if 'timestamp' in kwargs:
|
||||||
|
timestamp = kwargs['timestamp']
|
||||||
|
else:
|
||||||
|
timestamp = args[0]
|
||||||
if 'timezone' in kwargs:
|
if 'timezone' in kwargs:
|
||||||
timezone = kwargs['timezone']
|
timezone = kwargs['timezone']
|
||||||
|
elif len(args) > 1:
|
||||||
|
timezone = args[1]
|
||||||
else:
|
else:
|
||||||
timezone = 'US/Eastern'
|
timezone = 'US/Eastern'
|
||||||
parsed_timestamp = dateparser.parse(timestamp)
|
parsed_timestamp = dateparser.parse(timestamp)
|
||||||
|
|
|
@ -1,43 +1,67 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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:process id="Process_1dxw783" name="Get Localtime" isExecutable="true">
|
||||||
<bpmn:startEvent id="StartEvent_1">
|
<bpmn:startEvent id="StartEvent_1">
|
||||||
<bpmn:outgoing>Flow_0lnc9x0</bpmn:outgoing>
|
<bpmn:outgoing>Flow_0lnc9x0</bpmn:outgoing>
|
||||||
</bpmn:startEvent>
|
</bpmn:startEvent>
|
||||||
<bpmn:sequenceFlow id="Flow_0lnc9x0" sourceRef="StartEvent_1" targetRef="Activity_0aq21yg" />
|
<bpmn:sequenceFlow id="Flow_0lnc9x0" sourceRef="StartEvent_1" targetRef="Activity_GetData" />
|
||||||
<bpmn:sequenceFlow id="Flow_0gtgzcf" sourceRef="Activity_0aq21yg" targetRef="Activity_1by2ose" />
|
<bpmn:sequenceFlow id="Flow_0gtgzcf" sourceRef="Activity_GetData" targetRef="Activity_GetLocaltime" />
|
||||||
<bpmn:sequenceFlow id="Flow_0k1hbif" sourceRef="Activity_1by2ose" targetRef="Activity_0d5fjpa" />
|
<bpmn:sequenceFlow id="Flow_0k1hbif" sourceRef="Activity_GetLocaltime" targetRef="Activity_0d5fjpa" />
|
||||||
<bpmn:endEvent id="Event_1vxo45i">
|
<bpmn:endEvent id="Event_1vxo45i">
|
||||||
<bpmn:incoming>Flow_0kgtoh1</bpmn:incoming>
|
<bpmn:incoming>Flow_0kgtoh1</bpmn:incoming>
|
||||||
</bpmn:endEvent>
|
</bpmn:endEvent>
|
||||||
<bpmn:sequenceFlow id="Flow_0kgtoh1" sourceRef="Activity_0d5fjpa" targetRef="Event_1vxo45i" />
|
<bpmn:sequenceFlow id="Flow_0kgtoh1" sourceRef="Activity_0d5fjpa" targetRef="Event_1vxo45i" />
|
||||||
<bpmn:scriptTask id="Activity_0aq21yg" name="Send Email">
|
<bpmn:scriptTask id="Activity_GetLocaltime" name="Get Localtime">
|
||||||
<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:documentation>timestamp = email_model.timestamp
|
<bpmn:documentation>timestamp = email_model.timestamp
|
||||||
localtime = get_localtime(str(timestamp))</bpmn:documentation>
|
localtime = get_localtime(str(timestamp))</bpmn:documentation>
|
||||||
<bpmn:incoming>Flow_0gtgzcf</bpmn:incoming>
|
<bpmn:incoming>Flow_0gtgzcf</bpmn:incoming>
|
||||||
<bpmn:outgoing>Flow_0k1hbif</bpmn:outgoing>
|
<bpmn:outgoing>Flow_0k1hbif</bpmn:outgoing>
|
||||||
<bpmn:script>timestamp=email_model.timestamp
|
<bpmn:script>if with_timestamp:
|
||||||
localtime = get_localtime(timestamp=timestamp)
|
if with_timezone:
|
||||||
</bpmn:script>
|
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:scriptTask>
|
||||||
<bpmn:manualTask id="Activity_0d5fjpa" name="Display Times">
|
<bpmn:manualTask id="Activity_0d5fjpa" name="Display Times">
|
||||||
<bpmn:documentation># Timestamp
|
<bpmn:documentation># Timestamp
|
||||||
{{ timestamp }}
|
{{ timestamp }}
|
||||||
|
|
||||||
|
# Timezone
|
||||||
|
{{ timezone }}
|
||||||
|
|
||||||
# Localtime
|
# Localtime With
|
||||||
{{ localtime }}</bpmn:documentation>
|
{{ localtime_with }}
|
||||||
|
|
||||||
|
# Localtime Without
|
||||||
|
{{ localtime_without }}</bpmn:documentation>
|
||||||
<bpmn:incoming>Flow_0k1hbif</bpmn:incoming>
|
<bpmn:incoming>Flow_0k1hbif</bpmn:incoming>
|
||||||
<bpmn:outgoing>Flow_0kgtoh1</bpmn:outgoing>
|
<bpmn:outgoing>Flow_0kgtoh1</bpmn:outgoing>
|
||||||
</bpmn:manualTask>
|
</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>
|
</bpmn:process>
|
||||||
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
|
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
|
||||||
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1dxw783">
|
<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">
|
<bpmndi:BPMNShape id="Event_1vxo45i_di" bpmnElement="Event_1vxo45i">
|
||||||
<dc:Bounds x="752" y="99" width="36" height="36" />
|
<dc:Bounds x="752" y="99" width="36" height="36" />
|
||||||
</bpmndi:BPMNShape>
|
</bpmndi:BPMNShape>
|
||||||
<bpmndi:BPMNShape id="Activity_01qg6wo_di" bpmnElement="Activity_0aq21yg">
|
<bpmndi:BPMNShape id="Activity_0q4ycxr_di" bpmnElement="Activity_GetLocaltime">
|
||||||
<dc:Bounds x="270" y="77" width="100" height="80" />
|
|
||||||
</bpmndi:BPMNShape>
|
|
||||||
<bpmndi:BPMNShape id="Activity_0q4ycxr_di" bpmnElement="Activity_1by2ose">
|
|
||||||
<dc:Bounds x="430" y="77" width="100" height="80" />
|
<dc:Bounds x="430" y="77" width="100" height="80" />
|
||||||
</bpmndi:BPMNShape>
|
</bpmndi:BPMNShape>
|
||||||
<bpmndi:BPMNShape id="Activity_178gn50_di" bpmnElement="Activity_0d5fjpa">
|
<bpmndi:BPMNShape id="Activity_178gn50_di" bpmnElement="Activity_0d5fjpa">
|
||||||
<dc:Bounds x="590" y="77" width="100" height="80" />
|
<dc:Bounds x="590" y="77" width="100" height="80" />
|
||||||
</bpmndi:BPMNShape>
|
</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:BPMNPlane>
|
||||||
</bpmndi:BPMNDiagram>
|
</bpmndi:BPMNDiagram>
|
||||||
</bpmn:definitions>
|
</bpmn:definitions>
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
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
|
import dateparser
|
||||||
|
import datetime
|
||||||
|
|
||||||
|
|
||||||
class TestGetLocaltime(BaseTest):
|
class TestGetLocaltime(BaseTest):
|
||||||
|
@ -8,11 +9,51 @@ class TestGetLocaltime(BaseTest):
|
||||||
def test_get_localtime(self):
|
def test_get_localtime(self):
|
||||||
self.load_example_data()
|
self.load_example_data()
|
||||||
|
|
||||||
|
timestamp = datetime.datetime.utcnow()
|
||||||
workflow = self.create_workflow('get_localtime')
|
workflow = self.create_workflow('get_localtime')
|
||||||
|
|
||||||
workflow_api = self.get_workflow_api(workflow)
|
workflow_api = self.get_workflow_api(workflow)
|
||||||
task = workflow_api.next_task
|
task = workflow_api.next_task
|
||||||
|
|
||||||
timestamp = task.data['timestamp']
|
workflow_api = self.complete_form(workflow, task, {'with_timestamp': True,
|
||||||
localtime = task.data['localtime']
|
'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})
|
||||||
|
|
Loading…
Reference in New Issue