diff --git a/cg/cli/deliver/utils.py b/cg/cli/deliver/utils.py index bb1de9ea39..14e8255c51 100644 --- a/cg/cli/deliver/utils.py +++ b/cg/cli/deliver/utils.py @@ -2,8 +2,6 @@ from datetime import datetime from pathlib import Path -from cg.constants import Workflow -from cg.constants.constants import MICROBIAL_APP_TAGS from cg.services.deliver_files.deliver_files_service.deliver_files_service import ( DeliverFilesService, ) diff --git a/cg/services/deliver_files/deliver_files_service/deliver_files_service_factory.py b/cg/services/deliver_files/deliver_files_service/deliver_files_service_factory.py index 65cd467f53..47abde387f 100644 --- a/cg/services/deliver_files/deliver_files_service/deliver_files_service_factory.py +++ b/cg/services/deliver_files/deliver_files_service/deliver_files_service_factory.py @@ -108,9 +108,9 @@ def _validate_delivery_type(delivery_type: DataDelivery): ) def build_delivery_service( - self, case: Case, delivery_type: DataDelivery + self, case: Case, delivery_type: DataDelivery | None = None ) -> DeliverFilesService: - """Build a delivery service based on the workflow and delivery type.""" + """Build a delivery service based on a case.""" delivery_type: DataDelivery = self._sanitise_delivery_type( delivery_type if delivery_type else case.data_delivery ) diff --git a/tests/services/file_delivery/delivery_file_service/test_service_builder.py b/tests/services/file_delivery/delivery_file_service/test_service_builder.py index bc945ed581..d2c6798ec7 100644 --- a/tests/services/file_delivery/delivery_file_service/test_service_builder.py +++ b/tests/services/file_delivery/delivery_file_service/test_service_builder.py @@ -1,73 +1,77 @@ -import pytest from unittest.mock import MagicMock -from cg.constants import Workflow, DataDelivery +import pytest +from pydantic.v1 import BaseModel + +from cg.constants import DataDelivery, Workflow from cg.services.deliver_files.deliver_files_service.deliver_files_service import ( DeliverFilesService, ) from cg.services.deliver_files.deliver_files_service.deliver_files_service_factory import ( DeliveryServiceFactory, ) -from cg.services.deliver_files.tag_fetcher.sample_and_case_service import ( - SampleAndCaseDeliveryTagsFetcher, -) -from cg.services.deliver_files.file_fetcher.analysis_service import ( - AnalysisDeliveryFileFetcher, -) +from cg.services.deliver_files.file_fetcher.abstract import FetchDeliveryFilesService from cg.services.deliver_files.file_fetcher.analysis_raw_data_service import ( RawDataAndAnalysisDeliveryFileFetcher, ) -from cg.services.deliver_files.file_fetcher.raw_data_service import ( - RawDataDeliveryFileFetcher, -) +from cg.services.deliver_files.file_fetcher.analysis_service import AnalysisDeliveryFileFetcher +from cg.services.deliver_files.file_fetcher.raw_data_service import RawDataDeliveryFileFetcher from cg.services.deliver_files.file_formatter.utils.sample_concatenation_service import ( SampleFileConcatenationFormatter, ) -from cg.services.deliver_files.file_formatter.utils.sample_service import ( - SampleFileFormatter, -) -from cg.services.deliver_files.file_mover.service import ( - DeliveryFilesMover, +from cg.services.deliver_files.file_formatter.utils.sample_service import SampleFileFormatter +from cg.services.deliver_files.file_mover.service import DeliveryFilesMover +from cg.services.deliver_files.tag_fetcher.abstract import FetchDeliveryFileTagsService +from cg.services.deliver_files.tag_fetcher.sample_and_case_service import ( + SampleAndCaseDeliveryTagsFetcher, ) +from cg.store.store import Store + + +class DeliveryScenario(BaseModel): + app_tag: str + data_analysis: Workflow + delivery_type: DataDelivery + expected_tag_fetcher: type[FetchDeliveryFileTagsService] + expected_file_fetcher: type[FetchDeliveryFilesService] + expected_file_mover: type[DeliveryFilesMover] + expected_sample_file_formatter: type[SampleFileFormatter] @pytest.mark.parametrize( - "workflow,delivery_type,expected_tag_fetcher,expected_file_fetcher,expected_file_mover,expected_sample_file_formatter", + "scenario", [ - ( - Workflow.MICROSALT, - DataDelivery.FASTQ, - SampleAndCaseDeliveryTagsFetcher, - RawDataDeliveryFileFetcher, - DeliveryFilesMover, - SampleFileConcatenationFormatter, + DeliveryScenario( + app_tag="MWRNXTR003", + data_analysis=Workflow.RAW_DATA, + delivery_type=DataDelivery.FASTQ, + expected_tag_fetcher=SampleAndCaseDeliveryTagsFetcher, + expected_file_fetcher=RawDataDeliveryFileFetcher, + expected_file_mover=DeliveryFilesMover, + expected_sample_file_formatter=SampleFileConcatenationFormatter, ), - ( - Workflow.MUTANT, - DataDelivery.ANALYSIS_FILES, - SampleAndCaseDeliveryTagsFetcher, - AnalysisDeliveryFileFetcher, - DeliveryFilesMover, - SampleFileFormatter, + DeliveryScenario( + app_tag="VWGDPTR001", + data_analysis=Workflow.MUTANT, + delivery_type=DataDelivery.ANALYSIS_FILES, + expected_tag_fetcher=SampleAndCaseDeliveryTagsFetcher, + expected_file_fetcher=AnalysisDeliveryFileFetcher, + expected_file_mover=DeliveryFilesMover, + expected_sample_file_formatter=SampleFileFormatter, ), - ( - Workflow.BALSAMIC, - DataDelivery.FASTQ_ANALYSIS, - SampleAndCaseDeliveryTagsFetcher, - RawDataAndAnalysisDeliveryFileFetcher, - DeliveryFilesMover, - SampleFileFormatter, + DeliveryScenario( + app_tag="PANKTTR020", + data_analysis=Workflow.BALSAMIC, + delivery_type=DataDelivery.FASTQ_ANALYSIS, + expected_tag_fetcher=SampleAndCaseDeliveryTagsFetcher, + expected_file_fetcher=RawDataAndAnalysisDeliveryFileFetcher, + expected_file_mover=DeliveryFilesMover, + expected_sample_file_formatter=SampleFileFormatter, ), ], + ids=["microbial-fastq", "SARS-COV2", "Targeted"], ) -def test_build_delivery_service( - workflow, - delivery_type, - expected_tag_fetcher, - expected_file_fetcher, - expected_file_mover, - expected_sample_file_formatter, -): +def test_build_delivery_service(scenario: DeliveryScenario, store: Store): # GIVEN a delivery service builder with mocked store and hk_api builder = DeliveryServiceFactory( store=MagicMock(), @@ -77,15 +81,22 @@ def test_build_delivery_service( analysis_service=MagicMock(), ) + # GIVEN a case with mocked sample app tag + case_mock = MagicMock() + case_mock.data_delivery = scenario.delivery_type + case_mock.data_analysis = scenario.data_analysis + case_mock.samples = [ + MagicMock(application_version=MagicMock(application=MagicMock(tag=scenario.app_tag))) + ] + # WHEN building a delivery service - delivery_service: DeliverFilesService = builder.build_delivery_service( - workflow=workflow, delivery_type=delivery_type - ) + delivery_service: DeliverFilesService = builder.build_delivery_service(case=case_mock) # THEN the correct file formatter and file fetcher services are used - assert isinstance(delivery_service.file_manager.tags_fetcher, expected_tag_fetcher) - assert isinstance(delivery_service.file_manager, expected_file_fetcher) - assert isinstance(delivery_service.file_mover, expected_file_mover) + assert isinstance(delivery_service.file_manager.tags_fetcher, scenario.expected_tag_fetcher) + assert isinstance(delivery_service.file_manager, scenario.expected_file_fetcher) + assert isinstance(delivery_service.file_mover, scenario.expected_file_mover) assert isinstance( - delivery_service.file_formatter.sample_file_formatter, expected_sample_file_formatter + delivery_service.file_formatter.sample_file_formatter, + scenario.expected_sample_file_formatter, )