Skip to content

Commit

Permalink
unit test for adding new organism
Browse files Browse the repository at this point in the history
  • Loading branch information
diitaz93 committed Jan 22, 2025
1 parent d3738b2 commit e72ecee
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cg/store/crud/read.py
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,7 @@ def get_organism_by_internal_id(self, internal_id: str) -> Organism:
internal_id=internal_id,
).first()

def get_all_organisms(self) -> list[Organism]:
def get_all_organisms(self) -> Query[Organism]:
"""Return all organisms ordered by organism internal id."""
return self._get_query(table=Organism).order_by(Organism.internal_id)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
)
from cg.services.orders.validation.workflows.microsalt.models.order import MicrosaltOrder
from cg.services.orders.validation.workflows.mutant.models.order import MutantOrder
from cg.store.models import Case, Sample
from cg.store.models import Case, Organism, Sample
from cg.store.store import Store


Expand Down Expand Up @@ -48,6 +48,33 @@ def test_store_microsalt_order_data_in_status_db(
assert db_case.data_delivery == str(DataDelivery.FASTQ_QC_ANALYSIS)


def test_store_microbial_new_organism_in_status_db(
store_to_submit_and_validate_orders: Store,
microsalt_order: MicrosaltOrder,
store_microbial_order_service: StoreMicrobialOrderService,
):
"""Test that a new organism in a Microsalt order is stored in the status db."""
# GIVEN a store with no organisms
assert store_to_submit_and_validate_orders.get_all_organisms().count() == 0

# GIVEN a Microsalt order with a new organism
microsalt_order.samples[0].organism = "Canis lupus familiaris"
microsalt_order.samples[0].reference_genome = "UU_Cfam_GSD_1.0"

# WHEN storing the order
store_microbial_order_service.store_order_data_in_status_db(microsalt_order)

# THEN the organism should be stored in the status db
organisms: list[Organism] = store_to_submit_and_validate_orders.get_all_organisms().all()
dog: Organism = [
organism for organism in organisms if organism.name == "Canis lupus familiaris"
][0]
assert dog.reference_genome == "UU_Cfam_GSD_1.0"

# THEN the organism should not be verified
assert not dog.verified


def test_store_mutant_order_data_control_has_stored_value(
mutant_order: MutantOrder,
store_to_submit_and_validate_orders: Store,
Expand Down

0 comments on commit e72ecee

Please sign in to comment.