30 lines
2.0 KiB
Python
30 lines
2.0 KiB
Python
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
|
|
|