mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-12 10:11:52 +00:00
[3.x] Bot API 6.0 (#890)
* Base implementation * Bump license * Revert re-generated tests * Fix tests, improved docs * Remove TODO * Removed unreachable code * Changed type of `last_synchronization_error_date` * Fixed wrongly cleaned code
This commit is contained in:
parent
286cf39c8a
commit
497436595d
81 changed files with 1942 additions and 147 deletions
80
tests/test_utils/test_web_app.py
Normal file
80
tests/test_utils/test_web_app.py
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
import pytest
|
||||
|
||||
from aiogram.utils.web_app import (
|
||||
WebAppInitData,
|
||||
check_webapp_signature,
|
||||
parse_webapp_init_data,
|
||||
safe_parse_webapp_init_data,
|
||||
)
|
||||
|
||||
|
||||
class TestWebApp:
|
||||
@pytest.mark.parametrize(
|
||||
"token,case,result",
|
||||
[
|
||||
[
|
||||
"42:TEST",
|
||||
"auth_date=1650385342"
|
||||
"&user=%7B%22id%22%3A42%2C%22first_name%22%3A%22Test%22%7D"
|
||||
"&query_id=test"
|
||||
"&hash=46d2ea5e32911ec8d30999b56247654460c0d20949b6277af519e76271182803",
|
||||
True,
|
||||
],
|
||||
[
|
||||
"42:INVALID",
|
||||
"auth_date=1650385342"
|
||||
"&user=%7B%22id%22%3A42%2C%22first_name%22%3A%22Test%22%7D"
|
||||
"&query_id=test"
|
||||
"&hash=46d2ea5e32911ec8d30999b56247654460c0d20949b6277af519e76271182803",
|
||||
False,
|
||||
],
|
||||
[
|
||||
"42:TEST",
|
||||
"user=%7B%22id%22%3A42%2C%22first_name%22%3A%22Test%22%7D&query_id=test&hash=test",
|
||||
False,
|
||||
],
|
||||
[
|
||||
"42:TEST",
|
||||
"user=%7B%22id%22%3A42%2C%22first_name%22%3A%22Test%22%7D&query_id=test",
|
||||
False,
|
||||
],
|
||||
["42:TEST", "", False],
|
||||
["42:TEST", "test&foo=bar=baz", False],
|
||||
],
|
||||
)
|
||||
def test_check_webapp_signature(self, token, case, result):
|
||||
assert check_webapp_signature(token, case) is result
|
||||
|
||||
def test_parse_web_app_init_data(self):
|
||||
parsed = parse_webapp_init_data(
|
||||
"auth_date=1650385342"
|
||||
"&user=%7B%22id%22%3A42%2C%22first_name%22%3A%22Test%22%7D"
|
||||
"&query_id=test"
|
||||
"&hash=46d2ea5e32911ec8d30999b56247654460c0d20949b6277af519e76271182803",
|
||||
)
|
||||
assert isinstance(parsed, WebAppInitData)
|
||||
assert parsed.user
|
||||
assert parsed.user.first_name == "Test"
|
||||
assert parsed.user.id == 42
|
||||
assert parsed.query_id == "test"
|
||||
assert parsed.hash == "46d2ea5e32911ec8d30999b56247654460c0d20949b6277af519e76271182803"
|
||||
assert parsed.auth_date.year == 2022
|
||||
|
||||
def test_valid_safe_parse_webapp_init_data(self):
|
||||
assert safe_parse_webapp_init_data(
|
||||
"42:TEST",
|
||||
"auth_date=1650385342"
|
||||
"&user=%7B%22id%22%3A42%2C%22first_name%22%3A%22Test%22%7D"
|
||||
"&query_id=test"
|
||||
"&hash=46d2ea5e32911ec8d30999b56247654460c0d20949b6277af519e76271182803",
|
||||
)
|
||||
|
||||
def test_invalid_safe_parse_webapp_init_data(self):
|
||||
with pytest.raises(ValueError):
|
||||
safe_parse_webapp_init_data(
|
||||
"42:TOKEN",
|
||||
"auth_date=1650385342"
|
||||
"&user=%7B%22id%22%3A42%2C%22first_name%22%3A%22Test%22%7D"
|
||||
"&query_id=test"
|
||||
"&hash=test",
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue