Skip to content

Commit bb2285d

Browse files
authored
add test for validation pool (#4132)
add test for validation pool
1 parent 9052662 commit bb2285d

File tree

10 files changed

+66
-17
lines changed

10 files changed

+66
-17
lines changed

cg/services/orders/validation/workflows/fluffy/models/sample.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class FluffySample(Sample):
2727
well_position_rml: str | None = None
2828

2929
@model_validator(mode="after")
30-
def set_default_index_sequence(self):
30+
def set_default_index_sequence(self) -> "FluffySample":
3131
"""Set a default index_sequence from the index and index_number."""
3232
if not self.index_sequence and (self.index and self.index_number):
3333
try:

cg/services/orders/validation/workflows/rml/models/sample.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@ class RmlSample(Sample):
2323
pool: str
2424
priority: PriorityEnum
2525
rml_plate_name: str | None = None
26+
2627
volume: int
2728
well_position_rml: str | None = None
2829

2930
@model_validator(mode="after")
30-
def set_default_index_sequence(self):
31+
def set_default_index_sequence(self) -> "RmlSample":
3132
"""Set a default index_sequence from the index and index_number."""
3233
if not self.index_sequence and (self.index and self.index_number):
3334
try:

tests/conftest.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@
123123
"tests.fixture_plugins.orders_fixtures.order_form_fixtures",
124124
"tests.fixture_plugins.orders_fixtures.order_to_submit_fixtures",
125125
"tests.fixture_plugins.orders_fixtures.order_fixtures",
126+
"tests.fixture_plugins.orders_fixtures.path_fixtures",
126127
"tests.fixture_plugins.orders_fixtures.services_fixtures",
127128
"tests.fixture_plugins.orders_fixtures.store_fixtures",
128129
"tests.fixture_plugins.orders_fixtures.store_service_fixtures",
@@ -745,12 +746,6 @@ def apps_dir(fixtures_dir: Path) -> Path:
745746
return Path(fixtures_dir, "apps")
746747

747748

748-
@pytest.fixture(scope="session")
749-
def cgweb_orders_dir(fixtures_dir: Path) -> Path:
750-
"""Return the path to the cgweb_orders dir."""
751-
return Path(fixtures_dir, "cgweb_orders")
752-
753-
754749
@pytest.fixture(scope="session")
755750
def data_dir(fixtures_dir: Path) -> Path:
756751
"""Return the path to the data dir."""

tests/fixture_plugins/orders_fixtures/order_to_submit_fixtures.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ def tomte_order_to_submit(cgweb_orders_dir: Path) -> dict:
126126

127127

128128
@pytest.fixture(scope="session")
129-
def invalid_balsamic_order_to_submit(cgweb_orders_dir: Path) -> dict:
129+
def invalid_balsamic_order_to_submit(invalid_cgweb_orders_dir: Path) -> dict:
130130
"""Load an invalid example Balsamic order."""
131131
return ReadFile.get_content_from_file(
132-
file_format=FileFormat.JSON, file_path=Path(cgweb_orders_dir, "FAIL_balsamic.json")
132+
file_format=FileFormat.JSON, file_path=Path(invalid_cgweb_orders_dir, "balsamic_FAIL.json")
133133
)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from pathlib import Path
2+
3+
import pytest
4+
5+
6+
@pytest.fixture(scope="session")
7+
def cgweb_orders_dir(fixtures_dir: Path) -> Path:
8+
"""Return the path to the cgweb_orders dir."""
9+
return Path(fixtures_dir, "cgweb_orders")
10+
11+
12+
@pytest.fixture(scope="session")
13+
def invalid_cgweb_orders_dir(fixtures_dir: Path) -> Path:
14+
"""Return the path to the invalid_cgweb_orders dir."""
15+
return Path(fixtures_dir, "invalid_cgweb_orders")

tests/fixture_plugins/orders_fixtures/services_fixtures.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
)
88
from cg.services.orders.submitter.service import OrderSubmitter
99
from cg.services.orders.submitter.ticket_handler import TicketHandler
10+
from cg.services.orders.validation.model_validator.model_validator import ModelValidator
1011
from cg.services.orders.validation.service import OrderValidationService
1112
from cg.store.store import Store
1213
from tests.mocks.limsmock import MockLimsAPI
@@ -17,6 +18,11 @@ def freshdesk_client() -> FreshdeskClient:
1718
return FreshdeskClient(base_url="https://mock.freshdesk.com", api_key="mock_api_key")
1819

