test_github_backup_spool_fields.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. """The spool collector's field whitelist for Git backup (#2870).
  2. ``_collect_spools`` builds an explicit dict per spool, so anything missing
  3. from it is silently absent from the backup and therefore lost on restore.
  4. The owner's own bookkeeping — purchasing number (#2870), category and
  5. low-stock override (#729), free-text storage — belongs in the file.
  6. """
  7. import pytest
  8. from backend.app.models.spool import Spool
  9. from backend.app.services.github_backup import GitHubBackupService
  10. @pytest.mark.asyncio
  11. async def test_collects_the_owners_own_bookkeeping_fields(db_session):
  12. db_session.add(
  13. Spool(
  14. material="PLA",
  15. material_number="15",
  16. category="Production",
  17. low_stock_threshold_pct=40,
  18. storage_location="Shelf B",
  19. )
  20. )
  21. await db_session.commit()
  22. files: dict = {}
  23. await GitHubBackupService()._collect_spools(db_session, files)
  24. entry = files["spools/inventory.json"]["spools"][0]
  25. assert entry["material_number"] == "15"
  26. assert entry["category"] == "Production"
  27. assert entry["low_stock_threshold_pct"] == 40
  28. assert entry["storage_location"] == "Shelf B"
  29. @pytest.mark.asyncio
  30. async def test_location_id_is_left_out(db_session):
  31. """The locations table is not backed up, so the ID has nothing to mean."""
  32. db_session.add(Spool(material="PLA"))
  33. await db_session.commit()
  34. files: dict = {}
  35. await GitHubBackupService()._collect_spools(db_session, files)
  36. assert "location_id" not in files["spools/inventory.json"]["spools"][0]