aiogram/tests/test_utils/test_deep_linking.py
deepsource-autofix[bot] af4ceef153
Format code with black, autopep8 and isort
This commit fixes the style issues introduced in dd50a9b according to the output
from black, autopep8 and isort.

Details: 4e472085-2e87-4f61-b7a1-ed208506962f/
2020-11-08 21:49:34 +00:00

80 lines
2.3 KiB
Python

import pytest
from aiogram.utils.deep_linking import (decode_payload, encode_payload,
filter_payload, get_start_link,
get_startgroup_link)
from tests.types import dataset
# enable asyncio mode
pytestmark = pytest.mark.asyncio
PAYLOADS = [
"foo",
"AAbbCCddEEff1122334455",
"aaBBccDDeeFF5544332211",
-12345678901234567890,
12345678901234567890,
]
WRONG_PAYLOADS = [
"@BotFather",
"spaces spaces spaces",
1234567890123456789.0,
]
@pytest.fixture(params=PAYLOADS, name="payload")
def payload_fixture(request):
return request.param
@pytest.fixture(params=WRONG_PAYLOADS, name="wrong_payload")
def wrong_payload_fixture(request):
return request.param
@pytest.fixture(autouse=True)
def get_bot_user_fixture(monkeypatch):
""" Monkey patching of bot.me calling. """
from aiogram.utils import deep_linking
async def get_bot_user_mock():
from aiogram.types import User
return User(**dataset.USER)
monkeypatch.setattr(deep_linking, "_get_bot_user", get_bot_user_mock)
class TestDeepLinking:
async def test_get_start_link(self, payload):
link = await get_start_link(payload)
if link != f'https://t.me/{dataset.USER["username"]}?start={payload}':
raise AssertionError
async def test_wrong_symbols(self, wrong_payload):
with pytest.raises(ValueError):
await get_start_link(wrong_payload)
async def test_get_startgroup_link(self, payload):
link = await get_startgroup_link(payload)
if link != f'https://t.me/{dataset.USER["username"]}?startgroup={payload}':
raise AssertionError
async def test_filter_encode_and_decode(self, payload):
_payload = filter_payload(payload)
encoded = encode_payload(_payload)
decoded = decode_payload(encoded)
if decoded != str(payload):
raise AssertionError
async def test_get_start_link_with_encoding(self, payload):
# define link
link = await get_start_link(payload, encode=True)
# define reference link
payload = filter_payload(payload)
encoded_payload = encode_payload(payload)
if link != f'https://t.me/{dataset.USER["username"]}?start={encoded_payload}':
raise AssertionError