Skip to content

Commit

Permalink
Add tag "existing-data" to ticket (#4148)(patch)
Browse files Browse the repository at this point in the history
### Added
- If a ticket contains already existing data, a tag "existing-data" is added
  • Loading branch information
eliottBo authored Feb 4, 2025
1 parent 9e803cc commit 6cece60
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 1 deletion.
27 changes: 27 additions & 0 deletions cg/meta/orders/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
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
from cg.services.orders.validation.models.order import Order
from cg.services.orders.validation.models.order_with_cases import OrderWithCases


def contains_existing_data(order: OrderWithCases) -> bool:
"""Check if the order contains any existing data"""

for enumerated_case in order.enumerated_cases:
case: Case = enumerated_case[1]
if case.enumerated_existing_samples:
return True
return False


def get_ticket_tags(order: Order, order_type: OrderType) -> list[str]:
"""Generate ticket tags based on the order and order type"""

tags: list[str] = [ORDER_TYPE_WORKFLOW_MAP[order_type]]

if isinstance(order, OrderWithCases):
if contains_existing_data(order):
tags.append("existing-data")

return tags
5 changes: 4 additions & 1 deletion cg/services/orders/submitter/ticket_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +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.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 @@ -37,6 +38,8 @@ def create_ticket(
order_type=order_type,
)

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

with TemporaryDirectory() as temp_dir:
attachments: Path = self.create_attachment_file(order=order, temp_dir=temp_dir)

Expand All @@ -47,7 +50,7 @@ def create_ticket(
name=user_name,
subject=order.name,
type="Order",
tags=[ORDER_TYPE_WORKFLOW_MAP[order_type]],
tags=tags,
custom_fields={
"cf_environment": self.env,
},
Expand Down
12 changes: 12 additions & 0 deletions tests/fixture_plugins/orders_fixtures/order_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import pytest

from cg.services.orders.validation.models.existing_sample import ExistingSample
from cg.services.orders.validation.workflows.balsamic.models.order import BalsamicOrder
from cg.services.orders.validation.workflows.fastq.models.order import FastqOrder
from cg.services.orders.validation.workflows.fluffy.models.order import FluffyOrder
Expand Down Expand Up @@ -135,3 +136,14 @@ def tomte_order(tomte_order_to_submit: dict, ticket_id_as_int: int) -> TomteOrde
tomte_order = TomteOrder.model_validate(tomte_order_to_submit)
tomte_order._generated_ticket_id = ticket_id_as_int
return tomte_order


@pytest.fixture
def mip_dna_order_with_existing_samples(mip_dna_order_to_submit: dict) -> MipDnaOrder:
"""Returns a MIP DNA order containing an existing sample."""
mip_dna_order_to_submit["user_id"] = 1
mip_dna_order_with_existing_samples = MipDnaOrder.model_validate(mip_dna_order_to_submit)
mip_dna_order_with_existing_samples.cases[0].samples.append(
ExistingSample(internal_id="ACC1234")
)
return mip_dna_order_with_existing_samples
26 changes: 26 additions & 0 deletions tests/services/orders/submitter/test_order_submitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from cg.clients.freshdesk.models import TicketResponse
from cg.exc import TicketCreationError
from cg.meta.orders.utils import 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 @@ -180,3 +181,28 @@ def test_submit_ticketexception(
order_submitter.submit(
raw_order=raw_order, user=user, order_type=mip_dna_order.order_type
)


@pytest.mark.parametrize(
"order_fixture, order_type, expected_tags",
[
("mip_dna_order_with_existing_samples", OrderType.MIP_DNA, ["mip-dna", "existing-data"]),
("mip_dna_order", OrderType.MIP_DNA, ["mip-dna"]),
],
)
def test_get_ticket_tags(
request: pytest.FixtureRequest,
order_fixture: str,
order_type: OrderType,
expected_tags: list[str],
):
"""Test that the correct tags are generated based on the order and order type."""

# GIVEN an order with existing data
order: OrderWithCases = request.getfixturevalue(order_fixture)

# WHEN getting the ticket tags
tags = get_ticket_tags(order=order, order_type=order_type)

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

0 comments on commit 6cece60

Please sign in to comment.