Skip to content

Commit

Permalink
staging
Browse files Browse the repository at this point in the history
  • Loading branch information
KurosawaAngel committed Jan 21, 2025
1 parent 7607ce9 commit 9d7c1df
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/aiogram_dialog/context/media_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ async def get_media_id(
if not path and not url:
return None
cached = self.cache.get((path, url, type))
if cached is None:
return None
if cached[1] is not None:
mtime = self._get_file_mtime(path)
if mtime is not None and mtime > cached[1]:
Expand Down
44 changes: 44 additions & 0 deletions tests/widgets/media/test_media_storage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import os
import tempfile

import pytest
from aiogram.enums import ContentType

from aiogram_dialog.context.media_storage import MediaIdStorage


@pytest.mark.asyncio
async def test_get_media_id():
manager = MediaIdStorage()
with tempfile.NamedTemporaryFile() as file:
os.fsync(file)
media_id = await manager.get_media_id(
file.name,
None,
ContentType.DOCUMENT,
)
assert media_id is None

await manager.save_media_id(
file.name,
None,
ContentType.DOCUMENT,
"test1",
)

media_id = await manager.get_media_id(
file.name,
None,
ContentType.DOCUMENT,
)
assert media_id == "test1"

file.write(b"new info")
file.flush()

media_id = await manager.get_media_id(
file.name,
None,
ContentType.DOCUMENT,
)
assert media_id is None

0 comments on commit 9d7c1df

Please sign in to comment.