From cd127d46675a85a3971d6f3a537317c896cc3e13 Mon Sep 17 00:00:00 2001 From: islean Date: Thu, 16 Jan 2025 11:07:49 +0100 Subject: [PATCH] Add test --- .../orders_fixtures/order_fixtures.py | 9 ++ tests/fixtures/cgweb_orders/rnafusion.json | 93 +++++++------------ .../test_case_rules.py | 30 ++++++ 3 files changed, 73 insertions(+), 59 deletions(-) diff --git a/tests/fixture_plugins/orders_fixtures/order_fixtures.py b/tests/fixture_plugins/orders_fixtures/order_fixtures.py index d474e39218..906a05698e 100644 --- a/tests/fixture_plugins/orders_fixtures/order_fixtures.py +++ b/tests/fixture_plugins/orders_fixtures/order_fixtures.py @@ -15,6 +15,7 @@ from cg.services.order_validation_service.workflows.mutant.models.order import MutantOrder from cg.services.order_validation_service.workflows.pacbio_long_read.models.order import PacbioOrder from cg.services.order_validation_service.workflows.rml.models.order import RmlOrder +from cg.services.order_validation_service.workflows.rna_fusion.models.order import RnaFusionOrder @pytest.fixture @@ -110,3 +111,11 @@ def rml_order(rml_order_to_submit: dict, ticket_id_as_int: int) -> RmlOrder: rml_order = RmlOrder.model_validate(rml_order_to_submit) rml_order._generated_ticket_id = ticket_id_as_int return rml_order + + +@pytest.fixture +def rnafusion_order(rnafusion_order_to_submit: dict) -> RnaFusionOrder: + """Parse RNAFusion order example.""" + rnafusion_order = RnaFusionOrder.model_validate(rnafusion_order_to_submit) + rnafusion_order._generated_ticket_id = 123456 + return rnafusion_order diff --git a/tests/fixtures/cgweb_orders/rnafusion.json b/tests/fixtures/cgweb_orders/rnafusion.json index 203329ffc7..a3bd669e39 100644 --- a/tests/fixtures/cgweb_orders/rnafusion.json +++ b/tests/fixtures/cgweb_orders/rnafusion.json @@ -1,60 +1,35 @@ { - "name": "#123456", - "customer": "cust003", - "comment": "", - "samples": [ - { - "application": "RNAPOAR025", - "cohorts": [ - "" - ], - "container": "96 well plate", - "container_name": "CMMS", - "data_analysis": "rnafusion", - "data_delivery": "scout", - "family_name": "family1", - "name": "sample1-rna-t1", - "phenotype_groups": [ - "" - ], - "phenotype_terms": [ - "" - ], - "priority": "standard", - "quantity": "220", - "sex": "female", - "source": "tissue (fresh frozen)", - "synopsis": "", - "subject_id": "subject-sample1-rna-t1", - "volume": "1", - "well_position": "A:1" - }, - { - "application": "RNAPOAR025", - "cohorts": [ - "" - ], - "comment": "this is a sample comment", - "container": "96 well plate", - "container_name": "CMMS", - "data_analysis": "rnafusion", - "data_delivery": "scout", - "family_name": "family2", - "name": "sample1-rna-t2", - "phenotype_groups": [ - "" - ], - "phenotype_terms": [ - "" - ], - "priority": "standard", - "quantity": "220", - "sex": "female", - "source": "tissue (fresh frozen)", - "synopsis": "", - "subject_id": "subject-sample1-rna-t2", - "volume": "2", - "well_position": "B:1" - } - ] -} + "cases": [ + { + "cohorts": null, + "internal_id": null, + "name": "TestCase", + "panels": null, + "priority": "research", + "samples": [ + { + "application": "WGSWPFR400", + "father": null, + "internal_id": "ACC16411A7DS800C0M", + "mother": null, + "name": "ACC16411A7DS800C0M", + "processedAt": "2025-01-16T08:18:42.329Z", + "reference_genome": null, + "sex": "male", + "status": null, + "subject_id": null, + "tumour": false + } + ], + "synopsis": null + } + ], + "comment": null, + "customer": "cust000", + "data_delivery": "analysis", + "dataAnalysis": "rnafusion", + "delivery_type": "analysis", + "name": "Test", + "project_type": "rnafusion", + "ticket": null +} \ No newline at end of file diff --git a/tests/services/order_validation_service/test_case_rules.py b/tests/services/order_validation_service/test_case_rules.py index 85f73b1f94..536c88d35b 100644 --- a/tests/services/order_validation_service/test_case_rules.py +++ b/tests/services/order_validation_service/test_case_rules.py @@ -1,7 +1,9 @@ from cg.constants import GenePanelMasterList +from cg.models.orders.sample_base import ContainerEnum, SexEnum from cg.services.order_validation_service.errors.case_errors import ( CaseDoesNotExistError, CaseNameNotAvailableError, + MultipleSamplesInCaseError, RepeatedCaseNameError, ) from cg.services.order_validation_service.models.existing_case import ExistingCase @@ -10,7 +12,10 @@ validate_case_internal_ids_exist, validate_case_names_available, validate_case_names_not_repeated, + validate_one_sample_per_case, ) +from cg.services.order_validation_service.workflows.rna_fusion.models.order import RnaFusionOrder +from cg.services.order_validation_service.workflows.rna_fusion.models.sample import RnaFusionSample from cg.store.models import Case from cg.store.store import Store @@ -72,3 +77,28 @@ def test_repeated_case_names_not_allowed(order_with_repeated_case_names: OrderWi # THEN the errors are about the case names assert isinstance(errors[0], RepeatedCaseNameError) + + +def test_multiple_samples_in_case(rnafusion_order: RnaFusionOrder): + # GIVEN an RNAFusion order with multiple samples in the same case + rnafusion_sample = RnaFusionSample( + container=ContainerEnum.tube, + container_name="container_name", + application="DummyAppTag", + name="ExtraSample", + require_qc_ok=False, + sex=SexEnum.female, + source="blood", + subject_id="subject", + ) + rnafusion_order.cases[0].samples.append(rnafusion_sample) + + # WHEN validating that the order has at most one sample per case + errors: list[MultipleSamplesInCaseError] = validate_one_sample_per_case(rnafusion_order) + + # THEN an error should be returned + assert errors + + # THEN the error should concern the multiple samples in the first case + assert isinstance(errors[0], MultipleSamplesInCaseError) + assert errors[0].case_index == 0