Skip to content

Commit

Permalink
add tests, redirect to rna-scout when using upload
Browse files Browse the repository at this point in the history
  • Loading branch information
rannick committed Sep 3, 2024
1 parent d3e9e47 commit 134864a
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 14 deletions.
6 changes: 6 additions & 0 deletions cg/cli/upload/scout.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ def upload_to_scout(context, re_upload: bool, print_console: bool, case_id: str)
suggest_cases_to_upload(status_db=status_db)
return

case_obj: Case = status_db.get_case_by_internal_id(internal_id=case_id)
if case_obj.analyses == Workflow.TOMTE:
context.invoke(
upload_rna_to_scout, case_id=case_id, re_upload=re_upload, analysis=case_obj.analyses
)

context.invoke(
create_scout_load_config, case_id=case_id, print_console=print_console, re_upload=re_upload
)
Expand Down
7 changes: 0 additions & 7 deletions cg/meta/upload/scout/uploadscoutapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,13 +539,6 @@ def get_config_builder(self, analysis, hk_version) -> ScoutConfigBuilder:
Workflow.RNAFUSION: RnafusionConfigBuilder(
hk_version_obj=hk_version, analysis_obj=analysis, lims_api=self.lims
),
Workflow.TOMTE: TomteConfigBuilder(
hk_version_obj=hk_version,
analysis_obj=analysis,
mip_analysis_api=self.mip_analysis_api,
lims_api=self.lims,
madeline_api=self.madeline_api,
),
}

return config_builders[analysis.workflow]
Expand Down
47 changes: 40 additions & 7 deletions tests/cli/upload/test_cli_scout.py
Original file line number Diff line number Diff line change
@@ -1,53 +1,86 @@
import logging

import mock
import pytest
from click.testing import CliRunner, Result

from cg.cli.upload.scout import create_scout_load_config, get_upload_api
from cg.constants import EXIT_SUCCESS, Workflow
from cg.meta.upload.scout.uploadscoutapi import UploadScoutAPI
from cg.meta.upload.upload_api import UploadAPI
from cg.meta.workflow.analysis import AnalysisAPI
from cg.meta.workflow.balsamic import BalsamicAnalysisAPI
from cg.meta.workflow.mip_dna import MipDNAAnalysisAPI
from cg.meta.workflow.mip_rna import MipRNAAnalysisAPI
from cg.meta.workflow.rnafusion import RnafusionAnalysisAPI
from cg.meta.workflow.tomte import TomteAnalysisAPI
from cg.models.cg_config import CGConfig
from cg.store.models import Case
from cg.store.store import Store
from tests.mocks.scout import MockScoutLoadConfig
from tests.store_helpers import StoreHelpers

WORKFLOWS_TO_TEST: list = [
Workflow.BALSAMIC,
Workflow.MIP_DNA,
Workflow.MIP_RNA,
Workflow.RNAFUSION,
Workflow.TOMTE,
]

def test_get_upload_api(cg_context: CGConfig, case_id: str, helpers: StoreHelpers):
ANALYSIS_API: dict[Workflow, UploadAPI] = [
(Workflow.BALSAMIC, BalsamicAnalysisAPI)(Workflow.MIP_DNA, MipDNAAnalysisAPI)(
Workflow.MIP_RNA, MipRNAAnalysisAPI
)(Workflow.RNAFUSION, RnafusionAnalysisAPI)(Workflow.TOMTE, TomteAnalysisAPI)
]


@pytest.mark.parametrize(
"workflow,analysis_api",
ANALYSIS_API,
)
def test_get_upload_api(
cg_context: CGConfig,
case_id: str,
helpers: StoreHelpers,
workflow: Workflow,
analysis_api: AnalysisAPI,
):
"""Test to get the correct upload API for a BALSAMIC case."""
status_db: Store = cg_context.status_db

# GIVEN a case with a balsamic analysis
case: Case = helpers.ensure_case(
store=status_db, data_analysis=Workflow.BALSAMIC, case_id=case_id
)
helpers.add_analysis(store=status_db, case=case, workflow=Workflow.BALSAMIC)
helpers.add_analysis(store=status_db, case=case, workflow=workflow)

# WHEN getting the upload API
upload_api: UploadAPI = get_upload_api(cg_config=cg_context, case=case)

# THEN assert that the type of upload API is correct
assert type(upload_api.analysis_api) == BalsamicAnalysisAPI
assert type(upload_api.analysis_api) is analysis_api


@pytest.mark.parametrize(
"workflow",
WORKFLOWS_TO_TEST,
)
def test_create_scout_load_config(
caplog,
cli_runner: CliRunner,
cg_context: CGConfig,
case_id: str,
helpers: StoreHelpers,
workflow: Workflow,
):
"""Test to create a scout load config for a BALSAMIC case."""
caplog.set_level(logging.DEBUG)
status_db: Store = cg_context.status_db

# GIVEN a case with a balsamic analysis
case: Case = helpers.ensure_case(
store=status_db, data_analysis=Workflow.BALSAMIC, case_id=case_id
)
helpers.add_analysis(store=status_db, case=case, workflow=Workflow.BALSAMIC)
case: Case = helpers.ensure_case(store=status_db, data_analysis=workflow, case_id=case_id)
helpers.add_analysis(store=status_db, case=case, workflow=workflow)

with mock.patch.object(UploadScoutAPI, "generate_config", return_value=MockScoutLoadConfig()):
# WHEN creating the scout load config
Expand Down

0 comments on commit 134864a

Please sign in to comment.