337 partial fix

if the user calls the file_data_set function for a valid file with the key 'irb_code' and a value of a valid IRB document code, then we should set the irb code on the file.
This commit is contained in:
Kelly McDonald 2021-05-27 12:24:30 -04:00
parent ef7ee284b2
commit a5d67bb245
3 changed files with 76 additions and 2 deletions

View File

@ -3,6 +3,7 @@ from flask import g
from crc.api.common import ApiError
from crc.scripts.data_store_base import DataStoreBase
from crc.scripts.script import Script
from crc.services.file_service import FileService
class FileDataSet(Script, DataStoreBase):
@ -34,8 +35,19 @@ class FileDataSet(Script, DataStoreBase):
def do_task(self, task, study_id, workflow_id, *args, **kwargs):
if self.validate_kw_args(**kwargs):
myargs = [kwargs['key'],kwargs['value']]
fileid = kwargs['file_id']
try:
fileid = int(kwargs['file_id'])
except:
raise ApiError("invalid_file_id",
"Attempting to update DataStore for an invalid fileid '%s'" % kwargs['file_id'])
del(kwargs['file_id'])
if kwargs['key'] == 'irb_code':
irb_doc_code = kwargs['value']
FileService.update_irb_code(fileid,irb_doc_code)
return self.set_data_common(task.id,
None,
None,

View File

@ -97,6 +97,27 @@ class FileService(object):
review = any([f.is_review for f in files])
return review
@staticmethod
def update_irb_code(file_id, irb_doc_code):
"""Create a new file and associate it with the workflow
Please note that the irb_doc_code MUST be a known file in the irb_documents.xslx reference document."""
if not FileService.is_allowed_document(irb_doc_code):
raise ApiError("invalid_form_field_key",
"When uploading files, the form field id must match a known document in the "
"irb_docunents.xslx reference file. This code is not found in that file '%s'" % irb_doc_code)
""" """
file_model = session.query(FileModel)\
.filter(FileModel.id == file_id).first()
if file_model is None:
raise ApiError("invalid_file_id",
"When updating the irb_doc_code for a file, that file_id must already exist "
"This file_id is not found in the database '%d'" % file_id)
file_model.irb_doc_code = irb_doc_code
session.commit()
return True
@staticmethod
def add_workflow_file(workflow_id, irb_doc_code, name, content_type, binary_data):

View File

@ -113,4 +113,45 @@ class TestStudyDetailsDocumentsScript(BaseTest):
docs = StudyInfo().do_task(task, study.id, workflow_model.id, "documents")
self.assertTrue(isinstance(docs, Box))
self.assertEquals(1, len(docs.UVACompl_PRCAppr.files))
self.assertEquals("doodle", docs.UVACompl_PRCAppr.files[0].data_store.ginger)
self.assertEquals("doodle", docs.UVACompl_PRCAppr.files[0].data_store.ginger)
@patch('crc.services.protocol_builder.requests.get')
def test_file_data_set_changes_irb_code(self, mock_get):
mock_get.return_value.ok = True
mock_get.return_value.text = self.protocol_builder_response('required_docs.json')
self.load_example_data()
self.create_reference_document()
study = session.query(StudyModel).first()
workflow_spec_model = self.load_test_spec("two_forms")
workflow_model = StudyService._create_workflow_model(study, workflow_spec_model)
irb_code = "UVACompl_PRCAppr" # The first file referenced in pb required docs.
file = FileService.add_workflow_file(workflow_id=workflow_model.id,
name="anything.png", content_type="text",
binary_data=b'1234', irb_doc_code=irb_code)
processor = WorkflowProcessor(workflow_model)
task = processor.next_task()
FileDataSet().do_task(task, study.id, workflow_model.id, key="irb_code", value="Study_App_Doc", file_id=file.id)
docs = StudyInfo().do_task(task, study.id, workflow_model.id, "documents")
self.assertTrue(isinstance(docs, Box))
self.assertEquals(1, len(docs.Study_App_Doc.files))
self.assertEquals("Study_App_Doc", docs.Study_App_Doc.files[0].data_store.irb_code)
@patch('crc.services.protocol_builder.requests.get')
def test_file_data_set_invalid_irb_code_fails(self, mock_get):
mock_get.return_value.ok = True
mock_get.return_value.text = self.protocol_builder_response('required_docs.json')
self.load_example_data()
self.create_reference_document()
study = session.query(StudyModel).first()
workflow_spec_model = self.load_test_spec("two_forms")
workflow_model = StudyService._create_workflow_model(study, workflow_spec_model)
irb_code = "UVACompl_PRCAppr" # The first file referenced in pb required docs.
file = FileService.add_workflow_file(workflow_id=workflow_model.id,
name="anything.png", content_type="text",
binary_data=b'1234', irb_doc_code=irb_code)
processor = WorkflowProcessor(workflow_model)
task = processor.next_task()
with self.assertRaises(ApiError):
FileDataSet().do_task(task, study.id, workflow_model.id, key="irb_code", value="My_Pretty_Pony",
file_id=file.id)