| 1 |
from os import path |
| 2 |
from queue import Empty |
| 3 |
|
| 4 |
import pytest |
| 5 |
|
| 6 |
extra_plugin_dir = path.join(path.dirname(path.realpath(__file__)), "flow_plugin") |
| 7 |
|
| 8 |
|
| 9 |
def test_list_flows(testbot): |
| 10 |
assert len(testbot.bot.flow_executor.flow_roots) == 4 |
| 11 |
testbot.bot.push_message("!flows list") |
| 12 |
result = testbot.pop_message() |
| 13 |
assert "documentation of W1" in result |
| 14 |
assert "documentation of W2" in result |
| 15 |
assert "documentation of W3" in result |
| 16 |
assert "documentation of W4" in result |
| 17 |
assert "w1" in result |
| 18 |
assert "w2" in result |
| 19 |
assert "w3" in result |
| 20 |
assert "w4" in result |
| 21 |
|
| 22 |
|
| 23 |
def test_no_autotrigger(testbot): |
| 24 |
assert "a" in testbot.exec_command("!a") |
| 25 |
assert len(testbot.bot.flow_executor.in_flight) == 0 |
| 26 |
|
| 27 |
|
| 28 |
def test_autotrigger(testbot): |
| 29 |
assert "c" in testbot.exec_command("!c") |
| 30 |
flow_message = testbot.pop_message() |
| 31 |
assert "You are in the flow w2, you can continue with" in flow_message |
| 32 |
assert "!b" in flow_message |
| 33 |
assert len(testbot.bot.flow_executor.in_flight) == 1 |
| 34 |
assert testbot.bot.flow_executor.in_flight[0].name == "w2" |
| 35 |
|
| 36 |
|
| 37 |
def test_no_duplicate_autotrigger(testbot): |
| 38 |
assert "c" in testbot.exec_command("!c") |
| 39 |
flow_message = testbot.pop_message() |
| 40 |
assert "You are in the flow w2, you can continue with" in flow_message |
| 41 |
assert "c" in testbot.exec_command("!c") |
| 42 |
assert len(testbot.bot.flow_executor.in_flight) == 1 |
| 43 |
assert testbot.bot.flow_executor.in_flight[0].name == "w2" |
| 44 |
|
| 45 |
|
| 46 |
def test_secondary_autotrigger(testbot): |
| 47 |
assert "e" in testbot.exec_command("!e") |
| 48 |
second_message = testbot.pop_message() |
| 49 |
assert "You are in the flow w2, you can continue with" in second_message |
| 50 |
assert "!d" in second_message |
| 51 |
assert len(testbot.bot.flow_executor.in_flight) == 1 |
| 52 |
assert testbot.bot.flow_executor.in_flight[0].name == "w2" |
| 53 |
|
| 54 |
|
| 55 |
def test_manual_flow(testbot): |
| 56 |
assert "Flow w1 started" in testbot.exec_command("!flows start w1") |
| 57 |
flow_message = testbot.pop_message() |
| 58 |
assert "You are in the flow w1, you can continue with" in flow_message |
| 59 |
assert "!a" in flow_message |
| 60 |
assert "a" in testbot.exec_command("!a") |
| 61 |
flow_message = testbot.pop_message() |
| 62 |
assert "You are in the flow w1, you can continue with" in flow_message |
| 63 |
assert "!b" in flow_message |
| 64 |
assert "!c" in flow_message |
| 65 |
|
| 66 |
|
| 67 |
def test_manual_flow_with_or_without_hinting(testbot): |
| 68 |
assert "Flow w4 started" in testbot.exec_command("!flows start w4") |
| 69 |
assert "a" in testbot.exec_command("!a") |
| 70 |
assert "b" in testbot.exec_command("!b") |
| 71 |
flow_message = testbot.pop_message() |
| 72 |
assert "You are in the flow w4, you can continue with" in flow_message |
| 73 |
assert "!c" in flow_message |
| 74 |
|
| 75 |
|
| 76 |
def test_no_flyby_trigger_flow(testbot): |
| 77 |
testbot.bot.push_message("!flows start w1") |
| 78 |
# One message or the other can arrive first. |
| 79 |
flow_message = testbot.pop_message() |
| 80 |
assert "Flow w1 started" in flow_message or "You are in the flow w1" in flow_message |
| 81 |
flow_message = testbot.pop_message() |
| 82 |
assert "Flow w1 started" in flow_message or "You are in the flow w1" in flow_message |
| 83 |
assert "a" in testbot.exec_command("!a") |
| 84 |
flow_message = testbot.pop_message() |
| 85 |
assert "You are in the flow w1" in flow_message |
| 86 |
|
| 87 |
assert "c" in testbot.exec_command( |
| 88 |
"!c" |
| 89 |
) # c is a trigger for w2 but it should not trigger now. |
| 90 |
flow_message = testbot.pop_message() |
| 91 |
assert "You are in the flow w1" in flow_message |
| 92 |
assert len(testbot.bot.flow_executor.in_flight) == 1 |
| 93 |
|
| 94 |
|
| 95 |
def test_flow_only(testbot): |
| 96 |
assert "a" in testbot.exec_command("!a") # non flow_only should respond. |
| 97 |
testbot.push_message("!d") |
| 98 |
with pytest.raises(Empty): |
| 99 |
testbot.pop_message(timeout=1) |
| 100 |
|
| 101 |
|
| 102 |
def test_flow_only_help(testbot): |
| 103 |
testbot.push_message("!help") |
| 104 |
msg = testbot.bot.pop_message() |
| 105 |
assert "!a" in msg # non flow_only should be in help by default |
| 106 |
assert "!d" not in msg # flow_only should not be in help by default |
| 107 |
|
| 108 |
|
| 109 |
def test_flows_stop(testbot): |
| 110 |
assert "c" in testbot.exec_command("!c") |
| 111 |
flow_message = testbot.bot.pop_message() |
| 112 |
assert "You are in the flow w2" in flow_message |
| 113 |
assert "w2 stopped" in testbot.exec_command("!flows stop w2") |
| 114 |
assert len(testbot.bot.flow_executor.in_flight) == 0 |
| 115 |
|
| 116 |
|
| 117 |
def test_flows_kill(testbot): |
| 118 |
assert "c" in testbot.exec_command("!c") |
| 119 |
flow_message = testbot.bot.pop_message() |
| 120 |
assert "You are in the flow w2" in flow_message |
| 121 |
assert "w2 killed" in testbot.exec_command("!flows kill gbin@localhost w2") |
| 122 |
|
| 123 |
|
| 124 |
def test_room_flow(testbot): |
| 125 |
assert "Flow w3 started" in testbot.exec_command("!flows start w3") |
| 126 |
flow_message = testbot.pop_message() |
| 127 |
assert "You are in the flow w3, you can continue with" in flow_message |
| 128 |
assert "!a" in flow_message |
| 129 |
assert "a" in testbot.exec_command("!a") |
| 130 |
flow_message = testbot.pop_message() |
| 131 |
assert "You are in the flow w3, you can continue with" in flow_message |
| 132 |
assert "!b" in flow_message |