1+ import os
12import sys
3+ import tempfile
24from collections .abc import Generator
35from dataclasses import dataclass
46from pathlib import Path
5- from unittest .mock import patch
67
78import pytest
9+ import respx
810from typer import rich_utils
911
12+ from fastapi_cloud_cli .config import Settings
13+ from fastapi_cloud_cli .utils .config import CONFIG_DIR_ENV_VAR
14+
1015from .utils import create_jwt_token
1116
1217
18+ @pytest .fixture (autouse = True )
19+ def isolated_config_path () -> Generator [Path , None , None ]:
20+ with tempfile .TemporaryDirectory () as tmpdir :
21+ os .environ [CONFIG_DIR_ENV_VAR ] = tmpdir
22+
23+ yield Path (tmpdir )
24+
25+
26+ @pytest .fixture
27+ def temp_auth_config (
28+ isolated_config_path : Path , monkeypatch : pytest .MonkeyPatch
29+ ) -> Generator [Path , None , None ]:
30+ yield isolated_config_path / "auth.json"
31+
32+
1333@pytest .fixture (autouse = True )
1434def reset_syspath () -> Generator [None , None , None ]:
1535 initial_python_path = sys .path .copy ()
@@ -26,6 +46,17 @@ def setup_terminal() -> None:
2646 return
2747
2848
49+ @pytest .fixture
50+ def settings () -> Settings :
51+ return Settings .get ()
52+
53+
54+ @pytest .fixture
55+ def respx_mock (settings : Settings ) -> Generator [respx .MockRouter , None , None ]:
56+ with respx .mock (base_url = settings .base_api_url ) as mock_router :
57+ yield mock_router
58+
59+
2960@pytest .fixture
3061def logged_in_cli (temp_auth_config : Path ) -> Generator [None , None , None ]:
3162 valid_token = create_jwt_token ({"sub" : "test_user_12345" })
@@ -60,13 +91,3 @@ def configured_app(tmp_path: Path) -> ConfiguredApp:
6091 config_path .write_text (f'{{"app_id": "{ app_id } ", "team_id": "{ team_id } "}}' )
6192
6293 return ConfiguredApp (app_id = app_id , team_id = team_id , path = tmp_path )
63-
64-
65- @pytest .fixture
66- def temp_auth_config (tmp_path : Path ) -> Generator [Path , None , None ]:
67- """Provides a temporary auth config setup for testing file operations."""
68-
69- with patch (
70- "fastapi_cloud_cli.utils.config.get_config_folder" , return_value = tmp_path
71- ):
72- yield tmp_path / "auth.json"
0 commit comments