Skip to content

Commit

Permalink
Copy in current env for CLI login test
Browse files Browse the repository at this point in the history
  • Loading branch information
CasperWA committed Jan 15, 2024
1 parent 0f88732 commit c08b1b4
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions tests/cli/test_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ def test_login(
live_backend: bool,
) -> None:
"""Test the `entities-service login` CLI command."""
import os

from dlite_entities_service.cli._utils.global_settings import CONTEXT
from dlite_entities_service.cli.main import APP
from dlite_entities_service.models.auth import Token
Expand All @@ -52,28 +54,38 @@ def test_login(
json=mock_token.model_dump(),
)

cli_run_env = os.environ.copy()

# Run the CLI command
if input_method == "cli_option":
result = cli.invoke(
APP,
f"login --username {username} --password {password}",
catch_exceptions=False,
env=cli_run_env,
)
elif input_method == "stdin":
cli_run_env.update(
{"ENTITY_SERVICE_ADMIN_USER": "", "ENTITY_SERVICE_ADMIN_PASSWORD": ""}
)

result = cli.invoke(
APP,
"login",
input=f"{username}\n{password}\n",
env={"ENTITY_SERVICE_ADMIN_USER": "", "ENTITY_SERVICE_ADMIN_PASSWORD": ""},
env=cli_run_env,
)
elif input_method == "env":
cli_run_env.update(
{
"ENTITY_SERVICE_ADMIN_USER": username,
"ENTITY_SERVICE_ADMIN_PASSWORD": password,
}
)
result = cli.invoke(
APP,
"login",
env={
"ENTITY_SERVICE_ADMIN_USER": username,
"ENTITY_SERVICE_ADMIN_PASSWORD": password,
},
env=cli_run_env,
)

assert result.exit_code == 0, CLI_RESULT_FAIL_MESSAGE.format(
Expand Down

0 comments on commit c08b1b4

Please sign in to comment.