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 isolate_config () -> Generator [None ]:
20+ with tempfile .TemporaryDirectory () as tmpdir :
21+ os .environ [CONFIG_DIR_ENV_VAR ] = str (tmpdir )
22+
23+ yield
24+
25+
1326@pytest .fixture (autouse = True )
1427def reset_syspath () -> Generator [None , None , None ]:
1528 initial_python_path = sys .path .copy ()
@@ -26,6 +39,23 @@ def setup_terminal() -> None:
2639 return
2740
2841
42+ @pytest .fixture
43+ def settings () -> Settings :
44+ return Settings .get ()
45+
46+
47+ @pytest .fixture
48+ def respx_mock (
49+ request : pytest .FixtureRequest , settings : Settings
50+ ) -> Generator [respx .MockRouter , None , None ]:
51+ respx_marker = request .node .get_closest_marker ("respx" )
52+ kwargs = {} if respx_marker is None else dict (respx_marker .kwargs )
53+ kwargs .setdefault ("base_url" , settings .base_api_url )
54+
55+ with respx .mock (** kwargs ) as mock_router :
56+ yield mock_router
57+
58+
2959@pytest .fixture
3060def logged_in_cli (temp_auth_config : Path ) -> Generator [None , None , None ]:
3161 valid_token = create_jwt_token ({"sub" : "test_user_12345" })
@@ -63,10 +93,10 @@ def configured_app(tmp_path: Path) -> ConfiguredApp:
6393
6494
6595@pytest .fixture
66- def temp_auth_config (tmp_path : Path ) -> Generator [Path , None , None ]:
96+ def temp_auth_config (
97+ tmp_path : Path , monkeypatch : pytest .MonkeyPatch
98+ ) -> Generator [Path , None , None ]:
6799 """Provides a temporary auth config setup for testing file operations."""
68100
69- with patch (
70- "fastapi_cloud_cli.utils.config.get_config_folder" , return_value = tmp_path
71- ):
72- yield tmp_path / "auth.json"
101+ monkeypatch .setenv (CONFIG_DIR_ENV_VAR , str (tmp_path ))
102+ yield tmp_path / "auth.json"
0 commit comments