fix(cli): constrain timeseries option values
This commit is contained in:
@@ -245,6 +245,33 @@ def test_leaf_help_flag_includes_usage_and_example():
|
||||
assert "DURATION" in result.stdout
|
||||
|
||||
|
||||
def test_realtime_simulation_help_clarifies_type_values():
|
||||
result = runner.invoke(
|
||||
app,
|
||||
["data", "timeseries", "realtime", "simulation-by-id-time", "--help"],
|
||||
prog_name="tjwater-cli",
|
||||
)
|
||||
|
||||
assert result.exit_code == 0
|
||||
assert "links/nodes 是子命令" in result.stdout
|
||||
assert "pipe" in result.stdout
|
||||
assert "junction" in result.stdout
|
||||
|
||||
|
||||
def test_realtime_property_help_lists_supported_fields():
|
||||
result = runner.invoke(
|
||||
app,
|
||||
["data", "timeseries", "realtime", "simulation-by-time-property", "--help"],
|
||||
prog_name="tjwater-cli",
|
||||
)
|
||||
|
||||
assert result.exit_code == 0
|
||||
assert "flow" in result.stdout
|
||||
assert "pressure" in result.stdout
|
||||
assert "actual_demand" in result.stdout
|
||||
assert "velocity" in result.stdout
|
||||
|
||||
|
||||
def test_analysis_burst_returns_next_step_to_fetch_scheme(monkeypatch, tmp_path: Path):
|
||||
monkeypatch.setenv("TJWATER_SERVER", "http://server")
|
||||
monkeypatch.setenv("TJWATER_ACCESS_TOKEN", "abc")
|
||||
@@ -498,6 +525,79 @@ def test_main_missing_option_error_includes_usage_and_next_step(capsys):
|
||||
assert '"tjwater-cli help simulation run"' in stdout
|
||||
|
||||
|
||||
def test_main_invalid_enum_value_is_rejected_before_request(capsys):
|
||||
exit_code = main(
|
||||
[
|
||||
"data",
|
||||
"timeseries",
|
||||
"realtime",
|
||||
"simulation-by-id-time",
|
||||
"--id",
|
||||
"J1",
|
||||
"--type",
|
||||
"links",
|
||||
"--time",
|
||||
"2025-01-02T03:30:00+08:00",
|
||||
]
|
||||
)
|
||||
stdout = capsys.readouterr().out
|
||||
|
||||
assert exit_code == 2
|
||||
assert '"summary": "参数无效"' in stdout
|
||||
assert '"code": "INVALID_PARAMETER"' in stdout
|
||||
assert "links" in stdout
|
||||
assert "pipe" in stdout
|
||||
assert "junction" in stdout
|
||||
|
||||
|
||||
def test_main_invalid_pipe_property_is_rejected_before_request(capsys):
|
||||
exit_code = main(
|
||||
[
|
||||
"data",
|
||||
"timeseries",
|
||||
"realtime",
|
||||
"simulation-by-time-property",
|
||||
"--type",
|
||||
"pipe",
|
||||
"--time",
|
||||
"2025-01-02T03:30:00+08:00",
|
||||
"--property",
|
||||
"pressure",
|
||||
]
|
||||
)
|
||||
stdout = capsys.readouterr().out
|
||||
|
||||
assert exit_code == 2
|
||||
assert '"code": "INVALID_PROPERTY"' in stdout
|
||||
assert "flow" in stdout
|
||||
assert "velocity" in stdout
|
||||
|
||||
|
||||
def test_main_invalid_scada_field_is_rejected_before_request(capsys):
|
||||
exit_code = main(
|
||||
[
|
||||
"data",
|
||||
"timeseries",
|
||||
"scada",
|
||||
"query",
|
||||
"--device-id",
|
||||
"D1",
|
||||
"--start-time",
|
||||
"2025-01-02T03:00:00+08:00",
|
||||
"--end-time",
|
||||
"2025-01-02T04:00:00+08:00",
|
||||
"--field",
|
||||
"flow",
|
||||
]
|
||||
)
|
||||
stdout = capsys.readouterr().out
|
||||
|
||||
assert exit_code == 2
|
||||
assert '"code": "INVALID_FIELD"' in stdout
|
||||
assert "monitored_value" in stdout
|
||||
assert "cleaned_value" in stdout
|
||||
|
||||
|
||||
def test_main_bare_analysis_returns_typer_help_without_json_error(capsys):
|
||||
exit_code = main(["analysis"])
|
||||
stdout = capsys.readouterr().out
|
||||
|
||||
Reference in New Issue
Block a user