Fast IAAI implementation

This commit is contained in:
2026-04-24 00:20:42 +03:00
parent 2b0cffc118
commit 3cdb717789
31 changed files with 4880 additions and 0 deletions

66
tests/test_settings.py Normal file
View File

@@ -0,0 +1,66 @@
from __future__ import annotations
import pytest
from iaai_sync_service.settings import Settings
def test_settings_from_env_reads_required_values(monkeypatch) -> None: # noqa: ANN001
monkeypatch.setenv("DATABASE_URL", "postgres://user:pass@localhost:5432/db")
monkeypatch.setenv("CELERY_BROKER_URL", "redis://localhost:6379/0")
monkeypatch.setenv("IAAI_BASE_URL", "https://www.iaai.com")
monkeypatch.setenv("IAAI_LISTING_START_URL", "https://www.iaai.com/Search?url=abc")
monkeypatch.setenv("IAAI_FETCH_CONCURRENCY", "4")
monkeypatch.setenv("IAAI_SESSION_KEEPALIVE_ENABLED", "false")
monkeypatch.setenv("IAAI_SESSION_KEEPALIVE_INTERVAL_MINUTES", "20")
monkeypatch.setenv("IAAI_SCHEMA_BOOTSTRAP_ENABLED", "true")
settings = Settings.from_env()
assert settings.database_url == "postgresql+psycopg://user:pass@localhost:5432/db"
assert settings.celery_broker_url == "redis://localhost:6379/0"
assert settings.iaai_base_url == "https://www.iaai.com"
assert settings.iaai_listing_start_url == "https://www.iaai.com/Search?url=abc"
assert settings.fetch_concurrency == 4
assert settings.session_keepalive_enabled is False
assert settings.session_keepalive_interval_minutes == 20
assert settings.schema_bootstrap_enabled is True
def test_settings_rejects_non_positive_concurrency(monkeypatch) -> None: # noqa: ANN001
monkeypatch.setenv("DATABASE_URL", "postgresql://user:pass@localhost:5432/db")
monkeypatch.setenv("CELERY_BROKER_URL", "redis://localhost:6379/0")
monkeypatch.setenv("IAAI_BASE_URL", "https://www.iaai.com")
monkeypatch.setenv("IAAI_FETCH_CONCURRENCY", "0")
with pytest.raises(RuntimeError, match="IAAI_FETCH_CONCURRENCY"):
Settings.from_env()
def test_settings_bootstrap_flag_defaults_to_false(monkeypatch) -> None: # noqa: ANN001
monkeypatch.setenv("DATABASE_URL", "postgresql://user:pass@localhost:5432/db")
monkeypatch.setenv("CELERY_BROKER_URL", "redis://localhost:6379/0")
monkeypatch.setenv("IAAI_BASE_URL", "https://www.iaai.com")
settings = Settings.from_env()
assert settings.schema_bootstrap_enabled is False
def test_settings_rejects_invalid_listing_start_url(monkeypatch) -> None: # noqa: ANN001
monkeypatch.setenv("DATABASE_URL", "postgresql://user:pass@localhost:5432/db")
monkeypatch.setenv("CELERY_BROKER_URL", "redis://localhost:6379/0")
monkeypatch.setenv("IAAI_BASE_URL", "https://www.iaai.com")
monkeypatch.setenv("IAAI_LISTING_START_URL", "Search?url=abc")
with pytest.raises(RuntimeError, match="IAAI_LISTING_START_URL"):
Settings.from_env()
def test_settings_rejects_invalid_keepalive_interval(monkeypatch) -> None: # noqa: ANN001
monkeypatch.setenv("DATABASE_URL", "postgresql://user:pass@localhost:5432/db")
monkeypatch.setenv("CELERY_BROKER_URL", "redis://localhost:6379/0")
monkeypatch.setenv("IAAI_BASE_URL", "https://www.iaai.com")
monkeypatch.setenv("IAAI_SESSION_KEEPALIVE_INTERVAL_MINUTES", "0")
with pytest.raises(RuntimeError, match="IAAI_SESSION_KEEPALIVE_INTERVAL_MINUTES"):
Settings.from_env()