summaryrefslogtreecommitdiffstats
path: root/tests/cli_tests/test_warning.py
blob: 402c51b8a7d0a9ab5fce4e6855372821daf1fa8b (plain)
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
40
41
42
43
44
45
46
47
48
49
50
51
from iredis.warning import is_dangerous


def test_is_dangerous():
    assert is_dangerous("KEYS") == (
        True,
        "KEYS will hang redis server, use SCAN instead",
    )


def test_warning_for_dangerous_command(cli):
    cli.sendline("config set save '900 1'")
    cli.expect("Do you want to proceed?")
    cli.sendline("yes")

    cli.sendline("config get save")
    cli.expect("900 1")


def test_warnings_in_raw_mode(clean_redis, raw_cli):
    clean_redis.set("foo", "bar")
    raw_cli.sendline("keys *")
    raw_cli.expect("Do you want to proceed?")
    raw_cli.sendline("y")
    raw_cli.expect("foo")


def test_warnings_in_raw_mode_canceled(clean_redis, raw_cli):
    clean_redis.set("foo", "bar")
    raw_cli.sendline("keys *")
    raw_cli.expect("Do you want to proceed?")
    raw_cli.sendline("n")
    # the f should never appeared
    raw_cli.expect("Canceled![^f]+127.0.0.1")


def test_warnings_confirmed(clean_redis, cli):
    clean_redis.set("foo", "bar")
    cli.sendline("keys *")
    cli.expect("Do you want to proceed?")
    cli.sendline("y")
    cli.expect("foo")


def test_warnings_canceled(clean_redis, cli):
    clean_redis.set("foo", "bar")
    cli.sendline("keys *")
    cli.expect("Do you want to proceed?")
    cli.sendline("n")
    # the f should never appeared
    cli.expect("Canceled![^f]+127.0.0.1")