def test_ignore_other_channels(): handler = EchoHandler(channels=["a"]) message = create_message("hello", channel="a") response = handler(message, None) assert response == "hello" message = create_message("hello", channel="b") response = handler(message, None) assert response is None
def test_respond_to_all_channels(): handler = EchoHandler() for channel in ["a", "b", "c", "d"]: message = create_message("hello", channel=channel) response = handler(message, None) assert response == "hello"
def test_ignore_other_intents(): handler = EchoHandler( intents=[IntentName.ask_for_wise_quote, IntentName.play_among_us]) message = create_message("hello", channel="a") assert handler(message, Intent(name=IntentName.ask_for_wise_quote, probability=0.9)) == "hello" message = create_message("hello", channel="a") assert handler(message, Intent(name=IntentName.play_among_us, probability=0.9)) == "hello" message = create_message("hello", channel="a") assert handler(message, Intent(name=IntentName.thank_bot, probability=0.9)) is None
def test_response_timeout(): handler = EchoHandler(timeout=10) now = datetime.now() - timedelta(seconds=11) message = create_message("hello", channel="a", created_at=now) response = handler(message, None) assert response == "hello" message = create_message("hello", channel="a", created_at=now + timedelta(seconds=9)) response = handler(message, None) assert response is None message = create_message("hello", channel="a", created_at=now + timedelta(seconds=11)) response = handler(message, None) assert response == "hello"
def test_really_short_message(handler): response = handler.handle(create_message("I got 3"), intent={}) assert response is None
def test_only_english(handler): response = handler.handle(create_message("Who solved task 3?"), intent={}) assert response is None
def test_german_with_some_english(handler): response = handler.handle(create_message("Wer ist bei Among Us dabei?"), intent={}) assert response is not None
def test_only_german(handler): response = handler.handle(create_message("Wer hat die Aufgabe 3 gelöst?"), intent={}) assert response is not None