mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
Fix: default parent for __setitem__ (#806)
* fix: self is default parent * chore: mv bot fixture * chore: add update_chat test * fix: string CHAT_PHOTO data
This commit is contained in:
parent
b39672f9b6
commit
24e933bdde
7 changed files with 74 additions and 28 deletions
|
|
@ -240,7 +240,7 @@ class TelegramObject(ContextInstanceMixin, metaclass=MetaTelegramObject):
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
if key in self.props:
|
if key in self.props:
|
||||||
return self.props[key].set_value(self, value, self.conf.get('parent', None))
|
return self.props[key].set_value(self, value, self.conf.get('parent', self))
|
||||||
self.values[key] = value
|
self.values[key] = value
|
||||||
|
|
||||||
# Log warning when Telegram silently adds new Fields
|
# Log warning when Telegram silently adds new Fields
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,12 @@
|
||||||
|
import asyncio
|
||||||
|
|
||||||
import aioredis
|
import aioredis
|
||||||
import pytest
|
import pytest
|
||||||
from _pytest.config import UsageError
|
from _pytest.config import UsageError
|
||||||
|
|
||||||
|
from aiogram import Bot
|
||||||
|
from . import TOKEN
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import aioredis.util
|
import aioredis.util
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
|
@ -72,3 +77,14 @@ def redis_options(request):
|
||||||
raise UsageError(f"Invalid redis URI {redis_uri!r}: {e}")
|
raise UsageError(f"Invalid redis URI {redis_uri!r}: {e}")
|
||||||
|
|
||||||
raise UsageError("Unsupported aioredis version")
|
raise UsageError("Unsupported aioredis version")
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(name='bot')
|
||||||
|
async def bot_fixture():
|
||||||
|
"""Bot fixture."""
|
||||||
|
bot = Bot(TOKEN)
|
||||||
|
yield bot
|
||||||
|
session = await bot.get_session()
|
||||||
|
if session and not session.closed:
|
||||||
|
await session.close()
|
||||||
|
await asyncio.sleep(0.2)
|
||||||
|
|
|
||||||
|
|
@ -6,14 +6,6 @@ from . import FakeTelegram, TOKEN, BOT_ID
|
||||||
pytestmark = pytest.mark.asyncio
|
pytestmark = pytest.mark.asyncio
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name='bot')
|
|
||||||
async def bot_fixture():
|
|
||||||
""" Bot fixture """
|
|
||||||
_bot = Bot(TOKEN, parse_mode=types.ParseMode.MARKDOWN_V2)
|
|
||||||
yield _bot
|
|
||||||
await _bot.close()
|
|
||||||
|
|
||||||
|
|
||||||
async def test_get_me(bot: Bot):
|
async def test_get_me(bot: Bot):
|
||||||
""" getMe method test """
|
""" getMe method test """
|
||||||
from .types.dataset import USER
|
from .types.dataset import USER
|
||||||
|
|
|
||||||
|
|
@ -5,14 +5,6 @@ from aiogram import Dispatcher, Bot
|
||||||
pytestmark = pytest.mark.asyncio
|
pytestmark = pytest.mark.asyncio
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name='bot')
|
|
||||||
async def bot_fixture():
|
|
||||||
""" Bot fixture """
|
|
||||||
_bot = Bot(token='123456789:AABBCCDDEEFFaabbccddeeff-1234567890')
|
|
||||||
yield _bot
|
|
||||||
await _bot.close()
|
|
||||||
|
|
||||||
|
|
||||||
class TestDispatcherInit:
|
class TestDispatcherInit:
|
||||||
async def test_successful_init(self, bot):
|
async def test_successful_init(self, bot):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -8,16 +8,8 @@ from . import FakeTelegram, TOKEN
|
||||||
pytestmark = pytest.mark.asyncio
|
pytestmark = pytest.mark.asyncio
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name='bot')
|
|
||||||
async def bot_fixture():
|
|
||||||
""" Bot fixture """
|
|
||||||
_bot = Bot(TOKEN, parse_mode=types.ParseMode.HTML)
|
|
||||||
yield _bot
|
|
||||||
await _bot.close()
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture()
|
@pytest.fixture()
|
||||||
async def message(bot):
|
async def message(bot: Bot):
|
||||||
"""
|
"""
|
||||||
Message fixture
|
Message fixture
|
||||||
:param bot: Telegram bot fixture
|
:param bot: Telegram bot fixture
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,14 @@ CHAT = {
|
||||||
"type": "private",
|
"type": "private",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CHAT_PHOTO = {
|
||||||
|
"small_file_id": "small_file_id",
|
||||||
|
"small_file_unique_id": "small_file_unique_id",
|
||||||
|
"big_file_id": "big_file_id",
|
||||||
|
"big_file_unique_id": "big_file_unique_id",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
PHOTO = {
|
PHOTO = {
|
||||||
"file_id": "AgADBAADFak0G88YZAf8OAug7bHyS9x2ZxkABHVfpJywcloRAAGAAQABAg",
|
"file_id": "AgADBAADFak0G88YZAf8OAug7bHyS9x2ZxkABHVfpJywcloRAAGAAQABAg",
|
||||||
"file_size": 1101,
|
"file_size": 1101,
|
||||||
|
|
@ -485,3 +493,37 @@ REPLY_KEYBOARD_MARKUP = {
|
||||||
"keyboard": [[{"text": "something here"}]],
|
"keyboard": [[{"text": "something here"}]],
|
||||||
"resize_keyboard": True,
|
"resize_keyboard": True,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CHAT_PERMISSIONS = {
|
||||||
|
"can_send_messages": True,
|
||||||
|
"can_send_media_messages": True,
|
||||||
|
"can_send_polls": True,
|
||||||
|
"can_send_other_messages": True,
|
||||||
|
"can_add_web_page_previews": True,
|
||||||
|
"can_change_info": True,
|
||||||
|
"can_invite_users": True,
|
||||||
|
"can_pin_messages": True,
|
||||||
|
}
|
||||||
|
|
||||||
|
CHAT_LOCATION = {
|
||||||
|
"location": LOCATION,
|
||||||
|
"address": "address",
|
||||||
|
}
|
||||||
|
|
||||||
|
FULL_CHAT = {
|
||||||
|
**CHAT,
|
||||||
|
"photo": CHAT_PHOTO,
|
||||||
|
"bio": "bio",
|
||||||
|
"has_private_forwards": False,
|
||||||
|
"description": "description",
|
||||||
|
"invite_link": "invite_link",
|
||||||
|
"pinned_message": MESSAGE,
|
||||||
|
"permissions": CHAT_PERMISSIONS,
|
||||||
|
"slow_mode_delay": 10,
|
||||||
|
"message_auto_delete_time": 60,
|
||||||
|
"has_protected_content": True,
|
||||||
|
"sticker_set_name": "sticker_set_name",
|
||||||
|
"can_set_sticker_set": True,
|
||||||
|
"linked_chat_id": -1234567890,
|
||||||
|
"location": CHAT_LOCATION,
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,10 @@
|
||||||
from aiogram import types
|
import pytest
|
||||||
from .dataset import CHAT
|
|
||||||
|
from aiogram import Bot, types
|
||||||
|
from .dataset import CHAT, FULL_CHAT
|
||||||
|
from .. import FakeTelegram
|
||||||
|
|
||||||
|
pytestmark = pytest.mark.asyncio
|
||||||
|
|
||||||
chat = types.Chat(**CHAT)
|
chat = types.Chat(**CHAT)
|
||||||
|
|
||||||
|
|
@ -59,3 +64,10 @@ def test_chat_actions():
|
||||||
assert types.ChatActions.FIND_LOCATION == 'find_location'
|
assert types.ChatActions.FIND_LOCATION == 'find_location'
|
||||||
assert types.ChatActions.RECORD_VIDEO_NOTE == 'record_video_note'
|
assert types.ChatActions.RECORD_VIDEO_NOTE == 'record_video_note'
|
||||||
assert types.ChatActions.UPLOAD_VIDEO_NOTE == 'upload_video_note'
|
assert types.ChatActions.UPLOAD_VIDEO_NOTE == 'upload_video_note'
|
||||||
|
|
||||||
|
|
||||||
|
async def test_update_chat(bot: Bot):
|
||||||
|
Bot.set_current(bot)
|
||||||
|
async with FakeTelegram(message_data=FULL_CHAT):
|
||||||
|
await chat.update_chat()
|
||||||
|
assert chat.to_python() == types.Chat(**FULL_CHAT).to_python()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue