test_queue_target_model_case.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. """A target model is matched without regard to case, as the scheduler does (Q-U8).
  2. The scheduler finds printers for "x1c" among the X1Cs, but adding or editing a
  3. queue job refused the same name ("No active printers for model: x1c"). The job
  4. stores the printer's own spelling, so everything comparing it exactly agrees.
  5. """
  6. import pytest
  7. from sqlalchemy import select
  8. from backend.app.models.print_queue import PrintQueueItem
  9. pytestmark = [pytest.mark.asyncio, pytest.mark.integration]
  10. async def test_adding_a_job_for_a_model_in_lower_case(async_client, db_session, printer_factory, archive_factory):
  11. printer = await printer_factory(model="X1C")
  12. archive = await archive_factory(printer.id)
  13. response = await async_client.post("/api/v1/queue/", json={"archive_id": archive.id, "target_model": "x1c"})
  14. assert response.status_code == 200, response.text
  15. item = await db_session.scalar(select(PrintQueueItem).where(PrintQueueItem.id == response.json()["id"]))
  16. assert item.target_model == "X1C"
  17. async def test_editing_a_job_onto_a_model_in_lower_case(async_client, db_session, printer_factory, archive_factory):
  18. printer = await printer_factory(model="X1C")
  19. archive = await archive_factory(printer.id)
  20. created = await async_client.post("/api/v1/queue/", json={"archive_id": archive.id, "printer_id": printer.id})
  21. response = await async_client.patch(
  22. f"/api/v1/queue/{created.json()['id']}", json={"printer_id": None, "target_model": "x1c"}
  23. )
  24. assert response.status_code == 200, response.text
  25. assert response.json()["target_model"] == "X1C"
  26. async def test_a_model_no_active_printer_has_is_still_refused(async_client, printer_factory, archive_factory):
  27. printer = await printer_factory(model="X1C")
  28. archive = await archive_factory(printer.id)
  29. response = await async_client.post("/api/v1/queue/", json={"archive_id": archive.id, "target_model": "p1s"})
  30. assert response.status_code == 400
  31. @pytest.mark.parametrize(("strategy", "expected"), [("fill_one_first", "pinned"), ("max_parallel", "X1C")])
  32. async def test_a_pipeline_aimed_at_a_model_in_lower_case(db_session, printer_factory, strategy, expected):
  33. from backend.app.api.routes.pipeline_runs import _pick_assignments
  34. from backend.app.models.slicer_pipeline import SlicerPipeline
  35. printer = await printer_factory(model="X1C")
  36. pipeline = SlicerPipeline(target_kind="printer_class", target_model_class="x1c", fanout_strategy=strategy)
  37. assignments = await _pick_assignments(db_session, pipeline, 2)
  38. if expected == "pinned":
  39. assert assignments == [(printer.id, None)] * 2
  40. else:
  41. assert assignments == [(None, "X1C")] * 2