修复--auth-stdin读取失败的bug
This commit is contained in:
@@ -3,7 +3,7 @@ from pathlib import Path
|
||||
|
||||
from typer.testing import CliRunner
|
||||
|
||||
from tjwater_cli import core
|
||||
from tjwater_cli import common, core
|
||||
from tjwater_cli.main import app, main
|
||||
|
||||
|
||||
@@ -65,6 +65,38 @@ def test_build_runtime_context_uses_default_server(monkeypatch):
|
||||
assert runtime.server == core.DEFAULT_SERVER
|
||||
|
||||
|
||||
def test_auth_stdin_can_be_reused_with_runtime_context_cache(monkeypatch):
|
||||
observed_runtime_ids: list[int] = []
|
||||
|
||||
def fake_request_json(ctx, **kwargs):
|
||||
observed_runtime_ids.append(id(ctx))
|
||||
assert ctx.auth.access_token == "token-1"
|
||||
assert kwargs["params"] == {"network": "tjwater", "node": "11"}
|
||||
return {"node": "11"}, 5
|
||||
|
||||
monkeypatch.setattr(common, "request_json", fake_request_json)
|
||||
|
||||
result = runner.invoke(
|
||||
app,
|
||||
["--auth-stdin", "network", "get-node-properties", "--node", "11"],
|
||||
input=json.dumps(
|
||||
{
|
||||
"server": "http://server",
|
||||
"access_token": "token-1",
|
||||
"project_id": "project-1",
|
||||
"network": "tjwater",
|
||||
}
|
||||
),
|
||||
)
|
||||
|
||||
payload = json.loads(result.stdout)
|
||||
|
||||
assert result.exit_code == 0
|
||||
assert payload["ok"] is True
|
||||
assert payload["data"] == {"node": "11"}
|
||||
assert len(observed_runtime_ids) == 1
|
||||
|
||||
|
||||
def test_help_outputs_json_lists_commands():
|
||||
result = runner.invoke(app, ["help"])
|
||||
payload = json.loads(result.stdout)
|
||||
|
||||
Reference in New Issue
Block a user