146 lines
5.5 KiB
Python
146 lines
5.5 KiB
Python
"""Sorten-Routing: Profil (Meta/Matte) und Auto-ACE-Map."""
|
|
|
|
import unittest
|
|
|
|
from grotti import store
|
|
|
|
|
|
class ProfileMatchTests(unittest.TestCase):
|
|
def test_meta_not_matte(self):
|
|
self.assertTrue(store._profile_matches("Sunlu PLA Meta", "Sunlu PLA Meta"))
|
|
self.assertTrue(store._profile_matches("Sunlu PLA Meta", "Sunlu PLA Meta schwarz"))
|
|
self.assertFalse(store._profile_matches("Sunlu PLA Meta", "Sunlu PLA Matte"))
|
|
self.assertFalse(store._profile_matches("Sunlu PLA Matte", "Sunlu PLA"))
|
|
self.assertFalse(store._profile_matches("Sunlu PLA", "Sunlu PLA Matte"))
|
|
self.assertFalse(store._profile_matches("Sunlu PLA", "Sunlu PLA Meta"))
|
|
|
|
def test_empty_profile_always_ok(self):
|
|
self.assertTrue(store._profile_matches("", "Sunlu PLA Meta"))
|
|
|
|
def test_base_profile_helpers(self):
|
|
self.assertFalse(store._profile_has_variant("Sunlu PLA"))
|
|
self.assertTrue(store._profile_has_variant("Sunlu PLA Meta"))
|
|
self.assertEqual(store._profile_base_type("Sunlu PLA"), "pla")
|
|
self.assertEqual(store._profile_base_type("Generic PETG"), "petg")
|
|
|
|
|
|
class MatchSpoolsTests(unittest.TestCase):
|
|
def setUp(self):
|
|
self.have = [
|
|
{
|
|
"spool_id": 1,
|
|
"material_type": "pla",
|
|
"color": "#ff0000",
|
|
"remaining_g": 800,
|
|
"material_name": "sunlu pla meta",
|
|
"ace_slot": 1,
|
|
},
|
|
{
|
|
"spool_id": 2,
|
|
"material_type": "pla",
|
|
"color": "#000000",
|
|
"remaining_g": 500,
|
|
"material_name": "sunlu pla matte",
|
|
"ace_slot": 2,
|
|
},
|
|
{
|
|
"spool_id": 3,
|
|
"material_type": "pla",
|
|
"color": "",
|
|
"remaining_g": 900,
|
|
"material_name": "eryone pla",
|
|
"ace_slot": None,
|
|
},
|
|
]
|
|
|
|
def test_base_sunlu_pla_matches_any_pla(self):
|
|
need = {"profile": "Sunlu PLA", "material_type": "pla", "color": "", "paint_index": 0}
|
|
matched = store._match_spools_for_need(need, self.have)
|
|
ids = {m["spool_id"] for m in matched}
|
|
self.assertEqual(ids, {1, 2, 3})
|
|
|
|
def test_base_pla_matches_matte_alone(self):
|
|
need = {"profile": "Sunlu PLA", "material_type": "pla", "color": "#f2a900", "paint_index": 0}
|
|
have = [self.have[1]]
|
|
matched = store._match_spools_for_need(need, have)
|
|
self.assertEqual([m["spool_id"] for m in matched], [2])
|
|
|
|
def test_meta_falls_back_to_any_pla(self):
|
|
need = {"profile": "Sunlu PLA Meta", "material_type": "pla", "color": "", "paint_index": 0}
|
|
have = [self.have[1]]
|
|
matched = store._match_spools_for_need(need, have)
|
|
self.assertEqual([m["spool_id"] for m in matched], [2])
|
|
|
|
def test_petg_does_not_match_pla(self):
|
|
need = {"profile": "Sunlu PETG", "material_type": "petg", "color": "", "paint_index": 0}
|
|
self.assertEqual(store._match_spools_for_need(need, self.have), [])
|
|
|
|
def test_pla_lite_hex_matches_any_pla(self):
|
|
# Orca: Profil „Eryone PLA Lite“, Farbe #26A69A — Lager: Eryone/Sunlu PLA „Grau“
|
|
need = {
|
|
"profile": "Eryone PLA Lite",
|
|
"material_type": "pla",
|
|
"color": "#26A69A",
|
|
"paint_index": 0,
|
|
}
|
|
have = [
|
|
{
|
|
"spool_id": 15,
|
|
"material_type": "pla",
|
|
"color": "grau",
|
|
"remaining_g": 873,
|
|
"material_name": "sunlu pla",
|
|
"ace_slot": None,
|
|
},
|
|
{
|
|
"spool_id": 1,
|
|
"material_type": "pla",
|
|
"color": "grau",
|
|
"remaining_g": 800,
|
|
"material_name": "sunlu pla meta",
|
|
"ace_slot": 1,
|
|
},
|
|
]
|
|
matched = store._match_spools_for_need(need, have)
|
|
self.assertEqual({m["spool_id"] for m in matched}, {15, 1})
|
|
|
|
def test_picks_meta_not_matte(self):
|
|
need = {"profile": "Sunlu PLA Meta", "material_type": "pla", "color": "", "paint_index": 0}
|
|
matched = store._match_spools_for_need(need, self.have)
|
|
self.assertEqual(len(matched), 1)
|
|
self.assertEqual(matched[0]["spool_id"], 1)
|
|
|
|
def test_color_soft_among_profile(self):
|
|
need = {
|
|
"profile": "Sunlu PLA Meta",
|
|
"material_type": "pla",
|
|
"color": "#00ff00",
|
|
"paint_index": 0,
|
|
}
|
|
# Nur Meta vorhanden, Farbe anders → trotzdem Meta (Farbe soft)
|
|
matched = store._match_spools_for_need(need, self.have)
|
|
self.assertEqual(matched[0]["spool_id"], 1)
|
|
|
|
def test_auto_ace_map_assigns_slots(self):
|
|
# Ohne DB: Logik über _match + manuell wie auto_ace_map
|
|
need = [
|
|
{"profile": "Sunlu PLA Meta", "material_type": "pla", "color": "#ff0000", "paint_index": 1},
|
|
{"profile": "Sunlu PLA Matte", "material_type": "pla", "color": "#000000", "paint_index": 10},
|
|
]
|
|
used = set()
|
|
mapping = []
|
|
for n in need:
|
|
matched = store._match_spools_for_need(n, self.have, used)
|
|
self.assertTrue(matched)
|
|
chosen = matched[0]
|
|
used.add(chosen["spool_id"])
|
|
mapping.append({"paint_index": n["paint_index"], "ams_index": int(chosen["ace_slot"]) - 1})
|
|
self.assertEqual(mapping, [
|
|
{"paint_index": 1, "ams_index": 0},
|
|
{"paint_index": 10, "ams_index": 1},
|
|
])
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|