From d1e9334df46482b51c8cc8dd4d6977a8247d1c13 Mon Sep 17 00:00:00 2001 From: Or Bin Date: Sun, 17 Mar 2019 22:00:22 +0200 Subject: [PATCH] #10 Added tests for HasExactWordTrigger --- tests/triggers/test_text_triggers.py | 44 ++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/tests/triggers/test_text_triggers.py b/tests/triggers/test_text_triggers.py index c29b3f5..f5c2ae6 100644 --- a/tests/triggers/test_text_triggers.py +++ b/tests/triggers/test_text_triggers.py @@ -124,6 +124,44 @@ def test_multiple_substrings_not_exact(self, update): @pytest.mark.usefixtures('update') class TestExactWordTrigger: - def test_exact_word_trigger(self, update): - # TODO Write test - pass + def test_single_substring_exact(self, update): + word = 'ello' + trigger = _HasExactWordTrigger(word=word) + + update.message.text = 'ello' + result = trigger.check_trigger(update) + assert result.should_respond + assert 'match' in result.response_payload + match = result.response_payload['match'] + assert len(match) == 1 + assert match[0] == word + + update.message.text = 'hello' + result = trigger.check_trigger(update) + assert not result.should_respond + assert result.response_payload == {} + + def test_multiple_substrings_exact(self, update): + words = ['yellow', 'fellow'] + trigger = _HasExactWordTrigger(word=words) + + update.message.text = 'yellow' + result = trigger.check_trigger(update) + assert result.should_respond + assert 'match' in result.response_payload + match = result.response_payload['match'] + assert len(match) == 1 + assert match[0] in words + + update.message.text = 'fellow' + result = trigger.check_trigger(update) + assert result.should_respond + assert 'match' in result.response_payload + match = result.response_payload['match'] + assert len(match) == 1 + assert match[0] in words + + update.message.text = 'yellowstone' + result = trigger.check_trigger(update) + assert not result.should_respond + assert result.response_payload == {}