Skip to content

Refactor: time convert uses env vars for IO targets #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions bin/hours-convert.sh

This file was deleted.

12 changes: 9 additions & 3 deletions compiler_admin/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,14 @@ def setup_time_command(cmd_parsers: _SubParsersAction):

time_convert = add_sub_cmd(time_subcmds, "convert", help="Convert a time report from one format into another.")
time_convert.add_argument(
"--input", default=sys.stdin, help="The path to the source data for conversion. Defaults to stdin."
"--input",
default=os.environ.get("TOGGL_DATA", sys.stdin),
help="The path to the source data for conversion. Defaults to $TOGGL_DATA or stdin.",
)
time_convert.add_argument(
"--output", default=sys.stdout, help="The path to the file where converted data should be written. Defaults to stdout."
"--output",
default=os.environ.get("HARVEST_DATA", sys.stdout),
help="The path to the file where converted data should be written. Defaults to $HARVEST_DATA or stdout.",
)
time_convert.add_argument("--client", default=None, help="The name of the client to use in converted data.")

Expand All @@ -92,7 +96,9 @@ def setup_time_command(cmd_parsers: _SubParsersAction):
help="The end date of the reporting period. Defaults to the end of the prior month.",
)
time_download.add_argument(
"--output", default=sys.stdout, help="The path to the file where converted data should be written. Defaults to stdout."
"--output",
default=os.environ.get("TOGGL_DATA", sys.stdout),
help="The path to the file where downloaded data should be written. Defaults to $TOGGL_DATA or stdout.",
)
time_download.add_argument(
"--client",
Expand Down
20 changes: 20 additions & 0 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
from compiler_admin.services.google import DOMAIN


@pytest.fixture(autouse=True)
def reset_env(monkeypatch):
monkeypatch.delenv("HARVEST_DATA", raising=False)
monkeypatch.delenv("TOGGL_DATA", raising=False)


@pytest.fixture
def mock_local_now(mocker):
dt = datetime(2024, 9, 25, tzinfo=TZINFO)
Expand Down Expand Up @@ -114,6 +120,20 @@ def test_main_time_convert_default(mock_commands_time):
)


def test_main_time_convert_env(monkeypatch, mock_commands_time):
monkeypatch.setenv("HARVEST_DATA", "harvest")
monkeypatch.setenv("TOGGL_DATA", "toggl")

main(argv=["time", "convert"])

mock_commands_time.assert_called_once()
call_args = mock_commands_time.call_args.args
assert (
Namespace(func=mock_commands_time, command="time", subcommand="convert", client=None, input="toggl", output="harvest")
in call_args
)


@pytest.mark.usefixtures("mock_local_now")
def test_main_time_download_default(mock_commands_time, mock_start, mock_end):
main(argv=["time", "download"])
Expand Down
Loading