Skip to content

Commit

Permalink
#10 Created the first test!
Browse files Browse the repository at this point in the history
  • Loading branch information
OrBin committed Mar 16, 2019
1 parent 3d46324 commit aad23ca
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 2 deletions.
Empty file added __init__.py
Empty file.
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from setuptools import setup, find_packages
from setuptools import setup, find_namespace_packages

with open("README.md", "r") as f:
LONG_DESCRIPTION = f.read()
Expand Down Expand Up @@ -35,7 +35,7 @@

keywords='gramhopper telegram bot',

packages=find_packages(),
packages=find_namespace_packages(include=['gramhopper', 'gramhopper.*']),

entry_points={
'console_scripts': [
Expand Down
Empty file added tests/__init__.py
Empty file.
Empty file added tests/triggers/__init__.py
Empty file.
31 changes: 31 additions & 0 deletions tests/triggers/test_text_triggers.py
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 == {}

0 comments on commit aad23ca

Please sign in to comment.