Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhance order submission integration tests #4121

Merged
merged 6 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cg/services/orders/storing/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def store_order(self, order: Order):
pass

@staticmethod
def _fill_in_sample_ids(samples: list[Sample], lims_map: dict):
def _fill_in_sample_ids(samples: list[Sample], lims_map: dict) -> None:
"""Fill in LIMS sample ids."""
for sample in samples:
LOG.debug(f"{sample.name}: link sample to LIMS")
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
"tests.fixture_plugins.orders_fixtures.order_form_fixtures",
"tests.fixture_plugins.orders_fixtures.order_to_submit_fixtures",
"tests.fixture_plugins.orders_fixtures.order_fixtures",
"tests.fixture_plugins.orders_fixtures.services_and_api_fixtures",
"tests.fixture_plugins.orders_fixtures.services_fixtures",
"tests.fixture_plugins.orders_fixtures.store_fixtures",
"tests.fixture_plugins.orders_fixtures.store_service_fixtures",
"tests.fixture_plugins.pacbio_fixtures.context_fixtures",
Expand Down
31 changes: 22 additions & 9 deletions tests/fixture_plugins/orders_fixtures/order_to_submit_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,20 @@
from cg.constants.constants import FileFormat
from cg.io.controller import ReadFile

# Valid orders


@pytest.fixture(scope="session")
def balsamic_order_to_submit(cgweb_orders_dir: Path) -> dict:
"""Load an example cancer order."""
"""Load an example Balsamic order."""
return ReadFile.get_content_from_file(
file_format=FileFormat.JSON, file_path=Path(cgweb_orders_dir, "balsamic.json")
)


@pytest.fixture(scope="session")
def fastq_order_to_submit(cgweb_orders_dir) -> dict:
"""Load an example FASTQ order."""
"""Load an example Fastq order."""
return ReadFile.get_content_from_file(
file_format=FileFormat.JSON, file_path=Path(cgweb_orders_dir, "fastq.json")
)
Expand All @@ -34,23 +36,23 @@ def fluffy_order_to_submit(cgweb_orders_dir: Path) -> dict:

@pytest.fixture(scope="session")
def metagenome_order_to_submit(cgweb_orders_dir: Path) -> dict:
"""Load an example metagenome order."""
"""Load an example Metagenome order."""
return ReadFile.get_content_from_file(
file_format=FileFormat.JSON, file_path=Path(cgweb_orders_dir, "metagenome.json")
)


@pytest.fixture(scope="session")
def microbial_fastq_order_to_submit(cgweb_orders_dir: Path) -> dict:
"""Load an example microbial order."""
"""Load an example Microbial fastq order."""
return ReadFile.get_content_from_file(
file_format=FileFormat.JSON, file_path=Path(cgweb_orders_dir, "microbial_fastq.json")
)


@pytest.fixture(scope="session")
def microbial_order_to_submit(cgweb_orders_dir: Path) -> dict:
"""Load an example microbial order."""
"""Load an example Microsalt order."""
return ReadFile.get_content_from_file(
file_format=FileFormat.JSON, file_path=Path(cgweb_orders_dir, "microsalt.json")
)
Expand All @@ -66,7 +68,7 @@ def mip_dna_order_to_submit(cgweb_orders_dir: Path) -> dict:

@pytest.fixture(scope="session")
def mip_rna_order_to_submit(cgweb_orders_dir: Path) -> dict:
"""Load an example RNA order."""
"""Load an example MIP-RNA order."""
return ReadFile.get_content_from_file(
file_format=FileFormat.JSON, file_path=Path(cgweb_orders_dir, "mip_rna.json")
)
Expand All @@ -90,15 +92,15 @@ def rml_order_to_submit(cgweb_orders_dir: Path) -> dict:

@pytest.fixture(scope="session")
def rnafusion_order_to_submit(cgweb_orders_dir: Path) -> dict:
"""Load an example RNA order."""
"""Load an example RNA Fusion order."""
return ReadFile.get_content_from_file(
file_format=FileFormat.JSON, file_path=Path(cgweb_orders_dir, "rnafusion.json")
)


@pytest.fixture(scope="session")
def sarscov2_order_to_submit(cgweb_orders_dir: Path) -> dict:
"""Load an example sarscov2 order."""
"""Load an example Mutant order."""
return ReadFile.get_content_from_file(
file_format=FileFormat.JSON, file_path=Path(cgweb_orders_dir, "sarscov2.json")
)
Expand All @@ -114,7 +116,18 @@ def taxprofiler_order_to_submit(cgweb_orders_dir: Path) -> dict:

@pytest.fixture(scope="session")
def tomte_order_to_submit(cgweb_orders_dir: Path) -> dict:
"""Load an example TOMTE order."""
"""Load an example Tomte order."""
return ReadFile.get_content_from_file(
file_format=FileFormat.JSON, file_path=Path(cgweb_orders_dir, "tomte.json")
)


