gendesign/tradein-mvp/backend/tests/test_me_brand.py
bot-backend ea453c3ff2
All checks were successful
CI / openapi-codegen-check (pull_request) Has been skipped
CI / changes (pull_request) Successful in 6s
CI / backend-tests (pull_request) Has been skipped
CI / frontend-tests (pull_request) Has been skipped
fix(tradein): remove «Практика» white-label brand (DB row + account mapping + assets)
2026-06-19 12:53:37 +03:00

61 lines
2.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""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