| import base64 |
| import os |
| import tempfile |
|
|
| from calendar_out.ics import events_to_ics |
| from server.imageutil import to_data_uri |
| from server.schema import Event |
|
|
| _TINY_PNG = base64.b64decode( |
| "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+M8AAAMBAQDJ/pLvAAAAAElFTkSuQmCC" |
| ) |
|
|
|
|
| def test_ics_has_vevent(): |
| ics = events_to_ics([Event(title="X", start="2026-06-10T13:00:00", end="2026-06-10T14:00:00")]) |
| assert b"BEGIN:VCALENDAR" in ics |
| assert b"BEGIN:VEVENT" in ics |
|
|
|
|
| def test_to_data_uri_png(): |
| p = os.path.join(tempfile.gettempdir(), "ci_tiny.png") |
| with open(p, "wb") as f: |
| f.write(_TINY_PNG) |
| uri = to_data_uri(p) |
| assert uri and uri.startswith("data:image/png;base64,") |
|
|
|
|
| def test_to_data_uri_rejects_non_image(tmp_path): |
| p = tmp_path / "note.txt" |
| p.write_text("hello") |
| assert to_data_uri(str(p)) is None |
|
|