Skip to content

Commit 50f606f

Browse files
author
ChristianOertlin
authored
fix(set case priority research bug) (#3830) (patch)
# Description Fixes a bug in set case
1 parent c09b139 commit 50f606f

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

cg/cli/set/case.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Set case attributes in the status database."""
22

33
import logging
4+
from typing import Callable
45

56
import click
67

@@ -57,7 +58,7 @@ def set_case(
5758
data_analysis,
5859
data_delivery,
5960
]
60-
abort_on_empty_options(options=options)
61+
abort_on_empty_options(options=options, priority=priority)
6162

6263
status_db: Store = context.status_db
6364
case: Case = get_case(case_id=case_id, status_db=status_db)
@@ -77,14 +78,15 @@ def set_case(
7778
if panel_abbreviations:
7879
update_panels(case=case, panel_abbreviations=panel_abbreviations, status_db=status_db)
7980

80-
if priority:
81+
if isinstance(priority, Priority):
8182
update_priority(case=case, priority=priority)
8283

8384
status_db.session.commit()
8485

8586

86-
def abort_on_empty_options(options: list[str]) -> None:
87-
if not any(options):
87+
def abort_on_empty_options(options: list[str], priority: Priority | None) -> None:
88+
"""Abort if options are empty and bypass_check for priority returns False"""
89+
if not any(options) and not priority == Priority.research:
8890
LOG.error("Nothing to change")
8991
raise click.Abort
9092

tests/cli/set/test_cli_set_case.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,28 @@ def test_set_case_priority(
9898
assert case_query.first().priority_human == priority
9999

100100

101+
def test_set_case_priority_research(
102+
cli_runner: CliRunner, base_context: CGConfig, base_store: Store, helpers: StoreHelpers
103+
):
104+
"""Test that the added case gets the priority we send in."""
105+
# GIVEN a database with a case
106+
case_id: str = helpers.add_case(base_store).internal_id
107+
priority: str = "research"
108+
case_query = base_store._get_query(table=Case)
109+
110+
assert case_query.first().priority_human != priority
111+
112+
# WHEN setting a case
113+
result = cli_runner.invoke(
114+
set_case, [case_id, "--priority", priority], obj=base_context, catch_exceptions=False
115+
)
116+
117+
# THEN it should have been set
118+
assert result.exit_code == EXIT_SUCCESS
119+
assert case_query.count() == 1
120+
assert case_query.first().priority_human == priority
121+
122+
101123
def test_set_case_customer(
102124
cli_runner: CliRunner, base_context: CGConfig, base_store: Store, helpers: StoreHelpers
103125
):

0 commit comments

Comments
 (0)