feat(ext): Фаза 4/5 — охват всех источников/документов + все регионы
fgis_client: opendata_list/meta/download (15 датасетов: КСР/ФСНБ/СПСРП/оплата труда/9 ПССР), bim_leaf_docs (дерево писем-индексов), download_by_guid, all_subject_ids. xsd_client: скрейп .zip-схем экспертизы (html.parser, fail-loud на 0 ссылок). ext_pull: pull_opendata/bim/xsd, --source opendata/bim/xsd/all-sources, --regions all (все 86). ext_check: check_opendata (lastChangeDate)/check_bim(guid)/check_xsd(ссылки) + режим all-regions — чекер мониторит ВСЁ. 10 новых тестов.
This commit is contained in:
@@ -15,6 +15,15 @@ import fgis_client as fc # noqa: E402
|
||||
import pravo_client as pc # noqa: E402
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def _mock_new_sources(monkeypatch):
|
||||
"""По умолчанию opendata/bim/xsd не дают находок (не ходят в сеть). Тесты переопределяют."""
|
||||
import xsd_client
|
||||
monkeypatch.setattr(fc, "opendata_list", lambda client=None: [])
|
||||
monkeypatch.setattr(fc, "bim_leaf_docs", lambda client=None: [])
|
||||
monkeypatch.setattr(xsd_client, "schema_links", lambda client=None: [])
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def _tmp(monkeypatch, tmp_path):
|
||||
monkeypatch.setenv("EXT_SNAPSHOT_DIR", str(tmp_path))
|
||||
@@ -143,6 +152,26 @@ def test_rollback_reports_again(_tmp, monkeypatch):
|
||||
assert any(f["source"] == "fgis_split_form" and "426" in f["message"] for f in rep["findings"])
|
||||
|
||||
|
||||
def test_new_sources_detected_and_deduped(_tmp, monkeypatch):
|
||||
"""opendata (по lastChangeDate), bim (по guid), xsd (по ссылке) — находки + дедуп на 2-м прогоне."""
|
||||
import xsd_client
|
||||
_mock_fgis(monkeypatch, latest=426)
|
||||
_mock_pravo(monkeypatch, [])
|
||||
monkeypatch.setattr(fc, "opendata_list",
|
||||
lambda client=None: [{"id": 2, "datasetName": "КСР", "lastChangeDate": "2026-05-20"}])
|
||||
monkeypatch.setattr(fc, "bim_leaf_docs",
|
||||
lambda client=None: [{"guid": "G1", "name": "письмо 1 кв", "filePath": "/x.pdf"}])
|
||||
monkeypatch.setattr(xsd_client, "schema_links", lambda client=None: ["/a/KAC.zip"])
|
||||
with es.update_state() as st:
|
||||
st["sources"]["fgis_split_form"] = {"323/191": {"period_id": 426}}
|
||||
rep = ec.run_check(regions=[323], notify=False)
|
||||
srcs = {f["source"] for f in rep["findings"]}
|
||||
assert {"fgis_opendata", "fgis_bim", "xsd_schema"} <= srcs
|
||||
# второй прогон — те же не повторяются (дедуп)
|
||||
rep2 = ec.run_check(regions=[323], notify=False)
|
||||
assert not [f for f in rep2["findings"] if f["source"] in ("fgis_opendata", "fgis_bim", "xsd_schema")]
|
||||
|
||||
|
||||
def test_notify_called_only_with_findings(_tmp, monkeypatch):
|
||||
_mock_fgis(monkeypatch, latest=426)
|
||||
_mock_pravo(monkeypatch, [])
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
"""Фаза 4/5: парсеры новых источников (opendata, БИМ-дерево, XSD-скрейп). Моки MockTransport."""
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import httpx
|
||||
import pytest
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
||||
import fgis_client as fc # noqa: E402
|
||||
import xsd_client # noqa: E402
|
||||
|
||||
|
||||
def test_opendata_list_parses_items():
|
||||
resp = {"total": 2, "items": [
|
||||
{"id": 2, "datasetName": "КСР", "lastChangeDate": "2026-05-20"},
|
||||
{"id": 4, "datasetName": "ФСНБ-2022", "lastChangeDate": "2026-05-15"}]}
|
||||
with httpx.Client(transport=httpx.MockTransport(lambda r: httpx.Response(200, json=resp))) as c:
|
||||
items = fc.opendata_list(client=c)
|
||||
assert [i["id"] for i in items] == [2, 4]
|
||||
|
||||
|
||||
def test_opendata_list_format_error():
|
||||
with httpx.Client(transport=httpx.MockTransport(lambda r: httpx.Response(200, json={"x": 1}))) as c:
|
||||
with pytest.raises(fc.FgisFormatError):
|
||||
fc.opendata_list(client=c)
|
||||
|
||||
|
||||
def test_bim_tree_recursion_collects_leaf_docs():
|
||||
# корень (parentGuid отсутствует) → папка F1; F1 → лист L1 (есть filePath) + папка F2; F2 → лист L2
|
||||
def handler(r):
|
||||
pg = r.url.params.get("parentGuid")
|
||||
if pg is None:
|
||||
return httpx.Response(200, json={"": [{"guid": "F1", "name": "2026", "filePath": None}]})
|
||||
if pg == "F1":
|
||||
return httpx.Response(200, json={"": [
|
||||
{"guid": "L1", "name": "письмо A", "filePath": "/a.pdf"},
|
||||
{"guid": "F2", "name": "2 кв", "filePath": None}]})
|
||||
if pg == "F2":
|
||||
return httpx.Response(200, json={"": [{"guid": "L2", "name": "письмо B", "filePath": "/b.pdf"}]})
|
||||
return httpx.Response(200, json={"": []})
|
||||
with httpx.Client(transport=httpx.MockTransport(handler)) as c:
|
||||
docs = fc.bim_leaf_docs(client=c)
|
||||
guids = {d["guid"] for d in docs}
|
||||
assert guids == {"L1", "L2"} # только листья с filePath, папки — не документы
|
||||
|
||||
|
||||
def test_xsd_schema_links_extracted():
|
||||
html = '<a href="/upload/x/KAC-4_02.zip">КАЦ</a> <a href="/other.html">нет</a> ' \
|
||||
'<a href="/upload/y/LSR.zip">ЛСР</a>'
|
||||
with httpx.Client(transport=httpx.MockTransport(lambda r: httpx.Response(200, text=html))) as c:
|
||||
links = xsd_client.schema_links(client=c)
|
||||
assert links == ["/upload/x/KAC-4_02.zip", "/upload/y/LSR.zip"]
|
||||
assert xsd_client._fname("/upload/x/KAC-4_02.zip") == "KAC-4_02.zip"
|
||||
|
||||
|
||||
def test_xsd_fail_loud_on_zero_links():
|
||||
"""0 ссылок = вёрстка сменилась → FetchError, а не тихое «обновлений нет»."""
|
||||
with httpx.Client(transport=httpx.MockTransport(lambda r: httpx.Response(200, text="<html>no links</html>"))) as c:
|
||||
with pytest.raises(Exception):
|
||||
xsd_client.schema_links(client=c)
|
||||
Reference in New Issue
Block a user