Files
FabledSteward/tests/test_auth.py
T
bvandeusen 230b542015 feat: rename to FabledScryer, multi-dashboard system, plugin management, branding
- Rename package fablednetmon → fabledscryer throughout
- Multi-dashboard: ownership, per-user defaults, HTMX edit (add/remove/reorder)
- Read-only share tokens scoped to individual dashboards
- Dashboard edit is HTMX-driven (no page reloads)
- Plugin management system: remote catalog, download/install, hot-reload, in-app restart
- plugin_index.py: fetch/cache remote index.yaml; default URL → bvandeusen/fabledscryer-plugins
- plugin_manager.py: download_and_install_plugin, hot_reload_plugin, restart_app
  - ZIP extraction handles GitHub archive formats (name-v1.0.0/, name-main/)
- Settings split into tabbed sections: General, Notifications, Ansible, Plugins
- Plugins tab: catalog browser (HTMX), install/activate/update/restart actions
- UI/branding: dark palette (#07071a), crystal ball SVG logo, animated star field,
  Libertinus Serif applied to headings, nav, labels, and section titles
- Widget registry (core/widgets.py) for dashboard plugin integration
- UPS widget.html (dashboard card) and settings/_tabs.html include
- Migrations 0005–0008: dashboards, is_default, ownership, share tokens
- docs/plugins/: writing-a-plugin.md updated with publishing guide,
  index.yaml.example template for fabledscryer-plugins repo

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-22 18:27:56 -04:00

56 lines
1.9 KiB
Python

import pytest
import bcrypt
from unittest.mock import AsyncMock, patch
from fabledscryer.models.users import User, UserRole
def make_user(role=UserRole.admin):
return User(
id="test-id",
username="admin",
email="admin@example.com",
password_hash=bcrypt.hashpw(b"password", bcrypt.gensalt()).decode(),
role=role,
is_active=True,
)
@pytest.mark.asyncio
async def test_login_page_returns_200(client):
response = await client.get("/login")
assert response.status_code == 200
@pytest.mark.asyncio
async def test_login_redirects_to_setup_when_no_users(client, app):
with patch("fabledscryer.auth.routes.get_user_count", new=AsyncMock(return_value=0)):
response = await client.get("/login")
assert response.status_code == 302
assert "/setup" in response.headers["Location"]
@pytest.mark.asyncio
async def test_login_success_redirects_to_dashboard(client, app):
user = make_user()
with patch("fabledscryer.auth.routes.get_user_count", new=AsyncMock(return_value=1)), \
patch("fabledscryer.auth.routes.get_user_by_username", new=AsyncMock(return_value=user)):
response = await client.post("/login", form={"username": "admin", "password": "password"})
assert response.status_code == 302
assert "/" in response.headers["Location"]
@pytest.mark.asyncio
async def test_login_failure_returns_400(client, app):
user = make_user()
with patch("fabledscryer.auth.routes.get_user_count", new=AsyncMock(return_value=1)), \
patch("fabledscryer.auth.routes.get_user_by_username", new=AsyncMock(return_value=user)):
response = await client.post("/login", form={"username": "admin", "password": "wrong"})
assert response.status_code == 400
@pytest.mark.asyncio
async def test_require_role_redirects_unauthenticated(client):
response = await client.get("/")
assert response.status_code == 302
assert "/login" in response.headers["Location"]