Added mocked pb study_details since we now check whether a study has valid REVIEW_TYPEs
This commit is contained in:
parent
95c710768e
commit
445d3e5f0b
|
@ -2,6 +2,7 @@ from tests.base_test import BaseTest
|
||||||
from crc import session
|
from crc import session
|
||||||
from crc.models.study import StudyModel, StudyStatus, StudySchema
|
from crc.models.study import StudyModel, StudyStatus, StudySchema
|
||||||
import json
|
import json
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
|
||||||
class TestStudyActionsStatus(BaseTest):
|
class TestStudyActionsStatus(BaseTest):
|
||||||
|
@ -20,8 +21,11 @@ class TestStudyActionsStatus(BaseTest):
|
||||||
study_result = session.query(StudyModel).filter(StudyModel.id == study.id).first()
|
study_result = session.query(StudyModel).filter(StudyModel.id == study.id).first()
|
||||||
return study_result
|
return study_result
|
||||||
|
|
||||||
def test_hold_study(self):
|
@patch('crc.services.protocol_builder.ProtocolBuilderService.get_study_details') # mock_details
|
||||||
|
def test_hold_study(self, mock_details):
|
||||||
self.load_example_data()
|
self.load_example_data()
|
||||||
|
details_response = self.protocol_builder_response('study_details.json')
|
||||||
|
mock_details.return_value = json.loads(details_response)
|
||||||
|
|
||||||
study = session.query(StudyModel).first()
|
study = session.query(StudyModel).first()
|
||||||
self.assertEqual(study.status, StudyStatus.in_progress)
|
self.assertEqual(study.status, StudyStatus.in_progress)
|
||||||
|
@ -33,8 +37,11 @@ class TestStudyActionsStatus(BaseTest):
|
||||||
study_result = self.update_study_status(study, study_schema)
|
study_result = self.update_study_status(study, study_schema)
|
||||||
self.assertEqual(StudyStatus.hold, study_result.status)
|
self.assertEqual(StudyStatus.hold, study_result.status)
|
||||||
|
|
||||||
def test_abandon_study(self):
|
@patch('crc.services.protocol_builder.ProtocolBuilderService.get_study_details') # mock_details
|
||||||
|
def test_abandon_study(self, mock_details):
|
||||||
self.load_example_data()
|
self.load_example_data()
|
||||||
|
details_response = self.protocol_builder_response('study_details.json')
|
||||||
|
mock_details.return_value = json.loads(details_response)
|
||||||
|
|
||||||
study = session.query(StudyModel).first()
|
study = session.query(StudyModel).first()
|
||||||
self.assertEqual(study.status, StudyStatus.in_progress)
|
self.assertEqual(study.status, StudyStatus.in_progress)
|
||||||
|
@ -46,8 +53,11 @@ class TestStudyActionsStatus(BaseTest):
|
||||||
study_result = self.update_study_status(study, study_schema)
|
study_result = self.update_study_status(study, study_schema)
|
||||||
self.assertEqual(StudyStatus.abandoned, study_result.status)
|
self.assertEqual(StudyStatus.abandoned, study_result.status)
|
||||||
|
|
||||||
def test_open_enrollment_study(self):
|
@patch('crc.services.protocol_builder.ProtocolBuilderService.get_study_details') # mock_details
|
||||||
|
def test_open_enrollment_study(self, mock_details):
|
||||||
self.load_example_data()
|
self.load_example_data()
|
||||||
|
details_response = self.protocol_builder_response('study_details.json')
|
||||||
|
mock_details.return_value = json.loads(details_response)
|
||||||
|
|
||||||
study = session.query(StudyModel).first()
|
study = session.query(StudyModel).first()
|
||||||
self.assertEqual(study.status, StudyStatus.in_progress)
|
self.assertEqual(study.status, StudyStatus.in_progress)
|
||||||
|
|
|
@ -138,10 +138,13 @@ class TestSudySponsorsScript(BaseTest):
|
||||||
# who is allowed access
|
# who is allowed access
|
||||||
|
|
||||||
|
|
||||||
|
@patch('crc.services.protocol_builder.ProtocolBuilderService.get_study_details') # mock_details
|
||||||
@patch('crc.services.protocol_builder.requests.get')
|
@patch('crc.services.protocol_builder.requests.get')
|
||||||
def test_study_sponsors_script_ensure_access(self, mock_get):
|
def test_study_sponsors_script_ensure_access(self, mock_get, mock_details):
|
||||||
mock_get.return_value.ok = True
|
mock_get.return_value.ok = True
|
||||||
mock_get.return_value.text = self.protocol_builder_response('sponsors.json')
|
mock_get.return_value.text = self.protocol_builder_response('sponsors.json')
|
||||||
|
details_response = self.protocol_builder_response('study_details.json')
|
||||||
|
mock_details.return_value = json.loads(details_response)
|
||||||
flask.g.user = UserModel(uid='dhf8r')
|
flask.g.user = UserModel(uid='dhf8r')
|
||||||
app.config['PB_ENABLED'] = True
|
app.config['PB_ENABLED'] = True
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ from crc.models.study import StudyModel, StudySchema
|
||||||
from crc.models.workflow import WorkflowModel, WorkflowSpecModel
|
from crc.models.workflow import WorkflowModel, WorkflowSpecModel
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
|
||||||
class TestStudyCancellations(BaseTest):
|
class TestStudyCancellations(BaseTest):
|
||||||
|
@ -60,7 +61,10 @@ class TestStudyCancellations(BaseTest):
|
||||||
self.assertEqual('Activity_Modify', third_task.name)
|
self.assertEqual('Activity_Modify', third_task.name)
|
||||||
return workflow_api, third_task
|
return workflow_api, third_task
|
||||||
|
|
||||||
def test_before_cancel(self):
|
@patch('crc.services.protocol_builder.ProtocolBuilderService.get_study_details') # mock_details
|
||||||
|
def test_before_cancel(self, mock_details):
|
||||||
|
details_response = self.protocol_builder_response('study_details.json')
|
||||||
|
mock_details.return_value = json.loads(details_response)
|
||||||
|
|
||||||
workflow, study_id = self.load_workflow()
|
workflow, study_id = self.load_workflow()
|
||||||
self.get_first_task(workflow)
|
self.get_first_task(workflow)
|
||||||
|
@ -68,7 +72,10 @@ class TestStudyCancellations(BaseTest):
|
||||||
study_result = self.put_study_on_hold(study_id)
|
study_result = self.put_study_on_hold(study_id)
|
||||||
self.assertEqual('Beer consumption in the bipedal software engineer', study_result.title)
|
self.assertEqual('Beer consumption in the bipedal software engineer', study_result.title)
|
||||||
|
|
||||||
def test_first_cancel(self):
|
@patch('crc.services.protocol_builder.ProtocolBuilderService.get_study_details') # mock_details
|
||||||
|
def test_first_cancel(self, mock_details):
|
||||||
|
details_response = self.protocol_builder_response('study_details.json')
|
||||||
|
mock_details.return_value = json.loads(details_response)
|
||||||
workflow, study_id = self.load_workflow()
|
workflow, study_id = self.load_workflow()
|
||||||
workflow_api, first_task = self.get_first_task(workflow)
|
workflow_api, first_task = self.get_first_task(workflow)
|
||||||
|
|
||||||
|
@ -77,7 +84,10 @@ class TestStudyCancellations(BaseTest):
|
||||||
study_result = self.put_study_on_hold(study_id)
|
study_result = self.put_study_on_hold(study_id)
|
||||||
self.assertEqual('New Title', study_result.title)
|
self.assertEqual('New Title', study_result.title)
|
||||||
|
|
||||||
def test_second_cancel(self):
|
@patch('crc.services.protocol_builder.ProtocolBuilderService.get_study_details') # mock_details
|
||||||
|
def test_second_cancel(self, mock_details):
|
||||||
|
details_response = self.protocol_builder_response('study_details.json')
|
||||||
|
mock_details.return_value = json.loads(details_response)
|
||||||
|
|
||||||
workflow, study_id = self.load_workflow()
|
workflow, study_id = self.load_workflow()
|
||||||
workflow_api, first_task = self.get_first_task(workflow)
|
workflow_api, first_task = self.get_first_task(workflow)
|
||||||
|
@ -90,7 +100,10 @@ class TestStudyCancellations(BaseTest):
|
||||||
study_result = self.put_study_on_hold(study_id)
|
study_result = self.put_study_on_hold(study_id)
|
||||||
self.assertEqual('Second Title', study_result.title)
|
self.assertEqual('Second Title', study_result.title)
|
||||||
|
|
||||||
def test_after_cancel(self):
|
@patch('crc.services.protocol_builder.ProtocolBuilderService.get_study_details') # mock_details
|
||||||
|
def test_after_cancel(self, mock_details):
|
||||||
|
details_response = self.protocol_builder_response('study_details.json')
|
||||||
|
mock_details.return_value = json.loads(details_response)
|
||||||
|
|
||||||
workflow, study_id = self.load_workflow()
|
workflow, study_id = self.load_workflow()
|
||||||
workflow_api, first_task = self.get_first_task(workflow)
|
workflow_api, first_task = self.get_first_task(workflow)
|
||||||
|
|
|
@ -54,17 +54,20 @@ class TestStudyService(BaseTest):
|
||||||
ExampleDataLoader().load_reference_documents()
|
ExampleDataLoader().load_reference_documents()
|
||||||
return user
|
return user
|
||||||
|
|
||||||
|
@patch('crc.services.protocol_builder.ProtocolBuilderService.get_study_details') # mock_details
|
||||||
@patch('crc.services.protocol_builder.ProtocolBuilderService.get_required_docs') # mock_docs
|
@patch('crc.services.protocol_builder.ProtocolBuilderService.get_required_docs') # mock_docs
|
||||||
def test_total_tasks_updated(self, mock_docs):
|
def test_total_tasks_updated(self, mock_docs, mock_details):
|
||||||
"""Assure that as a users progress is available when getting a list of studies for that user."""
|
"""Assure that as a users progress is available when getting a list of studies for that user."""
|
||||||
app.config['PB_ENABLED'] = True
|
app.config['PB_ENABLED'] = True
|
||||||
docs_response = self.protocol_builder_response('required_docs.json')
|
docs_response = self.protocol_builder_response('required_docs.json')
|
||||||
mock_docs.return_value = json.loads(docs_response)
|
mock_docs.return_value = json.loads(docs_response)
|
||||||
|
details_response = self.protocol_builder_response('study_details.json')
|
||||||
|
mock_details.return_value = json.loads(details_response)
|
||||||
|
|
||||||
user = self.create_user_with_study_and_workflow()
|
user = self.create_user_with_study_and_workflow()
|
||||||
|
|
||||||
# The load example data script should set us up a user and at least one study, one category, and one workflow.
|
# The load example data script should set us up a user and at least one study, one category, and one workflow.
|
||||||
studies = StudyService.get_studies_for_user(user)
|
studies = StudyService().get_studies_for_user(user)
|
||||||
self.assertTrue(len(studies) == 1)
|
self.assertTrue(len(studies) == 1)
|
||||||
self.assertTrue(len(studies[0].categories) == 1)
|
self.assertTrue(len(studies[0].categories) == 1)
|
||||||
self.assertTrue(len(studies[0].categories[0].workflows) == 1)
|
self.assertTrue(len(studies[0].categories[0].workflows) == 1)
|
||||||
|
@ -82,7 +85,7 @@ class TestStudyService(BaseTest):
|
||||||
processor.do_engine_steps()
|
processor.do_engine_steps()
|
||||||
|
|
||||||
# Assure the workflow is now started, and knows the total and completed tasks.
|
# Assure the workflow is now started, and knows the total and completed tasks.
|
||||||
studies = StudyService.get_studies_for_user(user)
|
studies = StudyService().get_studies_for_user(user)
|
||||||
workflow = next(iter(studies[0].categories[0].workflows)) # Workflows is a set.
|
workflow = next(iter(studies[0].categories[0].workflows)) # Workflows is a set.
|
||||||
# self.assertEqual(WorkflowStatus.user_input_required, workflow.status)
|
# self.assertEqual(WorkflowStatus.user_input_required, workflow.status)
|
||||||
self.assertTrue(workflow.total_tasks > 0)
|
self.assertTrue(workflow.total_tasks > 0)
|
||||||
|
@ -95,21 +98,24 @@ class TestStudyService(BaseTest):
|
||||||
processor.save()
|
processor.save()
|
||||||
|
|
||||||
# Assure the workflow has moved on to the next task.
|
# Assure the workflow has moved on to the next task.
|
||||||
studies = StudyService.get_studies_for_user(user)
|
studies = StudyService().get_studies_for_user(user)
|
||||||
workflow = next(iter(studies[0].categories[0].workflows)) # Workflows is a set.
|
workflow = next(iter(studies[0].categories[0].workflows)) # Workflows is a set.
|
||||||
self.assertEqual(1, workflow.completed_tasks)
|
self.assertEqual(1, workflow.completed_tasks)
|
||||||
|
|
||||||
# Get approvals
|
# Get approvals
|
||||||
|
|
||||||
|
@patch('crc.services.protocol_builder.ProtocolBuilderService.get_study_details') # mock_details
|
||||||
@patch('crc.services.protocol_builder.ProtocolBuilderService.get_required_docs') # mock_docs
|
@patch('crc.services.protocol_builder.ProtocolBuilderService.get_required_docs') # mock_docs
|
||||||
def test_get_required_docs(self, mock_docs):
|
def test_get_required_docs(self, mock_docs, mock_details):
|
||||||
app.config['PB_ENABLED'] = True
|
app.config['PB_ENABLED'] = True
|
||||||
# mock out the protocol builder
|
# mock out the protocol builder
|
||||||
docs_response = self.protocol_builder_response('required_docs.json')
|
docs_response = self.protocol_builder_response('required_docs.json')
|
||||||
mock_docs.return_value = json.loads(docs_response)
|
mock_docs.return_value = json.loads(docs_response)
|
||||||
|
details_response = self.protocol_builder_response('study_details.json')
|
||||||
|
mock_details.return_value = json.loads(details_response)
|
||||||
|
|
||||||
user = self.create_user_with_study_and_workflow()
|
user = self.create_user_with_study_and_workflow()
|
||||||
studies = StudyService.get_studies_for_user(user)
|
studies = StudyService().get_studies_for_user(user)
|
||||||
study = studies[0]
|
study = studies[0]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,8 @@ from crc.models.protocol_builder import ProtocolBuilderStatus
|
||||||
from crc.models.study import StudySchema, StudyModel, StudyStatus
|
from crc.models.study import StudySchema, StudyModel, StudyStatus
|
||||||
from crc.models.user import UserModel
|
from crc.models.user import UserModel
|
||||||
|
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
|
||||||
class TestAuthentication(BaseTest):
|
class TestAuthentication(BaseTest):
|
||||||
admin_uid = 'dhf8r'
|
admin_uid = 'dhf8r'
|
||||||
|
@ -204,7 +206,10 @@ class TestAuthentication(BaseTest):
|
||||||
user_data = json.loads(rv.get_data(as_text=True))
|
user_data = json.loads(rv.get_data(as_text=True))
|
||||||
self.assertEqual(len(user_data), len(all_users))
|
self.assertEqual(len(user_data), len(all_users))
|
||||||
|
|
||||||
def test_admin_can_impersonate_another_user(self):
|
@patch('crc.services.protocol_builder.ProtocolBuilderService.get_study_details') # mock_details
|
||||||
|
def test_admin_can_impersonate_another_user(self, mock_details):
|
||||||
|
details_response = self.protocol_builder_response('study_details.json')
|
||||||
|
mock_details.return_value = json.loads(details_response)
|
||||||
# Switch production mode on
|
# Switch production mode on
|
||||||
app.config['PRODUCTION'] = True
|
app.config['PRODUCTION'] = True
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue