Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
diitaz93 committed Nov 21, 2024
1 parent 5665cae commit c0dcbb6
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 57 deletions.
2 changes: 0 additions & 2 deletions cg/cli/deliver/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
Original file line number Diff line number Diff line change
@@ -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(),
Expand All @@ -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,
)

0 comments on commit c0dcbb6

Please sign in to comment.