summaryrefslogtreecommitdiffstats
path: root/tests/cli_tests/test_transaction.py
blob: b5c6b4eb56aee2c9facdc4b359e7704586782662 (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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import pytest
import pexpect


def test_trasaction_rprompt(clean_redis, cli):
    cli.sendline("multi")
    cli.expect(["OK", "transaction", "127.0.0.1"])

    cli.sendline("get foo")
    cli.expect(["QUEUED", "127.0.0.1", "transaction"])

    cli.sendline("set hello world")
    cli.expect(["QUEUED", "127.0.0.1", "transaction"])

    cli.sendline("ping")
    cli.expect(["QUEUED", "127.0.0.1", "transaction"])

    cli.sendline("EXEC")
    cli.expect("(nil)")
    cli.expect("OK")
    cli.expect("PONG")
    cli.expect("127.0.0.1")

    with pytest.raises(pexpect.exceptions.TIMEOUT):
        cli.expect("transaction")


def test_trasaction_syntax_error(cli):
    cli.sendline("multi")
    cli.sendline("get foo 1")
    cli.expect(["wrong number of arguments for 'get' command", "transaction"])

    cli.sendline("EXEC")
    cli.expect("Transaction discarded because of previous errors.")
    with pytest.raises(pexpect.exceptions.TIMEOUT):
        cli.expect("transaction")


def test_trasaction_in_raw_mode(clean_redis, raw_cli):
    clean_redis.set("foo", "bar")

    raw_cli.sendline("multi")
    raw_cli.expect(["OK", "transaction", "127.0.0.1"])

    raw_cli.sendline("get foo")
    raw_cli.expect(["QUEUED", "127.0.0.1", "transaction"])

    raw_cli.sendline("EXEC")
    raw_cli.expect("bar")
    raw_cli.expect("127.0.0.1")

    with pytest.raises(pexpect.exceptions.TIMEOUT):
        raw_cli.expect("transaction")


def test_exec_return_nil_when_using_watch(clean_redis, cli):
    cli.sendline("watch foo")
    cli.expect("OK")

    cli.sendline("multi")
    cli.expect("OK")

    cli.sendline("get bar")
    cli.expect("QUEUED")

    # transaction will fail, return nil
    clean_redis.set("foo", "hello!")

    cli.sendline("exec")
    cli.expect("(nil)")