2021-04-05 17:16:43 +00:00
|
|
|
from tests.base_test import BaseTest
|
2020-02-20 18:30:04 +00:00
|
|
|
from unittest.mock import patch
|
|
|
|
|
2020-05-27 02:42:49 +00:00
|
|
|
from crc import app
|
2020-05-22 18:37:49 +00:00
|
|
|
from crc.services.protocol_builder import ProtocolBuilderService
|
2020-02-20 18:30:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestProtocolBuilder(BaseTest):
|
|
|
|
test_uid = "dhf8r"
|
|
|
|
test_study_id = 1
|
|
|
|
|
|
|
|
@patch('crc.services.protocol_builder.requests.get')
|
|
|
|
def test_get_studies(self, mock_get):
|
2020-05-27 02:42:49 +00:00
|
|
|
app.config['PB_ENABLED'] = True
|
2020-02-20 18:30:04 +00:00
|
|
|
mock_get.return_value.ok = True
|
2020-02-27 14:54:46 +00:00
|
|
|
mock_get.return_value.text = self.protocol_builder_response('user_studies.json')
|
|
|
|
response = ProtocolBuilderService.get_studies(self.test_uid)
|
2020-02-20 18:30:04 +00:00
|
|
|
self.assertIsNotNone(response)
|
|
|
|
|
|
|
|
@patch('crc.services.protocol_builder.requests.get')
|
|
|
|
def test_get_investigators(self, mock_get):
|
2020-05-27 02:42:49 +00:00
|
|
|
app.config['PB_ENABLED'] = True
|
2020-02-20 18:30:04 +00:00
|
|
|
mock_get.return_value.ok = True
|
2020-02-27 14:54:46 +00:00
|
|
|
mock_get.return_value.text = self.protocol_builder_response('investigators.json')
|
|
|
|
response = ProtocolBuilderService.get_investigators(self.test_study_id)
|
2020-02-20 18:30:04 +00:00
|
|
|
self.assertIsNotNone(response)
|
2020-07-07 21:16:33 +00:00
|
|
|
self.assertEqual(5, len(response))
|
2020-04-06 22:15:32 +00:00
|
|
|
self.assertEqual("DC", response[0]["INVESTIGATORTYPE"])
|
|
|
|
self.assertEqual("Department Contact", response[0]["INVESTIGATORTYPEFULL"])
|
|
|
|
self.assertEqual("asd3v", response[0]["NETBADGEID"])
|
2020-02-20 18:30:04 +00:00
|
|
|
|
|
|
|
@patch('crc.services.protocol_builder.requests.get')
|
2020-02-27 14:54:46 +00:00
|
|
|
def test_get_required_docs(self, mock_get):
|
2020-05-27 02:42:49 +00:00
|
|
|
app.config['PB_ENABLED'] = True
|
2020-02-20 18:30:04 +00:00
|
|
|
mock_get.return_value.ok = True
|
2020-02-27 14:54:46 +00:00
|
|
|
mock_get.return_value.text = self.protocol_builder_response('required_docs.json')
|
|
|
|
response = ProtocolBuilderService.get_required_docs(self.test_study_id)
|
2021-11-08 15:00:19 +00:00
|
|
|
auxdocs = response['AUXDOCS']
|
|
|
|
self.assertIsNotNone(auxdocs)
|
|
|
|
self.assertEqual(5, len(auxdocs))
|
|
|
|
self.assertEqual(6, auxdocs[0]['SS_AUXILIARY_DOC_TYPE_ID'])
|
2020-02-20 18:30:04 +00:00
|
|
|
|
|
|
|
@patch('crc.services.protocol_builder.requests.get')
|
2020-02-27 14:54:46 +00:00
|
|
|
def test_get_details(self, mock_get):
|
2020-05-27 02:42:49 +00:00
|
|
|
app.config['PB_ENABLED'] = True
|
2020-02-20 18:30:04 +00:00
|
|
|
mock_get.return_value.ok = True
|
2020-02-27 14:54:46 +00:00
|
|
|
mock_get.return_value.text = self.protocol_builder_response('study_details.json')
|
2021-11-08 15:00:19 +00:00
|
|
|
response = ProtocolBuilderService.get_study_details(self.test_study_id)[0]
|
2020-02-27 14:54:46 +00:00
|
|
|
self.assertIsNotNone(response)
|
2021-07-09 14:40:18 +00:00
|
|
|
self.assertEqual(65, len(response))
|
2021-05-14 16:35:36 +00:00
|
|
|
self.assertEqual('1234', response['IND_1'])
|
2020-08-25 15:08:13 +00:00
|
|
|
|
|
|
|
@patch('crc.services.protocol_builder.requests.get')
|
|
|
|
def test_get_study_sponsors(self, mock_get):
|
|
|
|
app.config['PB_ENABLED'] = True
|
|
|
|
mock_get.return_value.ok = True
|
|
|
|
mock_get.return_value.text = self.protocol_builder_response('sponsors.json')
|
|
|
|
response = ProtocolBuilderService.get_sponsors(self.test_study_id)
|
|
|
|
self.assertIsNotNone(response)
|
|
|
|
self.assertEqual(3, len(response))
|
|
|
|
self.assertEqual(2, response[0]["SS_STUDY"])
|
|
|
|
self.assertEqual(2453, response[0]["SPONSOR_ID"])
|
|
|
|
self.assertEqual("Abbott Ltd", response[0]["SP_NAME"])
|
2021-05-01 19:23:07 +00:00
|
|
|
|
|
|
|
@patch('crc.services.protocol_builder.requests.get')
|
|
|
|
def test_get_irb_info(self, mock_get):
|
|
|
|
app.config['PB_ENABLED'] = True
|
|
|
|
mock_get.return_value.ok = True
|
|
|
|
mock_get.return_value.text = self.protocol_builder_response('irb_info.json')
|
|
|
|
response = ProtocolBuilderService.get_irb_info(self.test_study_id)
|
|
|
|
self.assertIsNotNone(response)
|
|
|
|
self.assertEqual(3, len(response))
|
|
|
|
self.assertEqual('IRB Event 1', response[0]["IRBEVENT"])
|
|
|
|
self.assertEqual('IRB Event 2', response[1]["IRBEVENT"])
|
|
|
|
self.assertEqual('IRB Event 3', response[2]["IRBEVENT"])
|
2021-07-02 19:26:39 +00:00
|
|
|
|
|
|
|
@patch('crc.services.protocol_builder.requests.get')
|
|
|
|
def test_check_study(self, mock_get):
|
|
|
|
app.config['PB_ENABLED'] = True
|
|
|
|
mock_get.return_value.ok = True
|
|
|
|
mock_get.return_value.text = self.protocol_builder_response('check_study.json')
|
|
|
|
response = ProtocolBuilderService.check_study(self.test_study_id)
|
|
|
|
self.assertIsNotNone(response)
|
|
|
|
self.assertIn('DETAIL', response[0].keys())
|
|
|
|
self.assertIn('STATUS', response[0].keys())
|