aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_commands.py
blob: 3456d96e69efa6946f5d427007f808a367fc2eb0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# Test calling the correct function

from itertools import accumulate

from slack.commands import parse_options
from slack.shared import shared


def test_all_parent_commands_exist():
    for command in shared.commands:
        parents = accumulate(command.split(" "), lambda x, y: f"{x} {y}")
        for parent in parents:
            assert parent in shared.commands


def test_parse_options_without_options():
    pos_args, options = parse_options("workspace add wee-slack-test")
    assert pos_args == "workspace add wee-slack-test"
    assert options == {}


def test_parse_options_with_option():
    pos_args, options = parse_options("workspace add wee-slack-test -autoconnect")
    assert pos_args == "workspace add wee-slack-test"
    assert options == {"autoconnect": True}


def test_parse_options_option_in_middle():
    pos_args, options = parse_options("workspace add -autoconnect wee-slack-test")
    assert pos_args == "workspace add wee-slack-test"
    assert options == {"autoconnect": True}


def test_parse_options_option_with_value():
    pos_args, options = parse_options(
        "workspace add wee-slack-test -autoconnect -api_token=xoxp-1"
    )
    assert pos_args == "workspace add wee-slack-test"
    assert options == {"autoconnect": True, "api_token": "xoxp-1"}