Adding ability to autovivify an appropriate attachment point when manually entering a fit
This commit is contained in:
1 parent
92ca6b2a9f
commit
23d07505bd
3 files changed
+136
-6
No files matched your search
@@ -5,6 +5,7 @@ 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.fit import Fit, FitLabel
|
||||
from app.models.iso_thread import IsoThread
|
||||
from app.models.part_type import PartType
|
||||
from app.models.scope_info import ScopeInfo
|
||||
|
||||
@@ -151,6 +152,90 @@ async def test_detail_write_controls_for_fit_editor(
|
||||
assert "Recompute possible fits" in body
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create_fit_auto_creates_matching_attachment_point(
|
||||
client, seeded, make_user, db_sessionmaker
|
||||
):
|
||||
async with db_sessionmaker() as db:
|
||||
apn = AttachmentPointName(name="Objective")
|
||||
scope_t = PartType(name="Scope")
|
||||
cover_t = PartType(name="Flip Cover")
|
||||
db.add_all([apn, scope_t, cover_t])
|
||||
await db.flush()
|
||||
|
||||
thread = IsoThread(diameter_mm=42.0, pitch_mm=0.75)
|
||||
db.add(thread)
|
||||
await db.flush()
|
||||
|
||||
scope = AugmentedPart(
|
||||
description="Alpha 3-18x50",
|
||||
sku="ALP-318",
|
||||
colour_id=1,
|
||||
manufacturer_id=1,
|
||||
part_type_id=scope_t.id,
|
||||
)
|
||||
cover = AugmentedPart(
|
||||
description="Flip cover 50mm",
|
||||
colour_id=1,
|
||||
manufacturer_id=1,
|
||||
part_type_id=cover_t.id,
|
||||
)
|
||||
db.add_all([scope, cover])
|
||||
await db.flush()
|
||||
|
||||
own_ap = AttachmentPoint(
|
||||
augmented_part_id=scope.id,
|
||||
attachment_point_name_id=apn.id,
|
||||
iso_thread_id=thread.id,
|
||||
)
|
||||
db.add(own_ap)
|
||||
await db.commit()
|
||||
|
||||
scope_id, cover_id, own_ap_id = scope.id, cover.id, own_ap.id
|
||||
|
||||
perms = seeded["perms"]
|
||||
editor = await role_crud.create(
|
||||
db,
|
||||
name="fit-editor2",
|
||||
permission_ids=[
|
||||
perms["augmented_parts:read"].id,
|
||||
perms["fits:read"].id,
|
||||
perms["fits:write"].id,
|
||||
],
|
||||
)
|
||||
editor_id = editor.id
|
||||
await make_user("editor2@example.com", role_ids=[editor_id])
|
||||
await _web_login(client, "editor2@example.com")
|
||||
|
||||
resp = await client.post(
|
||||
f"/admin/augmented-parts/{scope_id}/fits",
|
||||
data={
|
||||
"own_attachment_point_id": own_ap_id,
|
||||
"other_augmented_part_id": cover_id,
|
||||
"other_attachment_point_id": "",
|
||||
"label": "possible",
|
||||
},
|
||||
)
|
||||
assert resp.status_code == 200
|
||||
body = resp.text
|
||||
assert "already exists" not in body
|
||||
assert "not found" not in body
|
||||
|
||||
async with db_sessionmaker() as db:
|
||||
cover_points = [
|
||||
ap
|
||||
for ap in (await db.execute(AttachmentPoint.__table__.select())).all()
|
||||
if ap.augmented_part_id == cover_id
|
||||
]
|
||||
assert len(cover_points) == 1
|
||||
assert cover_points[0].iso_thread_id == thread.id
|
||||
assert cover_points[0].attachment_point_name_id == apn.id
|
||||
|
||||
fits = (await db.execute(Fit.__table__.select())).all()
|
||||
assert len(fits) == 1
|
||||
assert fits[0].label == FitLabel.POSSIBLE
|
||||
|
||||
|
||||
@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])
|
||||
|
||||
Reference in new issue
Block a user