Add test and fix to make sure that an empty study associates list (or a blank list) will effectively clear the extra study associates

This commit is contained in:
Kelly McDonald 2021-06-01 11:46:43 -04:00
parent ef7ee284b2
commit 8c04e228e9
3 changed files with 124 additions and 14 deletions

View File

@ -4,13 +4,11 @@ from crc.services.study_service import StudyService
class UpdateStudyAssociates(Script): class UpdateStudyAssociates(Script):
argument_error_message = "You must supply at least one argument to the " \ argument_error_message = "You must supply at least one argument to the " \
"update_study_associates task, an array of objects in the form " \ "update_study_associates task, an array of objects in the form " \
"{'uid':'someid', 'role': 'text', 'send_email: 'boolean', " \ "{'uid':'someid', 'role': 'text', 'send_email: 'boolean', " \
"'access':'boolean'} " "'access':'boolean'} "
def get_description(self): def get_description(self):
return """ return """
Allows you to associate other users with a study - only 'uid' is required in the Allows you to associate other users with a study - only 'uid' is required in the
@ -26,20 +24,26 @@ associations already in place.
example : update_study_associates([{'uid':'sbp3ey','role':'Unicorn Herder', 'send_email': False, 'access':True}]) example : update_study_associates([{'uid':'sbp3ey','role':'Unicorn Herder', 'send_email': False, 'access':True}])
""" """
def validate_arg(self, arg): def validate_arg(self, arg):
if not isinstance(arg, list): if not isinstance(arg, list):
raise ApiError("invalid parameter", "This function is expecting a list of dictionaries") raise ApiError("invalid parameter", "This function is expecting a list of dictionaries")
if len(arg[0]) > 0:
if not len(arg) > 0 and not isinstance(arg[0], dict): if not len(arg) > 0 and not isinstance(arg[0], dict):
raise ApiError("invalid paramemter", "This function is expecting a list of dictionaries") raise ApiError("invalid paramemter", "This function is expecting a list of dictionaries")
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 len(args) == 0:
items = []
else:
items = args[0] items = args[0]
self.validate_arg(items) self.validate_arg(items)
return all([x.get('uid', False) for x in items]) return all([x.get('uid', False) for x in items])
def do_task(self, task, study_id, workflow_id, *args, **kwargs): def do_task(self, task, study_id, workflow_id, *args, **kwargs):
if len(args) == 0:
access_list = []
else:
access_list = args[0] access_list = args[0]
self.validate_arg(access_list) self.validate_arg(access_list)
return StudyService.update_study_associates(study_id, access_list) return StudyService.update_study_associates(study_id, access_list)

View File

@ -0,0 +1,79 @@
<?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_1on1n5v" />
<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='SuperGal',send_email=False,access=True)
update_study_associate(uid='lje5u',role='SuperGal2',send_email=False,access=False)</bpmn:script>
</bpmn:scriptTask>
<bpmn:endEvent id="Event_0c8gcuh">
<bpmn:incoming>Flow_0axwrzg</bpmn:incoming>
</bpmn:endEvent>
<bpmn:task id="Activity_0s3e9zu" name="Meaningless User Task">
<bpmn:documentation>This should just leave us a task to complete after the update_study_assocate script</bpmn:documentation>
<bpmn:incoming>Flow_1xi8k3i</bpmn:incoming>
<bpmn:outgoing>Flow_0axwrzg</bpmn:outgoing>
</bpmn:task>
<bpmn:sequenceFlow id="Flow_0axwrzg" sourceRef="Activity_0s3e9zu" targetRef="Event_0c8gcuh" />
<bpmn:sequenceFlow id="Flow_1xi8k3i" sourceRef="Activity_1on1n5v" targetRef="Activity_0s3e9zu" />
<bpmn:scriptTask id="Activity_1on1n5v" name="Zap Associates">
<bpmn:incoming>Flow_09cika8</bpmn:incoming>
<bpmn:outgoing>Flow_1xi8k3i</bpmn:outgoing>
<bpmn:script>update_study_associates()</bpmn:script>
</bpmn:scriptTask>
</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="Event_0c8gcuh_di" bpmnElement="Event_0c8gcuh">
<dc:Bounds x="1042" y="99" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0s3e9zu_di" bpmnElement="Activity_0s3e9zu">
<dc:Bounds x="790" y="77" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="Flow_0axwrzg_di" bpmnElement="Flow_0axwrzg">
<di:waypoint x="890" y="117" />
<di:waypoint x="1042" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1xi8k3i_di" bpmnElement="Flow_1xi8k3i">
<di:waypoint x="700" y="117" />
<di:waypoint x="790" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="Activity_13lcouw_di" bpmnElement="Activity_1on1n5v">
<dc:Bounds x="600" y="77" width="100" height="80" />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>

View File

@ -161,3 +161,30 @@ class TestSudySponsorsScript(BaseTest):
app.config['PB_ENABLED'] = False app.config['PB_ENABLED'] = False
output = user_studies() output = user_studies()
self.assertEqual(len(output),0) self.assertEqual(len(output),0)
@patch('crc.services.protocol_builder.requests.get')
def test_study_sponsors_script_ensure_delete(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_associates_delete")
workflow_model = StudyService._create_workflow_model(study, workflow_spec_model)
WorkflowService.test_spec("study_sponsors_associates_delete")
processor = WorkflowProcessor(workflow_model)
processor.do_engine_steps()
# change user and make sure we can access the study
flask.g.user = UserModel(uid='lb3dp')
flask.g.token = 'my spiffy token'
app.config['PB_ENABLED'] = False
output = user_studies()
self.assertEqual(len(output),0)
flask.g.token = 'my spiffy token'
app.config['PB_ENABLED'] = False
output = user_studies()
self.assertEqual(len(output),0)