Parse mixed education records and certificates, flag unresolved DPO

This commit is contained in:
codex committed 2026-11-20 16:02:16 +00:00
1 parent 8dfd700bd5
commit 65d851bb92
18 files changed
+335 -14

No files matched your search

+2 -2
View File
@@ -22,7 +22,7 @@ def test_health_returns_versions():
response = TestClient(app).get("/api/health")
assert response.status_code == 200
assert response.json()["backend_version"] == "2.2.1"
assert response.json()["backend_version"] == "2.3.0"
def test_api_employees_and_stats_require_admin_session():
@@ -202,7 +202,7 @@ def test_directory_export_uses_applied_filters_and_sort_across_pages(db_session)
assert [cell.value for cell in sheet[1]] == [
cell.get_text(strip=True) for cell in page.select(".directory-table th")
]
assert sheet.max_column == 15
assert sheet.max_column == 16
assert [cell.value for cell in sheet["A"][1:]] == [f"Export {number:02d}" for number in range(28)]
assert [cell.value for cell in sheet["A"][-3:]] == [
cell.get_text(strip=True) for cell in page.select("tbody [data-column='full_name']")
+1 -1
View File
@@ -230,7 +230,7 @@ def test_public_page_data_minimization_and_safe_links(db_session, export):
assert "javascript:" not in fragment.text and "private@example.org" not in fragment.text
assert "javascript:" not in response.text and "private@example.org" not in response.text
assert "/admin/employees/" not in response.text and "/admin/logout" not in response.text
assert "Backend 2.2.1 · Frontend 2.2.1" in response.text
assert "Backend 2.3.0 · Frontend 2.3.0" in response.text
assert "Вход в систему" in response.text
assert client.get("/admin/directory", follow_redirects=False).status_code in (302, 303, 401, 403)
assert "Сотрудники не найдены" in client.get("/admin/council?q=missing").text
+29
View File
@@ -0,0 +1,29 @@
from bs4 import BeautifulSoup
from app.parser.education_document import _certificate
from app.parser.profile import extract_sections
from app.services.resource_cache import ResourceCache
def test_education_events_preserve_ambiguities_and_separate_periods():
row = '<div><div class="person-list-hangover">{}</div><span>«Первая помощь»</span>, повышение квалификации, {}</div>'
html = ('<h2>Дополнительное образование</h2>' + row.format(2025, "НИУ ВШЭ") +
row.format(2025, "Высшая школа экономики") + row.format(2023, "НИУ ВШЭ") +
'<p>Прошел тест с присвоением степени</p><p>«Инженер»</p>'
'<p>Дополнительные сведения</p><p><a href="/mirror/pubs/share/1">Документ</a></p>')
section, = extract_sections(BeautifulSoup(html, "html.parser"), "https://www.hse.ru", lambda url: None)
assert len(section["items"]) == 3
assert section["items"][-1] == "Прошел тест с присвоением степени «Инженер»"
assert section["unresolved"] == ["Дополнительные сведения"]
assert section["unresolved_documents"][0]["url"] == "https://www.hse.ru/mirror/pubs/share/1"
def test_document_read_and_cache(db_session):
text = 'НИУ ВШЭ. Удостоверение о повышении квалификации по программе «Деловой английский» в объеме 24 часов. 2025 год'
result = _certificate(text)
assert result == "2025 «Деловой английский», повышение квалификации, НИУ ВШЭ, 24 часов"
assert _certificate("Сертификат 2025") is None
cache = ResourceCache(db_session)
assert cache.education_document("staff:test", "https://www.hse.ru/test", "1" * 64, lambda: result) == result
assert cache.education_document("staff:test", "https://www.hse.ru/test", "1" * 64, lambda: 1 / 0) == result
+31
View File
@@ -4,6 +4,37 @@ from app.parser.profile import enrich_sections_from_hse_widgets, extract_person_
from app.parser.profile_url import normalize_profile_url, parse_profile_identity
def test_mixed_additional_education_keeps_all_courses_and_omits_attachments():
structured = "".join(
f'<div class="g-ul"><div class="with-indent"><div class="person-list-hangover">{year}</div>'
f'<span>{title}</span><span>, {provider}</span></div></div>'
for year, title, provider in [(2025, "Экспортный контроль", "МИФИ"),
(2024, "Smart LMS", "ВШЭ"), (2018, "Методическая работа", "Дирекция")]
)
html = f'''<div tab-node="additional_education"><h2 class="c_14">Дополнительное образование</h2>
{structured}<div class="with-indent"><ul><li>2020 г. НИУ ВШЭ, организация учебного процесса</li></ul>
<p><a href="/f.pdf">Файл</a> (PDF, 407 Кб)</p>
<ul><li>2017 г. МГУ, методика <a href="/mirror/pubs/share/123">Сертификат</a></li>
<li>2016 г. КФУ, образовательные стандарты</li><li>2015 г. ЮФУ, ФГОС</li>
<li><strong>2015 г</strong>. МГТУ МИРЭА.</li></ul>
<p class="text">Направления совершенствования практической подготовки.</p>
<p><a href="/cert.jpg">Сертификат_МИРЭА</a> (JPG, 7,28 Мб).</p>
<ul><li>2014 г. АИОР, аккредитация.</li></ul>
<p><a href="/certificate">Свидетельство</a> (PDF, 9,36 Мб).</p>
<ul><li>2011 г. РАНХиГС.</li></ul>
<p>Курс <a href="/programme">Современные подходы</a>.</p>
<p><a href="/cert.jpg">Удостоверение</a> (JPG, 6,69 Мб).</p></div></div>'''
section, = extract_sections(BeautifulSoup(html, "html.parser"), "https://www.hse.ru/")
assert len(section["items"]) == 10
assert [row["year"] for row in section["year_entries"]] == [2025, 2024, 2018]
assert section["items"][0] == "2025 Экспортный контроль, МИФИ"
assert section["items"][7] == "2015 г. МГТУ МИРЭА. Направления совершенствования практической подготовки."
assert section["items"][9].startswith("2011 г. РАНХиГС. Курс Современные подходы")
assert section["links"] == [{"text": "Современные подходы", "url": "https://www.hse.ru/programme"}]
for fragment in ("Сертификат", "Файл", "Свидетельство", "Удостоверение", "PDF", "JPG"):
assert fragment not in str(section)
class FakeResponse:
def __init__(self, payload):
self.payload = payload