Coverage for tests/test_cli_logout.py: 100%

32 statements  

« prev     ^ index     » next       coverage.py v7.16.0, created at 2026-11-09 00:25 +0000

1import json 1abcdefg

2from pathlib import Path 1abcdefg

3 

4from typer.testing import CliRunner 1abcdefg

5 

6from fastapi_cloud_cli.cli import cloud_app as app 1abcdefg

7 

8runner = CliRunner() 1abcdefg

9 

10 

11def test_logout_with_existing_auth_file(temp_auth_config: Path) -> None: 1abcdefg

12 temp_auth_config.write_text('{"access_token": "test_token"}') 1hijklmn

13 

14 assert temp_auth_config.exists() 1hijklmn

15 

16 result = runner.invoke(app, ["logout"]) 1hijklmn

17 

18 assert result.exit_code == 0 1hijklmn

19 assert "You are now logged out!" in result.output 1hijklmn

20 

21 assert not temp_auth_config.exists() 1hijklmn

22 

23 

24def test_logout_with_no_auth_file(temp_auth_config: Path) -> None: 1abcdefg

25 assert not temp_auth_config.exists() 1CDEFGHI

26 

27 result = runner.invoke(app, ["logout"]) 1CDEFGHI

28 

29 assert result.exit_code == 0 1CDEFGHI

30 assert "You are now logged out!" in result.output 1CDEFGHI

31 

32 assert not temp_auth_config.exists() 1CDEFGHI

33 

34 

35def test_logout_json_with_existing_auth_file(temp_auth_config: Path) -> None: 1abcdefg

36 temp_auth_config.write_text('{"access_token": "test_token"}') 1opqrstu

37 

38 result = runner.invoke(app, ["logout", "--json"]) 1opqrstu

39 

40 assert result.exit_code == 0 1opqrstu

41 assert json.loads(result.stdout) == {"data": {"logged_out": True}} 1opqrstu

42 assert result.stderr == "" 1opqrstu

43 assert not temp_auth_config.exists() 1opqrstu

44 

45 

46def test_logout_json_with_no_auth_file(temp_auth_config: Path) -> None: 1abcdefg

47 assert not temp_auth_config.exists() 1vwxyzAB

48 

49 result = runner.invoke(app, ["logout", "--json"]) 1vwxyzAB

50 

51 assert result.exit_code == 0 1vwxyzAB

52 assert json.loads(result.stdout) == {"data": {"logged_out": True}} 1vwxyzAB

53 assert result.stderr == "" 1vwxyzAB

54 assert not temp_auth_config.exists() 1vwxyzAB