Debian Codegraph @

tests/cli_tests/test_command_input.py

raw
1 import os
2 import time
3
4 from packaging.version import parse as version_parse
5 import pytest
6
7
8 def test_wrong_select_db_index(cli):
9 cli.sendline("select 1")
10 cli.expect(["OK", "127.0.0.1"])
11
12 cli.sendline("select 128")
13 cli.expect(["DB index is out of range", "127.0.0.1:6379[1]>"])
14
15 if version_parse(os.environ["REDIS_VERSION"]) > version_parse("5"):
16 text = "value is not an integer or out of range"
17 else:
18 text = "invalid DB index"
19
20 cli.sendline("select abc")
21 cli.expect([text, "127.0.0.1:6379[1]>"])
22
23 cli.sendline("select 15")
24 cli.expect("OK")
25
26
27 def test_set_command_with_shash(clean_redis, cli):
28 cli.sendline("set a \\hello\\") # legal redis command
29 cli.expect("OK")
30
31 cli.sendline("get a")
32 cli.expect(r"hello")
33
34
35 def test_enter_key_binding(clean_redis, cli):
36 cli.send("set")
37 time.sleep(0.3) # Wait for completion menu
38 cli.expect("set")
39 cli.send("\033[B") # down
40 time.sleep(0.2)
41 cli.sendline() # enter
42
43 cli.sendline(" a 'hello'")
44 cli.expect("OK")
45
46 cli.sendline("get a")
47 cli.expect(r"hello")
48
49
50 @pytest.mark.skipif("version_parse(os.environ['REDIS_VERSION']) < version_parse('6')")
51 def test_auth_hidden_password_with_username(clean_redis, cli):
52 cli.send("auth default hello-world")
53 time.sleep(0.3) # Wait for display update
54 cli.expect("default")
55 cli.expect(r"\*{11}")
56
57
58 @pytest.mark.skipif("version_parse(os.environ['REDIS_VERSION']) > version_parse('5')")
59 def test_auth_hidden_password(clean_redis, cli):
60 cli.send("auth hello-world")
61 cli.expect("auth")
62 cli.expect(r"\*{11}")
63
64
65 def test_hello_command_is_not_supported(cli):
66 cli.sendline("hello 3")
67 cli.expect("IRedis currently not support RESP3")
68
69
70 @pytest.mark.xfail(reason="unstable, maybe due to github action's signal handling")
71 def test_abort_reading_connection(cli):
72 cli.sendline("blpop mylist 30")
73 cli.send(chr(3))
74 cli.expect(
75 r"KeyboardInterrupt received! User canceled reading response!", timeout=10
76 )
77
78 cli.sendline("set foo bar")
79 cli.expect("OK")
80 cli.sendline("get foo")
81 cli.expect("bar")