Skip to content

Commit

Permalink
Merge branch 'refs/heads/improve-order-flow-main' into add-pool-rules
Browse files Browse the repository at this point in the history
  • Loading branch information
islean committed Jan 10, 2025
2 parents f1ab7f9 + b10bd88 commit 5258b47
Show file tree
Hide file tree
Showing 13 changed files with 163 additions and 291 deletions.
5 changes: 2 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +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.orders_fixtures",
"tests.fixture_plugins.orders_fixtures.status_data_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",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,66 +1,71 @@
"""Fixtures for orders parsed into their respective models."""

import pytest

from cg.models.orders.constants import OrderType
from cg.services.order_validation_service.order_validation_service import OrderValidationService
from cg.services.order_validation_service.workflows.balsamic.models.order import BalsamicOrder
from cg.services.order_validation_service.workflows.fastq.models.order import FastqOrder
from cg.services.order_validation_service.workflows.fluffy.models.order import FluffyOrder
from cg.services.order_validation_service.workflows.metagenome.models.order import MetagenomeOrder
from cg.services.order_validation_service.workflows.microbial_fastq.models.order import (
MicrobialFastqOrder,
)
from cg.services.order_validation_service.workflows.microsalt.models.order import MicrosaltOrder
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
from cg.services.order_validation_service.workflows.rml.models.order import RmlOrder
from cg.services.orders.store_order_services.store_metagenome_order import (
StoreMetagenomeOrderService,
)
from cg.store.store import Store
from tests.store_helpers import StoreHelpers


@pytest.fixture
def metagenome_order(
metagenome_order_to_submit: dict, store_metagenome_order_service: StoreMetagenomeOrderService
) -> MetagenomeOrder:
"""Parse metagenome order example."""
order_validation_service = OrderValidationService(store_metagenome_order_service.status_db)
order: MetagenomeOrder = order_validation_service.parse_and_validate(
raw_order=metagenome_order_to_submit, order_type=OrderType.METAGENOME
)
order._generated_ticket_id = 123456
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
return fluffy_order


@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
Expand All @@ -74,45 +79,25 @@ def mip_dna_order(mip_dna_order_to_submit: dict) -> MipDnaOrder:


@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()
return base_store


@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
mip_rna_order._generated_ticket_id = 123456
return mip_rna_order


@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
def pacbio_order(pacbio_order_to_submit: dict, ticket_id_as_int: int) -> PacbioOrder:
order = PacbioOrder.model_validate(pacbio_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
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
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Fixtures for orders parsed from JSON files into dictionaries."""

from pathlib import Path

import pytest
Expand Down
99 changes: 0 additions & 99 deletions tests/fixture_plugins/orders_fixtures/orders_fixtures.py

This file was deleted.

49 changes: 49 additions & 0 deletions tests/fixture_plugins/orders_fixtures/store_fixtures.py
Original file line number Diff line number Diff line change
@@ -1,10 +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"]
Expand All @@ -16,3 +36,32 @@ def store_with_rml_applications(store: Store, helpers: StoreHelpers) -> Store:
)
helpers.ensure_customer(store=store, customer_id="cust000")
return store


@pytest.fixture
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 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()
return base_store
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion tests/fixtures/cgweb_orders/microbial_fastq.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"name": "Microbial Fastq order",
"customer": "cust002",
"customer": "cust000",
"delivery_type": "fastq",
"project_type": "microbial-fastq",
"user_id": 0,
"comment": "",
"samples": [
{
Expand Down
Loading

0 comments on commit 5258b47

Please sign in to comment.