Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions enferno/admin/validation/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,9 @@ class LabelValidationModel(StrictValidationModel):
# sent by tree view edit (build_tree node shape), not used by from_json
parent_label_id: Optional[int] = None
children: Optional[List] = None
# computed by to_dict for hierarchy display, not used by from_json
path: Optional[str] = None
path_ar: Optional[str] = None


class LabelRequestModel(BaseValidationModel):
Expand Down
20 changes: 20 additions & 0 deletions tests/test_lookup_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,26 @@ def test_lookup_search_by_translated_title(request, session, entity, list_url, f
assert item.id in ids


def test_label_update_accepts_its_own_serialization(request, session):
"""The edit form PUTs back what to_dict returned, path fields included."""
from enferno.admin.models import Label

parent = Label(title="Parent")
session.add(parent)
session.commit()
label = Label(title="Child", parent_label_id=parent.id)
session.add(label)
session.commit()

payload = label.to_dict()
assert "path" in payload and "path_ar" in payload
payload["title"] = "Renamed"

client = request.getfixturevalue("admin_client")
resp = client.put(f"/admin/api/label/{label.id}", json={"item": payload}, headers=HEADERS)
assert resp.status_code == 200


def test_label_mode2_includes_translated_title_and_path(session):
from enferno.admin.models import Label

Expand Down
Loading