diff --git a/cg/services/order_validation_service/rules/sample/rules.py b/cg/services/order_validation_service/rules/sample/rules.py index e4e1b7e807..ba3aa4306e 100644 --- a/cg/services/order_validation_service/rules/sample/rules.py +++ b/cg/services/order_validation_service/rules/sample/rules.py @@ -1,5 +1,4 @@ from cg.models.orders.constants import OrderType -from cg.models.orders.sample_base import ControlEnum from cg.services.order_validation_service.errors.sample_errors import ( ApplicationArchivedError, ApplicationNotCompatibleError, @@ -18,6 +17,7 @@ OrganismDoesNotExistError, PoolApplicationError, PoolPriorityError, + SampleNameNotAvailableControlError, SampleNameNotAvailableError, SampleNameRepeatedError, VolumeRequiredError, @@ -275,12 +275,12 @@ def validate_sample_names_available( def validate_non_control_sample_names_available( order: OrderWithControlSamples, store: Store, **kwargs -) -> list[SampleNameNotAvailableError]: +) -> list[SampleNameNotAvailableControlError]: """ Validate that non-control sample names do not exists in the database under the same customer. Applicable to all orders with control samples. """ - errors: list[SampleNameNotAvailableError] = get_sample_name_not_available_errors( + errors: list[SampleNameNotAvailableControlError] = get_sample_name_not_available_errors( order=order, store=store, has_order_control=True ) return errors diff --git a/cg/services/orders/validate_order_services/validate_pacbio_order.py b/cg/services/orders/validate_order_services/validate_pacbio_order.py deleted file mode 100644 index f9da34fad3..0000000000 --- a/cg/services/orders/validate_order_services/validate_pacbio_order.py +++ /dev/null @@ -1,45 +0,0 @@ -from cg.exc import OrderError -from cg.models.orders.order import OrderIn -from cg.models.orders.samples import PacBioSample -from cg.services.orders.store_order_services.store_order_service import ValidateOrderService -from cg.store.models import ApplicationVersion, Customer -from cg.store.store import Store - - -class ValidatePacbioOrderService(ValidateOrderService): - - def __init__(self, status_db: Store): - self.status_db = status_db - - def validate_order(self, order: OrderIn) -> None: - self._validate_customer_exists(order.customer) - self._validate_applications_exist(order.samples) - self._validate_sample_names_available(samples=order.samples, customer_id=order.customer) - - def _validate_customer_exists(self, customer_id: str) -> None: - customer: Customer = self.status_db.get_customer_by_internal_id( - customer_internal_id=customer_id - ) - if not customer: - raise OrderError(f"Unknown customer: {customer_id}") - - def _validate_applications_exist(self, samples: list[PacBioSample]) -> None: - for sample in samples: - application_tag = sample.application - application_version: ApplicationVersion = ( - self.status_db.get_current_application_version_by_tag(tag=application_tag) - ) - if application_version is None: - raise OrderError(f"Invalid application: {sample.application}") - - def _validate_sample_names_available( - self, samples: list[PacBioSample], customer_id: str - ) -> None: - customer: Customer = self.status_db.get_customer_by_internal_id(customer_id) - for sample in samples: - if self.status_db.get_sample_by_customer_and_name( - customer_entry_id=[customer.id], sample_name=sample.name - ): - raise OrderError( - f"Sample name already used in a previous order by the same customer: {sample.name}" - ) diff --git a/tests/fixture_plugins/orders_fixtures/order_to_submit_fixtures.py b/tests/fixture_plugins/orders_fixtures/order_to_submit_fixtures.py index 4103f86e84..ee006f2ff9 100644 --- a/tests/fixture_plugins/orders_fixtures/order_to_submit_fixtures.py +++ b/tests/fixture_plugins/orders_fixtures/order_to_submit_fixtures.py @@ -12,6 +12,7 @@ from cg.services.order_validation_service.workflows.fastq.models.order import FastqOrder from cg.services.order_validation_service.workflows.mip_dna.models.order import MipDnaOrder from cg.services.order_validation_service.workflows.mip_rna.models.order import MipRnaOrder +from cg.services.order_validation_service.workflows.pacbio_long_read.models.order import PacbioOrder @pytest.fixture(scope="session") @@ -145,9 +146,7 @@ def all_orders_to_submit( # ), OrderType.MIP_DNA: MipDnaOrder.model_validate(mip_dna_order_to_submit), OrderType.MIP_RNA: MipRnaOrder.model_validate(mip_rna_order_to_submit), - OrderType.PACBIO_LONG_READ: OrderIn.parse_obj( - pacbio_order_to_submit, project=OrderType.PACBIO_LONG_READ - ), + OrderType.PACBIO_LONG_READ: PacbioOrder.model_validate(pacbio_order_to_submit), # OrderType.RML: OrderIn.parse_obj(rml_order_to_submit, project=OrderType.RML), # OrderType.RNAFUSION: RnaFusionOrder.model_validate(rnafusion_order_to_submit), # OrderType.SARS_COV_2: OrderIn.parse_obj( diff --git a/tests/services/orders/test_validate_order_service/conftest.py b/tests/services/orders/test_validate_order_service/conftest.py deleted file mode 100644 index 27d2ae9d19..0000000000 --- a/tests/services/orders/test_validate_order_service/conftest.py +++ /dev/null @@ -1,41 +0,0 @@ -import pytest - -from cg.constants import DataDelivery, Workflow -from cg.models.orders.order import OrderIn -from cg.models.orders.sample_base import SexEnum -from cg.models.orders.samples import PacBioSample -from cg.services.orders.validate_order_services.validate_pacbio_order import ( - ValidatePacbioOrderService, -) -from cg.store.store import Store - - -@pytest.fixture -def pacbio_sample() -> PacBioSample: - return PacBioSample( - application="WGSPCFC060", - data_analysis=Workflow.RAW_DATA, - data_delivery=DataDelivery.NO_DELIVERY, - name="PacbioSample", - sex=SexEnum.unknown, - tumour=False, - volume="50", - buffer="buffer", - source="source", - subject_id="subject_id", - container="Tube", - ) - - -@pytest.fixture -def pacbio_order(pacbio_sample: PacBioSample) -> OrderIn: - return OrderIn( - customer="cust000", - name="PacbioOrder", - samples=[pacbio_sample], - ) - - -@pytest.fixture -def validate_pacbio_order_service(sample_store: Store) -> ValidatePacbioOrderService: - return ValidatePacbioOrderService(sample_store) diff --git a/tests/services/orders/test_validate_order_service/test_validate_pacbio_order_service.py b/tests/services/orders/test_validate_order_service/test_validate_pacbio_order_service.py deleted file mode 100644 index 872ccc2a64..0000000000 --- a/tests/services/orders/test_validate_order_service/test_validate_pacbio_order_service.py +++ /dev/null @@ -1,63 +0,0 @@ -import pytest - -from cg.exc import OrderError -from cg.models.orders.order import OrderIn -from cg.services.orders.validate_order_services.validate_pacbio_order import ( - ValidatePacbioOrderService, -) -from cg.store.store import Store - - -def test_validate_valid_pacbio_order( - validate_pacbio_order_service: ValidatePacbioOrderService, pacbio_order: OrderIn -): - # GIVEN a valid PacBio order - - # WHEN validating the order - validate_pacbio_order_service.validate_order(pacbio_order) - - # THEN no error is raised - - -def test_validate_pacbio_order_unknown_customer( - pacbio_order: OrderIn, validate_pacbio_order_service: ValidatePacbioOrderService -): - # GIVEN a PacBio order with an unknown customer - pacbio_order.customer = "unknown_customer" - - # WHEN validating the order - - # THEN an order error should be raised - with pytest.raises(OrderError): - validate_pacbio_order_service.validate_order(pacbio_order) - - -def test_validate_pacbio_order_invalid_application( - pacbio_order: OrderIn, validate_pacbio_order_service: ValidatePacbioOrderService -): - # GIVEN a PacBio order with an unknown application - pacbio_order.samples[0].application = "unknown_application" - - # WHEN validating the order - - # THEN an order error should be raised - with pytest.raises(OrderError): - validate_pacbio_order_service.validate_order(pacbio_order) - - -def test_validate_pacbio_order_reused_sample_name( - pacbio_order: OrderIn, validate_pacbio_order_service: ValidatePacbioOrderService -): - # GIVEN a PacBio order with a reused sample name - status_db: Store = validate_pacbio_order_service.status_db - customer = status_db.get_customer_by_internal_id(pacbio_order.customer) - old_sample_name: str = status_db.get_samples_by_customers_and_pattern(customers=[customer])[ - 0 - ].name - pacbio_order.samples[0].name = old_sample_name - - # WHEN validating the order - - # THEN an order error should be raised - with pytest.raises(OrderError): - validate_pacbio_order_service.validate_order(pacbio_order)