# Invalid orders


@pytest.fixture(scope="session")
def invalid_balsamic_order_to_submit(cgweb_orders_dir: Path) -> dict:
"""Load an invalid example Balsamic order."""
return ReadFile.get_content_from_file(
file_format=FileFormat.JSON, file_path=Path(cgweb_orders_dir, "FAIL_balsamic.json")
)
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ def freshdesk_client() -> FreshdeskClient:


@pytest.fixture
def order_validation_service(store_with_all_test_applications: Store) -> OrderValidationService:
return OrderValidationService(store_with_all_test_applications)
def order_validation_service(store_to_submit_and_validate_orders: Store) -> OrderValidationService:
return OrderValidationService(store_to_submit_and_validate_orders)


@pytest.fixture(scope="function")
Expand All @@ -42,6 +42,8 @@ def ticket_handler(store: Store, freshdesk_client: FreshdeskClient) -> TicketHan

@pytest.fixture
def storing_service_registry(
store_with_all_test_applications: Store, lims_api: MockLimsAPI
store_to_submit_and_validate_orders: Store, lims_api: MockLimsAPI
) -> StoringServiceRegistry:
return setup_storing_service_registry(lims=lims_api, status_db=store_with_all_test_applications)
return setup_storing_service_registry(
lims=lims_api, status_db=store_to_submit_and_validate_orders
)
65 changes: 4 additions & 61 deletions tests/fixture_plugins/orders_fixtures/store_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,74 +2,17 @@

import pytest

from cg.constants.sequencing import SeqLibraryPrepCategory
from cg.models.orders.constants import OrderType
from cg.services.orders.storing.constants import MAF_ORDER_ID
from cg.services.orders.validation.workflows.balsamic.models.order import BalsamicOrder
from cg.services.orders.validation.workflows.mip_dna.models.order import MipDnaOrder
from cg.store.models import Application, ApplicationVersion, Customer, Order
from cg.store.models import ApplicationVersion, Customer, Order
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
def store_to_submit_and_validate_orders(
store: Store, helpers: StoreHelpers, customer_id: str
) -> 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"]
for tag in app_tags:
helpers.ensure_application_version(
store=store,
application_tag=tag,
prep_category=SeqLibraryPrepCategory.READY_MADE_LIBRARY,
)
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


@pytest.fixture
def store_with_all_test_applications(store: Store, helpers: StoreHelpers) -> Store:
app_tags: dict[str, list[OrderType]] = {
"PANKTTR100": [OrderType.BALSAMIC],
"WGSPCFC030": [OrderType.FASTQ, OrderType.MIP_DNA],
Expand All @@ -92,7 +35,7 @@ def store_with_all_test_applications(store: Store, helpers: StoreHelpers) -> Sto
store=store, application_tag=tag
)
application_version.application.order_types = orders
customer: Customer = helpers.ensure_customer(store=store, customer_id="cust000")
customer: Customer = helpers.ensure_customer(store=store, customer_id=customer_id)
helpers.ensure_user(store=store, customer=customer)
helpers.ensure_panel(store=store, panel_abbreviation="AID")
helpers.ensure_panel(store=store, panel_abbreviation="Ataxi")
Expand Down
48 changes: 29 additions & 19 deletions tests/fixture_plugins/orders_fixtures/store_service_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,57 +16,67 @@
from cg.services.orders.storing.implementations.pool_order_service import StorePoolOrderService
from cg.store.store import Store
from tests.mocks.limsmock import MockLimsAPI
from tests.store_helpers import StoreHelpers


@pytest.fixture
def store_generic_order_service(base_store: Store, lims_api: MockLimsAPI) -> StoreCaseOrderService:
return StoreCaseOrderService(status_db=base_store, lims_service=OrderLimsService(lims_api))
def store_generic_order_service(
store_to_submit_and_validate_orders: Store, lims_api: MockLimsAPI
) -> StoreCaseOrderService:
return StoreCaseOrderService(
status_db=store_to_submit_and_validate_orders, lims_service=OrderLimsService(lims_api)
)


@pytest.fixture
def store_pool_order_service(
store_with_rml_applications: Store, lims_api: MockLimsAPI
store_to_submit_and_validate_orders: Store, lims_api: MockLimsAPI
) -> StorePoolOrderService:
return StorePoolOrderService(
status_db=store_with_rml_applications, lims_service=OrderLimsService(lims_api)
status_db=store_to_submit_and_validate_orders, lims_service=OrderLimsService(lims_api)
)


