Skip to content

Commit 3c0cabc

Browse files
committed
refactor(download): move default client_id to envvar
1 parent 06420c5 commit 3c0cabc

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

compiler_admin/commands/time/download.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,10 @@ def prior_month_start():
5656
"-c",
5757
"--client",
5858
"client_ids",
59-
multiple=True,
59+
envvar="TOGGL_CLIENT_ID",
6060
help="An ID for a Toggl Client to filter for in reports. Can be supplied more than once.",
6161
metavar="CLIENT_ID",
62+
multiple=True,
6263
type=int,
6364
)
6465
@click.option(

compiler_admin/services/toggl.py

-6
Original file line numberDiff line numberDiff line change
@@ -192,12 +192,6 @@ def download_time_entries(
192192
Returns:
193193
None. Either prints the resulting CSV data or writes to output_path.
194194
"""
195-
env_client_id = os.environ.get("TOGGL_CLIENT_ID")
196-
if env_client_id:
197-
env_client_id = int(env_client_id)
198-
if ("client_ids" not in kwargs or not kwargs["client_ids"]) and isinstance(env_client_id, int):
199-
kwargs["client_ids"] = [env_client_id]
200-
201195
token = os.environ.get("TOGGL_API_TOKEN")
202196
workspace = os.environ.get("TOGGL_WORKSPACE_ID")
203197
toggl = Toggl(token, workspace)

tests/commands/time/test_download.py

+23-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,29 @@ def test_download(cli_runner, mock_download_time_entries):
8989
)
9090

9191

92-
def test_download_all(cli_runner, mock_download_time_entries):
92+
def test_download_client_envvar(cli_runner, monkeypatch, mock_download_time_entries):
93+
monkeypatch.setenv("TOGGL_CLIENT_ID", 1234)
94+
95+
date = datetime.now(tz=TZINFO).replace(hour=0, minute=0, second=0, microsecond=0)
96+
args = [
97+
"--start",
98+
date.strftime("%Y-%m-%d %H:%M:%S%z"),
99+
"--end",
100+
date.strftime("%Y-%m-%d %H:%M:%S%z"),
101+
"--output",
102+
"output",
103+
]
104+
105+
result = cli_runner.invoke(download, args)
106+
107+
assert result.exit_code == RESULT_SUCCESS
108+
mock_download_time_entries.assert_called_once_with(
109+
start_date=date, end_date=date, output_path="output", output_cols=TOGGL_COLUMNS, billable=True, client_ids=(1234,)
110+
)
111+
112+
113+
def test_download_all(cli_runner, monkeypatch, mock_download_time_entries):
114+
monkeypatch.delenv("TOGGL_CLIENT_ID", raising=False)
93115
date = datetime.now(tz=TZINFO).replace(hour=0, minute=0, second=0, microsecond=0)
94116
args = [
95117
"--start",

0 commit comments

Comments
 (0)