2019-08-16 22:33:19 +03:00
|
|
|
import pytest
|
|
|
|
|
|
2019-11-23 12:02:30 +03:00
|
|
|
from aiogram.bot.api import check_token
|
2019-08-16 22:33:19 +03:00
|
|
|
from aiogram.utils.exceptions import ValidationError
|
|
|
|
|
|
2020-11-08 21:49:34 +00:00
|
|
|
VALID_TOKEN = "123456789:AABBCCDDEEFFaabbccddeeff-1234567890"
|
2019-11-23 12:02:30 +03:00
|
|
|
INVALID_TOKENS = [
|
2020-11-08 21:49:34 +00:00
|
|
|
"123456789:AABBCCDDEEFFaabbccddeeff 123456789", # space is exists
|
|
|
|
|
"ABC:AABBCCDDEEFFaabbccddeeff123456789", # left part is not digit
|
|
|
|
|
":AABBCCDDEEFFaabbccddeeff123456789", # there is no left part
|
|
|
|
|
"123456789:", # there is no right part
|
|
|
|
|
"ABC AABBCCDDEEFFaabbccddeeff123456789", # there is no ':' separator
|
2019-11-23 12:45:47 +03:00
|
|
|
None, # is None
|
|
|
|
|
12345678, # is digit
|
|
|
|
|
{}, # is dict
|
|
|
|
|
[], # is dict
|
2019-11-23 12:02:30 +03:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
2020-11-08 21:49:34 +00:00
|
|
|
@pytest.fixture(params=INVALID_TOKENS, name="invalid_token")
|
2019-11-23 12:02:30 +03:00
|
|
|
def invalid_token_fixture(request):
|
|
|
|
|
return request.param
|
2019-08-16 22:33:19 +03:00
|
|
|
|
|
|
|
|
|
2019-11-23 12:02:30 +03:00
|
|
|
class TestCheckToken:
|
2020-11-08 21:54:06 +00:00
|
|
|
@staticmethod
|
|
|
|
|
def test_valid():
|
2020-11-08 21:48:49 +00:00
|
|
|
if check_token(VALID_TOKEN) is not True:
|
|
|
|
|
raise AssertionError
|
2019-08-16 22:33:19 +03:00
|
|
|
|
2020-11-08 21:54:06 +00:00
|
|
|
@staticmethod
|
|
|
|
|
def test_invalid_token(invalid_token):
|
2019-08-16 22:33:19 +03:00
|
|
|
with pytest.raises(ValidationError):
|
2019-11-23 12:02:30 +03:00
|
|
|
check_token(invalid_token)
|