Coverage for tests/test_config.py: 100%
30 statements
« prev ^ index » next coverage.py v7.16.0, created at 2026-11-09 00:25 +0000
« prev ^ index » next coverage.py v7.16.0, created at 2026-11-09 00:25 +0000
1from pathlib import Path 1abcdefg
3import pytest 1abcdefg
4import typer 1abcdefg
6from fastapi_cloud_cli.config import Settings 1abcdefg
7from fastapi_cloud_cli.utils.config import get_config_folder 1abcdefg
10def test_loads_default_values_when_file_does_not_exist() -> None: 1abcdefg
11 default_settings = Settings() 1vwxyzAB
13 settings = Settings.from_user_settings(Path("non_existent_file.json")) 1vwxyzAB
15 assert settings.base_api_url == default_settings.base_api_url 1vwxyzAB
16 assert settings.client_id == default_settings.client_id 1vwxyzAB
19def test_loads_settings_even_when_file_is_broken(tmp_path: Path) -> None: 1abcdefg
20 broken_settings_path = tmp_path / "broken_settings.json" 1hijklmn
21 broken_settings_path.write_text("this is not json") 1hijklmn
23 default_settings = Settings() 1hijklmn
25 settings = Settings.from_user_settings(broken_settings_path) 1hijklmn
27 assert settings.base_api_url == default_settings.base_api_url 1hijklmn
28 assert settings.client_id == default_settings.client_id 1hijklmn
31def test_loads_partial_settings(tmp_path: Path) -> None: 1abcdefg
32 settings_path = tmp_path / "settings.json" 1opqrstu
33 settings_path.write_text('{"base_api_url": "https://example.com"}') 1opqrstu
35 default_settings = Settings() 1opqrstu
37 settings = Settings.from_user_settings(settings_path) 1opqrstu
39 assert settings.base_api_url == "https://example.com" 1opqrstu
40 assert settings.client_id == default_settings.client_id 1opqrstu
43def test_get_config_folder_reads_env_override( 1abcdefg
44 monkeypatch: pytest.MonkeyPatch, tmp_path: Path
45) -> None:
46 monkeypatch.setenv("FASTAPI_CLOUD_CLI_CONFIG_DIR", str(tmp_path)) 1CDEFGHI
48 assert get_config_folder() == tmp_path 1CDEFGHI
51def test_get_config_folder_defaults_to_app_dir( 1abcdefg
52 monkeypatch: pytest.MonkeyPatch,
53) -> None:
54 monkeypatch.delenv("FASTAPI_CLOUD_CLI_CONFIG_DIR", raising=False) 1JKLMNOP
56 assert get_config_folder() == Path(typer.get_app_dir("fastapi-cli")) 1JKLMNOP