service and scripts with working test - still needs a few more tests to try out, but should work to get Mike going

This commit is contained in:
Kelly McDonald 2021-02-24 12:55:23 -05:00
parent c795dd7aea
commit 9bd3aa8dcb
5 changed files with 165 additions and 8 deletions

View File

@ -68,7 +68,7 @@ class Script(object):
def make_closure_validate(subclass,task,study_id,workflow_id): def make_closure_validate(subclass,task,study_id,workflow_id):
instance = subclass() instance = subclass()
return lambda *a : subclass.do_task_validate_only(instance,task,study_id,workflow_id,*a) return lambda *a, **b: subclass.do_task_validate_only(instance,task,study_id,workflow_id,*a,**b)
execlist = {} execlist = {}
subclasses = Script.get_all_subclasses() subclasses = Script.get_all_subclasses()
for x in range(len(subclasses)): for x in range(len(subclasses)):

View File

@ -107,7 +107,7 @@ class StudyService(object):
person = db.session.query(StudyAssociated).filter((StudyAssociated.study_id == study_id)&( person = db.session.query(StudyAssociated).filter((StudyAssociated.study_id == study_id)&(
StudyAssociated.uid == uid)) StudyAssociated.uid == uid))
if person: if person:
newAssociate = {'uid',person.uid} newAssociate = {'uid':person.uid}
newAssociate['role'] = person.role newAssociate['role'] = person.role
newAssociate['send_email'] = person.send_email newAssociate['send_email'] = person.send_email
newAssociate['access'] = person.access newAssociate['access'] = person.access
@ -129,7 +129,7 @@ class StudyService(object):
people_list = [{'uid':ownerid,'role':'owner','send_email':True,'access':True}] people_list = [{'uid':ownerid,'role':'owner','send_email':True,'access':True}]
people = db.session.query(StudyAssociated).filter(StudyAssociated.study_id == study_id) people = db.session.query(StudyAssociated).filter(StudyAssociated.study_id == study_id)
for person in people: for person in people:
newAssociate = {'uid',person.uid} newAssociate = {'uid':person.uid}
newAssociate['role'] = person.role newAssociate['role'] = person.role
newAssociate['send_email'] = person.send_email newAssociate['send_email'] = person.send_email
newAssociate['access'] = person.access newAssociate['access'] = person.access
@ -165,12 +165,13 @@ class StudyService(object):
db.session.query(StudyAssociated).filter(StudyAssociated.study_id == study_id).delete() db.session.query(StudyAssociated).filter(StudyAssociated.study_id == study_id).delete()
for person in associates: for person in associates:
newAssociate = StudyAssociated() newAssociate = StudyAssociated()
newAssociate.study_id = study_id
newAssociate.uid = person['uid'] newAssociate.uid = person['uid']
newAssociate.role = person.get('role', None) newAssociate.role = person.get('role', None)
newAssociate.send_email = person.get('send_email', False) newAssociate.send_email = person.get('send_email', False)
newAssociate.access = person.get('access',False) newAssociate.access = person.get('access',False)
db.session.add(newAssociate) session.add(newAssociate)
db.commit() session.commit()
@staticmethod @staticmethod
def update_study_associate(study_id=None,uid=None,role="",send_email=False,access=False): def update_study_associate(study_id=None,uid=None,role="",send_email=False,access=False):
@ -191,13 +192,14 @@ class StudyService(object):
uid) ).delete() uid) ).delete()
newAssociate = StudyAssociated() newAssociate = StudyAssociated()
newAssociate.study_id = study_id
newAssociate.uid = uid newAssociate.uid = uid
newAssociate.role = role newAssociate.role = role
newAssociate.send_email = send_email newAssociate.send_email = send_email
newAssociate.access = access newAssociate.access = access
db.session.add(newAssociate) session.add(newAssociate)
db.commit() session.commit()
return true return True
@staticmethod @staticmethod

View File

