feat: add nowcast point alarm get client for id and recipient lookups
Reads IDs from CSV or TXT, writes per-query SUCCESS, NOT_FOUND or FAILED rows to CSV or JSON Lines and mirrors results into SQLite.
This commit is contained in:
@@ -7,11 +7,14 @@ from datetime import datetime
|
||||
from pathlib import Path
|
||||
|
||||
from common import ApiError, ConfigurationError
|
||||
from common.client import ApiResponse
|
||||
from point_alarm import (
|
||||
PointStore,
|
||||
fetch_pages,
|
||||
flatten_registration,
|
||||
load_point_alarm_filter,
|
||||
lookup_rows,
|
||||
read_id_list,
|
||||
mask_secrets,
|
||||
parse_polygon,
|
||||
timestamped_path,
|
||||
@@ -122,6 +125,35 @@ class PointAlarmTest(unittest.TestCase):
|
||||
with self.assertRaises(ConfigurationError):
|
||||
load_point_alarm_filter(bad)
|
||||
|
||||
def test_read_id_list(self) -> None:
|
||||
txt = self.dir / "ids.txt"
|
||||
txt.write_text("# c\n\na\nb\na\n", encoding="utf-8")
|
||||
self.assertEqual(read_id_list(txt, "registrationId"), ["a", "b"])
|
||||
csv_file = self.dir / "ids.csv"
|
||||
csv_file.write_text("x;recipientId\n1;r1\n2;r2\n", encoding="utf-8")
|
||||
self.assertEqual(read_id_list(csv_file, "recipientId"), ["r1", "r2"])
|
||||
with self.assertRaises(ConfigurationError):
|
||||
read_id_list(csv_file, "registrationId")
|
||||
|
||||
def test_lookup_rows(self) -> None:
|
||||
class Svc:
|
||||
def get_by_id(self, value):
|
||||
if value == "missing":
|
||||
raise ApiError("nf", status_code=404, response_data={"m": 1})
|
||||
if value == "boom":
|
||||
raise ApiError("e", status_code=500, response_data="bad")
|
||||
return ApiResponse(200, registration(1))
|
||||
|
||||
def get_by_recipient_id(self, value):
|
||||
return ApiResponse(200, [registration(1), registration(2)])
|
||||
|
||||
rows, _ = lookup_rows(Svc(), self.store, ["ok", "missing", "boom"], "id", None)
|
||||
self.assertEqual([r["status"] for r in rows], ["SUCCESS", "NOT_FOUND", "FAILED"])
|
||||
self.assertEqual(rows[2]["errorBody"], '"bad"')
|
||||
rows, _ = lookup_rows(Svc(), self.store, ["r1"], "recipient", None)
|
||||
self.assertEqual(len(rows), 2)
|
||||
self.assertEqual(self.store.count(), 2)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user