test_reslice_archive_status_cost.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. """A re-sliced, never-printed archive reads as not printed and shows a cost.
  2. It was stored with the default status "completed": listed under "Printed" and
  3. counted where completed archives are counted, although nothing was printed.
  4. Unprinted files are "archived" elsewhere (shown as "Not printed"). It also got
  5. grams but no cost, unlike every other archive with grams; the cost is now
  6. priced the same way print start prices it.
  7. """
  8. import pytest
  9. from sqlalchemy import select
  10. from backend.app.models.archive import PrintArchive
  11. from backend.tests.integration.test_slice_archive_output_path_2832 import _slice, archive_root # noqa: F401
  12. pytestmark = [pytest.mark.integration, pytest.mark.asyncio]
  13. async def _resliced(db_session, response):
  14. return await db_session.scalar(select(PrintArchive).where(PrintArchive.id == response.archive_id))
  15. async def test_it_is_not_printed(db_session, archive_factory, printer_factory, archive_root): # noqa: F811
  16. printer = await printer_factory()
  17. source = await archive_factory(printer.id, print_name="Bracket", filename="Bracket.3mf")
  18. archive = await _resliced(db_session, await _slice(db_session, source, "Bracket.3mf"))
  19. assert archive.status == "archived"
  20. assert (archive.started_at, archive.completed_at) == (None, None)
  21. async def test_it_is_priced_like_a_printed_archive(db_session, archive_factory, printer_factory, archive_root): # noqa: F811
  22. """12.5 g at the default 25 per kg; no filament of that type is on record."""
  23. printer = await printer_factory()
  24. source = await archive_factory(printer.id, print_name="Bracket", filename="Bracket.3mf", filament_type="PLA")
  25. archive = await _resliced(db_session, await _slice(db_session, source, "Bracket.3mf"))
  26. assert archive.filament_used_grams == 12.5
  27. assert archive.cost == pytest.approx(0.31)
  28. async def test_the_filament_on_record_sets_the_price(db_session, archive_factory, printer_factory, archive_root): # noqa: F811
  29. from backend.app.models.filament import Filament
  30. db_session.add(Filament(name="House PLA", type="PLA", cost_per_kg=40.0))
  31. await db_session.commit()
  32. printer = await printer_factory()
  33. source = await archive_factory(printer.id, print_name="Bracket", filename="Bracket.3mf", filament_type="PLA")
  34. archive = await _resliced(db_session, await _slice(db_session, source, "Bracket.3mf"))
  35. assert archive.cost == pytest.approx(0.5)