@ -0,0 +1,38 @@
"""empty message
Revision ID: cb892916166a
Revises: ff29528a9909
Create Date: 2021-02-24 12:16:45.779821
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'cb892916166a'
down_revision = 'ff29528a9909'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('study_associated_user',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('study_id', sa.Integer(), nullable=False),
sa.Column('uid', sa.String(), nullable=False),
sa.Column('role', sa.String(), nullable=True),
sa.Column('send_email', sa.Boolean(), nullable=True),
sa.Column('access', sa.Boolean(), nullable=True),
sa.ForeignKeyConstraint(['study_id'], ['study.id'], ),
sa.ForeignKeyConstraint(['uid'], ['ldap_model.uid'], ),
sa.PrimaryKeyConstraint('id')
)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('study_associated_user')
# ### end Alembic commands ###

View File

@ -0,0 +1,65 @@
<?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" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="Definitions_0kmksnn" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="3.7.0">
<bpmn:process id="Process_0exnnpv" isExecutable="true">
<bpmn:startEvent id="StartEvent_1">
<bpmn:outgoing>SequenceFlow_1nfe5m9</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:sequenceFlow id="SequenceFlow_1nfe5m9" sourceRef="StartEvent_1" targetRef="Task_Script_Load_Study_Sponsors" />
<bpmn:scriptTask id="Task_Script_Load_Study_Sponsors" name="Load Study Sponsors">
<bpmn:incoming>SequenceFlow_1nfe5m9</bpmn:incoming>
<bpmn:outgoing>SequenceFlow_1bqiin0</bpmn:outgoing>
<bpmn:script>sponsors = study_info('sponsors')</bpmn:script>
</bpmn:scriptTask>
<bpmn:sequenceFlow id="SequenceFlow_1bqiin0" sourceRef="Task_Script_Load_Study_Sponsors" targetRef="Activity_0cm6tn2" />
<bpmn:sequenceFlow id="Flow_09cika8" sourceRef="Activity_0cm6tn2" targetRef="Activity_0d8iftx" />
<bpmn:scriptTask id="Activity_0cm6tn2" name="setval">
<bpmn:incoming>SequenceFlow_1bqiin0</bpmn:incoming>
<bpmn:outgoing>Flow_09cika8</bpmn:outgoing>
<bpmn:script>update_study_associate(uid='lb3dp',role='SuperDude',send_email=False,access=True)</bpmn:script>
</bpmn:scriptTask>
<bpmn:scriptTask id="Activity_0d8iftx" name="getval">
<bpmn:incoming>Flow_09cika8</bpmn:incoming>
<bpmn:outgoing>Flow_0cttkwp</bpmn:outgoing>
<bpmn:script>out = get_study_associates()</bpmn:script>
</bpmn:scriptTask>
<bpmn:endEvent id="Event_0c8gcuh">
<bpmn:incoming>Flow_0cttkwp</bpmn:incoming>
</bpmn:endEvent>
<bpmn:sequenceFlow id="Flow_0cttkwp" sourceRef="Activity_0d8iftx" targetRef="Event_0c8gcuh" />
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_0exnnpv">
<bpmndi:BPMNEdge id="SequenceFlow_1bqiin0_di" bpmnElement="SequenceFlow_1bqiin0">
<di:waypoint x="370" y="117" />
<di:waypoint x="440" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="SequenceFlow_1nfe5m9_di" bpmnElement="SequenceFlow_1nfe5m9">
<di:waypoint x="215" y="117" />
<di:waypoint x="270" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
<dc:Bounds x="179" y="99" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="ScriptTask_1mp6xid_di" bpmnElement="Task_Script_Load_Study_Sponsors">
<dc:Bounds x="270" y="77" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="Flow_09cika8_di" bpmnElement="Flow_09cika8">
<di:waypoint x="540" y="117" />
<di:waypoint x="600" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="Activity_0wnwluq_di" bpmnElement="Activity_0cm6tn2">
<dc:Bounds x="440" y="77" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0cq37mm_di" bpmnElement="Activity_0d8iftx">
<dc:Bounds x="600" y="77" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_0c8gcuh_di" bpmnElement="Event_0c8gcuh">
<dc:Bounds x="762" y="99" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="Flow_0cttkwp_di" bpmnElement="Flow_0cttkwp">
<di:waypoint x="700" y="117" />
<di:waypoint x="762" y="117" />
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>

View File

@ -0,0 +1,52 @@
from unittest.mock import patch
import flask
from tests.base_test import BaseTest
from crc import session, app
from crc.models.study import StudyModel
from crc.models.user import UserModel
from crc.services.study_service import StudyService
from crc.services.workflow_processor import WorkflowProcessor
from crc.services.workflow_service import WorkflowService
class TestSudySponsorsScript(BaseTest):
test_uid = "dhf8r"
test_study_id = 1
def test_study_sponsors_script_validation(self):
flask.g.user = UserModel(uid='dhf8r')
self.load_example_data() # study_info script complains if irb_documents.xls is not loaded
# during the validate phase I'm going to assume that we will never
# have a case where irb_documents.xls is not loaded ??
self.load_test_spec("study_sponsors_associate")
WorkflowService.test_spec("study_sponsors_associate") # This would raise errors if it didn't validate
@patch('crc.services.protocol_builder.requests.get')
def test_study_sponsors_script(self, mock_get):
mock_get.return_value.ok = True
mock_get.return_value.text = self.protocol_builder_response('sponsors.json')
flask.g.user = UserModel(uid='dhf8r')
app.config['PB_ENABLED'] = True
self.load_example_data()
self.create_reference_document()
study = session.query(StudyModel).first()
workflow_spec_model = self.load_test_spec("study_sponsors_associate")
workflow_model = StudyService._create_workflow_model(study, workflow_spec_model)
WorkflowService.test_spec("study_sponsors_associate")
processor = WorkflowProcessor(workflow_model)
processor.do_engine_steps()
self.assertTrue(processor.bpmn_workflow.is_completed())
data = processor.next_task().data
self.assertIn('sponsors', data)
self.assertIn('out', data)
print(data['out'])
self.assertEquals([{'uid': 'dhf8r', 'role': 'owner', 'send_email': True, 'access': True},
{'uid': 'lb3dp', 'role': 'SuperDude', 'send_email': False, 'access': True}]
, data['out'])
self.assertEquals(3, len(data['sponsors']))