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
|
|
|
|
|
|
|
|
|
|
VALID_TOKEN = '123456789:AABBCCDDEEFFaabbccddeeff-1234567890'
|
2019-11-23 12:02:30 +03:00
|
|
|
INVALID_TOKENS = [
|
|
|
|
|
'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
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(params=INVALID_TOKENS, name='invalid_token')
|
|
|
|
|
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:
|
2019-08-16 22:33:19 +03:00
|
|
|
|
|
|
|
|
def test_valid(self):
|
|
|
|
|
assert check_token(VALID_TOKEN) is True
|
|
|
|
|
|
2019-11-23 12:02:30 +03:00
|
|
|
def test_invalid_token(self, 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)
|