Skip to content

Commit e1bb152

Browse files
committed
feat(time): wire up download command
compiler-admin time download --start YYYY-MM-DD --end YYYY-MM-DD --output path/to/file.csv small fix on convert test assertion
1 parent ba325c9 commit e1bb152

File tree

6 files changed

+71
-5
lines changed

6 files changed

+71
-5
lines changed

README.md

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,30 @@ The `time` command provides an interface for working with time entries from Comp
6262

6363
```bash
6464
$ compiler-admin time -h
65-
usage: compiler-admin time [-h] {convert} ...
65+
usage: compiler-admin time [-h] {convert,download} ...
6666
6767
positional arguments:
68-
{convert} The time command to run.
69-
convert Convert a time report from one format into another.
68+
{convert,download} The time command to run.
69+
convert Convert a time report from one format into another.
70+
download Download a Toggl report in CSV format.
7071
7172
options:
72-
-h, --help show this help message and exit
73+
-h, --help show this help message and exit
74+
```
75+
76+
### Downloading a Toggl report
77+
78+
Use this command to download a time report from Toggl in CSV format:
79+
80+
```bash
81+
$ compiler-admin time download -h
82+
usage: compiler-admin time download [-h] [--start YYYY-MM-DD] [--end YYYY-MM-DD] [--output OUTPUT]
83+
84+
options:
85+
-h, --help show this help message and exit
86+
--start YYYY-MM-DD The start date of the reporting period. Defaults to the beginning of the prior month.
87+
--end YYYY-MM-DD The end date of the reporting period. Defaults to the end of the prior month.
88+
--output OUTPUT The path to the file where converted data should be written. Defaults to stdout.
7389
```
7490

7591
### Converting an hours report

compiler_admin/commands/time/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from argparse import Namespace
22

33
from compiler_admin.commands.time.convert import convert # noqa: F401
4+
from compiler_admin.commands.time.download import download # noqa: F401
45

56

67
def time(args: Namespace, *extra):
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from argparse import Namespace
2+
3+
from compiler_admin import RESULT_SUCCESS
4+
from compiler_admin.services.toggl import INPUT_COLUMNS as TOGGL_COLUMNS, download_time_entries
5+
6+
7+
def download(args: Namespace, *extras):
8+
download_time_entries(args.start, args.end, args.output, TOGGL_COLUMNS)
9+
10+
return RESULT_SUCCESS

compiler_admin/main.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,25 @@ def setup_time_command(cmd_parsers: _SubParsersAction):
7575
)
7676
time_convert.add_argument("--client", default=None, help="The name of the client to use in converted data.")
7777

78+
time_download = add_sub_cmd(time_subcmds, "download", help="Download a Toggl report in CSV format.")
79+
time_download.add_argument(
80+
"--start",
81+
default=prior_month_start(),
82+
type=lambda s: datetime.strptime(s, "%Y-%m-%d").astimezone(TZINFO),
83+
help="The start date of the reporting period. Defaults to the beginning of the prior month.",
84+
metavar="YYYY-MM-DD",
85+
)
86+
time_download.add_argument(
87+
"--end",
88+
default=prior_month_end(),
89+
type=lambda s: datetime.strptime(s, "%Y-%m-%d").astimezone(TZINFO),
90+
help="The end date of the reporting period. Defaults to the end of the prior month.",
91+
metavar="YYYY-MM-DD",
92+
)
93+
time_download.add_argument(
94+
"--output", default=sys.stdout, help="The path to the file where converted data should be written. Defaults to stdout."
95+
)
96+
7897

7998
def setup_user_command(cmd_parsers: _SubParsersAction):
8099
user_cmd = add_sub_cmd(cmd_parsers, "user", help="Work with users in the Compiler org.")

tests/commands/time/test_download.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from argparse import Namespace
2+
from datetime import datetime
3+
import pytest
4+
5+
from compiler_admin import RESULT_SUCCESS
6+
from compiler_admin.commands.time.download import __name__ as MODULE, download, TOGGL_COLUMNS
7+
8+
9+
@pytest.fixture
10+
def mock_download_time_entries(mocker):
11+
return mocker.patch(f"{MODULE}.download_time_entries")
12+
13+
14+
def test_download(mock_download_time_entries):
15+
date = datetime.now()
16+
args = Namespace(start=date, end=date, output="output")
17+
res = download(args)
18+
19+
assert res == RESULT_SUCCESS
20+
mock_download_time_entries.assert_called_once_with(args.start, args.end, args.output, TOGGL_COLUMNS)

tests/commands/user/test_convert.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def test_convert_partner(mock_google_add_user_to_group, mock_google_move_user_ou
172172
res = convert(args)
173173

174174
assert res == RESULT_SUCCESS
175-
mock_google_add_user_to_group.call_count == 2
175+
assert mock_google_add_user_to_group.call_count == 2
176176
mock_google_move_user_ou.assert_called_once()
177177

178178

0 commit comments

Comments
 (0)