59 lines
3.9 KiB
Python
59 lines
3.9 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
|
||
from app.services.admin_data import _display_sections
|
||
|
||
|
||
def test_dated_lines_and_wrapped_title_survive_old_and_new_profiles():
|
||
html = ('<h2>Дополнительное образование</h2><p>2002 г. "Первый курс".<br>'
|
||
'2006 г. "Второй курс".<br>Продолжение описания.</p>')
|
||
section, = extract_sections(BeautifulSoup(html, "html.parser"), "https://www.hse.ru")
|
||
expected = ['2002 г. "Первый курс".', '2006 г. "Второй курс". Продолжение описания.']
|
||
assert section["items"] == expected
|
||
for old in ({"type": "additional_education", "items": [" ".join(expected)]},
|
||
{"type": "paragraphs", "paragraphs": [" ".join(expected)]}):
|
||
saved, = _display_sections({"sections": [{**old, "title": section["title"]}]})
|
||
assert saved["items"] == expected
|
||
|
||
|
||
def test_possible_duplicate_requires_review_even_without_attachments():
|
||
html = ('<h2>Повышение квалификации</h2>'
|
||
'<p>2018 г. "Комплексная безопасность". МАИ.</p>'
|
||
'<p>2018 г. "Комплексная безопасность". Удостоверение.</p>')
|
||
section, = extract_sections(BeautifulSoup(html, "html.parser"), "https://www.hse.ru")
|
||
assert len(section["items"]) == 2
|
||
assert section["unresolved"] == ["Возможный повтор: " + section["items"][1]]
|
||
|
||
|
||
def test_unlinked_certificate_images_are_reviewed_once():
|
||
html = '<h2>Повышение квалификации</h2><p>' + '<img src="/mirror/pubs/share/12">' * 2 + '</p>'
|
||
section, = extract_sections(BeautifulSoup(html, "html.parser"), "https://www.hse.ru", lambda url: None)
|
||
assert not section["items"]
|
||
assert section["unresolved_documents"] == [{"text": "Изображение документа", "url": "https://www.hse.ru/mirror/pubs/share/12"}]
|
||
|
||
|
||
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
|
||
|