fix: adapt autotest to updated service APIs

This commit is contained in:
2026-10-25 16:30:25 +03:00
parent 8d956c8063
commit 4203e5674c
13 changed files with 462 additions and 292 deletions
+23 -9
View File
@@ -1,4 +1,6 @@
from pathlib import Path
import os
import socket
import subprocess
import sys
import time
@@ -14,17 +16,21 @@ if str(SITE_DIR) not in sys.path:
# Путь к polygon: соседняя репа в корне autotest
POLYGON_DIR = Path(__file__).resolve().parents[2] / "polygon" / "site"
POLYGON_URL = "http://localhost:5000"
@pytest.fixture
def app_client():
"""Flask test client для app-autotest."""
def app_client(polygon_server):
"""Flask test client, направленный в локальный Polygon TEST."""
from app import app
old_polygon_endpoint = app.config.get("POLYGON_ENDPOINT", "")
app.config["POLYGON_ENDPOINT"] = f"{polygon_server}/api/v1/svc"
app.config.update(TESTING=True)
with app.test_client() as client:
yield client
try:
with app.test_client() as client:
yield client
finally:
app.config["POLYGON_ENDPOINT"] = old_polygon_endpoint
@pytest.fixture(scope="session")
@@ -37,18 +43,26 @@ def polygon_server():
if not POLYGON_DIR.is_dir():
pytest.skip("polygon repo not found")
with socket.socket() as port_socket:
port_socket.bind(("127.0.0.1", 0))
port = port_socket.getsockname()[1]
polygon_url = f"http://127.0.0.1:{port}"
env = os.environ.copy()
env["POLYGON_STANDS"] = "test:services/test"
proc = subprocess.Popen(
["python3", "app.py"],
["python3", "-c", f"import app; app.app.run(host='127.0.0.1', port={port}, debug=False)"],
cwd=str(POLYGON_DIR),
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
env=env,
)
# Ждём готовности (poll /health, timeout 10s)
deadline = time.time() + 10
while time.time() < deadline:
try:
r = requests.get(f"{POLYGON_URL}/health", timeout=2)
r = requests.get(f"{polygon_url}/health", timeout=2)
if r.status_code == 200:
break
except requests.ConnectionError:
@@ -58,7 +72,7 @@ def polygon_server():
proc.wait()
pytest.fail("polygon did not start within 10s")
yield POLYGON_URL
yield polygon_url
proc.terminate()
proc.wait()
@@ -67,5 +81,5 @@ def polygon_server():
@pytest.fixture(autouse=True)
def reset_polygon(polygon_server):
"""Перед каждым интеграционным тестом — сброс состояния polygon."""
requests.post(f"{polygon_server}/api/v1/svc/_mock/reset", timeout=5)
requests.post(f"{polygon_server}/test/api/v1/svc/_mock/reset", timeout=5)