diff --git a/spoolman/database/filament.py b/spoolman/database/filament.py index e4079624f..97898fd7a 100644 --- a/spoolman/database/filament.py +++ b/spoolman/database/filament.py @@ -168,6 +168,8 @@ async def update( filament.vendor = await vendor.get_by_id(db, v) elif k == "extra": filament.extra = [models.FilamentField(key=k, value=v) for k, v in v.items()] + elif k == "multi_color_direction": + filament.multi_color_direction = v.value if v is not None else None else: setattr(filament, k, v) await db.commit() diff --git a/tests_integration/tests/filament/test_update.py b/tests_integration/tests/filament/test_update.py index 375b4a7e6..b20799fc6 100644 --- a/tests_integration/tests/filament/test_update.py +++ b/tests_integration/tests/filament/test_update.py @@ -95,6 +95,49 @@ def test_update_filament(random_vendor: dict[str, Any]): httpx.delete(f"{URL}/api/v1/filament/{filament['id']}").raise_for_status() +def test_update_filament_multi_color(): + """Test updating a filament in the database.""" + # Setup + result = httpx.post( + f"{URL}/api/v1/filament", + json={ + "density": 1.25, + "diameter": 1.75, + "multi_color_hexes": "FF0000,00FF00", + "multi_color_direction": "coaxial", + }, + ) + result.raise_for_status() + added_filament = result.json() + + # Execute + new_multi_color_hexes = "00FF00,0000FF" + new_multi_color_direction = "longitudinal" + result = httpx.patch( + f"{URL}/api/v1/filament/{added_filament['id']}", + json={ + "multi_color_hexes": new_multi_color_hexes, + "multi_color_direction": new_multi_color_direction, + }, + ) + result.raise_for_status() + + # Verify + filament = result.json() + assert_dicts_compatible( + filament, + { + "id": added_filament["id"], + "registered": added_filament["registered"], + "multi_color_hexes": new_multi_color_hexes, + "multi_color_direction": new_multi_color_direction, + }, + ) + + # Clean up + httpx.delete(f"{URL}/api/v1/filament/{filament['id']}").raise_for_status() + + def test_update_filament_cant_set_none(random_vendor: dict[str, Any]): """Test updating a filament and setting density and diameter fields to None, should result in 422 error.""" # Setup