WIP: Mocks study details PB endpoint response

This commit is contained in:
Aaron Louie 2020-03-03 20:56:46 -05:00
parent 01720a8bbf
commit 8cbd6f892f
2 changed files with 19 additions and 11 deletions

View File

@ -92,7 +92,7 @@ def update_from_protocol_builder():
study_id=study_id,
body={
'inactive': True,
'protocol_builder_status': ProtocolBuilderStatus.INACTIVE._value_
'protocol_builder_status': ProtocolBuilderStatus.INACTIVE.name
}
)
@ -165,8 +165,11 @@ def map_pb_study_to_study(pb_study):
# Translate Protocol Builder states to enum values
status = ProtocolBuilderStatus.DRAFT
if 'Q_COMPLETE' in pb_study['Q_COMPLETE'] and pb_study['Q_COMPLETE']:
if 'UPLOAD_COMPLETE' in pb_study and pb_study['UPLOAD_COMPLETE']:
pb_details = ProtocolBuilderService.get_study_details(pb_study['STUDYID'])
print(pb_details)
if 'Q_COMPLETE' in pb_study and pb_study['Q_COMPLETE']:
if 'UPLOAD_COMPLETE' in pb_details and pb_details['UPLOAD_COMPLETE']:
if 'HSRNUMBER' in pb_study and pb_study['HSRNUMBER']:
status = ProtocolBuilderStatus.REVIEW_COMPLETE
else:
@ -174,7 +177,7 @@ def map_pb_study_to_study(pb_study):
else:
status = ProtocolBuilderStatus.IN_PROCESS
study_info['protocol_builder_status'] = status._value_
study_info['protocol_builder_status'] = status.name
study_info['inactive'] = False
return study_info

View File

@ -1,10 +1,10 @@
import json
from datetime import datetime, timezone
from unittest.mock import patch
from unittest.mock import patch, Mock
from crc import session
from crc.models.study import StudyModel, StudyModelSchema
from crc.models.protocol_builder import ProtocolBuilderStatus
from crc.models.protocol_builder import ProtocolBuilderStatus, ProtocolBuilderStudyDetailsSchema
from crc.models.workflow import WorkflowSpecModel, WorkflowSpecModelSchema, WorkflowModel, WorkflowStatus, \
WorkflowApiSchema
from tests.base_test import BaseTest
@ -49,7 +49,7 @@ class TestStudyApi(BaseTest):
self.load_example_data()
study: StudyModel = session.query(StudyModel).first()
study.title = "Pilot Study of Fjord Placement for Single Fraction Outcomes to Cortisol Susceptibility"
study.protocol_builder_status = ProtocolBuilderStatus.REVIEW_COMPLETE
study.protocol_builder_status = ProtocolBuilderStatus.REVIEW_COMPLETE.name
rv = self.app.put('/v1.0/study/%i' % study.id,
content_type="application/json",
headers=self.logged_in_headers(),
@ -61,15 +61,20 @@ class TestStudyApi(BaseTest):
self.assertEqual(study.protocol_builder_status, db_study.protocol_builder_status)
@patch('crc.services.protocol_builder.requests.get')
def test_get_all_studies(self, mock_get):
def test_get_all_studies(self):
self.load_example_data()
db_studies_before = session.query(StudyModel).all()
num_db_studies_before = len(db_studies_before)
# Mock Protocol Builder response
mock_get.return_value.ok = True
mock_get.return_value.text = self.protocol_builder_response('user_studies.json')
with patch('crc.services.protocol_builder.requests.get') as mock_get:
mock_get.return_value.ok = True
mock_get.return_value.text = self.protocol_builder_response('user_studies.json')
with patch('crc.services.protocol_builder.ProtocolBuilderService.get_study_details') as mock_details:
sd_response = self.protocol_builder_response('study_details.json')
mock_details.return_value = Mock()
mock_details.return_value.json.return_value = ProtocolBuilderStudyDetailsSchema().loads(sd_response)
self.load_example_data()
api_response = self.app.get('/v1.0/study',