From 01720a8bbfcadb046508aef994b683fe55a7ee82 Mon Sep 17 00:00:00 2001 From: Aaron Louie Date: Tue, 3 Mar 2020 16:01:36 -0500 Subject: [PATCH] Replaces migration and fixes broken tests --- crc/api.yml | 2 +- crc/api/study.py | 6 +++--- example_data.py | 5 +++-- .../versions/{cb3a03c10a0e_.py => 1c6e4e179f8e_.py} | 8 ++++---- tests/test_study_api.py | 4 ++-- 5 files changed, 13 insertions(+), 12 deletions(-) rename migrations/versions/{cb3a03c10a0e_.py => 1c6e4e179f8e_.py} (94%) diff --git a/crc/api.yml b/crc/api.yml index 783fde2d..de1220a3 100644 --- a/crc/api.yml +++ b/crc/api.yml @@ -733,7 +733,7 @@ components: example: "2019-12-25T09:12:33.001Z" protocol_builder_status: type: string - enum: [out_of_date, in_process, complete, updating] + enum: [DRAFT, IN_PROCESS, IN_REVIEW, REVIEW_COMPLETE, INACTIVE] example: done user_uid: type: string diff --git a/crc/api/study.py b/crc/api/study.py index f8d2a8b4..b1061036 100644 --- a/crc/api/study.py +++ b/crc/api/study.py @@ -165,9 +165,9 @@ def map_pb_study_to_study(pb_study): # Translate Protocol Builder states to enum values status = ProtocolBuilderStatus.DRAFT - if pb_study['Q_COMPLETE']: - if pb_study['UPLOAD_COMPLETE']: - if pb_study['HSRNUMBER']: + if 'Q_COMPLETE' in pb_study['Q_COMPLETE'] and pb_study['Q_COMPLETE']: + if 'UPLOAD_COMPLETE' in pb_study and pb_study['UPLOAD_COMPLETE']: + if 'HSRNUMBER' in pb_study and pb_study['HSRNUMBER']: status = ProtocolBuilderStatus.REVIEW_COMPLETE else: status = ProtocolBuilderStatus.IN_REVIEW diff --git a/example_data.py b/example_data.py index 0fc72d86..2421ce84 100644 --- a/example_data.py +++ b/example_data.py @@ -9,6 +9,7 @@ from crc.models.study import StudyModel from crc.models.user import UserModel from crc.models.workflow import WorkflowSpecModel from crc.services.workflow_processor import WorkflowProcessor +from models.protocol_builder import ProtocolBuilderStatus class ExampleDataLoader: @@ -31,7 +32,7 @@ class ExampleDataLoader: id=1, title='The impact of fried pickles on beer consumption in bipedal software developers.', last_updated=datetime.datetime.now(), - protocol_builder_status='in_process', + protocol_builder_status=ProtocolBuilderStatus.IN_PROCESS.name, primary_investigator_id='dhf8r', sponsor='Sartography Pharmaceuticals', ind_number='1234', @@ -41,7 +42,7 @@ class ExampleDataLoader: id=2, title='Requirement of hippocampal neurogenesis for the behavioral effects of soft pretzels', last_updated=datetime.datetime.now(), - protocol_builder_status='in_process', + protocol_builder_status=ProtocolBuilderStatus.IN_PROCESS.name, primary_investigator_id='dhf8r', sponsor='Makerspace & Co.', ind_number='5678', diff --git a/migrations/versions/cb3a03c10a0e_.py b/migrations/versions/1c6e4e179f8e_.py similarity index 94% rename from migrations/versions/cb3a03c10a0e_.py rename to migrations/versions/1c6e4e179f8e_.py index 0280235c..b6237cb0 100644 --- a/migrations/versions/cb3a03c10a0e_.py +++ b/migrations/versions/1c6e4e179f8e_.py @@ -1,8 +1,8 @@ """empty message -Revision ID: cb3a03c10a0e +Revision ID: 1c6e4e179f8e Revises: -Create Date: 2020-02-28 11:12:56.150837 +Create Date: 2020-03-03 15:51:45.550681 """ from alembic import op @@ -10,7 +10,7 @@ import sqlalchemy as sa # revision identifiers, used by Alembic. -revision = 'cb3a03c10a0e' +revision = '1c6e4e179f8e' down_revision = None branch_labels = None depends_on = None @@ -43,7 +43,7 @@ def upgrade(): sa.Column('id', sa.Integer(), nullable=False), sa.Column('title', sa.String(), nullable=True), sa.Column('last_updated', sa.DateTime(timezone=True), nullable=True), - sa.Column('protocol_builder_status', sa.Enum('out_of_date', 'in_process', 'complete', 'updating', name='protocolbuilderstatus'), nullable=True), + sa.Column('protocol_builder_status', sa.Enum('DRAFT', 'IN_PROCESS', 'IN_REVIEW', 'REVIEW_COMPLETE', 'INACTIVE', name='protocolbuilderstatus'), nullable=True), sa.Column('primary_investigator_id', sa.String(), nullable=True), sa.Column('sponsor', sa.String(), nullable=True), sa.Column('hsr_number', sa.String(), nullable=True), diff --git a/tests/test_study_api.py b/tests/test_study_api.py index a8d142fe..5129836c 100644 --- a/tests/test_study_api.py +++ b/tests/test_study_api.py @@ -24,7 +24,7 @@ class TestStudyApi(BaseTest): "title": "Phase III Trial of Genuine People Personalities (GPP) Autonomous Intelligent Emotional Agents " "for Interstellar Spacecraft", "last_updated": datetime.now(tz=timezone.utc), - "protocol_builder_status": ProtocolBuilderStatus.in_process, + "protocol_builder_status": ProtocolBuilderStatus.IN_PROCESS, "primary_investigator_id": "tricia.marie.mcmillan@heartofgold.edu", "sponsor": "Sirius Cybernetics Corporation", "ind_number": "567890", @@ -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.complete + study.protocol_builder_status = ProtocolBuilderStatus.REVIEW_COMPLETE rv = self.app.put('/v1.0/study/%i' % study.id, content_type="application/json", headers=self.logged_in_headers(),