Coverage for tests/test_tutorial/test_commands/test_help/test_tutorial001_an.py: 100%

77 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-09-09 18:26 +0000

1import subprocess 1abcdefgh

2import sys 1abcdefgh

3 

4from typer.testing import CliRunner 1abcdefgh

5 

6from docs_src.commands.help import tutorial001_an as mod 1abcdefgh

7 

8app = mod.app 1abcdefgh

9 

10runner = CliRunner() 1abcdefgh

11 

12 

13def test_help(): 1abcdefgh

14 result = runner.invoke(app, ["--help"]) 1abcdefgh

15 assert result.exit_code == 0 1abcdefgh

16 assert "Awesome CLI user manager." in result.output 1abcdefgh

17 assert "create" in result.output 1abcdefgh

18 assert "Create a new user with USERNAME." in result.output 1abcdefgh

19 assert "delete" in result.output 1abcdefgh

20 assert "Delete a user with USERNAME." in result.output 1abcdefgh

21 assert "delete-all" in result.output 1abcdefgh

22 assert "Delete ALL users in the database." in result.output 1abcdefgh

23 assert "init" in result.output 1abcdefgh

24 assert "Initialize the users database." in result.output 1abcdefgh

25 

26 

27def test_help_create(): 1abcdefgh

28 result = runner.invoke(app, ["create", "--help"]) 1abcdefgh

29 assert result.exit_code == 0 1abcdefgh

30 assert "create [OPTIONS] USERNAME" in result.output 1abcdefgh

31 assert "Create a new user with USERNAME." in result.output 1abcdefgh

32 

33 

34def test_help_delete(): 1abcdefgh

35 result = runner.invoke(app, ["delete", "--help"]) 1abcdefgh

36 assert result.exit_code == 0 1abcdefgh

37 assert "delete [OPTIONS] USERNAME" in result.output 1abcdefgh

38 assert "Delete a user with USERNAME." in result.output 1abcdefgh

39 assert "--force" in result.output 1abcdefgh

40 assert "--no-force" in result.output 1abcdefgh

41 assert "Force deletion without confirmation." in result.output 1abcdefgh

42 

43 

44def test_help_delete_all(): 1abcdefgh

45 result = runner.invoke(app, ["delete-all", "--help"]) 1abcdefgh

46 assert result.exit_code == 0 1abcdefgh

47 assert "delete-all [OPTIONS]" in result.output 1abcdefgh

48 assert "Delete ALL users in the database." in result.output 1abcdefgh

49 assert "If --force is not used, will ask for confirmation." in result.output 1abcdefgh

50 assert "[required]" in result.output 1abcdefgh

51 assert "--force" in result.output 1abcdefgh

52 assert "--no-force" in result.output 1abcdefgh

53 assert "Force deletion without confirmation." in result.output 1abcdefgh

54 

55 

56def test_help_init(): 1abcdefgh

57 result = runner.invoke(app, ["init", "--help"]) 1abcdefgh

58 assert result.exit_code == 0 1abcdefgh

59 assert "init [OPTIONS]" in result.output 1abcdefgh

60 assert "Initialize the users database." in result.output 1abcdefgh

61 

62 

63def test_create(): 1abcdefgh

64 result = runner.invoke(app, ["create", "Camila"]) 1abcdefgh

65 assert result.exit_code == 0 1abcdefgh

66 assert "Creating user: Camila" in result.output 1abcdefgh

67 

68 

69def test_delete(): 1abcdefgh

70 result = runner.invoke(app, ["delete", "Camila"], input="y\n") 1abcdefgh

71 assert result.exit_code == 0 1abcdefgh

72 assert "Are you sure you want to delete the user? [y/n]:" in result.output 1abcdefgh

73 assert "Deleting user: Camila" in result.output 1abcdefgh

74 

75 

76def test_no_delete(): 1abcdefgh

77 result = runner.invoke(app, ["delete", "Camila"], input="n\n") 1abcdefgh

78 assert result.exit_code == 0 1abcdefgh

79 assert "Are you sure you want to delete the user? [y/n]:" in result.output 1abcdefgh

80 assert "Operation cancelled" in result.output 1abcdefgh

81 

82 

83def test_delete_all(): 1abcdefgh

84 result = runner.invoke(app, ["delete-all"], input="y\n") 1abcdefgh

85 assert result.exit_code == 0 1abcdefgh

86 assert "Are you sure you want to delete ALL users? [y/n]:" in result.output 1abcdefgh

87 assert "Deleting all users" in result.output 1abcdefgh

88 

89 

90def test_no_delete_all(): 1abcdefgh

91 result = runner.invoke(app, ["delete-all"], input="n\n") 1abcdefgh

92 assert result.exit_code == 0 1abcdefgh

93 assert "Are you sure you want to delete ALL users? [y/n]:" in result.output 1abcdefgh

94 assert "Operation cancelled" in result.output 1abcdefgh

95 

96 

97def test_init(): 1abcdefgh

98 result = runner.invoke(app, ["init"]) 1abcdefgh

99 assert result.exit_code == 0 1abcdefgh

100 assert "Initializing user database" in result.output 1abcdefgh

101 

102 

103def test_script(): 1abcdefgh

104 result = subprocess.run( 1abcdefgh

105 [sys.executable, "-m", "coverage", "run", mod.__file__, "--help"], 

106 capture_output=True, 

107 encoding="utf-8", 

108 ) 

109 assert "Usage" in result.stdout 1abcdefgh