Skip to content

Commit e19de3a

Browse files
authored
test: add test for mutually exclusive fields (#107)
1 parent 6985744 commit e19de3a

File tree

4 files changed

+39
-4
lines changed

4 files changed

+39
-4
lines changed

.env.example

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,7 @@ GOOGLE_API_KEY=key
44
# SERVICE_DESK Integration
55
SERVICE_DESK_URL=
66
SERVICE_DESK_USER=
7-
SERVICE_DESK_TOKEN=
7+
SERVICE_DESK_TOKEN=
8+
9+
# Your time zone. Defaults to UTC.
10+
TIME_ZONE=

.github/workflows/conventional-label.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ jobs:
88
steps:
99
- uses: bcoe/conventional-release-labels@886f696738527c7be444262c327c89436dfb95a8 #v1.3.1
1010
with:
11-
type_labels: '{"feat": "feature", "fix": "fix", "breaking": "breaking", "ci": "CI", "build": "build", "refactor": "refactor"}'
11+
type_labels: '{"feat": "feature", "fix": "fix", "breaking": "breaking", "ci": "CI", "build": "build", "refactor": "refactor", "test": "test"}'

src/lightman_ai/cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ def run(
9393
load_dotenv(env_file)
9494
configure_sentry()
9595

96-
mutually_exclusive_fields_set = [x for x in [start_date, today, yesterday] if x]
97-
if len(mutually_exclusive_fields_set) > 1:
96+
mutually_exclusive_date_fields = [x for x in [start_date, today, yesterday] if x]
97+
if len(mutually_exclusive_date_fields) > 1:
9898
raise click.UsageError("--today, --yesterday and --start-date are mutually exclusive. Set one at a time.")
9999
elif today:
100100
now = datetime.now(ZoneInfo(settings.TIME_ZONE))

tests/test_cli.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from unittest.mock import ANY, Mock, call, patch
33
from zoneinfo import ZoneInfo
44

5+
import pytest
56
from click.testing import CliRunner
67
from freezegun import freeze_time
78
from lightman_ai import cli
@@ -57,6 +58,37 @@ def test_arguments(self, m_prompt: Mock, m_config: Mock, m_lightman: Mock, m_loa
5758
assert m_prompt.call_args == call(path="prompt file")
5859
assert m_load_dotenv.call_args == call(".env") # Default env file
5960

61+
@pytest.mark.parametrize(
62+
("field1", "field2", "field3"),
63+
[
64+
("--today", "--yesterday", ""),
65+
("--today", "--start-date", "2025-07-29"),
66+
("--yesterday", "--start-date", "2025-07-29"),
67+
],
68+
)
69+
@patch("lightman_ai.cli.lightman")
70+
def test_today_yesterday_start_date_mutualle_exlusive(
71+
self,
72+
m_lightman: Mock,
73+
field1: str,
74+
field2: str,
75+
field3: str,
76+
) -> None:
77+
runner = CliRunner()
78+
79+
args = [field1, field2]
80+
if field3:
81+
args.append(field3)
82+
with patch_config_file():
83+
result = runner.invoke(
84+
cli.run,
85+
args,
86+
)
87+
88+
assert result.exit_code == 2
89+
assert "--today, --yesterday and --start-date are mutually exclusive. Set one at a time." in result.output
90+
assert m_lightman.call_count == 0
91+
6092
@patch("lightman_ai.cli.load_dotenv")
6193
@patch("lightman_ai.cli.lightman")
6294
@patch("lightman_ai.cli.FileConfig.get_config_from_file")

0 commit comments

Comments
 (0)