2019-08-16 22:33:19 +03:00
|
|
|
import pytest
|
|
|
|
|
|
2020-11-09 00:34:51 +03:00
|
|
|
from aiogram.utils.auth_widget import (check_integrity, check_token,
|
|
|
|
|
generate_hash)
|
2019-08-16 22:33:19 +03:00
|
|
|
|
2020-11-08 21:49:34 +00:00
|
|
|
TOKEN = "123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11"
|
2019-08-16 22:33:19 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
|
def data():
|
|
|
|
|
return {
|
2020-11-08 21:49:34 +00:00
|
|
|
"id": "42",
|
|
|
|
|
"first_name": "John",
|
|
|
|
|
"last_name": "Smith",
|
|
|
|
|
"username": "username",
|
|
|
|
|
"photo_url": "https://t.me/i/userpic/320/picname.jpg",
|
|
|
|
|
"auth_date": "1565810688",
|
|
|
|
|
"hash": "c303db2b5a06fe41d23a9b14f7c545cfc11dcc7473c07c9c5034ae60062461ce",
|
2019-08-16 22:33:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_generate_hash(data):
|
|
|
|
|
res = generate_hash(data, TOKEN)
|
2020-11-08 21:49:34 +00:00
|
|
|
if res != data["hash"]:
|
2020-11-08 21:48:49 +00:00
|
|
|
raise AssertionError
|
2019-08-16 22:33:19 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class Test_check_token:
|
|
|
|
|
"""
|
|
|
|
|
This case gonna be deleted
|
|
|
|
|
"""
|
2020-11-08 21:49:34 +00:00
|
|
|
|
2020-11-08 21:54:06 +00:00
|
|
|
@staticmethod
|
|
|
|
|
def test_ok(data):
|
2020-11-08 21:48:49 +00:00
|
|
|
if check_token(data, 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_fail(data):
|
2020-11-08 21:49:34 +00:00
|
|
|
data.pop("username")
|
2020-11-08 21:48:49 +00:00
|
|
|
if check_token(data, TOKEN) is not False:
|
|
|
|
|
raise AssertionError
|
2019-08-16 22:33:19 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class Test_check_integrity:
|
2020-11-08 21:54:06 +00:00
|
|
|
@staticmethod
|
|
|
|
|
def test_ok(data):
|
2020-11-08 21:48:49 +00:00
|
|
|
if check_integrity(TOKEN, data) is not True:
|
|
|
|
|
raise AssertionError
|
2019-08-16 22:33:19 +03:00
|
|
|
|
2020-11-08 21:54:06 +00:00
|
|
|
@staticmethod
|
|
|
|
|
def test_fail(data):
|
2020-11-08 21:49:34 +00:00
|
|
|
data.pop("username")
|
2020-11-08 21:48:49 +00:00
|
|
|
if check_integrity(TOKEN, data) is not False:
|
|
|
|
|
raise AssertionError
|