Skip to content

Commit

Permalink
Ticket status for existing samples (#4150)(patch)
Browse files Browse the repository at this point in the history
### Added
- Ticket with only existing samples get the status open
  • Loading branch information
eliottBo authored Feb 4, 2025
1 parent 7014a2f commit 69d87b8
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 2 deletions.
18 changes: 18 additions & 0 deletions cg/meta/orders/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from cg.clients.freshdesk.constants import Status
from cg.models.orders.constants import OrderType
from cg.services.orders.constants import ORDER_TYPE_WORKFLOW_MAP
from cg.services.orders.validation.models.case import Case
Expand Down Expand Up @@ -25,3 +26,20 @@ def get_ticket_tags(order: Order, order_type: OrderType) -> list[str]:
tags.append("existing-data")

return tags


def contains_only_existing_samples(order: OrderWithCases) -> bool:
"""Check if the order contains only existing samples"""

if order.enumerated_new_samples:
return False
return True


def get_ticket_status(order: Order) -> Status:
"""Get the ticket status based on the order"""

if isinstance(order, OrderWithCases):
if contains_only_existing_samples(order=order):
return Status.OPEN
return Status.PENDING
4 changes: 3 additions & 1 deletion cg/services/orders/submitter/ticket_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from cg.clients.freshdesk.freshdesk_client import FreshdeskClient
from cg.clients.freshdesk.models import TicketCreate, TicketResponse
from cg.meta.orders.utils import get_ticket_tags
from cg.meta.orders.utils import get_ticket_status, get_ticket_tags
from cg.models.orders.constants import OrderType
from cg.services.orders.constants import ORDER_TYPE_WORKFLOW_MAP
from cg.services.orders.validation.models.order import Order
Expand Down Expand Up @@ -39,6 +39,7 @@ def create_ticket(
)

tags: list[str] = get_ticket_tags(order=order, order_type=order_type)
status: int = get_ticket_status(order=order)

with TemporaryDirectory() as temp_dir:
attachments: Path = self.create_attachment_file(order=order, temp_dir=temp_dir)
Expand All @@ -55,6 +56,7 @@ def create_ticket(
"cf_environment": self.env,
},
attachments=[],
status=status,
)
ticket_response: TicketResponse = self.client.create_ticket(
ticket=freshdesk_ticket, attachments=[attachments]
Expand Down
10 changes: 10 additions & 0 deletions tests/fixture_plugins/orders_fixtures/order_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,13 @@ def mip_dna_order_with_existing_samples(mip_dna_order_to_submit: dict) -> MipDna
ExistingSample(internal_id="ACC1234")
)
return mip_dna_order_with_existing_samples


@pytest.fixture
def mip_dna_order_with_only_existing_samples(mip_dna_order_to_submit: dict) -> MipDnaOrder:
"""Returns a MIP DNA order containing only existing samples."""
mip_dna_order_to_submit["user_id"] = 1
mip_dna_order_with_only_existing_samples = MipDnaOrder.model_validate(mip_dna_order_to_submit)
for case in mip_dna_order_with_only_existing_samples.cases:
case.samples = [ExistingSample(internal_id="ACC1234")]
return mip_dna_order_with_only_existing_samples
26 changes: 25 additions & 1 deletion tests/services/orders/submitter/test_order_submitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@

import pytest

from cg.clients.freshdesk.constants import Status
from cg.clients.freshdesk.models import TicketResponse
from cg.exc import TicketCreationError
from cg.meta.orders.utils import get_ticket_tags
from cg.meta.orders.utils import get_ticket_status, get_ticket_tags
from cg.models.orders.constants import OrderType
from cg.services.orders.constants import ORDER_TYPE_WORKFLOW_MAP
from cg.services.orders.storing.constants import MAF_ORDER_ID
Expand Down Expand Up @@ -206,3 +207,26 @@ def test_get_ticket_tags(

# THEN the tags should be correct
assert tags == expected_tags


@pytest.mark.parametrize(
"order_fixture, expected_status",
[
("mip_dna_order", Status.PENDING),
("mip_dna_order_with_existing_samples", Status.PENDING),
("mip_dna_order_with_only_existing_samples", Status.OPEN),
],
)
def test_get_ticket_status(
request: pytest.FixtureRequest, order_fixture: str, expected_status: int
):
"""Test that the correct ticket status is returned based on the order samples."""

# GIVEN an order
order: Order = request.getfixturevalue(order_fixture)

# WHEN getting the ticket status
status = get_ticket_status(order=order)

# THEN the status should be correct
assert status == expected_status

0 comments on commit 69d87b8

Please sign in to comment.