nightwave / tests /test_server.py
ratandeep's picture
SP1: session memory + caller dedication callback (Sam remembers you)
eddd90b verified
Raw
History Blame Contribute Delete
1.15 kB
"""Route tests for space/server.py (offline; mock mode)."""
import os
import sys
_HERE = os.path.dirname(os.path.abspath(__file__))
_SPACE_DIR = os.path.dirname(_HERE)
if _SPACE_DIR not in sys.path:
sys.path.insert(0, _SPACE_DIR)
def test_api_locale_mock(monkeypatch):
monkeypatch.setenv("NIGHTWAVE_MOCK", "1")
from fastapi.testclient import TestClient
import server
client = TestClient(server.create_api())
r = client.post("/api/locale", json={"lat": 30.27, "lon": -97.74})
assert r.status_code == 200
body = r.json()
assert body["resolved"] is True and body["city"]
def test_api_locale_bad_body_still_safe(monkeypatch):
monkeypatch.setenv("NIGHTWAVE_MOCK", "1")
from fastapi.testclient import TestClient
import server
client = TestClient(server.create_api())
r = client.post("/api/locale", json={"lat": "not-a-number", "lon": 0})
assert r.status_code == 422 # pydantic rejects; never 500s
def test_fallback_payload_has_memory_keys():
import server
p = server._fallback_payload("", include_caller=True)
assert p["memory_patch"] is None and p["queue_dedication"] is False