diff --git a/tests/conftest.py b/tests/conftest.py index 6645c5eb17..7b719aee9c 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -118,10 +118,10 @@ "tests.fixture_plugins.observations_fixtures.observations_api_fixtures", "tests.fixture_plugins.observations_fixtures.observations_input_files_fixtures", "tests.fixture_plugins.orders_fixtures.order_form_fixtures", - "tests.fixture_plugins.orders_fixtures.order_store_service_fixtures", "tests.fixture_plugins.orders_fixtures.order_to_submit_fixtures", "tests.fixture_plugins.orders_fixtures.order_fixtures", "tests.fixture_plugins.orders_fixtures.store_fixtures", + "tests.fixture_plugins.orders_fixtures.store_service_fixtures", "tests.fixture_plugins.pacbio_fixtures.context_fixtures", "tests.fixture_plugins.pacbio_fixtures.dto_fixtures", "tests.fixture_plugins.pacbio_fixtures.file_data_fixtures", diff --git a/tests/fixture_plugins/orders_fixtures/order_fixtures.py b/tests/fixture_plugins/orders_fixtures/order_fixtures.py index 1674dcbf54..42ed7557b0 100644 --- a/tests/fixture_plugins/orders_fixtures/order_fixtures.py +++ b/tests/fixture_plugins/orders_fixtures/order_fixtures.py @@ -1,3 +1,5 @@ +"""Fixtures for orders parsed into their respective models.""" + import pytest from cg.services.order_validation_service.workflows.balsamic.models.order import BalsamicOrder @@ -15,26 +17,24 @@ @pytest.fixture -def metagenome_order( - metagenome_order_to_submit: dict, - ticket_id_as_int: int, -) -> MetagenomeOrder: - """Parse metagenome order example.""" - order = MetagenomeOrder.model_validate(metagenome_order_to_submit) - order._generated_ticket_id = ticket_id_as_int - return order +def balsamic_order(balsamic_order_to_submit: dict) -> BalsamicOrder: + balsamic_order_to_submit["user_id"] = 1 + balsamic_order = BalsamicOrder.model_validate(balsamic_order_to_submit) + balsamic_order._generated_ticket_id = 123456 + for case_index, sample_index, sample in balsamic_order.enumerated_new_samples: + sample._generated_lims_id = f"ACC{case_index}-{sample_index}" + return balsamic_order @pytest.fixture -def valid_rml_order(rml_order_to_submit: dict, ticket_id_as_int: int) -> RmlOrder: - """Parse rml order example.""" - rml_order = RmlOrder.model_validate(rml_order_to_submit) - rml_order._generated_ticket_id = ticket_id_as_int - return rml_order +def fastq_order(fastq_order_to_submit: dict) -> FastqOrder: + fastq_order = FastqOrder.model_validate(fastq_order_to_submit) + fastq_order._generated_ticket_id = 123456 + return fastq_order @pytest.fixture -def valid_fluffy_order(fluffy_order_to_submit: dict, ticket_id_as_int: int) -> FluffyOrder: +def fluffy_order(fluffy_order_to_submit: dict, ticket_id_as_int: int) -> FluffyOrder: """Parse Fluffy order example.""" fluffy_order = FluffyOrder.model_validate(fluffy_order_to_submit) fluffy_order._generated_ticket_id = ticket_id_as_int @@ -42,20 +42,30 @@ def valid_fluffy_order(fluffy_order_to_submit: dict, ticket_id_as_int: int) -> F @pytest.fixture -def fastq_order(fastq_order_to_submit: dict) -> FastqOrder: - fastq_order = FastqOrder.model_validate(fastq_order_to_submit) - fastq_order._generated_ticket_id = 123456 - return fastq_order +def metagenome_order( + metagenome_order_to_submit: dict, + ticket_id_as_int: int, +) -> MetagenomeOrder: + """Parse metagenome order example.""" + order = MetagenomeOrder.model_validate(metagenome_order_to_submit) + order._generated_ticket_id = ticket_id_as_int + return order @pytest.fixture -def mip_rna_order(mip_rna_order_to_submit: dict) -> MipRnaOrder: - mip_rna_order_to_submit["user_id"] = 1 - mip_rna_order = MipRnaOrder.model_validate(mip_rna_order_to_submit) - for case_index, sample_index, sample in mip_rna_order.enumerated_new_samples: - sample._generated_lims_id = f"ACC{case_index}-{sample_index}" - mip_rna_order._generated_ticket_id = 123456 - return mip_rna_order +def microbial_fastq_order( + microbial_fastq_order_to_submit: dict, ticket_id_as_int: int +) -> MicrobialFastqOrder: + order = MicrobialFastqOrder.model_validate(microbial_fastq_order_to_submit) + order._generated_ticket_id = ticket_id_as_int + return order + + +@pytest.fixture +def microsalt_order(microbial_order_to_submit: dict) -> MicrosaltOrder: + order = MicrosaltOrder.model_validate(microbial_order_to_submit) + order._generated_ticket_id = 123456 + return order @pytest.fixture @@ -69,20 +79,13 @@ def mip_dna_order(mip_dna_order_to_submit: dict) -> MipDnaOrder: @pytest.fixture -def balsamic_order(balsamic_order_to_submit: dict) -> BalsamicOrder: - balsamic_order_to_submit["user_id"] = 1 - balsamic_order = BalsamicOrder.model_validate(balsamic_order_to_submit) - balsamic_order._generated_ticket_id = 123456 - for case_index, sample_index, sample in balsamic_order.enumerated_new_samples: +def mip_rna_order(mip_rna_order_to_submit: dict) -> MipRnaOrder: + mip_rna_order_to_submit["user_id"] = 1 + mip_rna_order = MipRnaOrder.model_validate(mip_rna_order_to_submit) + for case_index, sample_index, sample in mip_rna_order.enumerated_new_samples: sample._generated_lims_id = f"ACC{case_index}-{sample_index}" - return balsamic_order - - -@pytest.fixture -def microsalt_order(microbial_order_to_submit: dict) -> MicrosaltOrder: - order = MicrosaltOrder.model_validate(microbial_order_to_submit) - order._generated_ticket_id = 123456 - return order + mip_rna_order._generated_ticket_id = 123456 + return mip_rna_order @pytest.fixture @@ -93,9 +96,8 @@ def pacbio_order(pacbio_order_to_submit: dict, ticket_id_as_int: int) -> PacbioO @pytest.fixture -def microbial_fastq_order( - microbial_fastq_order_to_submit: dict, ticket_id_as_int: int -) -> MicrobialFastqOrder: - order = MicrobialFastqOrder.model_validate(microbial_fastq_order_to_submit) - order._generated_ticket_id = ticket_id_as_int - return order +def rml_order(rml_order_to_submit: dict, ticket_id_as_int: int) -> RmlOrder: + """Parse rml order example.""" + rml_order = RmlOrder.model_validate(rml_order_to_submit) + rml_order._generated_ticket_id = ticket_id_as_int + return rml_order 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 a1860fb6de..4103f86e84 100644 --- a/tests/fixture_plugins/orders_fixtures/order_to_submit_fixtures.py +++ b/tests/fixture_plugins/orders_fixtures/order_to_submit_fixtures.py @@ -1,3 +1,5 @@ +"""Fixtures for orders parsed from JSON files into dictionaries.""" + from pathlib import Path import pytest diff --git a/tests/fixture_plugins/orders_fixtures/store_fixtures.py b/tests/fixture_plugins/orders_fixtures/store_fixtures.py index 85e66bcedb..aa96cdb5df 100644 --- a/tests/fixture_plugins/orders_fixtures/store_fixtures.py +++ b/tests/fixture_plugins/orders_fixtures/store_fixtures.py @@ -1,12 +1,30 @@ +"""Store fixtures for the order services tests.""" + import pytest from cg.constants.sequencing import SeqLibraryPrepCategory +from cg.models.orders.constants import OrderType from cg.services.order_validation_service.workflows.balsamic.models.order import BalsamicOrder from cg.services.order_validation_service.workflows.mip_dna.models.order import MipDnaOrder +from cg.store.models import Application from cg.store.store import Store from tests.store_helpers import StoreHelpers +@pytest.fixture +def balsamic_submit_store( + base_store: Store, balsamic_order: BalsamicOrder, helpers: StoreHelpers +) -> Store: + for _, _, sample in balsamic_order.enumerated_new_samples: + if not base_store.get_application_by_tag(sample.application): + application_version = helpers.ensure_application_version( + store=base_store, application_tag=sample.application + ) + base_store.session.add(application_version) + base_store.session.commit() + return base_store + + @pytest.fixture def store_with_rml_applications(store: Store, helpers: StoreHelpers) -> Store: app_tags: list[str] = ["RMLP15R100", "RMLP15R200", "RMLP15R400", "RMLP15R500"] @@ -21,24 +39,25 @@ def store_with_rml_applications(store: Store, helpers: StoreHelpers) -> Store: @pytest.fixture -def mip_dna_submit_store( - base_store: Store, mip_dna_order: MipDnaOrder, helpers: StoreHelpers -) -> Store: - for _, _, sample in mip_dna_order.enumerated_new_samples: - if not base_store.get_application_by_tag(sample.application): - application_version = helpers.ensure_application_version( - store=base_store, application_tag=sample.application - ) - base_store.session.add(application_version) - base_store.session.commit() +def metagenome_storing_store(base_store: Store, helpers: StoreHelpers) -> Store: + metagenome_application: Application = helpers.ensure_application_version( + store=base_store, application_tag="METPCFR030" + ).application + metagenome_application.order_types = [OrderType.METAGENOME] + metagenome_application: Application = helpers.ensure_application_version( + store=base_store, application_tag="METWPFR030" + ).application + metagenome_application.order_types = [OrderType.METAGENOME] + customer = base_store.get_customer_by_internal_id("cust000") + helpers.ensure_user(store=base_store, customer=customer) return base_store @pytest.fixture -def balsamic_submit_store( - base_store: Store, balsamic_order: BalsamicOrder, helpers: StoreHelpers +def mip_dna_submit_store( + base_store: Store, mip_dna_order: MipDnaOrder, helpers: StoreHelpers ) -> Store: - for _, _, sample in balsamic_order.enumerated_new_samples: + for _, _, sample in mip_dna_order.enumerated_new_samples: if not base_store.get_application_by_tag(sample.application): application_version = helpers.ensure_application_version( store=base_store, application_tag=sample.application diff --git a/tests/fixture_plugins/orders_fixtures/order_store_service_fixtures.py b/tests/fixture_plugins/orders_fixtures/store_service_fixtures.py similarity index 79% rename from tests/fixture_plugins/orders_fixtures/order_store_service_fixtures.py rename to tests/fixture_plugins/orders_fixtures/store_service_fixtures.py index d30ef92984..ce4f3216de 100644 --- a/tests/fixture_plugins/orders_fixtures/order_store_service_fixtures.py +++ b/tests/fixture_plugins/orders_fixtures/store_service_fixtures.py @@ -1,6 +1,5 @@ import pytest -from cg.models.orders.constants import OrderType from cg.services.orders.order_lims_service.order_lims_service import OrderLimsService from cg.services.orders.store_order_services.store_case_order import StoreCaseOrderService from cg.services.orders.store_order_services.store_fastq_order_service import StoreFastqOrderService @@ -15,7 +14,6 @@ StorePacBioOrderService, ) from cg.services.orders.store_order_services.store_pool_order import StorePoolOrderService -from cg.store.models import Application from cg.store.store import Store from tests.mocks.limsmock import MockLimsAPI from tests.store_helpers import StoreHelpers @@ -45,21 +43,6 @@ def store_pacbio_order_service(base_store: Store, lims_api: MockLimsAPI) -> Stor return StorePacBioOrderService(status_db=base_store, lims_service=OrderLimsService(lims_api)) -@pytest.fixture -def metagenome_storing_store(base_store: Store, helpers: StoreHelpers): - metagenome_application: Application = helpers.ensure_application_version( - store=base_store, application_tag="METPCFR030" - ).application - metagenome_application.order_types = [OrderType.METAGENOME] - metagenome_application: Application = helpers.ensure_application_version( - store=base_store, application_tag="METWPFR030" - ).application - metagenome_application.order_types = [OrderType.METAGENOME] - customer = base_store.get_customer_by_internal_id("cust000") - helpers.ensure_user(store=base_store, customer=customer) - return base_store - - @pytest.fixture def store_metagenome_order_service( metagenome_storing_store: Store, lims_api: MockLimsAPI, helpers: StoreHelpers diff --git a/tests/services/orders/order_store_service/test_pool_order_store_service.py b/tests/services/orders/order_store_service/test_pool_order_store_service.py index be803fc6e3..490e3aadf0 100644 --- a/tests/services/orders/order_store_service/test_pool_order_store_service.py +++ b/tests/services/orders/order_store_service/test_pool_order_store_service.py @@ -11,7 +11,7 @@ @pytest.mark.parametrize( "order_fixture, workflow", - [("valid_rml_order", Workflow.RAW_DATA), ("valid_fluffy_order", Workflow.FLUFFY)], + [("rml_order", Workflow.RAW_DATA), ("fluffy_order", Workflow.FLUFFY)], ids=["RML", "Fluffy"], ) def test_store_order_data_in_status_db(