def test_event_handler_with_invalid_type(): with pytest.raises(ValueError): EventHandler({ "type": "INVALID_TYPE", "space": "", "user": "" }, Commands()).process()
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
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_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
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_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)
def test_removed_from_dm(): payload = load_payload("removed_from_dm") EventHandler(payload, Commands()).process()
def test_event_handler_with_invalid_commands(): payload = {"type": "", "space": "", "user": ""} with pytest.raises(TypeError): EventHandler(payload, None)
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())
def test_event_handler_with_none_payload(): with pytest.raises(TypeError): EventHandler(None, 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