fix: allow first-run license activation
This commit is contained in:
1 parent
e315aaf80b
commit
407c3b37c2
10 files changed
+715
-23
No files matched your search
@@ -78,34 +78,83 @@ def test_dashboard_gui_runs_update_bootstrap_before_gui_imports():
|
||||
def test_dashboard_gui_main_forces_license_required(monkeypatch):
|
||||
from gui.dashboard_app import app as dashboard_app
|
||||
|
||||
calls = {"app_started": False, "monitor_started": False, "required_at_check": ""}
|
||||
calls = {
|
||||
"app_started": False,
|
||||
"monitor_started": False,
|
||||
"required_at_check": "",
|
||||
"initial_page": "",
|
||||
"license_locked": None,
|
||||
}
|
||||
|
||||
class FakeDashboardApp:
|
||||
def __init__(self) -> None:
|
||||
def __init__(self, *, initial_page="数据看板", license_locked=False) -> None:
|
||||
calls["app_started"] = True
|
||||
calls["initial_page"] = initial_page
|
||||
calls["license_locked"] = license_locked
|
||||
|
||||
def _on_runner_line(self, line: str) -> None:
|
||||
pass
|
||||
|
||||
def _start_license_monitor_once(self) -> None:
|
||||
calls["monitor_started"] = True
|
||||
|
||||
def run(self) -> None:
|
||||
calls["run_called"] = True
|
||||
|
||||
class MissingStatus:
|
||||
ok = False
|
||||
|
||||
def fake_require_online_license_or_exit() -> None:
|
||||
calls["required_at_check"] = os.environ.get("DOUYIN_LICENSE_REQUIRED", "")
|
||||
|
||||
def fake_start_online_license_monitor(**_kwargs):
|
||||
calls["monitor_started"] = True
|
||||
return None
|
||||
|
||||
monkeypatch.delenv("DOUYIN_LICENSE_REQUIRED", raising=False)
|
||||
monkeypatch.setattr(dashboard_app, "check_license", lambda: MissingStatus())
|
||||
monkeypatch.setattr(dashboard_app, "DashboardApp", FakeDashboardApp)
|
||||
monkeypatch.setattr(dashboard_app, "require_online_license_or_exit", fake_require_online_license_or_exit)
|
||||
|
||||
dashboard_app.main()
|
||||
|
||||
assert os.environ.get("DOUYIN_LICENSE_REQUIRED") == "1"
|
||||
assert calls["required_at_check"] == ""
|
||||
assert calls["app_started"] is True
|
||||
assert calls["initial_page"] == "授权"
|
||||
assert calls["license_locked"] is True
|
||||
assert calls["monitor_started"] is False
|
||||
assert calls["run_called"] is True
|
||||
|
||||
|
||||
def test_dashboard_gui_main_checks_online_license_when_local_license_exists(monkeypatch):
|
||||
from gui.dashboard_app import app as dashboard_app
|
||||
|
||||
calls = {"required_at_check": "", "monitor_started": False, "initial_page": ""}
|
||||
|
||||
class FakeDashboardApp:
|
||||
def __init__(self, *, initial_page="数据看板", license_locked=False) -> None:
|
||||
calls["initial_page"] = initial_page
|
||||
calls["license_locked"] = license_locked
|
||||
|
||||
def _start_license_monitor_once(self) -> None:
|
||||
calls["monitor_started"] = True
|
||||
|
||||
def run(self) -> None:
|
||||
calls["run_called"] = True
|
||||
|
||||
class OkStatus:
|
||||
ok = True
|
||||
|
||||
def fake_require_online_license_or_exit() -> None:
|
||||
calls["required_at_check"] = os.environ.get("DOUYIN_LICENSE_REQUIRED", "")
|
||||
|
||||
monkeypatch.delenv("DOUYIN_LICENSE_REQUIRED", raising=False)
|
||||
monkeypatch.setattr(dashboard_app, "check_license", lambda: OkStatus())
|
||||
monkeypatch.setattr(dashboard_app, "DashboardApp", FakeDashboardApp)
|
||||
monkeypatch.setattr(dashboard_app, "require_online_license_or_exit", fake_require_online_license_or_exit)
|
||||
monkeypatch.setattr(dashboard_app, "start_online_license_monitor", fake_start_online_license_monitor)
|
||||
|
||||
dashboard_app.main()
|
||||
|
||||
assert calls["required_at_check"] == "1"
|
||||
assert calls["app_started"] is True
|
||||
assert calls["initial_page"] == "数据看板"
|
||||
assert calls["license_locked"] is False
|
||||
assert calls["monitor_started"] is True
|
||||
assert calls["run_called"] is True
|
||||
|
||||
|
||||
Reference in new issue
Block a user