|
| 1 | +from pathlib import Path |
| 2 | +from unittest.mock import patch |
| 3 | + |
| 4 | +from typer.testing import CliRunner |
| 5 | + |
| 6 | +from fastapi_cloud_cli.cli import app |
| 7 | + |
| 8 | +runner = CliRunner() |
| 9 | + |
| 10 | + |
| 11 | +def test_unlink_removes_fastapicloud_dir(tmp_path: Path) -> None: |
| 12 | + config_dir = tmp_path / ".fastapicloud" |
| 13 | + config_dir.mkdir(parents=True) |
| 14 | + |
| 15 | + cloud_json = config_dir / "cloud.json" |
| 16 | + cloud_json.write_text('{"app_id": "123", "team_id": "456"}') |
| 17 | + |
| 18 | + readme_file = config_dir / "README.md" |
| 19 | + readme_file.write_text("# FastAPI Cloud Configuration") |
| 20 | + |
| 21 | + gitignore_file = config_dir / ".gitignore" |
| 22 | + gitignore_file.write_text("*") |
| 23 | + |
| 24 | + with patch("fastapi_cloud_cli.commands.unlink.Path.cwd", return_value=tmp_path): |
| 25 | + result = runner.invoke(app, ["unlink"]) |
| 26 | + |
| 27 | + assert result.exit_code == 0 |
| 28 | + assert ( |
| 29 | + "FastAPI Cloud configuration has been unlinked successfully! 🚀" |
| 30 | + in result.output |
| 31 | + ) |
| 32 | + |
| 33 | + assert not config_dir.exists() |
| 34 | + assert not cloud_json.exists() |
| 35 | + assert not readme_file.exists() |
| 36 | + assert not gitignore_file.exists() |
| 37 | + |
| 38 | + |
| 39 | +def test_unlink_when_no_configuration_exists(tmp_path: Path) -> None: |
| 40 | + config_dir = tmp_path / ".fastapicloud" |
| 41 | + assert not config_dir.exists() |
| 42 | + |
| 43 | + with patch("fastapi_cloud_cli.commands.unlink.Path.cwd", return_value=tmp_path): |
| 44 | + result = runner.invoke(app, ["unlink"]) |
| 45 | + |
| 46 | + assert result.exit_code == 1 |
| 47 | + assert ( |
| 48 | + "No FastAPI Cloud configuration found in the current directory." |
| 49 | + in result.output |
| 50 | + ) |
0 commit comments