Expose project_id across labor and calendar endpoints for unambiguous project matching. Use only project_id in /api/projects and /api/project-report; update docs, UI tables, and tests. Co-authored-by: Cursor <cursoragent@cursor.com>
47 lines
1.3 KiB
Python
47 lines
1.3 KiB
Python
from app.project_fields import (
|
|
ensure_project_id,
|
|
ensure_project_ids,
|
|
project_catalog_item,
|
|
)
|
|
|
|
|
|
def test_project_id_from_project_column():
|
|
row = ensure_project_id({"project": 86, "date": "2026-01-01"})
|
|
assert row["project_id"] == 86
|
|
assert row["project"] == 86
|
|
|
|
|
|
def test_project_id_from_catalog_id():
|
|
row = ensure_project_id({"id": 96, "code": "0000-0000", "name": "Test"})
|
|
assert row["project_id"] == 96
|
|
|
|
|
|
def test_project_id_from_project_report_id():
|
|
row = ensure_project_id({"id": 86, "project_code": "2025-0016"})
|
|
assert row["project_id"] == 86
|
|
|
|
|
|
def test_work_report_does_not_confuse_emp_id():
|
|
row = ensure_project_id({"id": 46, "employee": "Иванов", "project_code": "X"})
|
|
assert "project_id" not in row
|
|
|
|
|
|
def test_ensure_project_ids_list():
|
|
rows = ensure_project_ids([{"project": 1}, {"id": 2, "code": "A"}])
|
|
assert rows[0]["project_id"] == 1
|
|
assert rows[1]["project_id"] == 2
|
|
|
|
|
|
def test_project_catalog_item_uses_only_project_id():
|
|
row = project_catalog_item(
|
|
{"id": 96, "code": "0000-0000", "name": "Test", "project_id": 96}
|
|
)
|
|
assert row["project_id"] == 96
|
|
assert "id" not in row
|
|
|
|
|
|
def test_project_catalog_item_from_id():
|
|
row = project_catalog_item({"id": 86, "code": "2025-0016"})
|
|
assert row["project_id"] == 86
|
|
assert "id" not in row
|