61 lines
2.3 KiB
Python
61 lines
2.3 KiB
Python
"""Tests for #657 brand-by-account — UserScope.brand resolution.
|
||
|
||
Pure-function tests against app.core.auth. White-label бренд «Практика» снят
|
||
целиком (бизнес-решение 2026-06-19): маппинг аккаунт→бренд пустой, поэтому ВСЕ
|
||
юзеры (включая praktika/kopylov) резолвятся в None (generic UI/PDF).
|
||
get_user_scope прокидывает brand в scope, который /me отдаёт фронту.
|
||
|
||
Без БД и сети: читается реальный auth/roles.yaml (ancestor-walk внутри репо).
|
||
"""
|
||
|
||
from __future__ import annotations
|
||
|
||
import os
|
||
import sys
|
||
from unittest.mock import MagicMock
|
||
|
||
# DATABASE_URL required by config before any app import (см. test_dadata.py).
|
||
os.environ.setdefault("DATABASE_URL", "postgresql+psycopg://test:test@localhost:5432/test")
|
||
|
||
# WeasyPrint stub — not installed без GTK (consistent с прочими тестами).
|
||
_wp_mock = MagicMock()
|
||
sys.modules.setdefault("weasyprint", _wp_mock)
|
||
|
||
import pytest # noqa: E402
|
||
|
||
from app.core.auth import get_brand_for_user, get_user_scope # noqa: E402
|
||
|
||
|
||
@pytest.mark.parametrize(
|
||
("username", "expected"),
|
||
[
|
||
# «Практика» снята целиком (2026-06-19): praktika/kopylov больше не
|
||
# брендируются — маппинг пустой, все аккаунты → generic UI/PDF.
|
||
("praktika", None),
|
||
("kopylov", None),
|
||
("admin", None),
|
||
("user1", None),
|
||
("unknown_user", None),
|
||
],
|
||
)
|
||
def test_get_brand_for_user(username: str, expected: str | None) -> None:
|
||
assert get_brand_for_user(username) == expected
|
||
|
||
|
||
def test_user_scope_brand_none_for_kopylov() -> None:
|
||
# Регресс-гард: бренд снят, kopylov-оценки рендерят generic PDF.
|
||
scope = get_user_scope("kopylov")
|
||
assert scope["brand"] is None
|
||
assert scope["username"] == "kopylov"
|
||
|
||
|
||
def test_user_scope_brand_none_for_praktika() -> None:
|
||
# Бренд «Практика» удалён — praktika-аккаунт теперь generic.
|
||
scope = get_user_scope("praktika")
|
||
assert scope["brand"] is None
|
||
assert scope["username"] == "praktika"
|
||
|
||
|
||
def test_user_scope_brand_none_for_generic_user() -> None:
|
||
scope = get_user_scope("user1")
|
||
assert scope["brand"] is None
|