gendesign/backend/tests/services/test_own_developer_ids_config.py
Light1YT df34e55ab4
All checks were successful
CI / changes (push) Successful in 6s
CI / frontend-tests (push) Has been skipped
CI / changes (pull_request) Successful in 6s
CI / frontend-tests (pull_request) Has been skipped
CI / backend-tests (push) Successful in 6m25s
CI / backend-tests (pull_request) Successful in 6m22s
Deploy / build-frontend (push) Has been skipped
Deploy / changes (push) Successful in 5s
Deploy / build-backend (push) Successful in 1m31s
Deploy / build-worker (push) Successful in 2m39s
Deploy / deploy (push) Successful in 1m12s
feat(site-finder): own-portfolio data source for §25.3 cannibalization (#1169 PR1)
Foundation PR: unified "our projects" source the §25.3 overlap engine (PR2)
will consume. Two origins normalized to OwnProject (class/timing/price/unit-mix):
- current <- domrf_kn_objects filtered by settings.own_developer_ids (numeric
  prefix of composite dev_id; empty -> [] graceful, no DB hit, no hardcoded id)
- future  <- new manual-entry own_planned_project entity (migration 148)

Adds OWN_DEVELOPER_IDS config (comma-sep -> list[int], default []),
own_planned_project table (range/unit_mix CHECKs via IMMUTABLE helper, generated
geom), /api/v1/own-projects CRUD (created_by from X-Authenticated-User), and
get_own_portfolio(db). Per-source graceful degradation; psycopg-v3 CAST clean.

Does not touch special_indices.py or parcels.py (out of scope).

Refs #1169
2026-06-08 16:21:53 +05:00

50 lines
2.4 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.

"""Config-parse тесты для own_developer_ids (#1169 PR1, ТЗ §25.3).
Критично: own_developer_ids СТРОГО default [] (пусто), НИ ОДНОГО реального id в коде.
OWN_DEVELOPER_IDS читается из env как comma-separated → list[int]; пусто/не задано → [].
Пустой список = §25.3 own-portfolio деградирует изящно (proxy/None), а не падает.
"""
from __future__ import annotations
from app.core.config import Settings
def test_own_developer_ids_empty_by_default() -> None:
"""Default [] — ни одного id не зашито; §25.3 деградирует изящно без конфигурации."""
s = Settings(_env_file=None) # type: ignore[call-arg]
assert s.own_developer_ids == []
def test_own_developer_ids_parses_comma_separated(monkeypatch) -> None:
"""'12345,67890,42' → [12345, 67890, 42] (fake-id, не реальные)."""
monkeypatch.setenv("OWN_DEVELOPER_IDS", "12345,67890,42")
s = Settings(_env_file=None) # type: ignore[call-arg]
assert s.own_developer_ids == [12345, 67890, 42]
def test_own_developer_ids_trims_whitespace_and_skips_empties(monkeypatch) -> None:
"""' 12345 , 67890 ,, ' → [12345, 67890] (trim + пропуск пустых токенов)."""
monkeypatch.setenv("OWN_DEVELOPER_IDS", " 12345 , 67890 ,, ")
s = Settings(_env_file=None) # type: ignore[call-arg]
assert s.own_developer_ids == [12345, 67890]
def test_own_developer_ids_empty_string_is_empty_list(monkeypatch) -> None:
"""Пустая строка env → [] (а не падение / [0])."""
monkeypatch.setenv("OWN_DEVELOPER_IDS", "")
s = Settings(_env_file=None) # type: ignore[call-arg]
assert s.own_developer_ids == []
def test_own_developer_ids_single_value(monkeypatch) -> None:
"""Один id без запятой → [12345]."""
monkeypatch.setenv("OWN_DEVELOPER_IDS", "12345")
s = Settings(_env_file=None) # type: ignore[call-arg]
assert s.own_developer_ids == [12345]
def test_own_developer_ids_accepts_list_input() -> None:
"""list-вход (JSON-env / прямая инициализация) нормализуется в list[int]."""
s = Settings(_env_file=None, own_developer_ids=[12345, 67890]) # type: ignore[call-arg]
assert s.own_developer_ids == [12345, 67890]