列表分页与服务端搜索:分页控件、全量导出、排序索引

This commit is contained in:
DeepFal committed 2026-10-19 13:14:18 +08:00
1 parent 897828f506
commit f69e0a5a69
2 files changed
+137 -23

No files matched your search

+38
View File
@@ -341,6 +341,44 @@ class PathPrefixTests(unittest.TestCase):
store.close()
class PaginationTests(unittest.TestCase):
def test_pagination_and_search(self):
with tempfile.TemporaryDirectory() as directory:
store = watch.Store(os.path.join(directory, "ips.db"))
for index, ip in enumerate(("203.0.113.9", "203.0.113.10",
"198.51.100.77")):
store.upsert({"ip": ip, "tier": watch.TIER_MALICIOUS,
"score": 90.0, "total": 100 + index,
"window": 3600, "first_seen":
"2026-10-17T16:0%d:00Z" % index,
"rules": {"probe_java": 2},
"reasons": ["敏感路径探测"]},
"2026-10-17T16:30:00Z")
store.sync_fused()
server = ThreadingHTTPServer(("127.0.0.1", 0),
watch.make_handler(store, 3600, 60))
threading.Thread(target=server.serve_forever, daemon=True).start()
base = "http://127.0.0.1:%d" % server.server_address[1]
try:
with urllib.request.urlopen(
base + "/api/ips?page_size=2&page=2", timeout=5) as response:
page = json.loads(response.read().decode("utf-8"))
self.assertEqual(page["total"], 3)
self.assertEqual(page["pages"], 2)
self.assertEqual(page["page"], 2)
self.assertEqual(len(page["items"]), 1)
with urllib.request.urlopen(
base + "/api/ips?q=203.0.113", timeout=5) as response:
filtered = json.loads(response.read().decode("utf-8"))
self.assertEqual(filtered["total"], 2)
self.assertEqual(len(filtered["items"]), 2)
finally:
server.shutdown()
server.server_close()
store.close()
class StatusIndicatorTests(unittest.TestCase):
def test_status_endpoint(self):
with tempfile.TemporaryDirectory() as directory: