Debian Codegraph @

tests/cli_tests/test_history.py

raw
1 import os
2 import pexpect
3 from pathlib import Path
4 from textwrap import dedent
5
6
7 def test_history_not_log_auth(cli):
8 cli.sendline("AUTH 123")
9 cli.expect(["Client sent AUTH, but no password is set", "127.0.0.1"])
10 cli.sendline("set foo bar")
11 cli.expect("OK")
12
13 with open(os.path.expanduser("~/.iredis_history")) as history_file:
14 content = history_file.read()
15
16 assert "set foo bar" in content
17 assert "AUTH" not in content
18
19
20 def test_history_create_and_writing_with_config():
21 config_content = dedent(
22 """
23 [main]
24 history_location = /tmp/iredis_history.txt
25 """
26 )
27 with open("/tmp/iredisrc", "w+") as etc_config:
28 etc_config.write(config_content)
29
30 cli = pexpect.spawn("iredis -n 15 --iredisrc /tmp/iredisrc", timeout=2)
31 cli.expect("127.0.0.1")
32 cli.sendline("set hello world")
33 cli.expect("OK")
34 cli.close()
35
36 log = Path("/tmp/iredis_history.txt")
37 assert log.exists()
38
39 with open(log) as logfile:
40 content = logfile.read()
41
42 assert "set hello world" in content