-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
33 additions
and
2 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from datetime import datetime | ||
from pytest import fixture | ||
from telegram import Message, User, Chat, Update | ||
from ...gramhopper.triggers.text_triggers import _RegExpTrigger | ||
|
||
|
||
@fixture(scope='module') | ||
def update(): | ||
return Update(0, Message(0, User(0, 'Testuser', False), datetime.now(), | ||
Chat(0, 'private'))) | ||
|
||
|
||
def test_regexp_trigger(update): | ||
EMAIL_PATTERN = '^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$' | ||
trigger = _RegExpTrigger(EMAIL_PATTERN) | ||
|
||
# Assuring that the regexp matches the message text | ||
update.message.text = '[email protected]' | ||
result = trigger.check_trigger(update) | ||
assert result.should_respond | ||
assert 'match' in result.response_payload | ||
match = result.response_payload['match'] | ||
assert match[0] == 'user' | ||
assert match[1] == 'example' | ||
assert match[2] == 'com' | ||
|
||
# Assuring that the regexp doesn't match the message text | ||
update.message.text = '' | ||
result = trigger.check_trigger(update) | ||
assert not result.should_respond | ||
assert result.response_payload == {} |