| 1 |
import pytest |
| 2 |
import pexpect |
| 3 |
|
| 4 |
|
| 5 |
def test_trasaction_rprompt(clean_redis, cli): |
| 6 |
cli.sendline("multi") |
| 7 |
cli.expect(["OK", "transaction", "127.0.0.1"]) |
| 8 |
|
| 9 |
cli.sendline("get foo") |
| 10 |
cli.expect(["QUEUED", "127.0.0.1", "transaction"]) |
| 11 |
|
| 12 |
cli.sendline("set hello world") |
| 13 |
cli.expect(["QUEUED", "127.0.0.1", "transaction"]) |
| 14 |
|
| 15 |
cli.sendline("ping") |
| 16 |
cli.expect(["QUEUED", "127.0.0.1", "transaction"]) |
| 17 |
|
| 18 |
cli.sendline("EXEC") |
| 19 |
cli.expect("(nil)") |
| 20 |
cli.expect("OK") |
| 21 |
cli.expect("PONG") |
| 22 |
cli.expect("127.0.0.1") |
| 23 |
|
| 24 |
with pytest.raises(pexpect.exceptions.TIMEOUT): |
| 25 |
cli.expect("transaction") |
| 26 |
|
| 27 |
|
| 28 |
def test_trasaction_syntax_error(cli): |
| 29 |
cli.sendline("multi") |
| 30 |
cli.sendline("get foo 1") |
| 31 |
cli.expect(["wrong number of arguments for 'get' command", "transaction"]) |
| 32 |
|
| 33 |
cli.sendline("EXEC") |
| 34 |
cli.expect("Transaction discarded because of previous errors.") |
| 35 |
with pytest.raises(pexpect.exceptions.TIMEOUT): |
| 36 |
cli.expect("transaction") |
| 37 |
|
| 38 |
|
| 39 |
def test_trasaction_in_raw_mode(clean_redis, raw_cli): |
| 40 |
clean_redis.set("foo", "bar") |
| 41 |
|
| 42 |
raw_cli.sendline("multi") |
| 43 |
raw_cli.expect(["OK", "transaction", "127.0.0.1"]) |
| 44 |
|
| 45 |
raw_cli.sendline("get foo") |
| 46 |
raw_cli.expect(["QUEUED", "127.0.0.1", "transaction"]) |
| 47 |
|
| 48 |
raw_cli.sendline("EXEC") |
| 49 |
raw_cli.expect("bar") |
| 50 |
raw_cli.expect("127.0.0.1") |
| 51 |
|
| 52 |
with pytest.raises(pexpect.exceptions.TIMEOUT): |
| 53 |
raw_cli.expect("transaction") |
| 54 |
|
| 55 |
|
| 56 |
def test_exec_return_nil_when_using_watch(clean_redis, cli): |
| 57 |
cli.sendline("watch foo") |
| 58 |
cli.expect("OK") |
| 59 |
|
| 60 |
cli.sendline("multi") |
| 61 |
cli.expect("OK") |
| 62 |
|
| 63 |
cli.sendline("get bar") |
| 64 |
cli.expect("QUEUED") |
| 65 |
|
| 66 |
# transaction will fail, return nil |
| 67 |
clean_redis.set("foo", "hello!") |
| 68 |
|
| 69 |
cli.sendline("exec") |
| 70 |
cli.expect("(nil)") |