Skip to content

Commit 657ea5d

Browse files
committed
feat(time): flag allows downloading all time entries
not just billable, which remains the default
1 parent 560f08a commit 657ea5d

File tree

4 files changed

+25
-26
lines changed

4 files changed

+25
-26
lines changed

compiler_admin/commands/time/download.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55

66

77
def download(args: Namespace, *extras):
8-
params = dict(start_date=args.start, end_date=args.end, output_path=args.output, output_cols=TOGGL_COLUMNS)
8+
params = dict(
9+
start_date=args.start, end_date=args.end, output_path=args.output, output_cols=TOGGL_COLUMNS, billable=args.billable
10+
)
911

1012
if args.client_ids:
1113
params.update(dict(client_ids=args.client_ids))

compiler_admin/main.py

+7
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,13 @@ def setup_time_command(cmd_parsers: _SubParsersAction):
115115
default=os.environ.get("TOGGL_DATA", sys.stdout),
116116
help="The path to the file where downloaded data should be written. Defaults to $TOGGL_DATA or stdout.",
117117
)
118+
time_download.add_argument(
119+
"--all",
120+
default=True,
121+
action="store_false",
122+
dest="billable",
123+
help="Download all time entries. The default is to download only billable time entries.",
124+
)
118125
time_download.add_argument(
119126
"--client",
120127
dest="client_ids",

tests/commands/time/test_download.py

+12-25
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,18 @@ def mock_download_time_entries(mocker):
1111
return mocker.patch(f"{MODULE}.download_time_entries")
1212

1313

14-
def test_download_default(mock_download_time_entries):
14+
@pytest.mark.parametrize("billable", [True, False])
15+
def test_download(mock_download_time_entries, billable):
1516
date = datetime.now()
1617
args = Namespace(
1718
start=date,
1819
end=date,
1920
output="output",
20-
client_ids=None,
21-
project_ids=None,
22-
task_ids=None,
23-
user_ids=None,
21+
billable=billable,
22+
client_ids=["c1", "c2"],
23+
project_ids=["p1", "p2"],
24+
task_ids=["t1", "t2"],
25+
user_ids=["u1", "u2"],
2426
)
2527

2628
res = download(args)
@@ -31,24 +33,9 @@ def test_download_default(mock_download_time_entries):
3133
end_date=args.end,
3234
output_path=args.output,
3335
output_cols=TOGGL_COLUMNS,
34-
)
35-
36-
37-
def test_download_ids(mock_download_time_entries):
38-
date = datetime.now()
39-
ids = [1, 2, 3]
40-
args = Namespace(start=date, end=date, output="output", client_ids=ids, project_ids=ids, task_ids=ids, user_ids=ids)
41-
42-
res = download(args)
43-
44-
assert res == RESULT_SUCCESS
45-
mock_download_time_entries.assert_called_once_with(
46-
start_date=args.start,
47-
end_date=args.end,
48-
output_path=args.output,
49-
output_cols=TOGGL_COLUMNS,
50-
client_ids=ids,
51-
project_ids=ids,
52-
task_ids=ids,
53-
user_ids=ids,
36+
billable=args.billable,
37+
client_ids=args.client_ids,
38+
project_ids=args.project_ids,
39+
task_ids=args.task_ids,
40+
user_ids=args.user_ids,
5441
)

tests/test_main.py

+3
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ def test_main_time_download_default(mock_commands_time, mock_start, mock_end):
164164
start=mock_start,
165165
end=mock_end,
166166
output=sys.stdout,
167+
billable=True,
167168
client_ids=None,
168169
project_ids=None,
169170
task_ids=None,
@@ -184,6 +185,7 @@ def test_main_time_download_args(mock_commands_time):
184185
"2024-01-31",
185186
"--output",
186187
"file.csv",
188+
"--all",
187189
"--client",
188190
"1",
189191
"--client",
@@ -225,6 +227,7 @@ def test_main_time_download_args(mock_commands_time):
225227
start=expected_start,
226228
end=expected_end,
227229
output="file.csv",
230+
billable=False,
228231
client_ids=ids,
229232
project_ids=ids,
230233
task_ids=ids,

0 commit comments

Comments
 (0)