Skip to content

Commit

Permalink
add test for validation pool (#4132)
Browse files Browse the repository at this point in the history
add test for validation pool
  • Loading branch information
diitaz93 authored Jan 21, 2025
1 parent 9052662 commit bb2285d
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class FluffySample(Sample):
well_position_rml: str | None = None

@model_validator(mode="after")
def set_default_index_sequence(self):
def set_default_index_sequence(self) -> "FluffySample":
"""Set a default index_sequence from the index and index_number."""
if not self.index_sequence and (self.index and self.index_number):
try:
Expand Down
3 changes: 2 additions & 1 deletion cg/services/orders/validation/workflows/rml/models/sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ class RmlSample(Sample):
pool: str
priority: PriorityEnum
rml_plate_name: str | None = None

volume: int
well_position_rml: str | None = None

@model_validator(mode="after")
def set_default_index_sequence(self):
def set_default_index_sequence(self) -> "RmlSample":
"""Set a default index_sequence from the index and index_number."""
if not self.index_sequence and (self.index and self.index_number):
try:
Expand Down
7 changes: 1 addition & 6 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +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.path_fixtures",
"tests.fixture_plugins.orders_fixtures.services_fixtures",
"tests.fixture_plugins.orders_fixtures.store_fixtures",
"tests.fixture_plugins.orders_fixtures.store_service_fixtures",
Expand Down Expand Up @@ -745,12 +746,6 @@ def apps_dir(fixtures_dir: Path) -> Path:
return Path(fixtures_dir, "apps")


@pytest.fixture(scope="session")
def cgweb_orders_dir(fixtures_dir: Path) -> Path:
"""Return the path to the cgweb_orders dir."""
return Path(fixtures_dir, "cgweb_orders")


@pytest.fixture(scope="session")
def data_dir(fixtures_dir: Path) -> Path:
"""Return the path to the data dir."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ def tomte_order_to_submit(cgweb_orders_dir: Path) -> dict:


@pytest.fixture(scope="session")
def invalid_balsamic_order_to_submit(cgweb_orders_dir: Path) -> dict:
def invalid_balsamic_order_to_submit(invalid_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")
file_format=FileFormat.JSON, file_path=Path(invalid_cgweb_orders_dir, "balsamic_FAIL.json")
)
15 changes: 15 additions & 0 deletions tests/fixture_plugins/orders_fixtures/path_fixtures.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from pathlib import Path

import pytest


@pytest.fixture(scope="session")
def cgweb_orders_dir(fixtures_dir: Path) -> Path:
"""Return the path to the cgweb_orders dir."""
return Path(fixtures_dir, "cgweb_orders")


@pytest.fixture(scope="session")
def invalid_cgweb_orders_dir(fixtures_dir: Path) -> Path:
"""Return the path to the invalid_cgweb_orders dir."""
return Path(fixtures_dir, "invalid_cgweb_orders")
16 changes: 11 additions & 5 deletions tests/fixture_plugins/orders_fixtures/services_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
)
from cg.services.orders.submitter.service import OrderSubmitter
from cg.services.orders.submitter.ticket_handler import TicketHandler
from cg.services.orders.validation.model_validator.model_validator import ModelValidator
from cg.services.orders.validation.service import OrderValidationService
from cg.store.store import Store
from tests.mocks.limsmock import MockLimsAPI
Expand All @@ -17,6 +18,11 @@ def freshdesk_client() -> FreshdeskClient:
return FreshdeskClient(base_url="https://mock.freshdesk.com", api_key="mock_api_key")


@pytest.fixture
def model_validator() -> ModelValidator:
return ModelValidator()


@pytest.fixture
def order_validation_service(store_to_submit_and_validate_orders: Store) -> OrderValidationService:
return OrderValidationService(store_to_submit_and_validate_orders)
Expand All @@ -35,15 +41,15 @@ def order_submitter(
)


@pytest.fixture
def ticket_handler(store: Store, freshdesk_client: FreshdeskClient) -> TicketHandler:
return TicketHandler(db=store, client=freshdesk_client, system_email_id=12345, env="production")


@pytest.fixture
def storing_service_registry(
store_to_submit_and_validate_orders: Store, lims_api: MockLimsAPI
) -> StoringServiceRegistry:
return setup_storing_service_registry(
lims=lims_api, status_db=store_to_submit_and_validate_orders
)


@pytest.fixture
def ticket_handler(store: Store, freshdesk_client: FreshdeskClient) -> TicketHandler:
return TicketHandler(db=store, client=freshdesk_client, system_email_id=12345, env="production")
2 changes: 1 addition & 1 deletion tests/fixtures/cgweb_orders/fluffy.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"formalin_fixation_time": null,
"index": "IDT DupSeq 10 bp Set B",
"index_number": "3",
"index_sequence": "C01 IDT_10nt_568 (TGTGAGCGAA-AACTCCGATC)",
"index_sequence": "",
"internal_id": null,
"lab_code": null,
"mother": null,
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/cgweb_orders/rml.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"formalin_fixation_time": null,
"index": "IDT DupSeq 10 bp Set B",
"index_number": "3",
"index_sequence": "C01 IDT_10nt_568 (TGTGAGCGAA-AACTCCGATC)",
"index_sequence": "",
"internal_id": null,
"lab_code": null,
"mother": null,
Expand Down
32 changes: 32 additions & 0 deletions tests/services/orders/validation_service/test_model_validator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import pytest

from cg.services.orders.validation.model_validator.model_validator import ModelValidator
from cg.services.orders.validation.models.order import Order
from cg.services.orders.validation.workflows.fluffy.models.order import FluffyOrder
from cg.services.orders.validation.workflows.rml.models.order import RmlOrder


@pytest.mark.parametrize(
"order_fixture, expected_index_sequence, order_model",
[
("fluffy_order_to_submit", "C01 IDT_10nt_568 (TGTGAGCGAA-AACTCCGATC)", FluffyOrder),
("rml_order_to_submit", "C01 IDT_10nt_568 (TGTGAGCGAA-AACTCCGATC)", RmlOrder),
],
ids=["fluffy", "rml"],
)
def test_validate_pool_sample_default_index(
order_fixture: str,
expected_index_sequence: str,
order_model: type[Order],
model_validator: ModelValidator,
request: pytest.FixtureRequest,
):
# GIVEN a pool raw order with a sample without index sequence but correct index and index number
raw_order: dict = request.getfixturevalue(order_fixture)
assert raw_order["samples"][0]["index_sequence"] == ""

# WHEN validating the order
order, _ = model_validator.validate(order=raw_order, model=order_model)

# THEN the index sequence should be set to the default index sequence
assert order.samples[0].index_sequence == expected_index_sequence

0 comments on commit bb2285d

Please sign in to comment.