Adding Manual connection point to allow undeclared fits
This commit is contained in:
1 parent
7e246be39c
commit
b4dcb68bea
15 files changed
+227
-23
No files matched your search
@@ -0,0 +1,106 @@
|
||||
from app.models.attachment_point_name import AttachmentPointName
|
||||
from app.models.augmented_part import AugmentedPart
|
||||
from app.models.iso_thread import IsoThread
|
||||
from app.models.manufacturer import Manufacturer
|
||||
from app.models.part_colour import PartColour
|
||||
from app.models.part_type import PartType
|
||||
|
||||
|
||||
async def _seed_part(db):
|
||||
manufacturer = Manufacturer(name="Acme", url="https://acme.test")
|
||||
colour = PartColour(name="Black")
|
||||
part_type = PartType(name="Flip Cover")
|
||||
apn = AttachmentPointName(name="Mount")
|
||||
iso = IsoThread(diameter_mm=52.0, pitch_mm=0.75)
|
||||
db.add_all([manufacturer, colour, part_type, apn, iso])
|
||||
await db.flush()
|
||||
|
||||
part = AugmentedPart(
|
||||
description="Flip cover",
|
||||
colour_id=colour.id,
|
||||
manufacturer_id=manufacturer.id,
|
||||
part_type_id=part_type.id,
|
||||
)
|
||||
db.add(part)
|
||||
await db.flush()
|
||||
await db.commit()
|
||||
return part.id, apn.id, iso.id
|
||||
|
||||
|
||||
async def _token(client, email, password="secret123"):
|
||||
resp = await client.post(
|
||||
"/api/auth/login", data={"username": email, "password": password}
|
||||
)
|
||||
assert resp.status_code == 200, resp.text
|
||||
return resp.json()["access_token"]
|
||||
|
||||
|
||||
async def test_create_manual_attachment_point_with_no_connection_succeeds(
|
||||
client, seeded, make_user, db_sessionmaker
|
||||
):
|
||||
await make_user("root@example.com", is_superuser=True)
|
||||
headers = {"Authorization": f"Bearer {await _token(client, 'root@example.com')}"}
|
||||
async with db_sessionmaker() as db:
|
||||
part_id, apn_id, _ = await _seed_part(db)
|
||||
|
||||
resp = await client.post(
|
||||
"/api/attachment-points",
|
||||
json={
|
||||
"augmented_part_id": part_id,
|
||||
"attachment_point_name_id": apn_id,
|
||||
},
|
||||
headers=headers,
|
||||
)
|
||||
assert resp.status_code == 201, resp.text
|
||||
body = resp.json()
|
||||
assert body["iso_thread_id"] is None
|
||||
assert body["unc_thread_id"] is None
|
||||
assert body["clamp_connection_id"] is None
|
||||
assert body["static_connection_id"] is None
|
||||
|
||||
|
||||
async def test_create_attachment_point_with_two_connections_rejected(
|
||||
client, seeded, make_user, db_sessionmaker
|
||||
):
|
||||
await make_user("root2@example.com", is_superuser=True)
|
||||
headers = {"Authorization": f"Bearer {await _token(client, 'root2@example.com')}"}
|
||||
async with db_sessionmaker() as db:
|
||||
part_id, apn_id, iso_id = await _seed_part(db)
|
||||
from app.crud import static_connection as static_connection_crud
|
||||
|
||||
static = await static_connection_crud.create(db, od_mm=40.0, od_in=1.57)
|
||||
static_id = static.id
|
||||
|
||||
resp = await client.post(
|
||||
"/api/attachment-points",
|
||||
json={
|
||||
"augmented_part_id": part_id,
|
||||
"attachment_point_name_id": apn_id,
|
||||
"iso_thread_id": iso_id,
|
||||
"static_connection_id": static_id,
|
||||
},
|
||||
headers=headers,
|
||||
)
|
||||
assert resp.status_code == 400
|
||||
assert "at most one" in resp.json()["detail"].lower()
|
||||
|
||||
|
||||
async def test_create_attachment_point_with_one_connection_still_works(
|
||||
client, seeded, make_user, db_sessionmaker
|
||||
):
|
||||
await make_user("root3@example.com", is_superuser=True)
|
||||
headers = {"Authorization": f"Bearer {await _token(client, 'root3@example.com')}"}
|
||||
async with db_sessionmaker() as db:
|
||||
part_id, apn_id, iso_id = await _seed_part(db)
|
||||
|
||||
resp = await client.post(
|
||||
"/api/attachment-points",
|
||||
json={
|
||||
"augmented_part_id": part_id,
|
||||
"attachment_point_name_id": apn_id,
|
||||
"iso_thread_id": iso_id,
|
||||
},
|
||||
headers=headers,
|
||||
)
|
||||
assert resp.status_code == 201, resp.text
|
||||
assert resp.json()["iso_thread_id"] == iso_id
|
||||
@@ -284,6 +284,41 @@ async def test_fit_reference_without_attachment_points_creates_matching_one(
|
||||
assert acc_aps[0].id in linked_ap_ids
|
||||
|
||||
|
||||
async def test_scope_fit_without_scope_attachment_point_creates_manual_one(
|
||||
db_sessionmaker,
|
||||
):
|
||||
async with db_sessionmaker() as db:
|
||||
_, acc_ap = await _make_accessory(db, "ACC-1", od_mm=40)
|
||||
|
||||
# No ocular_outer_diameter_mm, so the scope itself has no Ocular AP,
|
||||
# but an ocular_fit reference is still given.
|
||||
data = _workbook(
|
||||
[_scope_row(ocular_outer_diameter_mm=None, ocular_fit="ACC-1")]
|
||||
)
|
||||
result = await scope_import_service.import_from_bytes(db, data)
|
||||
assert result.created == 1
|
||||
msgs = " ".join(result.rows[0].messages)
|
||||
assert "created a manual one to record the fit" in msgs
|
||||
|
||||
part = await augmented_part_crud.get_by_sku(db, "SCOPE-A")
|
||||
scope_aps = await attachment_point_crud.list_for_augmented_part(db, part.id)
|
||||
by_label = {ap.attachment_point_name.name: ap for ap in scope_aps}
|
||||
assert "Ocular" in by_label
|
||||
ocular_ap = by_label["Ocular"]
|
||||
assert ocular_ap.iso_thread is None
|
||||
assert ocular_ap.unc_thread is None
|
||||
assert ocular_ap.clamp_connection is None
|
||||
assert ocular_ap.static_connection is None
|
||||
# Objective still gets its normal thread-based AP.
|
||||
assert "Objective" in by_label
|
||||
|
||||
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 ocular_ap.id in linked_ap_ids
|
||||
assert acc_ap.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")])
|
||||
|
||||
Reference in new issue
Block a user