コード例 #1
0
def test_add_command_with_alias():
    commands = Commands()
    commands.add_command(Hello)

    expected = OrderedDict(hello=Hello,
                           hi=Hello,
                           hey=Hello,
                           ping=Ping,
                           help=Help)
    assert commands.get_commands() == expected
コード例 #2
0
def test_event_handler_with_invalid_type():
    with pytest.raises(ValueError):
        EventHandler({
            "type": "INVALID_TYPE",
            "space": "",
            "user": ""
        }, Commands()).process()
コード例 #3
0
def test_event_handler_with_unimplemented_command():
    payload = {
        "type": "MESSAGE",
        "message": {
            "text": "not-implemented-command",
            "sender": {}
        },
        "space": "",
        "user": "",
    }

    commands = Commands()
    commands.add_command(NotImplementedCommand)

    expected = {"text": "Oops, something went wrong!"}

    assert EventHandler(payload, commands).process() == expected
コード例 #4
0
def test_event_handler_hello():
    payload = {
        "type": "MESSAGE",
        "message": {
            "text": "hello Jean",
            "sender": {}
        },
        "space": "",
        "user": "",
    }

    commands = Commands()
    commands.add_command(Hello)

    expected = {"text": "Hello, Jean!"}

    assert EventHandler(payload, commands).process() == expected
コード例 #5
0
def test_added_to_room():
    payload = load_payload("added_to_room")

    expected = {
        "text":
        "Hello people! Thanks for adding me to *Testing room*!\n\nPlease, type *help* for more information about the commands available."
    }

    assert EventHandler(payload, Commands()).process() == expected
コード例 #6
0
def test_message_invalid():
    payload = load_payload("message_invalid")

    expected = {
        "text":
        "Invalid command: *invalid*\n\nPlease, type *help* for more information about the commands available."
    }

    assert EventHandler(payload, Commands()).process() == expected
コード例 #7
0
def test_added_to_dm():
    payload = load_payload("added_to_dm")

    expected = {
        "text":
        "Hello <users/123456789123456789123>! How are you?\n\nPlease, type *help* for more information about the commands available."
    }

    assert EventHandler(payload, Commands()).process() == expected
コード例 #8
0
def test_event_handler_dependency():
    payload = {
        "type": "MESSAGE",
        "message": {
            "text": "dependency",
            "sender": {}
        },
        "space": "",
        "user": "",
    }

    commands = Commands()
    commands.add_command(DependencyInjection)

    expected = {"text": "Repository = some-repository"}

    assert (EventHandler(payload, commands,
                         repository="some-repository").process() == expected)
コード例 #9
0
def test_message_empty():
    payload = load_payload("message_empty")

    expected = {
        "text":
        "Commands available:\n\n"
        "*`help`*\nList commands available\n\n"
        'HINT: If you need to specify multiple words for a parameter, use quotes (").'
    }

    assert EventHandler(payload, Commands()).process() == expected
コード例 #10
0
def test_event_handler_help_with_multiple_commands():
    payload = {
        "type": "MESSAGE",
        "message": {
            "text": "help",
            "sender": {}
        },
        "space": "",
        "user": "",
    }

    commands = Commands()
    commands.add_command(Ciao)
    commands.add_command(Hello)

    expected = {
        "text":
        "Commands available:\n\n"
        "*`ciao`*\nSay ciao\n\n"
        "*`hello`*`<name>`\nSay hello\n\n"
        "*`help`*\nList commands available\n\n"
        'HINT: If you need to specify multiple words for a parameter, use quotes (").'
    }

    assert EventHandler(payload, commands).process() == expected
コード例 #11
0
def test_add_command():
    commands = Commands()
    commands.add_command(Ciao)

    expected = OrderedDict(ciao=Ciao, ping=Ping, help=Help)
    assert commands.get_commands() == expected
コード例 #12
0
def test_add_command_incomplete_class():
    commands = Commands()
    with pytest.raises(TypeError):
        commands.add_command(WithoutCommand)
コード例 #13
0
def test_add_command_invalid_class():
    commands = Commands()
    with pytest.raises(TypeError):
        commands.add_command(Invalid)
コード例 #14
0
def test_add_command_none():
    commands = Commands()
    with pytest.raises(TypeError):
        commands.add_command(None)
コード例 #15
0
def test_removed_from_dm():
    payload = load_payload("removed_from_dm")
    EventHandler(payload, Commands()).process()
コード例 #16
0
def test_add_command_from_module_none():
    commands = Commands()
    with pytest.raises(TypeError):
        commands.add_commands_from_module(None)
コード例 #17
0
def test_event_handler_with_none_payload():
    with pytest.raises(TypeError):
        EventHandler(None, Commands())
コード例 #18
0
def test_event_handler_non_empty_without_type():
    with pytest.raises(ValueError):
        EventHandler({"foo": "bar"}, Commands())
コード例 #19
0
def test_event_handler_with_empty_payload():
    with pytest.raises(ValueError):
        EventHandler({}, Commands())
コード例 #20
0
def test_add_command_from_module():
    commands = Commands()

    import tests.unit.commands

    commands.add_commands_from_module(tests.unit.commands)
def test_message_simple_mention_on_room():
    payload = load_payload("message_simple_mention_on_room")

    expected = {"text": "pong"}

    assert EventHandler(payload, Commands()).process() == expected