Skip to content

Commit

Permalink
Merge pull request #106 from preset-io/workspaces_from_env
Browse files Browse the repository at this point in the history
feat: allow reading workspaces from the environment
  • Loading branch information
betodealmeida authored Oct 7, 2022
2 parents 55d1fae + 7f6d098 commit 19e9eed
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/preset_cli/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def is_help() -> bool:
@click.option("--api-token", envvar="PRESET_API_TOKEN")
@click.option("--api-secret", envvar="PRESET_API_SECRET")
@click.option("--jwt-token", envvar="PRESET_JWT_TOKEN")
@click.option("--workspaces", callback=split_comma)
@click.option("--workspaces", envvar="PRESET_WORKSPACES", callback=split_comma)
@click.option("--loglevel", default="INFO")
@click.version_option()
@click.pass_context
Expand Down
25 changes: 25 additions & 0 deletions tests/cli/main_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,31 @@ def test_workspaces(mocker: MockerFixture) -> None:
assert obj["WORKSPACES"] == ["https://ws1", "https://ws2"]


def test_workspaces_from_env(
mocker: MockerFixture,
monkeypatch: pytest.MonkeyPatch,
) -> None:
"""
Test that we don't prompt user for their workspaces if defined in the environment.
"""
monkeypatch.setenv("PRESET_WORKSPACES", "https://ws1,https://ws2")

PresetClient = mocker.patch("preset_cli.cli.main.PresetClient")
client = PresetClient()

runner = CliRunner()
obj: Dict[str, Any] = {}
result = runner.invoke(
preset_cli,
["--jwt-token", "JWT_TOKEN", "superset", "--help"],
catch_exceptions=False,
obj=obj,
)
assert result.exit_code == 0
assert obj["WORKSPACES"] == ["https://ws1", "https://ws2"]
client.get_workspaces.assert_not_called()


def test_workspaces_help(mocker: MockerFixture) -> None:
"""
Test that we don't prompt user for their workspaces if ``--help`` is passed.
Expand Down

0 comments on commit 19e9eed

Please sign in to comment.