pravo_client: documents/recent/new_since (открытый API, форма ответа с реальной фикстуры), релевантность по ключевым словам (смет/индекс/ФСНБ/…) — подсветка, показываем все новые; download_pdf. Сигнал обновления = новый eoNumber. 4 теста + живой смоук за EXT_SMOKE.
56 lines
2.0 KiB
Python
56 lines
2.0 KiB
Python
"""Срез 2.1: мониторинг приказов Минстроя. Мок на реальной фикстуре pravo.gov.ru."""
|
|
import json
|
|
import os
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
import httpx
|
|
import pytest
|
|
|
|
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
|
import pravo_client as pc # noqa: E402
|
|
|
|
FIX = Path(__file__).resolve().parent / "fixtures" / "ext" / "pravo_documents.json"
|
|
|
|
|
|
def _client():
|
|
fixture = json.loads(FIX.read_text(encoding="utf-8"))
|
|
return httpx.Client(transport=httpx.MockTransport(
|
|
lambda r: httpx.Response(200, json=fixture) if r.url.path == "/api/Documents"
|
|
else httpx.Response(404)))
|
|
|
|
|
|
def test_recent_normalized():
|
|
with _client() as c:
|
|
docs = pc.recent(client=c)
|
|
assert docs and all("eoNumber" in d and "pdf_url" in d for d in docs)
|
|
assert docs[0]["number"] == "362/пр"
|
|
assert docs[0]["pdf_url"].endswith("eoNumber=" + docs[0]["eoNumber"])
|
|
|
|
|
|
def test_new_since_dedup():
|
|
with _client() as c:
|
|
first = pc.recent(client=c)
|
|
seen = {first[0]["eoNumber"]}
|
|
new = pc.new_since(seen, client=c)
|
|
assert all(d["eoNumber"] != first[0]["eoNumber"] for d in new)
|
|
assert len(new) == len(first) - 1
|
|
|
|
|
|
def test_relevance_flag():
|
|
assert pc._is_relevant({"name": "Об утверждении индексов изменения сметной стоимости"}) is True
|
|
assert pc._is_relevant({"name": "О внесении изменений в ФСНБ"}) is True
|
|
assert pc._is_relevant({"name": "О типовых индикаторах риска"}) is False
|
|
|
|
|
|
def test_format_error_on_bad_shape():
|
|
with httpx.Client(transport=httpx.MockTransport(lambda r: httpx.Response(200, json={"foo": 1}))) as c:
|
|
with pytest.raises(pc.PravoFormatError):
|
|
pc.documents(client=c)
|
|
|
|
|
|
@pytest.mark.skipif(os.environ.get("EXT_SMOKE") != "1", reason="живой запрос к pravo.gov.ru только при EXT_SMOKE=1")
|
|
def test_smoke_live_pravo():
|
|
docs = pc.recent()
|
|
assert docs and docs[0]["eoNumber"]
|