Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ticket status for existing samples #4150

Open
wants to merge 12 commits into
base: ticket-tag-existing-data
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 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 @@ -26,3 +27,18 @@ 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):
eliottBo marked this conversation as resolved.
Show resolved Hide resolved
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
Loading