mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
Add tests for token validator and widget util.
This commit is contained in:
parent
f3580def03
commit
65edaeb2b5
2 changed files with 58 additions and 9 deletions
41
tests/test_token.py
Normal file
41
tests/test_token.py
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
import pytest
|
||||
|
||||
from aiogram.bot import api
|
||||
from aiogram.utils import auth_widget, exceptions
|
||||
|
||||
VALID_TOKEN = '123456789:AABBCCDDEEFFaabbccddeeff-1234567890'
|
||||
INVALID_TOKEN = '123456789:AABBCCDDEEFFaabbccddeeff 123456789' # Space in token and wrong length
|
||||
|
||||
VALID_DATA = {
|
||||
'date': 1525385236,
|
||||
'first_name': 'Test',
|
||||
'last_name': 'User',
|
||||
'id': 123456789,
|
||||
'username': 'username',
|
||||
'hash': '69a9871558fbbe4cd0dbaba52fa1cc4f38315d3245b7504381a64139fb024b5b'
|
||||
}
|
||||
INVALID_DATA = {
|
||||
'date': 1525385237,
|
||||
'first_name': 'Test',
|
||||
'last_name': 'User',
|
||||
'id': 123456789,
|
||||
'username': 'username',
|
||||
'hash': '69a9871558fbbe4cd0dbaba52fa1cc4f38315d3245b7504381a64139fb024b5b'
|
||||
}
|
||||
|
||||
|
||||
def test_valid_token():
|
||||
assert api.check_token(VALID_TOKEN)
|
||||
|
||||
|
||||
def test_invalid_token():
|
||||
with pytest.raises(exceptions.ValidationError):
|
||||
api.check_token(INVALID_TOKEN)
|
||||
|
||||
|
||||
def test_widget():
|
||||
assert auth_widget.check_token(VALID_DATA, VALID_TOKEN)
|
||||
|
||||
|
||||
def test_invalid_widget_data():
|
||||
assert not auth_widget.check_token(INVALID_DATA, VALID_TOKEN)
|
||||
Loading…
Add table
Add a link
Reference in a new issue