Coverage for tests/test_tutorial/test_commands/test_options/test_tutorial001.py: 100%

50 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.options import tutorial001 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 "Commands" in result.output 1abcdefgh

17 assert "create" in result.output 1abcdefgh

18 assert "delete" in result.output 1abcdefgh

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

20 assert "init" in result.output 1abcdefgh

21 

22 

23def test_create(): 1abcdefgh

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

25 assert result.exit_code == 0 1abcdefgh

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

27 

28 

29def test_delete(): 1abcdefgh

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

31 assert result.exit_code == 0 1abcdefgh

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

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

34 

35 

36def test_no_delete(): 1abcdefgh

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

38 assert result.exit_code == 0 1abcdefgh

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

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

41 

42 

43def test_delete_all(): 1abcdefgh

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

45 assert result.exit_code == 0 1abcdefgh

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

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

48 

49 

50def test_no_delete_all(): 1abcdefgh

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

52 assert result.exit_code == 0 1abcdefgh

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

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

55 

56 

57def test_delete_all_force(): 1abcdefgh

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

59 assert result.exit_code == 0 1abcdefgh

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

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

62 

63 

64def test_init(): 1abcdefgh

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

66 assert result.exit_code == 0 1abcdefgh

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

68 

69 

70def test_script(): 1abcdefgh

71 result = subprocess.run( 1abcdefgh

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

73 capture_output=True, 

74 encoding="utf-8", 

75 ) 

76 assert "Usage" in result.stdout 1abcdefgh