v0.13.7
This commit is contained in:
+39
-4
@@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Developer smoke/integration tests for GREE Controller API 0.13.6.
|
||||
"""Developer smoke/integration tests for GREE Controller API 0.13.7.
|
||||
|
||||
Default mode is read-only and safe to run against a real controller.
|
||||
Use --settings-write to additionally round-trip all split settings resources and
|
||||
@@ -26,7 +26,7 @@ from typing import Any, Callable, Iterable, Optional
|
||||
|
||||
DEFAULT_BASE_URL = os.environ.get("GREE_API_URL", "http://127.0.0.1:8787")
|
||||
DEFAULT_TOKEN = os.environ.get("GREE_API_TOKEN", "")
|
||||
DEFAULT_EXPECTED_VERSION = "0.13.6"
|
||||
DEFAULT_EXPECTED_VERSION = "0.13.7"
|
||||
|
||||
SETTINGS_PATHS: dict[str, set[str]] = {
|
||||
"/api/settings/application": {"simulator_enabled"},
|
||||
@@ -131,6 +131,10 @@ EXPECTED_OPENAPI_PATHS = set(SETTINGS_PATHS) | {
|
||||
"/api/integrations/home-assistant/snapshot",
|
||||
}
|
||||
|
||||
BOOTSTRAP_SETTINGS_SECTIONS = {
|
||||
"application", "gree", "history", "influxdb", "notifications", "night", "home_assistant", "debug"
|
||||
}
|
||||
|
||||
|
||||
class TestFailure(AssertionError):
|
||||
pass
|
||||
@@ -343,6 +347,36 @@ def test_openapi(client: ApiClient, expected_version: str) -> str:
|
||||
return f"paths={len(paths)}, version={version}"
|
||||
|
||||
|
||||
def test_bootstrap_contract(client: ApiClient) -> str:
|
||||
resp = client.get("/api/bootstrap")
|
||||
assert_status(resp, 200)
|
||||
data = assert_json_object(resp)
|
||||
required = {
|
||||
"devices", "zones", "groups", "schedules", "automations", "flows",
|
||||
"access_tokens", "settings", "house", "outdoor_temperature",
|
||||
"control_plan", "control_plan_revision", "system",
|
||||
}
|
||||
missing = sorted(required - set(data))
|
||||
if missing:
|
||||
raise TestFailure(f"bootstrap missing fields: {missing}")
|
||||
settings = data.get("settings")
|
||||
if not isinstance(settings, dict):
|
||||
raise TestFailure("bootstrap.settings is not an object")
|
||||
missing_sections = sorted(BOOTSTRAP_SETTINGS_SECTIONS - set(settings))
|
||||
if missing_sections:
|
||||
raise TestFailure(f"bootstrap.settings missing sections: {missing_sections}")
|
||||
forbidden = {
|
||||
"influxdb": {"password", "token"},
|
||||
"home_assistant": {"token"},
|
||||
"notifications": {"pushover_app_token", "pushover_user_key", "slack_webhook_url", "discord_webhook_url"},
|
||||
}
|
||||
for section, fields in forbidden.items():
|
||||
leaked = sorted(fields & set(settings.get(section, {})))
|
||||
if leaked:
|
||||
raise TestFailure(f"bootstrap.settings.{section} leaks secret fields: {leaked}")
|
||||
return f"settings_sections={len(BOOTSTRAP_SETTINGS_SECTIONS)}, control_plan_revision={data.get('control_plan_revision')}"
|
||||
|
||||
|
||||
def test_protected_auth(client: ApiClient) -> str:
|
||||
if not client.token:
|
||||
raise SkipTest("no token supplied; controller may be in trusted-LAN mode")
|
||||
@@ -519,7 +553,8 @@ def run_suite(args: argparse.Namespace) -> int:
|
||||
print(f"Settings write tests: {'ENABLED' if args.settings_write else 'disabled'}\n")
|
||||
|
||||
runner.run("public health", lambda: test_health(client, args.expected_version))
|
||||
runner.run("OpenAPI 0.13.6 contract", lambda: test_openapi(client, args.expected_version))
|
||||
runner.run("OpenAPI 0.13.7 contract", lambda: test_openapi(client, args.expected_version))
|
||||
runner.run("bootstrap snapshot contract", lambda: test_bootstrap_contract(client))
|
||||
runner.run("protected API requires auth", lambda: test_protected_auth(client))
|
||||
|
||||
for path in SAFE_GET_PATHS:
|
||||
@@ -587,7 +622,7 @@ def run_suite(args: argparse.Namespace) -> int:
|
||||
|
||||
def parse_args(argv: Optional[Iterable[str]] = None) -> argparse.Namespace:
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Developer smoke/integration tests for GREE Controller API 0.13.6.",
|
||||
description="Developer smoke/integration tests for GREE Controller API 0.13.7.",
|
||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||
epilog="""Examples:
|
||||
python3 scripts/api_dev_test.py
|
||||
|
||||
Reference in New Issue
Block a user