test_timelapse_changes_announced.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. """Every change to an archive's timelapse tells open Archives pages (TL-5).
  2. Only the automatic scan sent ``archive_updated``. A video attached any other
  3. way (picked or uploaded by hand, the external camera's, the MP4 conversion)
  4. or deleted showed on other open pages only once they refetched.
  5. """
  6. from unittest.mock import AsyncMock, patch
  7. import pytest
  8. pytestmark = [pytest.mark.asyncio, pytest.mark.integration]
  9. async def test_an_attach_is_announced(db_session, archive_factory, printer_factory, tmp_path, monkeypatch):
  10. from backend.app.core.config import settings as app_config
  11. from backend.app.services.archive import ArchiveService
  12. monkeypatch.setattr(app_config, "base_dir", tmp_path)
  13. monkeypatch.setattr(app_config, "archive_dir", tmp_path / "archive")
  14. printer = await printer_factory()
  15. archive = await archive_factory(printer.id)
  16. announce = AsyncMock()
  17. with patch("backend.app.services.archive._announce_timelapse", announce):
  18. assert await ArchiveService(db_session).attach_timelapse(archive.id, b"video", "clip.mp4")
  19. announce.assert_awaited_once_with(archive.id, attached=True)
  20. async def test_a_delete_is_announced(async_client, db_session, archive_factory, printer_factory, tmp_path, monkeypatch):
  21. from backend.app.core.config import settings as app_config
  22. monkeypatch.setattr(app_config, "base_dir", tmp_path)
  23. printer = await printer_factory()
  24. archive = await archive_factory(printer.id, timelapse_path="archive/x/clip.mp4")
  25. announce = AsyncMock()
  26. with patch("backend.app.services.archive._announce_timelapse", announce):
  27. response = await async_client.delete(f"/api/v1/archives/{archive.id}/timelapse")
  28. assert response.status_code == 200, response.text
  29. announce.assert_awaited_once_with(archive.id, attached=False)