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
Example #2
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
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
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
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)
Example #6
0
def test_add_command():
    commands = Commands()
    commands.add_command(Ciao)

    expected = OrderedDict(ciao=Ciao, ping=Ping, help=Help)
    assert commands.get_commands() == expected
Example #7
0
def test_add_command_incomplete_class():
    commands = Commands()
    with pytest.raises(TypeError):
        commands.add_command(WithoutCommand)
Example #8
0
def test_add_command_invalid_class():
    commands = Commands()
    with pytest.raises(TypeError):
        commands.add_command(Invalid)
Example #9
0
def test_add_command_none():
    commands = Commands()
    with pytest.raises(TypeError):
        commands.add_command(None)