Files
maskanx_cm_backend/tests/test_postgres_config.py
T
AFFAANhandClaude Opus 5 19e1e84fb7 Initial commit: MaskanX backend
Independent FastAPI backend for the MaskanX agentic growth platform.

Includes the agent runtime, MCP client integrations (Meta Ads, LinkedIn,
HubSpot, Tavily, Exa, xAI, Citedy, image generation), PostgreSQL storage
for chats and cron jobs, provider and secret management, and the CLI.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-01 10:28:22 +05:30

51 lines
1.6 KiB
Python

# -*- coding: utf-8 -*-
from __future__ import annotations
from adclaw.db.config import (
database_url,
load_database_config,
storage_backend,
use_postgres_storage,
)
def test_postgres_config_uses_db_env(monkeypatch):
monkeypatch.delenv("DATABASE_URL", raising=False)
monkeypatch.delenv("MASKANX_DATABASE_URL", raising=False)
monkeypatch.setenv("MASKANX_STORAGE_BACKEND", "postgres")
monkeypatch.setenv("DB_HOST", "localhost")
monkeypatch.setenv("DB_PORT", "5432")
monkeypatch.setenv("DB_NAME", "campaign")
monkeypatch.setenv("DB_USER", "postgres")
monkeypatch.setenv("DB_PASSWORD", "postgres")
monkeypatch.setenv("DB_SSLMODE", "prefer")
cfg = load_database_config()
assert use_postgres_storage() is True
assert storage_backend() == "postgres"
assert cfg.host == "localhost"
assert cfg.port == 5432
assert cfg.name == "campaign"
assert database_url() == (
"postgresql://postgres:postgres@localhost:5432/"
"campaign?sslmode=prefer"
)
def test_database_url_overrides_db_parts(monkeypatch):
monkeypatch.setenv("DATABASE_URL", "postgresql://u:p@db.example.com:5432/prod")
monkeypatch.setenv("DB_HOST", "localhost")
monkeypatch.setenv("DB_NAME", "campaign")
assert database_url() == "postgresql://u:p@db.example.com:5432/prod"
def test_postgres_is_the_default_operational_storage(monkeypatch):
monkeypatch.delenv("MASKANX_STORAGE_BACKEND", raising=False)
monkeypatch.delenv("ADCLAW_STORAGE_BACKEND", raising=False)
monkeypatch.delenv("STORAGE_BACKEND", raising=False)
assert storage_backend() == "postgres"
assert use_postgres_storage() is True