feat: comprehensive test infrastructure improvements
Deploy Dashboard (Dev) / deploy-dev (push) Successful in 2m26s
Run Tests / Backend Tests (push) Failing after 2m36s
Run Tests / Frontend Tests (push) Failing after 2m23s
Run Tests / Test Summary (push) Failing after 13s

- Fix unit test imports: add env setup in conftest.py before module imports
- Add 24 new auth router tests (RBAC, preferences, password validation)
- Add 16 new tests for litellm and chat_summary routers
- Apply black formatting and ruff linting across codebase
- Add pre-commit hooks configuration (black, ruff, file checks)
- Increase CI coverage threshold from 40% to 50%

Test Results:
- 206 tests passing (91 unit + 115 integration)
- Coverage: 58.79% on core modules
- auth.py: 57% → 85%, litellm.py: 23% → 87%, chat_summary.py: 41% → 100%
- auth_service: 96.51%, config: 100%, rbac: 93.48%
This commit is contained in:
Gan, Jimmy
2026-04-08 00:21:32 +08:00
parent fcc95ac23f
commit b981c06d59
44 changed files with 1732 additions and 924 deletions
+16 -16
View File
@@ -1,19 +1,20 @@
"""
Unit tests for rbac.py - Role-based access control.
"""
import pytest
import json
import os
from rbac import (
load_rbac,
save_rbac,
update_rbac,
resolve_role,
DEFAULT_RBAC,
ROLE_GROUP_MAP,
get_pages,
get_sidebar_links,
get_sidebar_order,
DEFAULT_RBAC,
ROLE_GROUP_MAP,
load_rbac,
resolve_role,
save_rbac,
update_rbac,
)
@@ -58,7 +59,7 @@ class TestSaveRBAC:
rbac_file = os.path.join(temp_volume_root, "docker/nas-dashboard/rbac.json")
test_data = {
"role_defaults": {"admin": {"pages": "*"}},
"user_overrides": {"testuser": {"pages": ["dashboard"]}}
"user_overrides": {"testuser": {"pages": ["dashboard"]}},
}
save_rbac(test_data)
@@ -74,6 +75,7 @@ class TestSaveRBAC:
# Remove directory
import shutil
if os.path.exists(os.path.dirname(rbac_file)):
shutil.rmtree(os.path.dirname(rbac_file))
@@ -88,6 +90,7 @@ class TestUpdateRBAC:
def test_update_rbac_with_mutator(self, mock_config, temp_rbac_file):
"""Test updating RBAC with mutator function."""
def add_user_override(data):
data["user_overrides"]["newuser"] = {"pages": ["dashboard", "docker"]}
return "success"
@@ -188,6 +191,7 @@ class TestGetPages:
def test_get_pages_with_user_override(self, mock_config, temp_rbac_file):
"""Test getting pages with user-specific override."""
# Add user override
def add_override(data):
data["user_overrides"]["customuser"] = {"pages": ["dashboard", "files"]}
@@ -223,11 +227,9 @@ class TestGetSidebarLinks:
def test_get_sidebar_links_with_user_override(self, mock_config, temp_rbac_file):
"""Test getting sidebar links with user override."""
def add_override(data):
data["user_overrides"]["customuser"] = {
"pages": "*",
"sidebar_links": ["dashboard", "docker", "files"]
}
data["user_overrides"]["customuser"] = {"pages": "*", "sidebar_links": ["dashboard", "docker", "files"]}
update_rbac(add_override)
@@ -236,6 +238,7 @@ class TestGetSidebarLinks:
def test_get_sidebar_links_no_override(self, mock_config, temp_rbac_file):
"""Test that user without sidebar_links override gets role default."""
def add_override(data):
data["user_overrides"]["customuser"] = {"pages": ["dashboard"]}
# No sidebar_links specified
@@ -256,10 +259,7 @@ class TestGetSidebarOrder:
def test_get_sidebar_order_with_override(self, mock_config, temp_rbac_file):
"""Test getting sidebar order with user override."""
custom_order = {
"Main": ["dashboard", "docker"],
"Media": ["navidrome", "immich"]
}
custom_order = {"Main": ["dashboard", "docker"], "Media": ["navidrome", "immich"]}
def add_override(data):
data["user_overrides"]["customuser"] = {"sidebar_order": custom_order}