Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
islean committed Jan 16, 2025
1 parent 800c7e4 commit cd127d4
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 59 deletions.
9 changes: 9 additions & 0 deletions tests/fixture_plugins/orders_fixtures/order_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
93 changes: 34 additions & 59 deletions tests/fixtures/cgweb_orders/rnafusion.json
Original file line number Diff line number Diff line change
@@ -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
}
30 changes: 30 additions & 0 deletions tests/services/order_validation_service/test_case_rules.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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

0 comments on commit cd127d4

Please sign in to comment.