-
-
Notifications
You must be signed in to change notification settings - Fork 624
/
test_tutorial001.py
96 lines (74 loc) · 2.95 KB
/
test_tutorial001.py
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import subprocess
from typer.testing import CliRunner
from docs_src.commands.options import tutorial001 as mod
app = mod.app
runner = CliRunner()
def test_help():
result = runner.invoke(app, ["--help"])
assert result.exit_code == 0
assert "Commands:" in result.output
assert "create" in result.output
assert "delete" in result.output
assert "delete-all" in result.output
assert "init" in result.output
def test_create():
result = runner.invoke(app, ["create", "Camila"])
assert result.exit_code == 0
assert "Creating user: Camila" in result.output
def test_delete():
result = runner.invoke(app, ["delete", "Camila"], input="y\n")
assert result.exit_code == 0
# TODO: when deprecating Click 7, remove second option
assert (
"Are you sure you want to delete the user? [y/n]:" in result.output
or "Are you sure you want to delete the user? [y/N]:" in result.output
)
assert "Deleting user: Camila" in result.output
def test_no_delete():
result = runner.invoke(app, ["delete", "Camila"], input="n\n")
assert result.exit_code == 0
# TODO: when deprecating Click 7, remove second option
assert (
"Are you sure you want to delete the user? [y/n]:" in result.output
or "Are you sure you want to delete the user? [y/N]:" in result.output
)
assert "Operation cancelled" in result.output
def test_delete_all():
result = runner.invoke(app, ["delete-all"], input="y\n")
assert result.exit_code == 0
# TODO: when deprecating Click 7, remove second option
assert (
"Are you sure you want to delete ALL users? [y/n]:" in result.output
or "Are you sure you want to delete ALL users? [y/N]:" in result.output
)
assert "Deleting all users" in result.output
def test_no_delete_all():
result = runner.invoke(app, ["delete-all"], input="n\n")
assert result.exit_code == 0
# TODO: when deprecating Click 7, remove second option
assert (
"Are you sure you want to delete ALL users? [y/n]:" in result.output
or "Are you sure you want to delete ALL users? [y/N]:" in result.output
)
assert "Operation cancelled" in result.output
def test_delete_all_force():
result = runner.invoke(app, ["delete-all", "--force"])
assert result.exit_code == 0
# TODO: when deprecating Click 7, remove second option
assert (
"Are you sure you want to delete ALL users? [y/n]:" not in result.output
or "Are you sure you want to delete ALL users? [y/N]:" not in result.output
)
assert "Deleting all users" in result.output
def test_init():
result = runner.invoke(app, ["init"])
assert result.exit_code == 0
assert "Initializing user database" in result.output
def test_script():
result = subprocess.run(
["coverage", "run", mod.__file__, "--help"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
encoding="utf-8",
)
assert "Usage" in result.stdout