@pytest.fixture
def store_fastq_order_service(base_store: Store, lims_api: MockLimsAPI) -> StoreFastqOrderService:
return StoreFastqOrderService(status_db=base_store, lims_service=OrderLimsService(lims_api))
def store_fastq_order_service(
store_to_submit_and_validate_orders: Store, lims_api: MockLimsAPI
) -> StoreFastqOrderService:
return StoreFastqOrderService(
status_db=store_to_submit_and_validate_orders, lims_service=OrderLimsService(lims_api)
)


@pytest.fixture
def store_pacbio_order_service(base_store: Store, lims_api: MockLimsAPI) -> StorePacBioOrderService:
return StorePacBioOrderService(status_db=base_store, lims_service=OrderLimsService(lims_api))
def store_pacbio_order_service(
store_to_submit_and_validate_orders: Store, lims_api: MockLimsAPI
) -> StorePacBioOrderService:
return StorePacBioOrderService(
status_db=store_to_submit_and_validate_orders, lims_service=OrderLimsService(lims_api)
)


@pytest.fixture
def store_metagenome_order_service(
metagenome_storing_store: Store, lims_api: MockLimsAPI, helpers: StoreHelpers
store_to_submit_and_validate_orders: Store, lims_api: MockLimsAPI
) -> StoreMetagenomeOrderService:
return StoreMetagenomeOrderService(
status_db=metagenome_storing_store, lims_service=OrderLimsService(lims_api)
status_db=store_to_submit_and_validate_orders, lims_service=OrderLimsService(lims_api)
)


@pytest.fixture
def store_microbial_order_service(
base_store: Store, lims_api: MockLimsAPI, helpers: StoreHelpers
store_to_submit_and_validate_orders: Store,
lims_api: MockLimsAPI,
) -> StoreMicrobialOrderService:
helpers.ensure_application_version(store=base_store, application_tag="MWRNXTR003")
helpers.ensure_application_version(store=base_store, application_tag="MWXNXTR003")
helpers.ensure_application_version(store=base_store, application_tag="VWGNXTR001")

return StoreMicrobialOrderService(status_db=base_store, lims_service=OrderLimsService(lims_api))
return StoreMicrobialOrderService(
status_db=store_to_submit_and_validate_orders, lims_service=OrderLimsService(lims_api)
)


@pytest.fixture
def store_microbial_fastq_order_service(
base_store: Store, lims_api: MockLimsAPI
store_to_submit_and_validate_orders: Store, lims_api: MockLimsAPI
) -> StoreMicrobialFastqOrderService:
return StoreMicrobialFastqOrderService(
status_db=base_store, lims_service=OrderLimsService(lims_api)
status_db=store_to_submit_and_validate_orders, lims_service=OrderLimsService(lims_api)
)
61 changes: 61 additions & 0 deletions tests/fixtures/cgweb_orders/FAIL_balsamic.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"cases": [
{
"cohorts": null,
"name": "B",
"panels": null,
"priority": "FAIL",
"samples": [
{
"age_at_sampling": "17.2",
"application": "PANKTTR100",
"capture_kit": "GMCKsolid",
"comment": "This is a sample comment",
"concentration_ng_ul": null,
"container": "96 well plate",
"container_name": "BalsamicPlate",
"control": "FAIL",
"data_analysis": null,
"data_delivery": null,
"elution_buffer": "Tris-HCl",
"family_name": null,
"father": null,
"formalin_fixation_time": "15",
"mother": null,
"name": "BalsamicSample",
"phenotype_groups": [
"PhGroup"
],
"phenotype_terms": [
"PhTerm"
],
"post_formalin_fixation_time": "3",
"priority": null,
"quantity": null,
"reference_genome": null,
"require_qc_ok": false,
"sex": "male",
"source": "cytology (FFPE)",
"source_comment": null,
"status": null,
"subject_id": "Subject1",
"tissue_block_size": "large",
"tumour": true,
"tumour_purity": "13",
"volume": 42,
"well_position": "A:1"
}
],
"synopsis": "A synopsis"
}
],
"comment": null,
"customer": "cust000",
"data_analysis": "balsamic",
"data_delivery": null,
"delivery_type": "analysis-scout",
"name": "BalsamicOrder",
"project_type": "balsamic",
"ticket": null,
"user_id": 1
}
4 changes: 2 additions & 2 deletions tests/fixtures/cgweb_orders/sarscov2.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"internal_id": null,
"lab_code": null,
"mother": null,
"name": "sarscov2sample1",
"name": "control-positive",
"organism": "SARS-CoV-2",
"organism_other": "",
"original_lab": "Karolinska University Hospital Solna",
Expand Down Expand Up @@ -94,7 +94,7 @@
"internal_id": null,
"lab_code": null,
"mother": null,
"name": "sarscov2sample2",
"name": "control-negative",
"organism": "SARS-CoV-2",
"organism_other": "",
"original_lab": "Synlab Medilab",
Expand Down
Loading
Loading