#238 Added /start Pattern test cases

This commit is contained in:
Oleg A 2019-11-30 00:21:38 +03:00
parent c23c7a2025
commit 5489e4cc18

View file

@ -1,3 +1,6 @@
import re
from typing import Match
import pytest
from aiogram.dispatcher.filters import Text, CommandStart
@ -265,6 +268,8 @@ class TestCommandStart:
START = '/start'
GOOD = 'foo'
BAD = 'bar'
GOOD_PATTERN = re.compile(r'^f..$')
BAD_PATTERN = re.compile(r'^b..$')
ENCODED = 'Zm9v'
async def test_start_command_without_payload(self):
@ -285,6 +290,20 @@ class TestCommandStart:
result = await test_filter.check(message)
assert result is False
async def test_start_command_payload_pattern_is_matched(self):
test_filter = CommandStart(deep_link=self.GOOD_PATTERN)
message = Message(text=f'{self.START} {self.GOOD}')
result = await test_filter.check(message)
assert isinstance(result, dict)
match = result.get('deep_link')
assert isinstance(match, Match)
async def test_start_command_payload_pattern_is_not_matched(self):
test_filter = CommandStart(deep_link=self.BAD_PATTERN)
message = Message(text=f'{self.START} {self.GOOD}')
result = await test_filter.check(message)
assert result is False
async def test_start_command_payload_is_encoded(self):
test_filter = CommandStart(deep_link=self.GOOD, encoded=True)
message = Message(text=f'{self.START} {self.ENCODED}')