Add CRM stub flag, deploy/backup scripts, CI and prod runbook
- CRM_USE_STUB: local runs no longer reach the live CRM. With only the Checkbox stub, a stub receipt would still move the real order to PACKED. Refused in production, same as CHECKBOX_USE_STUB. - scripts/deploy.sh: backup, fast-forward main, build, health check and code rollback on failure. scripts/backup.sh: pg_dump with verification and 14-day rotation (used by cron and deploy.sh). - Gitea Actions CI: ruff + pytest, oxlint + build. - DEPLOY.md runbook; CLAUDE.md rules for safe local development. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
"""Выбор реализации CRM-клиента по `CRM_USE_STUB`."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Iterator
|
||||
|
||||
import pytest
|
||||
|
||||
from app.core.config import settings
|
||||
from app.services.crm.client import get_crm_client
|
||||
from app.services.crm.exo_client import ExoCrmClient
|
||||
from app.services.crm.stub_client import StubCrmClient
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def _fresh_factory() -> Iterator[None]:
|
||||
get_crm_client.cache_clear()
|
||||
yield
|
||||
get_crm_client.cache_clear()
|
||||
|
||||
|
||||
def test_real_client_by_default(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
monkeypatch.setattr(settings, "crm_use_stub", False)
|
||||
assert isinstance(get_crm_client(), ExoCrmClient)
|
||||
|
||||
|
||||
def test_stub_when_enabled(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
monkeypatch.setattr(settings, "crm_use_stub", True)
|
||||
monkeypatch.setattr(settings, "environment", "local")
|
||||
assert isinstance(get_crm_client(), StubCrmClient)
|
||||
|
||||
|
||||
def test_stub_forbidden_in_production(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
monkeypatch.setattr(settings, "crm_use_stub", True)
|
||||
monkeypatch.setattr(settings, "environment", "production")
|
||||
with pytest.raises(RuntimeError, match="CRM_USE_STUB"):
|
||||
get_crm_client()
|
||||
Reference in New Issue
Block a user