{{ section.title }} diff --git a/app/version.py b/app/version.py index f2e93fa..6a65aac 100644 --- a/app/version.py +++ b/app/version.py @@ -1,3 +1,3 @@ -APP_VERSION = "1.5.0" -FRONTEND_VERSION = "1.5.0" -BACKEND_VERSION = "1.5.0" +APP_VERSION = "1.5.1" +FRONTEND_VERSION = "1.5.1" +BACKEND_VERSION = "1.5.1" diff --git a/pyproject.toml b/pyproject.toml index 13917d1..4d7c7ee 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "miem-workers" -version = "1.5.0" +version = "1.5.1" description = "MIEM employees parser, admin API, and web admin" requires-python = ">=3.11" dependencies = [ diff --git a/tests/test_api.py b/tests/test_api.py index db9b42d..f97c474 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -18,7 +18,7 @@ def test_health_returns_versions(): response = TestClient(app).get("/api/health") assert response.status_code == 200 - assert response.json()["backend_version"] == "1.5.0" + assert response.json()["backend_version"] == "1.5.1" def test_api_employees_and_stats_require_admin_session(): diff --git a/tests/test_council.py b/tests/test_council.py index dcd8c4b..4d4b2c8 100644 --- a/tests/test_council.py +++ b/tests/test_council.py @@ -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 1.5.0 · Frontend 1.5.0" in response.text + assert "Backend 1.5.1 · Frontend 1.5.1" 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 diff --git a/tests/test_employee_detail_template.py b/tests/test_employee_detail_template.py index 1c69087..771145d 100644 --- a/tests/test_employee_detail_template.py +++ b/tests/test_employee_detail_template.py @@ -1,5 +1,13 @@ from pathlib import Path +import pytest +from bs4 import BeautifulSoup +from jinja2 import Environment, FileSystemLoader +from starlette.requests import Request + +from app.models import Employee, EmployeeNewsLink +from app.services.admin_data import employee_detail_payload + def test_employee_detail_template_is_human_readable(): template = Path("app/templates/employee_detail.html").read_text(encoding="utf-8") @@ -33,3 +41,41 @@ def test_employee_detail_template_is_human_readable(): assert "Обновить данные" in template assert 'action="/admin/employees/{{ employee.id }}/refresh"' in template assert "Снапшоты" in template + + +@pytest.mark.parametrize("news_source", [None, "snapshot", "stored"]) +@pytest.mark.parametrize("has_other_section", [False, True]) +def test_employee_news_render_once_in_closed_disclosure(db_session, news_source, has_other_section): + sections = [{"title": "Биография", "type": "generic", "paragraphs": ["Текст биографии"]}] if has_other_section else [] + if news_source: + sections.append({"title": "В новостях", "type": "news", + "news_links": [{"title": "Новость из профиля", "url": "https://example.test/snapshot"}], + "paragraphs": ["Дублирующий текст новостей"]}) + employee = Employee(profile_key="staff:news", canonical_url="https://example.test/profile", + full_name="Тестовый сотрудник", status="active", current_data={"sections": sections}) + db_session.add(employee) + db_session.flush() + if news_source == "stored": + db_session.add(EmployeeNewsLink(employee_id=employee.id, title="Сохранённая новость", + url="https://example.test/stored", summary="Описание новости", source_hash="a" * 64)) + db_session.flush() + template = Environment(loader=FileSystemLoader("app/templates"), autoescape=True).get_template("employee_detail.html") + rendered = template.render(employee=employee, employee_view=employee_detail_payload(employee), snapshots=[], + request=Request({"type": "http", "scheme": "http", "headers": [], + "path": f"/admin/employees/{employee.id}"})) + soup = BeautifulSoup(rendered, "html.parser") + assert not any(badge.get_text(strip=True) == "news" for badge in soup.select(".employee-section__type")) + assert "Дублирующий текст новостей" not in rendered + assert ("Текст биографии" in rendered) == has_other_section + assert ("Разделы профиля не найдены." in rendered) == (not has_other_section) + news = soup.select("details.employee-card__section--news") + assert len(news) == (1 if news_source else 0) + if news_source: + assert not news[0].has_attr("open") + assert news[0].summary.h3.get_text(strip=True) == "В новостях" + expected_url = f"https://example.test/{'stored' if news_source == 'stored' else 'snapshot'}" + assert [link["href"] for link in news[0].select("a")] == [expected_url] + assert len(soup.select(f'a[href="{expected_url}"]')) == 1 + if news_source == "stored": + assert "Описание новости" in news[0].get_text() + assert "Новость из профиля" not in rendered