Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
KurosawaAngel committed Jan 22, 2025
1 parent 9d7c1df commit b3fab2d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/aiogram_dialog/context/media_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ async def get_media_id(
return None
if cached[1] is not None:
mtime = self._get_file_mtime(path)
if mtime is not None and mtime > cached[1]:
if mtime is not None and mtime != cached[1]:
return None
return cached[0]

Expand Down
22 changes: 14 additions & 8 deletions tests/widgets/media/test_media_storage.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import asyncio
import os
import tempfile

Expand All @@ -10,34 +11,39 @@
@pytest.mark.asyncio
async def test_get_media_id():
manager = MediaIdStorage()
with tempfile.NamedTemporaryFile() as file:
os.fsync(file)
with tempfile.TemporaryDirectory() as d:
filename = os.path.join(d, "file_test") # noqa: PTH118
media_id = await manager.get_media_id(
file.name,
filename,
None,
ContentType.DOCUMENT,
)
assert media_id is None

with open(filename, "w") as file: # noqa: PTH123
file.write("test1")

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

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

file.write(b"new info")
file.flush()
await asyncio.sleep(0.1)

with open(filename, "w") as file: # noqa: PTH123
file.write("test2")

media_id = await manager.get_media_id(
file.name,
filename,
None,
ContentType.DOCUMENT,
)
Expand Down

0 comments on commit b3fab2d

Please sign in to comment.