Making objective_lens a thing

This commit is contained in:
Ian Roddis committed 2026-08-04 16:48:00 -03:00
1 parent fcb4dbaa62
commit 12e6984c63
17 files changed
+115 -119

No files matched your search

+34 -8
View File
@@ -34,20 +34,40 @@ def test_same_label_never_matches_even_with_identical_threads():
def test_unc_thread_exact_match():
a = _ap(1, 1, unc_thread=UncThread(diameter_fraction="1/4", tpi=20, series=UncSeries.UNC))
b = _ap(2, 2, unc_thread=UncThread(diameter_fraction="1/4", tpi=20, series=UncSeries.UNC))
a = _ap(
1,
1,
unc_thread=UncThread(diameter_fraction="1/4", tpi=20, series=UncSeries.UNC),
)
b = _ap(
2,
2,
unc_thread=UncThread(diameter_fraction="1/4", tpi=20, series=UncSeries.UNC),
)
assert attachment_points_match(a, b)
def test_unc_thread_series_mismatch():
a = _ap(1, 1, unc_thread=UncThread(diameter_fraction="1/4", tpi=20, series=UncSeries.UNC))
b = _ap(2, 2, unc_thread=UncThread(diameter_fraction="1/4", tpi=20, series=UncSeries.UNF))
a = _ap(
1,
1,
unc_thread=UncThread(diameter_fraction="1/4", tpi=20, series=UncSeries.UNC),
)
b = _ap(
2,
2,
unc_thread=UncThread(diameter_fraction="1/4", tpi=20, series=UncSeries.UNF),
)
assert not attachment_points_match(a, b)
def test_iso_and_unc_never_match_each_other():
a = _ap(1, 1, iso_thread=IsoThread(diameter_mm=8, pitch_mm=1.25))
b = _ap(2, 2, unc_thread=UncThread(diameter_fraction="1/4", tpi=20, series=UncSeries.UNC))
b = _ap(
2,
2,
unc_thread=UncThread(diameter_fraction="1/4", tpi=20, series=UncSeries.UNC),
)
assert not attachment_points_match(a, b)
@@ -94,9 +114,15 @@ def test_two_bare_attachment_points_never_match():
def test_parts_could_fit_requires_different_types_and_identity():
a = AugmentedPart(id=1, part_type_id=1, description="a", colour_id=1, manufacturer_id=1)
b = AugmentedPart(id=2, part_type_id=1, description="b", colour_id=1, manufacturer_id=1)
c = AugmentedPart(id=3, part_type_id=2, description="c", colour_id=1, manufacturer_id=1)
a = AugmentedPart(
id=1, part_type_id=1, description="a", colour_id=1, manufacturer_id=1
)
b = AugmentedPart(
id=2, part_type_id=1, description="b", colour_id=1, manufacturer_id=1
)
c = AugmentedPart(
id=3, part_type_id=2, description="c", colour_id=1, manufacturer_id=1
)
assert not parts_could_fit(a, b)
assert parts_could_fit(a, c)
assert not parts_could_fit(a, a)
+1 -3
View File
@@ -80,9 +80,7 @@ async def test_ldap_login_is_idempotent(
assert await user_crud.count(db) == 1
async def test_ldap_login_bad_credentials(
client, seeded, monkeypatch, ldap_enabled
):
async def test_ldap_login_bad_credentials(client, seeded, monkeypatch, ldap_enabled):
async def fake_authenticate(username, password):
return None
+11 -36
View File
@@ -1,12 +1,9 @@
import pytest
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.part_type import PartType
from app.models.scope_info import ScopeInfo
from app.models.static_connection import StaticConnection
from app.models.sub_part_type import SubPartType
from app.services import scope_guide
@@ -34,7 +31,9 @@ async def _seed_guide_data(db):
db.add(p)
return p
s1 = part("Alpha 3-18x50", scope_t.id, manufacturer_id=10, sub_part_type_id=rifle.id)
s1 = part(
"Alpha 3-18x50", scope_t.id, manufacturer_id=10, sub_part_type_id=rifle.id
)
s2 = part("Zeta 1-6x24", scope_t.id, manufacturer_id=20, sub_part_type_id=reddot.id)
fc1 = part("Flip cover 50mm", cover_t.id)
a1 = part("ARD 50mm", ard_t.id)
@@ -46,6 +45,7 @@ async def _seed_guide_data(db):
augmented_part_id=s1.id,
magnification_min=3,
magnification_max=18,
objective_lens_diameter_mm=50,
objective_thread_pitch="M52x0.75",
)
)
@@ -172,9 +172,7 @@ async def test_build_filters_by_required_fit_type(db_sessionmaker):
async def _web_login(client, email, password="secret123"):
resp = await client.post(
"/login", data={"email": email, "password": password}
)
resp = await client.post("/login", data={"email": email, "password": password})
assert resp.status_code == 303
@@ -206,45 +204,22 @@ async def test_scopes_page_renders_rows_and_fits(
@pytest.mark.asyncio
async def test_build_includes_objective_diameter(db_sessionmaker):
async def test_build_includes_objective_lens_diameter(db_sessionmaker):
async with db_sessionmaker() as db:
ids = await _seed_guide_data(db)
apn = AttachmentPointName(name="Objective")
db.add(apn)
await db.flush()
db.add(
AttachmentPoint(
augmented_part_id=ids["s1"].id,
attachment_point_name_id=apn.id,
static_connection=StaticConnection(od_mm=50, od_in=1.9685),
)
)
await db.commit()
await _seed_guide_data(db)
guide = await scope_guide.build(db)
rows = {r["scope"].description: r for r in guide["rows"]}
assert rows["Alpha 3-18x50"]["objective_diameter_mm"] == 50
assert rows["Zeta 1-6x24"]["objective_diameter_mm"] is None
assert rows["Alpha 3-18x50"]["info"].objective_lens_diameter_mm == 50
assert rows["Zeta 1-6x24"]["info"] is None
@pytest.mark.asyncio
async def test_scopes_page_renders_objective_diameter_in_magnification(
async def test_scopes_page_renders_objective_lens_diameter_in_magnification(
client, seeded, make_user, db_sessionmaker
):
async with db_sessionmaker() as db:
ids = await _seed_guide_data(db)
apn = AttachmentPointName(name="Objective")
db.add(apn)
await db.flush()
db.add(
AttachmentPoint(
augmented_part_id=ids["s1"].id,
attachment_point_name_id=apn.id,
static_connection=StaticConnection(od_mm=50, od_in=1.9685),
)
)
await db.commit()
await _seed_guide_data(db)
await make_user("reader4@example.com", role_ids=[seeded["roles"]["user"].id])
await _web_login(client, "reader4@example.com")
resp = await client.get("/scopes")
+10 -10
View File
@@ -19,7 +19,7 @@ HEADERS = [
"model",
"magnification_min",
"magnification_max",
"objective_lens_outside_diameter_mm",
"objective_lens_diameter_mm",
"model_suffix",
"sub_part_type",
"product_number",
@@ -52,7 +52,7 @@ def _scope_row(**overrides):
"model": "Viper",
"magnification_min": 5,
"magnification_max": 25,
"objective_lens_outside_diameter_mm": 56,
"objective_lens_diameter_mm": 56,
"model_suffix": "PST",
"sub_part_type": "Riflescope",
"product_number": "SCOPE-A",
@@ -141,6 +141,7 @@ async def test_import_creates_scope_with_info_and_attachment_points(db_sessionma
assert info.magnification_min == 5
assert info.magnification_max == 25
assert info.model_suffix == "PST"
assert info.objective_lens_diameter_mm == 56
assert info.objective_thread_pitch == "0.75"
aps = await attachment_point_crud.list_for_augmented_part(db, part.id)
@@ -151,14 +152,13 @@ async def test_import_creates_scope_with_info_and_attachment_points(db_sessionma
assert len(by_label["Ocular"]) == 1
assert by_label["Ocular"][0].static_connection.od_mm == 40
# The lens diameter is descriptive only: the sole Objective point is the
# thread.
objectives = by_label["Objective"]
assert len(objectives) == 2 # static OD + thread
static_obj = [a for a in objectives if a.static_connection is not None]
thread_obj = [a for a in objectives if a.iso_thread is not None]
assert static_obj and static_obj[0].static_connection.od_mm == 56
assert thread_obj
assert thread_obj[0].iso_thread.diameter_mm == 40
assert thread_obj[0].iso_thread.pitch_mm == 0.75
assert len(objectives) == 1
assert objectives[0].static_connection is None
assert objectives[0].iso_thread.diameter_mm == 40
assert objectives[0].iso_thread.pitch_mm == 0.75
async def test_import_resolves_ocular_and_objective_fits(db_sessionmaker):
@@ -200,7 +200,7 @@ async def test_import_upserts_on_product_number(db_sessionmaker):
# Attachment points were rebuilt, not duplicated.
aps = await attachment_point_crud.list_for_augmented_part(db, matching[0].id)
assert len(aps) == 3
assert len(aps) == 2
async def test_row_without_product_number_is_skipped(db_sessionmaker):