mirror of
https://github.com/RunLit/Bambu-Run.git
synced 2026-10-21 15:37:38 +01:00
fix(mcp): exclude -1 sentinel from min_remaining_grams filter in list_filaments
This commit is contained in:
@@ -41,7 +41,7 @@ def list_filaments(
|
||||
if min_remaining_percent is not None:
|
||||
qs = qs.exclude(remaining_percent=-1).filter(remaining_percent__gte=min_remaining_percent)
|
||||
if min_remaining_grams is not None:
|
||||
qs = qs.exclude(remaining_weight_grams__isnull=True).filter(remaining_weight_grams__gte=min_remaining_grams)
|
||||
qs = qs.exclude(remaining_percent=-1).exclude(remaining_weight_grams__isnull=True).filter(remaining_weight_grams__gte=min_remaining_grams)
|
||||
|
||||
spools = [_spool_summary(f, include_history) for f in qs.order_by("-remaining_percent")[:limit]]
|
||||
return {"filaments": spools}
|
||||
|
||||
@@ -28,6 +28,26 @@ def test_list_filaments_min_remaining_grams_excludes_unread_sentinel():
|
||||
assert result["filaments"][0]["color_name"] == "Orange"
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_list_filaments_min_remaining_grams_excludes_unread_even_with_low_threshold():
|
||||
# The existing test only checks min_remaining_grams=250, which happens to
|
||||
# exclude a -10g sentinel-derived value anyway. This test uses a threshold
|
||||
# low enough that a naive filter would let the sentinel spool through.
|
||||
Filament.objects.create(
|
||||
type="ABS", brand="Bambu Lab", color="Mint",
|
||||
remaining_percent=-1, remaining_weight_grams=-10,
|
||||
)
|
||||
Filament.objects.create(
|
||||
type="ABS", brand="Bambu Lab", color="Orange",
|
||||
remaining_percent=68, remaining_weight_grams=680,
|
||||
)
|
||||
|
||||
result = list_filaments(material="ABS", min_remaining_grams=-20)
|
||||
|
||||
assert len(result["filaments"]) == 1
|
||||
assert result["filaments"][0]["color_name"] == "Orange"
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_list_filaments_unread_sentinel_status_not_low():
|
||||
Filament.objects.create(type="ABS", brand="Bambu Lab", color="Mint", remaining_percent=-1)
|
||||
|
||||
Reference in New Issue
Block a user