Adding AugmentedItem notes

This commit is contained in:
Ian Roddis committed 2026-07-31 09:12:41 -03:00
1 parent 30a13644ce
commit 34679d53e8
10 files changed
+254 -12

No files matched your search

+42 -8
View File
@@ -3,7 +3,7 @@ import pytest
from app.crud import role as role_crud
from app.models.attachment_point import AttachmentPoint
from app.models.attachment_point_name import AttachmentPointName
from app.models.augmented_part import AugmentedPart
from app.models.augmented_part import AugmentedPart, AugmentedPartNote
from app.models.fit import Fit, FitLabel, FitNote
from app.models.iso_thread import IsoThread
from app.models.part_type import PartType
@@ -41,12 +41,8 @@ async def _seed_part_with_fit(db):
objective_thread_pitch="M52x0.75",
)
)
ap_s = AttachmentPoint(
augmented_part_id=scope.id, attachment_point_name_id=apn.id
)
ap_c = AttachmentPoint(
augmented_part_id=cover.id, attachment_point_name_id=apn.id
)
ap_s = AttachmentPoint(augmented_part_id=scope.id, attachment_point_name_id=apn.id)
ap_c = AttachmentPoint(augmented_part_id=cover.id, attachment_point_name_id=apn.id)
db.add_all([ap_s, ap_c])
await db.flush()
@@ -92,6 +88,7 @@ async def test_detail_shows_attributes_and_fits_readonly(
assert "Add fit" not in body
assert "Mark Exact" not in body
assert "Recompute possible fits" not in body
assert "Add note" not in body
# ...and attachment-point add/edit/delete controls are hidden too
assert 'name="attachment_point_name_id"' not in body
assert "Delete this attachment point?" not in body
@@ -310,6 +307,41 @@ async def test_create_fit_with_note_creates_fit_note(
assert notes[0].body == "Confirmed fit on the bench."
@pytest.mark.asyncio
async def test_create_augmented_part_note(client, seeded, make_user, db_sessionmaker):
async with db_sessionmaker() as db:
ids = await _seed_part_with_fit(db)
perms = seeded["perms"]
editor = await role_crud.create(
db,
name="ap-note-editor",
permission_ids=[
perms["augmented_parts:read"].id,
perms["augmented_parts:write"].id,
],
)
editor_id = editor.id
await make_user("noteeditor@example.com", role_ids=[editor_id])
await _web_login(client, "noteeditor@example.com")
resp = await client.get(f"/admin/augmented-parts/{ids['scope_id']}")
assert resp.status_code == 200
assert "Add note" in resp.text
resp = await client.post(
f"/admin/augmented-parts/{ids['scope_id']}/notes",
data={"body": "Verified thread depth on the bench."},
)
assert resp.status_code == 200
assert "Verified thread depth on the bench." in resp.text
async with db_sessionmaker() as db:
notes = (await db.execute(AugmentedPartNote.__table__.select())).all()
assert len(notes) == 1
assert notes[0].augmented_part_id == ids["scope_id"]
assert notes[0].body == "Verified thread depth on the bench."
@pytest.mark.asyncio
async def test_detail_404_for_missing_part(client, seeded, make_user):
await make_user("reader2@example.com", role_ids=[seeded["roles"]["user"].id])
@@ -319,7 +351,9 @@ async def test_detail_404_for_missing_part(client, seeded, make_user):
@pytest.mark.asyncio
async def test_detail_requires_read_permission(client, seeded, make_user, db_sessionmaker):
async def test_detail_requires_read_permission(
client, seeded, make_user, db_sessionmaker
):
async with db_sessionmaker() as db:
ids = await _seed_part_with_fit(db)
await make_user("plain@example.com") # no roles, not superuser