@@ -274,6 +274,63 @@ def test_estimated_route_accessible(self, app):
274274 assert any ("/estimated/" in r for r in rules )
275275
276276
277+ # ============================================================
278+ # /api/query/result
279+ # ============================================================
280+
281+ class TestQueryResult :
282+ def _seed_result (self , received_dir , data , filename = "result_20250101_000000_aaaa.json" ):
283+ path = os .path .join (received_dir , filename )
284+ with open (path , "w" ) as f :
285+ json .dump (data , f )
286+
287+ def test_query_returns_latest_match (self , client , tmp_dirs ):
288+ received , _ = tmp_dirs
289+ old = {"system" : "Fugaku" , "code" : "qws" , "Exp" : "default" , "FOM" : 1.0 }
290+ new = {"system" : "Fugaku" , "code" : "qws" , "Exp" : "default" , "FOM" : 9.9 }
291+ self ._seed_result (received , old , "result_20250101_000000_aaaa.json" )
292+ self ._seed_result (received , new , "result_20250102_000000_bbbb.json" )
293+
294+ resp = client .get (
295+ "/api/query/result?system=Fugaku&code=qws" ,
296+ headers = {"X-API-Key" : API_KEY },
297+ )
298+ assert resp .status_code == 200
299+ assert resp .get_json ()["FOM" ] == 9.9
300+
301+ def test_query_with_exp_filter (self , client , tmp_dirs ):
302+ received , _ = tmp_dirs
303+ d1 = {"system" : "Fugaku" , "code" : "qws" , "Exp" : "A" , "FOM" : 1.0 }
304+ d2 = {"system" : "Fugaku" , "code" : "qws" , "Exp" : "B" , "FOM" : 2.0 }
305+ self ._seed_result (received , d1 , "result_20250101_000000_aaaa.json" )
306+ self ._seed_result (received , d2 , "result_20250102_000000_bbbb.json" )
307+
308+ resp = client .get (
309+ "/api/query/result?system=Fugaku&code=qws&exp=A" ,
310+ headers = {"X-API-Key" : API_KEY },
311+ )
312+ assert resp .status_code == 200
313+ assert resp .get_json ()["FOM" ] == 1.0
314+
315+ def test_query_no_match_returns_404 (self , client , tmp_dirs ):
316+ resp = client .get (
317+ "/api/query/result?system=Fugaku&code=nonexistent" ,
318+ headers = {"X-API-Key" : API_KEY },
319+ )
320+ assert resp .status_code == 404
321+
322+ def test_query_missing_params_returns_400 (self , client ):
323+ resp = client .get (
324+ "/api/query/result?system=Fugaku" ,
325+ headers = {"X-API-Key" : API_KEY },
326+ )
327+ assert resp .status_code == 400
328+
329+ def test_query_missing_api_key_returns_401 (self , client ):
330+ resp = client .get ("/api/query/result?system=Fugaku&code=qws" )
331+ assert resp .status_code == 401
332+
333+
277334# ============================================================
278335# ヘルパー
279336# ============================================================
0 commit comments