설정이 .env(시크릿)+toml(설정)로 갈려 있던 것을 config.local.toml 하나로 통합. DB 비번이 이미 toml 에 있어 분리 기준이 임의적이었고, backend(하우스 패턴)도 toml 단일이라 일관성 확보. 환경별로 바뀌는 값(DB_HOST 등)만 env override 유지. - config_models: NaverConfig(keys 로테이션)·OpenAIConfig·DecodoConfig 추가 - server_configs: 3개 로드, load_dotenv 제거(python-dotenv 의존성도 제거) - proxy/naver/similarity/keyword/worker_main: os.environ → config 객체 참조 - config.local.toml.example: [NaverConfig]/[OpenAIConfig]/[DecodoConfig] 섹션 - .env/.env.example 삭제, README/주석 갱신 (배포는 toml 마운트 or env override) - tests: DecodoConfig 기반으로 갱신 → 전체 44/44 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
42 lines
1.5 KiB
Python
42 lines
1.5 KiB
Python
"""DECODO 프록시 제공자 테스트 (포트 기반 sticky, 순수·네트워크 불필요)."""
|
|
|
|
from config.config_models import DecodoConfig
|
|
from services.search.proxy import DecodoProxy
|
|
|
|
|
|
def _p(**kw):
|
|
base = dict(host="gate.decodo.com", username="user1", password="pw", port_start=10001, port_end=10010, session_minutes=10)
|
|
base.update(kw)
|
|
return DecodoProxy(DecodoConfig(**base))
|
|
|
|
|
|
def test_disabled_when_credentials_missing():
|
|
assert DecodoProxy(DecodoConfig()).enabled is False # 전부 비어있음
|
|
assert _p(password="").enabled is False
|
|
assert _p(port_end=0).enabled is False # 포트 미설정
|
|
assert _p().enabled is True
|
|
|
|
|
|
def test_playwright_proxy_shape():
|
|
cfg = _p().playwright_proxy()
|
|
assert cfg["username"] == "user1" and cfg["password"] == "pw" # 고정 자격증명
|
|
assert cfg["server"].startswith("http://gate.decodo.com:")
|
|
port = int(cfg["server"].rsplit(":", 1)[1])
|
|
assert 10001 <= port <= 10010 # 포트 범위 안
|
|
|
|
|
|
def test_disabled_returns_none():
|
|
assert DecodoProxy(DecodoConfig()).playwright_proxy() is None
|
|
|
|
|
|
def test_port_selected_within_range_and_stable_in_window():
|
|
p = _p()
|
|
port = p._port()
|
|
assert 10001 <= port <= 10010
|
|
assert p._port() == port # 같은 시간창에서는 동일 포트(동일 sticky IP)
|
|
|
|
|
|
def test_single_port_range():
|
|
p = _p(port_start=10001, port_end=10001)
|
|
assert p._port() == 10001 # 포트 1개면 항상 그 포트
|