test_maintenance_log_csv.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. """Free text in the maintenance log CSV stays text in a spreadsheet.
  2. Comments, printer, task and user names are typed by people and may be opened
  3. in Excel or LibreOffice by someone else; a cell a spreadsheet would run as a
  4. formula gets a leading quote. Old comments copied in on upgrade were never
  5. trimmed, so leading whitespace and line breaks are looked past too.
  6. """
  7. from __future__ import annotations
  8. import pytest
  9. from backend.app.services.export import _spreadsheet_text
  10. @pytest.mark.parametrize(
  11. ("value", "expected"),
  12. [
  13. ("plain note", "plain note"),
  14. ("a = b", "a = b"),
  15. ("=1+1", "'=1+1"),
  16. ("+49 123", "'+49 123"),
  17. ("-0.2 mm offset", "'-0.2 mm offset"),
  18. ("@SUM(A1)", "'@SUM(A1)"),
  19. (" =1+1", "' =1+1"),
  20. ("\n=1+1", "'\n=1+1"),
  21. ("\r\nnote", "'\r\nnote"),
  22. ("\tnote", "'\tnote"),
  23. ("=HYPERLINK(1)", "'=HYPERLINK(1)"),
  24. ("@SUM(A1)", "'@SUM(A1)"),
  25. ("", ""),
  26. (None, None), # written as an empty cell by the csv writer
  27. ],
  28. )
  29. def test_a_formula_like_cell_gets_a_leading_quote(value, expected):
  30. assert _spreadsheet_text(value) == expected