-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #460 from KurosawaAngel/develop
Add check modified time for path
- Loading branch information
Showing
2 changed files
with
80 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import asyncio | ||
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.TemporaryDirectory() as d: | ||
filename = os.path.join(d, "file_test") # noqa: PTH118 | ||
media_id = await manager.get_media_id( | ||
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( | ||
filename, | ||
None, | ||
ContentType.DOCUMENT, | ||
"test1", | ||
) | ||
|
||
media_id = await manager.get_media_id( | ||
filename, | ||
None, | ||
ContentType.DOCUMENT, | ||
) | ||
assert media_id == "test1" | ||
|
||
await asyncio.sleep(0.1) | ||
|
||
with open(filename, "w") as file: # noqa: PTH123 | ||
file.write("test2") | ||
|
||
media_id = await manager.get_media_id( | ||
filename, | ||
None, | ||
ContentType.DOCUMENT, | ||
) | ||
assert media_id is None |