fix: isolate token_hex mock to wizard module and fix mypy annotation

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-02-23 10:01:07 +00:00
parent 4e1cd73338
commit 0188575c27
4 changed files with 6 additions and 5 deletions
+2 -1
View File
@@ -22,6 +22,7 @@ nothing has changed.
import logging
import time
from typing import Any
import redis
from celery.signals import task_prerun
@@ -67,7 +68,7 @@ def register_settings_reload_signal() -> None:
"""
@task_prerun.connect(weak=False)
def _reload_if_stale(sender, **kwargs) -> None: # type: ignore[misc]
def _reload_if_stale(sender: Any, **kwargs: Any) -> None:
"""Reload settings from DB if the Redis version key has changed."""
global _last_seen_version
try:
+2 -2
View File
@@ -3,7 +3,7 @@ Setup wizard views for initial system configuration.
"""
import logging
import secrets
from secrets import token_hex
from fastapi import Depends, Form, Request
from fastapi.responses import RedirectResponse
@@ -104,7 +104,7 @@ async def setup_wizard_save(request: Request, step: int = Form(...), db: Session
if value and value.strip():
# Auto-generate session_secret if needed
if key == "session_secret" and value == "auto-generate":
value = secrets.token_hex(32)
value = token_hex(32)
logger.info("Auto-generated session secret")
# Save to database
+1 -1
View File
@@ -84,7 +84,7 @@ class TestWizardViewsPost:
assert mock_save.call_count == 0
@patch("app.views.wizard.save_setting_to_db")
@patch("app.views.wizard.secrets.token_hex")
@patch("app.views.wizard.token_hex")
def test_setup_wizard_auto_generate_session_secret(self, mock_token, mock_save, client):
"""Test auto-generation of session secret."""
mock_token.return_value = "auto_generated_secret_token_12345678"
+1 -1
View File
@@ -61,7 +61,7 @@ class TestSetupWizardDbPersist:
mock_notify.assert_not_called()
@patch("app.views.wizard.notify_settings_updated")
@patch("app.views.wizard.secrets.token_hex")
@patch("app.views.wizard.token_hex")
@patch("app.views.wizard.save_setting_to_db")
def test_auto_generate_session_secret(self, mock_save, mock_token, mock_notify, client):
"""Test that session_secret auto-generate path produces a real token."""