Merge pull request #313 from sartography/feature/add_file_data_store_properties_to_file
Assure that any data store values associated with a file come back as…
This commit is contained in:
commit
668e2f4e3c
|
@ -6,11 +6,13 @@ from typing import List
|
|||
import flask
|
||||
import requests
|
||||
from SpiffWorkflow import WorkflowException
|
||||
from SpiffWorkflow.bpmn.PythonScriptEngine import Box
|
||||
from SpiffWorkflow.exceptions import WorkflowTaskExecException
|
||||
from ldap3.core.exceptions import LDAPSocketOpenError
|
||||
|
||||
from crc import db, session, app
|
||||
from crc.api.common import ApiError
|
||||
from crc.models.data_store import DataStoreModel
|
||||
from crc.models.email import EmailModel
|
||||
from crc.models.file import FileDataModel, FileModel, FileModelSchema, File, LookupFileModel, LookupDataModel
|
||||
from crc.models.ldap import LdapSchema
|
||||
|
@ -297,21 +299,27 @@ class StudyService(object):
|
|||
if hasattr(flask.g,'user'):
|
||||
token = flask.g.user.encode_auth_token()
|
||||
for file in doc_files:
|
||||
doc['files'].append({'file_id': file.id,
|
||||
'name': file.name,
|
||||
'url': app.config['APPLICATION_ROOT']+
|
||||
'file/' + str(file.id) +
|
||||
'/download?auth_token='+
|
||||
urllib.parse.quote_plus(token),
|
||||
'workflow_id': file.workflow_id})
|
||||
|
||||
file_data = {'file_id': file.id,
|
||||
'name': file.name,
|
||||
'url': app.config['APPLICATION_ROOT']+
|
||||
'file/' + str(file.id) +
|
||||
'/download?auth_token='+
|
||||
urllib.parse.quote_plus(token),
|
||||
'workflow_id': file.workflow_id
|
||||
}
|
||||
data = db.session.query(DataStoreModel).filter(DataStoreModel.file_id==file.id).all()
|
||||
data_store_data = {}
|
||||
for d in data:
|
||||
data_store_data[d.key] = d.value
|
||||
file_data["data_store"] = data_store_data
|
||||
doc['files'].append(Box(file_data))
|
||||
# update the document status to match the status of the workflow it is in.
|
||||
if 'status' not in doc or doc['status'] is None:
|
||||
workflow: WorkflowModel = session.query(WorkflowModel).filter_by(id=file.workflow_id).first()
|
||||
doc['status'] = workflow.status.value
|
||||
|
||||
documents[code] = doc
|
||||
return documents
|
||||
return Box(documents)
|
||||
|
||||
@staticmethod
|
||||
def get_investigators(study_id, all=False):
|
||||
|
|
|
@ -14,6 +14,7 @@ from crc.scripts.study_info import StudyInfo
|
|||
from crc.services.file_service import FileService
|
||||
from crc.services.study_service import StudyService
|
||||
from crc.services.workflow_processor import WorkflowProcessor
|
||||
from crc.scripts.file_data_set import FileDataSet
|
||||
|
||||
|
||||
class TestStudyDetailsDocumentsScript(BaseTest):
|
||||
|
@ -93,3 +94,23 @@ class TestStudyDetailsDocumentsScript(BaseTest):
|
|||
docs = StudyInfo().do_task_validate_only(task, study.id, workflow_model.id, "documents")
|
||||
self.assertTrue(isinstance(docs, Box))
|
||||
|
||||
@patch('crc.services.protocol_builder.requests.get')
|
||||
def test_study_info_returns_document_data_store_values_with_documents(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="ginger", value="doodle", 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.UVACompl_PRCAppr.files))
|
||||
self.assertEquals("doodle", docs.UVACompl_PRCAppr.files[0].data_store.ginger)
|
Loading…
Reference in New Issue