|
@@ -2153,7 +2153,7 @@ def _full_spoolman_spool(spool_id: int) -> dict:
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestNfcWriteTagSpoolman:
|
|
class TestNfcWriteTagSpoolman:
|
|
|
- """nfc/write-tag falls back to Spoolman when local DB has no matching spool."""
|
|
|
|
|
|
|
+ """nfc/write-tag encodes the Spoolman spool in Spoolman mode."""
|
|
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
@pytest.mark.asyncio
|
|
|
@pytest.mark.integration
|
|
@pytest.mark.integration
|
|
@@ -2221,10 +2221,10 @@ class TestNfcWriteTagSpoolman:
|
|
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
@pytest.mark.asyncio
|
|
|
@pytest.mark.integration
|
|
@pytest.mark.integration
|
|
|
- async def test_404_when_neither_local_nor_spoolman(
|
|
|
|
|
|
|
+ async def test_404_when_spoolman_has_no_such_spool(
|
|
|
self, async_client: AsyncClient, device_factory, spoolman_settings
|
|
self, async_client: AsyncClient, device_factory, spoolman_settings
|
|
|
):
|
|
):
|
|
|
- """404 returned when spool is missing from both local DB and Spoolman."""
|
|
|
|
|
|
|
+ """404 returned when the spool is missing from Spoolman."""
|
|
|
await device_factory(device_id="sb-miss")
|
|
await device_factory(device_id="sb-miss")
|
|
|
mock_client = _mock_spoolman_client()
|
|
mock_client = _mock_spoolman_client()
|
|
|
mock_client.get_spool = AsyncMock(side_effect=SpoolmanNotFoundError("Spool 9999 not found"))
|
|
mock_client.get_spool = AsyncMock(side_effect=SpoolmanNotFoundError("Spool 9999 not found"))
|
|
@@ -2246,6 +2246,34 @@ class TestNfcWriteTagSpoolman:
|
|
|
|
|
|
|
|
assert resp.status_code == 404
|
|
assert resp.status_code == 404
|
|
|
|
|
|
|
|
|
|
+ @pytest.mark.asyncio
|
|
|
|
|
+ @pytest.mark.integration
|
|
|
|
|
+ async def test_spoolman_spool_wins_over_a_leftover_built_in_spool(
|
|
|
|
|
+ self, async_client: AsyncClient, device_factory, db_session, spool_factory, spoolman_settings
|
|
|
|
|
+ ):
|
|
|
|
|
+ """Built-in spools are kept after switching to Spoolman; one with the
|
|
|
|
|
+ same id as the Spoolman spool must not be the one written to the tag."""
|
|
|
|
|
+ import json as _json
|
|
|
|
|
+
|
|
|
|
|
+ leftover = await spool_factory(material="PETG")
|
|
|
|
|
+ device = await device_factory(device_id="sb-leftover")
|
|
|
|
|
+ mock_client = _mock_spoolman_client()
|
|
|
|
|
+ mock_client.get_spool = AsyncMock(return_value=_full_spoolman_spool(leftover.id))
|
|
|
|
|
+
|
|
|
|
|
+ with (
|
|
|
|
|
+ patch("backend.app.services.spoolman.get_spoolman_client", AsyncMock(return_value=mock_client)),
|
|
|
|
|
+ patch("backend.app.services.spoolman.init_spoolman_client", AsyncMock(return_value=mock_client)),
|
|
|
|
|
+ ):
|
|
|
|
|
+ resp = await async_client.post(
|
|
|
|
|
+ f"{API}/nfc/write-tag",
|
|
|
|
|
+ json={"device_id": "sb-leftover", "spool_id": leftover.id},
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+ assert resp.status_code == 200, resp.text
|
|
|
|
|
+ mock_client.get_spool.assert_called_once_with(leftover.id)
|
|
|
|
|
+ await db_session.refresh(device)
|
|
|
|
|
+ assert _json.loads(device.pending_write_payload)["data_origin"] == "spoolman"
|
|
|
|
|
+
|
|
|
@pytest.mark.asyncio
|
|
@pytest.mark.asyncio
|
|
|
@pytest.mark.integration
|
|
@pytest.mark.integration
|
|
|
async def test_local_spool_used_when_present(self, async_client: AsyncClient, device_factory, spool_factory):
|
|
async def test_local_spool_used_when_present(self, async_client: AsyncClient, device_factory, spool_factory):
|