mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-12 10:11:52 +00:00
Tests. Let's start.
This commit is contained in:
parent
104d6d1731
commit
ee84d753c7
3 changed files with 62 additions and 0 deletions
25
tests/dataset.py
Normal file
25
tests/dataset.py
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
UPDATE = {
|
||||||
|
"update_id": 128526,
|
||||||
|
"message": {
|
||||||
|
"message_id": 11223,
|
||||||
|
"from": {
|
||||||
|
"id": 12345678,
|
||||||
|
"is_bot": False,
|
||||||
|
"first_name": "FirstName",
|
||||||
|
"last_name": "LastName",
|
||||||
|
"username": "username",
|
||||||
|
"language_code": "ru"
|
||||||
|
},
|
||||||
|
"chat": {
|
||||||
|
"id": 12345678,
|
||||||
|
"first_name": "FirstName",
|
||||||
|
"last_name": "LastName",
|
||||||
|
"username": "username",
|
||||||
|
"type": "private"
|
||||||
|
},
|
||||||
|
"date": 1508709711,
|
||||||
|
"text": "Hi, world!"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MESSAGE = UPDATE['message']
|
||||||
35
tests/test_message.py
Normal file
35
tests/test_message.py
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
import datetime
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
from aiogram import types
|
||||||
|
from dataset import MESSAGE
|
||||||
|
|
||||||
|
|
||||||
|
class TestMessage(unittest.TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
self.message = types.Message(**MESSAGE)
|
||||||
|
|
||||||
|
def test_update_id(self):
|
||||||
|
self.assertEqual(self.message.message_id, MESSAGE['message_id'], 'test')
|
||||||
|
self.assertEqual(self.message['message_id'], MESSAGE['message_id'])
|
||||||
|
|
||||||
|
def test_from(self):
|
||||||
|
self.assertIsInstance(self.message.from_user, types.User)
|
||||||
|
self.assertEqual(self.message.from_user, self.message['from'])
|
||||||
|
|
||||||
|
def test_chat(self):
|
||||||
|
self.assertIsInstance(self.message.chat, types.Chat)
|
||||||
|
self.assertEqual(self.message.chat, self.message['chat'])
|
||||||
|
|
||||||
|
def test_date(self):
|
||||||
|
self.assertIsInstance(self.message.date, datetime.datetime)
|
||||||
|
self.assertEqual(int(self.message.date.timestamp()), MESSAGE['date'])
|
||||||
|
self.assertEqual(self.message.date, self.message['date'])
|
||||||
|
|
||||||
|
def test_text(self):
|
||||||
|
self.assertEqual(self.message.text, MESSAGE['text'])
|
||||||
|
self.assertEqual(self.message['text'], MESSAGE['text'])
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
||||||
2
tests/utils.py
Normal file
2
tests/utils.py
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
def out(*message, sep=' '):
|
||||||
|
print('Test', sep.join(message))
|
||||||
Loading…
Add table
Add a link
Reference in a new issue