DFiP_Budget_planing/perf/tests/test_coauthor.py
Andrey Epifancev 419a20e950 perf: бот-соавтор и скролл при соавторе
Refs #202

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-25 23:20:48 +04:00

44 lines
1.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""Интеграционные тесты бота-соавтора (нужен поднятый стенд): pytest -m stand tests/test_coauthor.py"""
import json
import subprocess
import sys
import time
import pytest
from perfkit import PERF_DIR, RESULTS_DIR
from perfkit.manifest import load
pytestmark = pytest.mark.stand
def _sheet():
m = load(RESULTS_DIR / "manifest-s1.json")
# соавтор - rf_coauthor, права только на листы owner=rf (FORM_1 принадлежит ССП)
first = next(s for s in m.sheets if s.owner == "rf")
return first
def _run(*extra, timeout=30):
s = _sheet()
cmd = [sys.executable, "-m", "perfkit.coauthor", "--form-id", str(s.form_id), "--sheet", s.sheet, *extra]
if s.direction:
cmd += ["--direction", s.direction]
t0 = time.monotonic()
p = subprocess.run(cmd, cwd=PERF_DIR, capture_output=True, text=True, timeout=timeout)
return p, time.monotonic() - t0
def test_coauthor_first_edit_echoed():
p, _ = _run("--rate", "1", "--duration", "3")
assert p.returncode == 0, p.stderr
stats = json.loads(p.stdout.strip().splitlines()[-1])
assert stats["echoed"] >= 1
assert stats["sent"] >= stats["echoed"]
def test_coauthor_bad_token_fails_fast():
p, dt = _run("--rate", "1", "--duration", "3", "--token", "not-a-token")
assert p.returncode == 2, p.stderr # 2 - нет эха первой правки (в т.ч. неверный токен)
assert dt <= 5.5, f"бот завершился за {dt:.1f} с"