mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-08 17:13:56 +00:00
Move tests of types to test/types/ directory.
This commit is contained in:
parent
b178f3ad0d
commit
997d5b4181
10 changed files with 0 additions and 0 deletions
0
tests/types/__init__.py
Normal file
0
tests/types/__init__.py
Normal file
75
tests/types/dataset.py
Normal file
75
tests/types/dataset.py
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
USER = {
|
||||
"id": 12345678,
|
||||
"is_bot": False,
|
||||
"first_name": "FirstName",
|
||||
"last_name": "LastName",
|
||||
"username": "username",
|
||||
"language_code": "ru-RU"
|
||||
}
|
||||
|
||||
CHAT = {
|
||||
"id": 12345678,
|
||||
"first_name": "FirstName",
|
||||
"last_name": "LastName",
|
||||
"username": "username",
|
||||
"type": "private"
|
||||
}
|
||||
|
||||
MESSAGE = {
|
||||
"message_id": 11223,
|
||||
"from": USER,
|
||||
"chat": CHAT,
|
||||
"date": 1508709711,
|
||||
"text": "Hi, world!"
|
||||
}
|
||||
|
||||
DOCUMENT = {
|
||||
"file_name": "test.docx",
|
||||
"mime_type": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
||||
"file_id": "BQADAgADpgADy_JxS66XQTBRHFleAg",
|
||||
"file_size": 21331
|
||||
}
|
||||
|
||||
MESSAGE_WITH_DOCUMENT = {
|
||||
"message_id": 12345,
|
||||
"from": USER,
|
||||
"chat": CHAT,
|
||||
"date": 1508768012,
|
||||
"document": DOCUMENT,
|
||||
"caption": "doc description"
|
||||
}
|
||||
|
||||
UPDATE = {
|
||||
"update_id": 128526,
|
||||
"message": MESSAGE
|
||||
}
|
||||
|
||||
PHOTO = {
|
||||
"file_id": "AgADBAADFak0G88YZAf8OAug7bHyS9x2ZxkABHVfpJywcloRAAGAAQABAg",
|
||||
"file_size": 1101,
|
||||
"width": 90,
|
||||
"height": 51
|
||||
}
|
||||
|
||||
ANIMATION = {
|
||||
"file_name": "a9b0e0ca537aa344338f80978f0896b7.gif.mp4",
|
||||
"mime_type": "video/mp4",
|
||||
"thumb": PHOTO,
|
||||
"file_id": "CgADBAAD4DUAAoceZAe2WiE9y0crrAI",
|
||||
"file_size": 65837
|
||||
}
|
||||
|
||||
GAME = {
|
||||
"title": "Karate Kido",
|
||||
"description": "No trees were harmed in the making of this game :)",
|
||||
"photo": [PHOTO, PHOTO, PHOTO],
|
||||
"animation": ANIMATION
|
||||
}
|
||||
|
||||
MESSAGE_WITH_GAME = {
|
||||
"message_id": 12345,
|
||||
"from": USER,
|
||||
"chat": CHAT,
|
||||
"date": 1508824810,
|
||||
"game": GAME
|
||||
}
|
||||
39
tests/types/test_animation.py
Normal file
39
tests/types/test_animation.py
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
from aiogram import types
|
||||
from .dataset import ANIMATION
|
||||
|
||||
animation = types.Animation(**ANIMATION)
|
||||
|
||||
|
||||
def test_export():
|
||||
exported = animation.to_python()
|
||||
assert isinstance(exported, dict)
|
||||
assert exported == ANIMATION
|
||||
|
||||
|
||||
def test_file_name():
|
||||
assert isinstance(animation.file_name, str)
|
||||
assert animation.file_name == ANIMATION['file_name']
|
||||
|
||||
|
||||
def test_mime_type():
|
||||
assert isinstance(animation.mime_type, str)
|
||||
assert animation.mime_type == ANIMATION['mime_type']
|
||||
|
||||
|
||||
def test_file_id():
|
||||
assert isinstance(animation.file_id, str)
|
||||
# assert hash(animation) == ANIMATION['file_id']
|
||||
assert animation.file_id == ANIMATION['file_id']
|
||||
|
||||
|
||||
def test_file_size():
|
||||
assert isinstance(animation.file_size, int)
|
||||
assert animation.file_size == ANIMATION['file_size']
|
||||
|
||||
|
||||
def test_thumb():
|
||||
assert isinstance(animation.thumb, types.PhotoSize)
|
||||
assert animation.thumb.file_id == ANIMATION['thumb']['file_id']
|
||||
assert animation.thumb.width == ANIMATION['thumb']['width']
|
||||
assert animation.thumb.height == ANIMATION['thumb']['height']
|
||||
assert animation.thumb.file_size == ANIMATION['thumb']['file_size']
|
||||
61
tests/types/test_chat.py
Normal file
61
tests/types/test_chat.py
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
from aiogram import types
|
||||
from .dataset import CHAT
|
||||
|
||||
chat = types.Chat(**CHAT)
|
||||
|
||||
|
||||
def test_export():
|
||||
exported = chat.to_python()
|
||||
assert isinstance(exported, dict)
|
||||
assert exported == CHAT
|
||||
|
||||
|
||||
def test_id():
|
||||
assert isinstance(chat.id, int)
|
||||
assert chat.id == CHAT['id']
|
||||
assert hash(chat) == CHAT['id']
|
||||
|
||||
|
||||
def test_name():
|
||||
assert isinstance(chat.first_name, str)
|
||||
assert chat.first_name == CHAT['first_name']
|
||||
|
||||
assert isinstance(chat.last_name, str)
|
||||
assert chat.last_name == CHAT['last_name']
|
||||
|
||||
assert isinstance(chat.username, str)
|
||||
assert chat.username == CHAT['username']
|
||||
|
||||
|
||||
def test_type():
|
||||
assert isinstance(chat.type, str)
|
||||
assert chat.type == CHAT['type']
|
||||
|
||||
|
||||
def test_chat_types():
|
||||
assert types.ChatType.PRIVATE == 'private'
|
||||
assert types.ChatType.GROUP == 'group'
|
||||
assert types.ChatType.SUPER_GROUP == 'supergroup'
|
||||
assert types.ChatType.CHANNEL == 'channel'
|
||||
|
||||
|
||||
def test_chat_type_filters():
|
||||
from . import test_message
|
||||
assert types.ChatType.is_private(test_message.message)
|
||||
assert not types.ChatType.is_group(test_message.message)
|
||||
assert not types.ChatType.is_super_group(test_message.message)
|
||||
assert not types.ChatType.is_group_or_super_group(test_message.message)
|
||||
assert not types.ChatType.is_channel(test_message.message)
|
||||
|
||||
|
||||
def test_chat_actions():
|
||||
assert types.ChatActions.TYPING == 'typing'
|
||||
assert types.ChatActions.UPLOAD_PHOTO == 'upload_photo'
|
||||
assert types.ChatActions.RECORD_VIDEO == 'record_video'
|
||||
assert types.ChatActions.UPLOAD_VIDEO == 'upload_video'
|
||||
assert types.ChatActions.RECORD_AUDIO == 'record_audio'
|
||||
assert types.ChatActions.UPLOAD_AUDIO == 'upload_audio'
|
||||
assert types.ChatActions.UPLOAD_DOCUMENT == 'upload_document'
|
||||
assert types.ChatActions.FIND_LOCATION == 'find_location'
|
||||
assert types.ChatActions.RECORD_VIDEO_NOTE == 'record_video_note'
|
||||
assert types.ChatActions.UPLOAD_VIDEO_NOTE == 'upload_video_note'
|
||||
35
tests/types/test_document.py
Normal file
35
tests/types/test_document.py
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
from aiogram import types
|
||||
from .dataset import DOCUMENT
|
||||
|
||||
document = types.Document(**DOCUMENT)
|
||||
|
||||
|
||||
def test_export():
|
||||
exported = document.to_python()
|
||||
assert isinstance(exported, dict)
|
||||
assert exported == DOCUMENT
|
||||
|
||||
|
||||
def test_file_name():
|
||||
assert isinstance(document.file_name, str)
|
||||
assert document.file_name == DOCUMENT['file_name']
|
||||
|
||||
|
||||
def test_mime_type():
|
||||
assert isinstance(document.mime_type, str)
|
||||
assert document.mime_type == DOCUMENT['mime_type']
|
||||
|
||||
|
||||
def test_file_id():
|
||||
assert isinstance(document.file_id, str)
|
||||
# assert hash(document) == DOCUMENT['file_id']
|
||||
assert document.file_id == DOCUMENT['file_id']
|
||||
|
||||
|
||||
def test_file_size():
|
||||
assert isinstance(document.file_size, int)
|
||||
assert document.file_size == DOCUMENT['file_size']
|
||||
|
||||
|
||||
def test_thumb():
|
||||
assert document.thumb is None
|
||||
29
tests/types/test_game.py
Normal file
29
tests/types/test_game.py
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
from aiogram import types
|
||||
from .dataset import GAME
|
||||
|
||||
game = types.Game(**GAME)
|
||||
|
||||
def test_export():
|
||||
exported = game.to_python()
|
||||
assert isinstance(exported, dict)
|
||||
assert exported == GAME
|
||||
|
||||
|
||||
def test_title():
|
||||
assert isinstance(game.title, str)
|
||||
assert game.title == GAME['title']
|
||||
|
||||
|
||||
def test_description():
|
||||
assert isinstance(game.description, str)
|
||||
assert game.description == GAME['description']
|
||||
|
||||
|
||||
def test_photo():
|
||||
assert isinstance(game.photo, list)
|
||||
assert len(game.photo) == len(GAME['photo'])
|
||||
assert all(map(lambda t: isinstance(t, types.PhotoSize), game.photo))
|
||||
|
||||
|
||||
def test_animation():
|
||||
assert isinstance(game.animation, types.Animation)
|
||||
39
tests/types/test_message.py
Normal file
39
tests/types/test_message.py
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
import datetime
|
||||
|
||||
from aiogram import types
|
||||
from .dataset import MESSAGE
|
||||
|
||||
message = types.Message(**MESSAGE)
|
||||
|
||||
|
||||
def test_export():
|
||||
exported_chat = message.to_python()
|
||||
assert isinstance(exported_chat, dict)
|
||||
assert exported_chat == MESSAGE
|
||||
|
||||
|
||||
def test_message_id():
|
||||
assert hash(message) == MESSAGE['message_id']
|
||||
assert message.message_id == MESSAGE['message_id']
|
||||
assert message['message_id'] == MESSAGE['message_id']
|
||||
|
||||
|
||||
def test_from():
|
||||
assert isinstance(message.from_user, types.User)
|
||||
assert message.from_user == message['from']
|
||||
|
||||
|
||||
def test_chat():
|
||||
assert isinstance(message.chat, types.Chat)
|
||||
assert message.chat == message['chat']
|
||||
|
||||
|
||||
def test_date():
|
||||
assert isinstance(message.date, datetime.datetime)
|
||||
assert int(message.date.timestamp()) == MESSAGE['date']
|
||||
assert message.date == message['date']
|
||||
|
||||
|
||||
def test_text():
|
||||
assert message.text == MESSAGE['text']
|
||||
assert message['text'] == MESSAGE['text']
|
||||
27
tests/types/test_photo.py
Normal file
27
tests/types/test_photo.py
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
from aiogram import types
|
||||
from .dataset import PHOTO
|
||||
|
||||
photo = types.PhotoSize(**PHOTO)
|
||||
|
||||
|
||||
def test_export():
|
||||
exported = photo.to_python()
|
||||
assert isinstance(exported, dict)
|
||||
assert exported == PHOTO
|
||||
|
||||
|
||||
def test_file_id():
|
||||
assert isinstance(photo.file_id, str)
|
||||
assert photo.file_id == PHOTO['file_id']
|
||||
|
||||
|
||||
def test_file_size():
|
||||
assert isinstance(photo.file_size, int)
|
||||
assert photo.file_size == PHOTO['file_size']
|
||||
|
||||
|
||||
def test_size():
|
||||
assert isinstance(photo.width, int)
|
||||
assert isinstance(photo.height, int)
|
||||
assert photo.width == PHOTO['width']
|
||||
assert photo.height == PHOTO['height']
|
||||
20
tests/types/test_update.py
Normal file
20
tests/types/test_update.py
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
from aiogram import types
|
||||
from .dataset import UPDATE
|
||||
|
||||
update = types.Update(**UPDATE)
|
||||
|
||||
|
||||
def test_export():
|
||||
exported = update.to_python()
|
||||
assert isinstance(exported, dict)
|
||||
assert exported == UPDATE
|
||||
|
||||
|
||||
def test_update_id():
|
||||
assert isinstance(update.update_id, int)
|
||||
assert hash(update) == UPDATE['update_id']
|
||||
assert update.update_id == UPDATE['update_id']
|
||||
|
||||
|
||||
def test_message():
|
||||
assert isinstance(update.message, types.Message)
|
||||
48
tests/types/test_user.py
Normal file
48
tests/types/test_user.py
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
from babel import Locale
|
||||
|
||||
from aiogram import types
|
||||
from .dataset import USER
|
||||
|
||||
user = types.User(**USER)
|
||||
|
||||
|
||||
def test_export():
|
||||
exported = user.to_python()
|
||||
assert isinstance(exported, dict)
|
||||
assert exported == USER
|
||||
|
||||
|
||||
def test_id():
|
||||
assert isinstance(user.id, int)
|
||||
assert user.id == USER['id']
|
||||
assert hash(user) == USER['id']
|
||||
|
||||
|
||||
def test_bot():
|
||||
assert isinstance(user.is_bot, bool)
|
||||
assert user.is_bot == USER['is_bot']
|
||||
|
||||
|
||||
def test_name():
|
||||
assert user.first_name == USER['first_name']
|
||||
assert user.last_name == USER['last_name']
|
||||
assert user.username == USER['username']
|
||||
|
||||
|
||||
def test_language_code():
|
||||
assert user.language_code == USER['language_code']
|
||||
assert user.locale == Locale.parse(USER['language_code'], sep='-')
|
||||
|
||||
|
||||
def test_full_name():
|
||||
assert user.full_name == f"{USER['first_name']} {USER['last_name']}"
|
||||
|
||||
|
||||
def test_mention():
|
||||
assert user.mention == f"@{USER['username']}"
|
||||
assert user.get_mention('foo') == f"[foo](tg://user?id={USER['id']})"
|
||||
assert user.get_mention('foo', as_html=True) == f"<a href=\"tg://user?id={USER['id']}\">foo</a>"
|
||||
|
||||
|
||||
def test_url():
|
||||
assert user.url == f"tg://user?id={USER['id']}"
|
||||
Loading…
Add table
Add a link
Reference in a new issue