1920

21+
@pytest.fixture
22+
def model_validator() -> ModelValidator:
23+
return ModelValidator()
24+
25+
2026
@pytest.fixture
2127
def order_validation_service(store_to_submit_and_validate_orders: Store) -> OrderValidationService:
2228
return OrderValidationService(store_to_submit_and_validate_orders)
@@ -35,15 +41,15 @@ def order_submitter(
3541
)
3642

3743

38-
@pytest.fixture
39-
def ticket_handler(store: Store, freshdesk_client: FreshdeskClient) -> TicketHandler:
40-
return TicketHandler(db=store, client=freshdesk_client, system_email_id=12345, env="production")
41-
42-
4344
@pytest.fixture
4445
def storing_service_registry(
4546
store_to_submit_and_validate_orders: Store, lims_api: MockLimsAPI
4647
) -> StoringServiceRegistry:
4748
return setup_storing_service_registry(
4849
lims=lims_api, status_db=store_to_submit_and_validate_orders
4950
)
51+
52+
53+
@pytest.fixture
54+
def ticket_handler(store: Store, freshdesk_client: FreshdeskClient) -> TicketHandler:
55+
return TicketHandler(db=store, client=freshdesk_client, system_email_id=12345, env="production")

tests/fixtures/cgweb_orders/fluffy.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"formalin_fixation_time": null,
3131
"index": "IDT DupSeq 10 bp Set B",
3232
"index_number": "3",
33-
"index_sequence": "C01 IDT_10nt_568 (TGTGAGCGAA-AACTCCGATC)",
33+
"index_sequence": "",
3434
"internal_id": null,
3535
"lab_code": null,
3636
"mother": null,

tests/fixtures/cgweb_orders/rml.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"formalin_fixation_time": null,
3131
"index": "IDT DupSeq 10 bp Set B",
3232
"index_number": "3",
33-
"index_sequence": "C01 IDT_10nt_568 (TGTGAGCGAA-AACTCCGATC)",
33+
"index_sequence": "",
3434
"internal_id": null,
3535
"lab_code": null,
3636
"mother": null,
File renamed without changes.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import pytest
2+
3+
from cg.services.orders.validation.model_validator.model_validator import ModelValidator
4+
from cg.services.orders.validation.models.order import Order
5+
from cg.services.orders.validation.workflows.fluffy.models.order import FluffyOrder
6+
from cg.services.orders.validation.workflows.rml.models.order import RmlOrder
7+
8+
9+
@pytest.mark.parametrize(
10+
"order_fixture, expected_index_sequence, order_model",
11+
[
12+
("fluffy_order_to_submit", "C01 IDT_10nt_568 (TGTGAGCGAA-AACTCCGATC)", FluffyOrder),
13+
("rml_order_to_submit", "C01 IDT_10nt_568 (TGTGAGCGAA-AACTCCGATC)", RmlOrder),
14+
],
15+
ids=["fluffy", "rml"],
16+
)
17+
def test_validate_pool_sample_default_index(
18+
order_fixture: str,
19+
expected_index_sequence: str,
20+
order_model: type[Order],
21+
model_validator: ModelValidator,
22+
request: pytest.FixtureRequest,
23+
):
24+
# GIVEN a pool raw order with a sample without index sequence but correct index and index number
25+
raw_order: dict = request.getfixturevalue(order_fixture)
26+
assert raw_order["samples"][0]["index_sequence"] == ""
27+
28+
# WHEN validating the order
29+
order, _ = model_validator.validate(order=raw_order, model=order_model)
30+
31+
# THEN the index sequence should be set to the default index sequence
32+
assert order.samples[0].index_sequence == expected_index_sequence

0 commit comments

Comments
 (0)