test_history_retention_minimum.py 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. """History retention can no longer be set so that it deletes all history.
  2. ``printer_sensor_history_retention_days`` had no UI and, like the AMS one, no
  3. minimum: 0 or less put the daily cleanup's cutoff at now and deleted every row.
  4. Both settings now take at least one day, and the cleanup reads a stored value
  5. the API accepted before as at least one day too.
  6. """
  7. import pytest
  8. from pydantic import ValidationError
  9. from backend.app.main import _retention_days
  10. from backend.app.schemas.settings import AppSettingsUpdate
  11. @pytest.mark.parametrize("key", ["ams_history_retention_days", "printer_sensor_history_retention_days"])
  12. @pytest.mark.parametrize("value", [0, -5])
  13. def test_less_than_a_day_is_refused(key, value):
  14. with pytest.raises(ValidationError):
  15. AppSettingsUpdate(**{key: value})
  16. @pytest.mark.parametrize("key", ["ams_history_retention_days", "printer_sensor_history_retention_days"])
  17. def test_a_day_or_more_is_taken(key):
  18. assert getattr(AppSettingsUpdate(**{key: 1}), key) == 1
  19. @pytest.mark.parametrize(
  20. ("stored", "days"),
  21. [(None, 30), ("90", 90), ("0", 1), ("-3", 1), ("not a number", 30)],
  22. )
  23. def test_the_cleanup_reads_a_stored_value_as_at_least_a_day(stored, days):
  24. assert _retention_days(stored, 30) == days