Adding autovivify aps

This commit is contained in:
Ian Roddis committed 2026-08-18 16:33:23 -03:00
1 parent 34d538f9a0
commit 7e246be39c
2 files changed
+84 -8

No files matched your search

+49
View File
@@ -235,6 +235,55 @@ async def test_unknown_fit_reference_is_reported(db_sessionmaker):
assert await fit_crud.list_for_part(db, part.id) == []
async def _make_bare_part(db, sku):
"""A non-scope part with no attachment points at all."""
colour = await part_colour_crud.get_by_name(db, "Black")
if colour is None:
colour = await part_colour_crud.create(db, name="Black")
manu = await manufacturer_crud.get_by_name(db, "Armament")
if manu is None:
manu = await manufacturer_crud.create(db, name="Armament", url="")
pt = await part_type_crud.get_by_name(db, "Flip Cover")
if pt is None:
pt = await part_type_crud.create(db, name="Flip Cover")
return await augmented_part_crud.create(
db,
sku=sku,
description=f"Accessory {sku}",
colour_id=colour.id,
manufacturer_id=manu.id,
scope_model_id=None,
part_type_id=pt.id,
sub_part_type_id=None,
)
async def test_fit_reference_without_attachment_points_creates_matching_one(
db_sessionmaker,
):
async with db_sessionmaker() as db:
await _make_bare_part(db, "ACC-BARE")
data = _workbook([_scope_row(ocular_fit="ACC-BARE")])
result = await scope_import_service.import_from_bytes(db, data)
assert result.created == 1
msgs = " ".join(result.rows[0].messages)
assert "created one matching the scope's attachment point" in msgs
acc = await augmented_part_crud.get_by_sku(db, "ACC-BARE")
acc_aps = await attachment_point_crud.list_for_augmented_part(db, acc.id)
assert len(acc_aps) == 1
assert acc_aps[0].static_connection is not None
assert acc_aps[0].static_connection.od_mm == 40
assert acc_aps[0].attachment_point_name.name == "Ocular"
part = await augmented_part_crud.get_by_sku(db, "SCOPE-A")
fits = await fit_crud.list_for_part(db, part.id)
assert len(fits) == 1
linked_ap_ids = {fits[0].attachment_point_a_id, fits[0].attachment_point_b_id}
assert acc_aps[0].id in linked_ap_ids
async def test_unc_objective_thread_creates_unc_attachment_point(db_sessionmaker):
async with db_sessionmaker() as db:
data = _workbook([_scope_row(objective_thread="1.750-32 UNS")])