fires: resolve FIRMS_MAP_KEY from Postgres keystore, not just env
All checks were successful
build-and-deploy / build (push) Successful in 1m40s
All checks were successful
build-and-deploy / build (push) Successful in 1m40s
Key saved via the dashboard Keys page sat unused in api_keys while ingest_fires only checked the env var. Now env first, keystore fallback, picked up on next poll without a restart.
This commit is contained in:
parent
b1c611d4c4
commit
e6648ec1ed
2 changed files with 72 additions and 6 deletions
|
|
@ -73,6 +73,65 @@ def test_parse_firms_csv_empty_and_garbage():
|
|||
|
||||
|
||||
def test_ingest_fires_idles_without_map_key(monkeypatch):
|
||||
# No key -> returns 0 without attempting a network call.
|
||||
monkeypatch.setattr("fire_sources.FIRMS_MAP_KEY", "")
|
||||
# No key anywhere -> returns 0 without attempting a network call.
|
||||
monkeypatch.setenv("FIRMS_MAP_KEY", "")
|
||||
monkeypatch.setattr(
|
||||
"fire_sources.get_api_key", lambda name: _async_none()
|
||||
)
|
||||
assert asyncio.run(ingest_fires()) == 0
|
||||
|
||||
|
||||
def test_ingest_fires_uses_keystore_key(monkeypatch):
|
||||
# Key saved via the dashboard Keys page (Postgres) is picked up.
|
||||
monkeypatch.setenv("FIRMS_MAP_KEY", "")
|
||||
monkeypatch.setattr(
|
||||
"fire_sources.get_api_key",
|
||||
lambda name: _async_return("a" * 32),
|
||||
)
|
||||
|
||||
captured = {}
|
||||
|
||||
class FakeResp:
|
||||
status_code = 200
|
||||
text = SAMPLE_CSV
|
||||
|
||||
def raise_for_status(self):
|
||||
pass
|
||||
|
||||
class FakeClient:
|
||||
def __init__(self, **kw):
|
||||
pass
|
||||
|
||||
async def __aenter__(self):
|
||||
return self
|
||||
|
||||
async def __aexit__(self, *exc):
|
||||
return False
|
||||
|
||||
async def get(self, url):
|
||||
captured["url"] = url
|
||||
return FakeResp()
|
||||
|
||||
monkeypatch.setattr("fire_sources.httpx.AsyncClient", FakeClient)
|
||||
|
||||
published = []
|
||||
|
||||
async def fake_publish(points):
|
||||
published.extend(points)
|
||||
return len(points)
|
||||
|
||||
monkeypatch.setattr("fire_sources.publish_fire_batch", fake_publish)
|
||||
|
||||
assert asyncio.run(ingest_fires()) == 5
|
||||
assert "a" * 32 in captured["url"]
|
||||
|
||||
|
||||
def _async_return(value):
|
||||
async def inner():
|
||||
return value
|
||||
|
||||
return inner()
|
||||
|
||||
|
||||
def _async_none():
|
||||
return _async_return(None)
|
||||
|
|
|
|||
Loading…
Reference in a new issue