mirror of
https://github.com/sartography/cr-connect-workflow.git
synced 2025-02-23 21:28:32 +00:00
Because this changes the endpoint for all existing document details, I've modified all the test and static bpmn files to use the new format. Shorting up the SponsorsList.xls file makes for slightly faster tests. seems senseless to load 5000 everytime we reset the data. Tried to test all of this carefully in the test_study_details_documents.py test.
68 lines
2.8 KiB
Python
68 lines
2.8 KiB
Python
import json
|
|
from unittest.mock import patch
|
|
|
|
from crc import db, session
|
|
from crc.api.common import ApiError
|
|
from crc.models.file import FileDataModel, FileModel
|
|
from crc.models.protocol_builder import ProtocolBuilderRequiredDocumentSchema
|
|
from crc.models.study import StudyModel
|
|
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 tests.base_test import BaseTest
|
|
|
|
|
|
class TestStudyDetailsDocumentsScript(BaseTest):
|
|
test_uid = "dhf8r"
|
|
test_study_id = 1
|
|
|
|
"""
|
|
1. get a list of all documents related to the study.
|
|
2. For this study, is this document required accroding to the protocol builder?
|
|
3. For ALL uploaded documents, what the total number of files that were uploaded? per instance of this document naming
|
|
convention that we are implementing for the IRB.
|
|
"""
|
|
|
|
def test_validate_returns_error_if_reference_files_do_not_exist(self):
|
|
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)
|
|
processor = WorkflowProcessor(workflow_model)
|
|
task = processor.next_task()
|
|
|
|
# Remove the reference file.
|
|
file_model = db.session.query(FileModel). \
|
|
filter(FileModel.is_reference == True). \
|
|
filter(FileModel.name == FileService.IRB_PRO_CATEGORIES_FILE).first()
|
|
if file_model:
|
|
db.session.query(FileDataModel).filter(FileDataModel.file_model_id == file_model.id).delete()
|
|
db.session.query(FileModel).filter(FileModel.id == file_model.id).delete()
|
|
db.session.commit()
|
|
db.session.flush()
|
|
|
|
with self.assertRaises(ApiError):
|
|
StudyInfo().do_task_validate_only(task, study.id, "documents")
|
|
|
|
def test_no_validation_error_when_correct_file_exists(self):
|
|
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)
|
|
processor = WorkflowProcessor(workflow_model)
|
|
task = processor.next_task()
|
|
StudyInfo().do_task_validate_only(task, study.id, "documents")
|
|
|
|
def test_load_lookup_data(self):
|
|
self.create_reference_document()
|
|
dict = FileService.get_file_reference_dictionary()
|
|
self.assertIsNotNone(dict)
|
|
|
|
def get_required_docs(self):
|
|
string_data = self.protocol_builder_response('required_docs.json')
|
|
return ProtocolBuilderRequiredDocumentSchema(many=True).loads(string_data)
|
|
|