ai did his job.
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
import pytest
|
||||
|
||||
from favorite_stickers.store import StickerRecord, Store, StoreLockedError
|
||||
|
||||
|
||||
def test_store_finds_sticker_by_original_or_generated_telegram_id(tmp_path) -> None:
|
||||
store = Store(tmp_path / "bot.sqlite3")
|
||||
store.initialize()
|
||||
store.add_pack(7, 1, "favorites_7_by_testbot")
|
||||
record = StickerRecord(
|
||||
user_id=7,
|
||||
pack_name="favorites_7_by_testbot",
|
||||
source_unique_id="original-id",
|
||||
content_hash="abc",
|
||||
sticker_file_id="file-id",
|
||||
sticker_unique_id="generated-id",
|
||||
)
|
||||
store.add_sticker(record)
|
||||
|
||||
assert store.find_sticker(7, telegram_unique_id="original-id") == record
|
||||
assert store.find_sticker(7, telegram_unique_id="generated-id") == record
|
||||
assert store.find_sticker(7, content_hash="abc") == record
|
||||
assert store.find_sticker(8, telegram_unique_id="original-id") is None
|
||||
|
||||
|
||||
def test_removing_sticker_updates_pack_count(tmp_path) -> None:
|
||||
store = Store(tmp_path / "bot.sqlite3")
|
||||
store.initialize()
|
||||
store.add_pack(7, 1, "favorites_7_by_testbot")
|
||||
record = StickerRecord(7, "favorites_7_by_testbot", "src", "abc", "file", "unique")
|
||||
sticker_id = store.add_sticker(record)
|
||||
|
||||
pack = store.latest_pack(7)
|
||||
assert pack is not None
|
||||
assert pack.sticker_count == 1
|
||||
store.remove_sticker(sticker_id)
|
||||
pack = store.latest_pack(7)
|
||||
assert pack is not None
|
||||
assert pack.sticker_count == 0
|
||||
|
||||
|
||||
def test_only_one_store_process_can_own_database(tmp_path) -> None:
|
||||
path = tmp_path / "bot.sqlite3"
|
||||
first = Store(path)
|
||||
first.initialize()
|
||||
second = Store(path)
|
||||
|
||||
with pytest.raises(StoreLockedError, match="запущен"):
|
||||
second.initialize()
|
||||
|
||||
first.close()
|
||||
second.initialize()
|
||||
second.close()
|
||||
Reference in New Issue
Block a user