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

Merged
merged 22 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
2f0dfa6
Add utility functions for order data validation and ticket tag genera…
eliottBo Jan 20, 2025
4062b04
Integrate ticket tag generation into TicketHandler
eliottBo Jan 20, 2025
71909ce
Add unit test for ticket tag generation based on order type
eliottBo Jan 20, 2025
da49a5c
Refactor ticket tag generation and enhance unit tests for accuracy
eliottBo Jan 20, 2025
5555920
Rename function and update references in ticket tag generation
eliottBo Jan 21, 2025
19efd0f
Add fixture for MIP DNA order with existing samples
eliottBo Jan 21, 2025
0af8611
Update internal_id for existing sample in MIP DNA order fixture
eliottBo Jan 21, 2025
5fad3d0
Rename function for clarity and update ticket tag generation logic to…
eliottBo Jan 23, 2025
c905331
Add functions to check if only existing samples and retrieve ticket s…
eliottBo Jan 22, 2025
b5db7a7
Update ticket status constants in get_ticket_status function
eliottBo Jan 22, 2025
bd6401c
Add fixture for MIP DNA order with only existing samples and test tic…
eliottBo Jan 22, 2025
dbd8bf1
Add ticket status retrieval in TicketHandler for ticket creation
eliottBo Jan 22, 2025
93b5448
Refactor contains_only_existing_samples to accept OrderWithCases and …
eliottBo Jan 22, 2025
9770d13
Fix return value in mip_dna_order_with_only_existing_samples function…
eliottBo Jan 22, 2025
7efea83
Update cg/meta/orders/utils.py
eliottBo Jan 24, 2025
384ea30
Update tests/services/orders/submitter/test_order_submitter.py
eliottBo Jan 24, 2025
a3836a0
Remove space cg/meta/orders/utils.py
eliottBo Jan 24, 2025
0965558
Add import for Status constant in test_order_submitter.py
eliottBo Jan 24, 2025
7eca66f
Update cg/meta/orders/utils.py
eliottBo Jan 29, 2025
c08b4ba
Fix indentation in contains_only_existing_samples function in utils.py
eliottBo Jan 29, 2025
4c2bcb1
Merge branch 'master' into ticket-status-for-existing-samples
eliottBo Feb 4, 2025
b35dfcf
Black formatting
eliottBo Feb 4, 2025
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
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):
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