Exemplo n.º 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
def test_event_handler_with_invalid_type():
    with pytest.raises(ValueError):
        EventHandler({
            "type": "INVALID_TYPE",
            "space": "",
            "user": ""
        }, Commands()).process()
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_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
Exemplo n.º 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
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
Exemplo n.º 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
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)
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
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
Exemplo n.º 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
Exemplo n.º 12
0
def test_add_command_incomplete_class():
    commands = Commands()
    with pytest.raises(TypeError):
        commands.add_command(WithoutCommand)
Exemplo n.º 13
0
def test_add_command_invalid_class():
    commands = Commands()
    with pytest.raises(TypeError):
        commands.add_command(Invalid)
Exemplo n.º 14
0
def test_add_command_none():
    commands = Commands()
    with pytest.raises(TypeError):
        commands.add_command(None)
Exemplo n.º 15
0
def test_removed_from_dm():
    payload = load_payload("removed_from_dm")
    EventHandler(payload, Commands()).process()
Exemplo n.º 16
0
def test_add_command_from_module_none():
    commands = Commands()
    with pytest.raises(TypeError):
        commands.add_commands_from_module(None)
def test_event_handler_with_none_payload():
    with pytest.raises(TypeError):
        EventHandler(None, Commands())
def test_event_handler_non_empty_without_type():
    with pytest.raises(ValueError):
        EventHandler({"foo": "bar"}, Commands())
def test_event_handler_with_empty_payload():
    with pytest.raises(ValueError):
        EventHandler({}, Commands())
Exemplo n.º 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