mirror of
https://github.com/sartography/cr-connect-workflow.git
synced 2025-02-23 05:08:32 +00:00
Merge pull request #512 from sartography/bug/same_uid_different_roles
Study Associates Bug
This commit is contained in:
commit
65da5a34ce
@ -236,16 +236,19 @@ class StudyService(object):
|
||||
study = db.session.query(StudyModel).filter(StudyModel.id == study_id).first()
|
||||
if study is None:
|
||||
raise ApiError('study_id not found', "A study with id# %d was not found" % study_id)
|
||||
db.session.query(StudyAssociated).filter((StudyAssociated.study_id == study_id) & (StudyAssociated.uid ==
|
||||
uid)).delete()
|
||||
|
||||
newAssociate = StudyAssociated()
|
||||
newAssociate.study_id = study_id
|
||||
newAssociate.uid = uid
|
||||
newAssociate.role = role
|
||||
newAssociate.send_email = send_email
|
||||
newAssociate.access = access
|
||||
session.add(newAssociate)
|
||||
assoc = db.session.query(StudyAssociated).filter((StudyAssociated.study_id == study_id) &
|
||||
(StudyAssociated.uid == uid) &
|
||||
(StudyAssociated.role == role)).first()
|
||||
if not assoc:
|
||||
assoc = StudyAssociated()
|
||||
|
||||
assoc.study_id = study_id
|
||||
assoc.uid = uid
|
||||
assoc.role = role
|
||||
assoc.send_email = send_email
|
||||
assoc.access = access
|
||||
session.add(assoc)
|
||||
session.commit()
|
||||
return True
|
||||
|
||||
|
33
tests/scripts/test_set_study_associate.py
Normal file
33
tests/scripts/test_set_study_associate.py
Normal file
@ -0,0 +1,33 @@
|
||||
from tests.base_test import BaseTest
|
||||
|
||||
from crc import session, db
|
||||
from crc.models.study import StudyModel, StudyAssociated
|
||||
from crc.scripts.update_study_associate import UpdateStudyAssociates
|
||||
|
||||
|
||||
class TestSetStudyAssociate(BaseTest):
|
||||
|
||||
def setUp(self):
|
||||
self.workflow = self.create_workflow('study_associates_validation')
|
||||
self.workflow_api = self.get_workflow_api(self.workflow)
|
||||
self.task = self.workflow_api.next_task
|
||||
self.study_id = self.workflow.study_id
|
||||
self.update_script = UpdateStudyAssociates()
|
||||
|
||||
def test_update_study_associate(self):
|
||||
self.update_script.do_task(self.task, self.study_id, self.workflow.id, uid='dhf8r', role='PI')
|
||||
associates = db.session.query(StudyAssociated).filter(StudyAssociated.study_id == self.study_id).all()
|
||||
self.assertEqual(1, len(associates))
|
||||
|
||||
def test_no_duplicate_associates(self):
|
||||
self.update_script.do_task(self.task, self.study_id, self.workflow.id, uid='dhf8r', role='PI')
|
||||
self.update_script.do_task(self.task, self.study_id, self.workflow.id, uid='dhf8r', role='PI')
|
||||
self.update_script.do_task(self.task, self.study_id, self.workflow.id, uid='dhf8r', role='PI')
|
||||
associates = db.session.query(StudyAssociated).filter(StudyAssociated.study_id == self.study_id).all()
|
||||
self.assertEqual(1, len(associates))
|
||||
|
||||
def test_same_uid_in_two_rules(self):
|
||||
self.update_script.do_task(self.task, self.study_id, self.workflow.id, uid='dhf8r', role='PI')
|
||||
self.update_script.do_task(self.task, self.study_id, self.workflow.id, uid='dhf8r', role='DC')
|
||||
associates = db.session.query(StudyAssociated).filter(StudyAssociated.study_id == self.study_id).all()
|
||||
self.assertEqual(2, len(associates))
|
Loading…
x
Reference in New Issue
Block a user