reworking the test_study_service to run from a clean state, this is growing so complex. Tests really need to be isolated better.
This commit is contained in:
parent
17796193de
commit
c86f3321c5
|
@ -12,30 +12,39 @@ from crc.models.workflow import WorkflowSpecModel, WorkflowSpecModelSchema, Work
|
|||
WorkflowSpecCategoryModel
|
||||
from crc.services.study_service import StudyService
|
||||
from crc.services.workflow_processor import WorkflowProcessor
|
||||
from example_data import ExampleDataLoader
|
||||
from tests.base_test import BaseTest
|
||||
|
||||
|
||||
class TestStudyService(BaseTest):
|
||||
"""Largely tested via the test_study_api, and time is tight, but adding new tests here."""
|
||||
|
||||
@patch('crc.services.protocol_builder.ProtocolBuilderService.get_study_details') # mock_details
|
||||
@patch('crc.services.protocol_builder.ProtocolBuilderService.get_studies') # mock_studies
|
||||
def test_total_tasks_updated(self, mock_studies, mock_details):
|
||||
"""Assure that as a user makes progress"""
|
||||
self.load_example_data()
|
||||
|
||||
# Mock Protocol Builder responses
|
||||
studies_response = self.protocol_builder_response('user_studies.json')
|
||||
mock_studies.return_value = ProtocolBuilderStudySchema(many=True).loads(studies_response)
|
||||
details_response = self.protocol_builder_response('study_details.json')
|
||||
mock_details.return_value = ProtocolBuilderStudyDetailsSchema().loads(details_response)
|
||||
def test_total_tasks_updated(self):
|
||||
"""Assure that as a users progress is available when getting a list of studies for that user."""
|
||||
|
||||
# Assure some basic models are in place, This is a damn mess. Our database models need an overhaul to make
|
||||
# this easier - better relationship modeling is now critical.
|
||||
self.load_test_spec("top_level_workflow", master_spec=True)
|
||||
user = UserModel(uid="dhf8r", email_address="whatever@stuff.com", display_name="Stayathome Smellalots")
|
||||
db.session.add(user)
|
||||
db.session.commit()
|
||||
study = StudyModel(title="My title", protocol_builder_status=ProtocolBuilderStatus.IN_PROCESS, user_uid=user.uid)
|
||||
cat = WorkflowSpecCategoryModel(name="cat", display_name="cat", display_order=0)
|
||||
db.session.add_all([study, cat])
|
||||
db.session.commit()
|
||||
self.load_test_spec("random_fact", category_id=cat.id)
|
||||
workflow = WorkflowModel(workflow_spec_id="random_fact", study_id=study.id, status=WorkflowStatus.not_started)
|
||||
db.session.add(workflow)
|
||||
db.session.commit()
|
||||
# Assure there is a master specification, one standard spec, and lookup tables.
|
||||
ExampleDataLoader().load_reference_documents()
|
||||
|
||||
# The load example data script should set us up a user and at least one study, one category, and one workflow.
|
||||
user = db.session.query(UserModel).first()
|
||||
studies = StudyService.get_studies_for_user(user)
|
||||
self.assertTrue(len(studies) > 1)
|
||||
self.assertTrue(len(studies[0].categories) > 1)
|
||||
self.assertTrue(len(studies[0].categories[0].workflows) > 1)
|
||||
self.assertTrue(len(studies) == 1)
|
||||
self.assertTrue(len(studies[0].categories) == 1)
|
||||
self.assertTrue(len(studies[0].categories[0].workflows) == 1)
|
||||
|
||||
workflow = next(iter(studies[0].categories[0].workflows)) # Workflows is a set.
|
||||
|
||||
|
|
Loading…
Reference in New Issue