Skip to content

Commit

Permalink
add tests for parse and validate
Browse files Browse the repository at this point in the history
  • Loading branch information
diitaz93 committed Jan 20, 2025
1 parent 5096370 commit 9242715
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 10 deletions.
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")
)
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
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import pytest

from cg.exc import OrderError
from cg.models.orders.constants import OrderType
from cg.services.orders.validation.service import OrderValidationService


def test_parse_and_validate_pydantic_error(
order_validation_service: OrderValidationService, invalid_balsamic_order_to_submit: dict
):
# GIVEN a raw order that will fail validation and a validation service

# WHEN parsing and validating the order

# THEN an OrderError should be raised
with pytest.raises(OrderError):
order_validation_service.parse_and_validate(
raw_order=invalid_balsamic_order_to_submit,
order_type=OrderType.BALSAMIC,
user_id=1,
)

0 comments on commit 9242715

Please sign in to comment.