예제 #1
0
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
예제 #2
0
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"
예제 #3
0
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
예제 #4
0
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"
예제 #5
0
def test_really_short_message(handler):
    response = handler.handle(create_message("I got 3"), intent={})
    assert response is None
예제 #6
0
def test_only_english(handler):
    response = handler.handle(create_message("Who solved task 3?"), intent={})
    assert response is None
예제 #7
0
def test_german_with_some_english(handler):
    response = handler.handle(create_message("Wer ist bei Among Us dabei?"),
                              intent={})
    assert response is not None
예제 #8
0
def test_only_german(handler):
    response = handler.handle(create_message("Wer hat die Aufgabe 3 gelöst?"),
                              intent={})
    assert response is not None