|
4 | 4 | from pydantic import ValidationError |
5 | 5 | from pydantic_settings import SettingsConfigDict |
6 | 6 |
|
7 | | -from titiler.eopf.settings import DataStoreSettings |
| 7 | +from titiler.eopf.settings import DataStoreSettings, EOPFCacheSettings |
8 | 8 |
|
9 | 9 |
|
10 | 10 | class IsolatedDataStoreSettings(DataStoreSettings): |
@@ -54,3 +54,33 @@ def test_datastore_settings_error(params, monkeypatch): |
54 | 54 | monkeypatch.delenv("TITILER_EOPF_STORE_PATH", raising=False) |
55 | 55 | with pytest.raises(ValidationError): |
56 | 56 | IsolatedDataStoreSettings(**params) |
| 57 | + |
| 58 | + |
| 59 | +class IsolatedEOPFCacheSettings(EOPFCacheSettings): |
| 60 | + """EOPFCacheSettings without .env loading.""" |
| 61 | + |
| 62 | + model_config = SettingsConfigDict( |
| 63 | + env_prefix="TITILER_EOPF_CACHE_", env_file=None, extra="ignore" |
| 64 | + ) |
| 65 | + |
| 66 | + |
| 67 | +def test_eopf_cache_resolves_redis_db(monkeypatch): |
| 68 | + """EOPFCacheSettings resolves the Redis db from TITILER_EOPF_CACHE_REDIS_DB. |
| 69 | +
|
| 70 | + The reader dataset cache and the response/tile cache both connect through |
| 71 | + ``EOPFCacheSettings.redis``, so a configured ``db`` must propagate to that |
| 72 | + shared ``CacheRedisSettings`` — otherwise the two caches would target |
| 73 | + different Redis databases. |
| 74 | + """ |
| 75 | + monkeypatch.setenv("TITILER_EOPF_CACHE_ENABLE", "true") |
| 76 | + monkeypatch.setenv("TITILER_EOPF_CACHE_BACKEND", "redis") |
| 77 | + monkeypatch.setenv("TITILER_EOPF_CACHE_REDIS_HOST", "redis.example") |
| 78 | + monkeypatch.setenv("TITILER_EOPF_CACHE_REDIS_PORT", "6380") |
| 79 | + monkeypatch.setenv("TITILER_EOPF_CACHE_REDIS_DB", "3") |
| 80 | + |
| 81 | + settings = IsolatedEOPFCacheSettings() |
| 82 | + |
| 83 | + assert settings.redis is not None |
| 84 | + assert settings.redis.host == "redis.example" |
| 85 | + assert settings.redis.port == 6380 |
| 86 | + assert settings.redis.db == 3 |
0 commit comments