"""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")) 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, }, ] 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()