All checks were successful
CI / lint-and-test (push) Successful in 23s
- Add saved_searches_collection to database.py with index on created_by+created_at - New routes/saved_searches.py: GET /api/saved-searches, POST, DELETE - Saved searches are scoped per user (created_by = token sub) - Mount router in main.py - Frontend: Save filters button, saved search pills with load/delete - loadSavedSearches called on initApp - applySavedSearch restores filters and validates services against current options - Add CSS for saved-searches row - Add tests for CRUD, delete 404, and name validation
49 lines
2.1 KiB
Python
49 lines
2.1 KiB
Python
import mongomock
|
|
import pytest
|
|
from fastapi.testclient import TestClient
|
|
|
|
|
|
@pytest.fixture(scope="function")
|
|
def mock_events_collection():
|
|
client = mongomock.MongoClient()
|
|
db = client["micro_soc"]
|
|
coll = db["events"]
|
|
return coll
|
|
|
|
|
|
@pytest.fixture(scope="function")
|
|
def mock_watermarks_collection():
|
|
client = mongomock.MongoClient()
|
|
db = client["micro_soc"]
|
|
coll = db["watermarks"]
|
|
return coll
|
|
|
|
|
|
@pytest.fixture(scope="function")
|
|
def client(mock_events_collection, mock_watermarks_collection, monkeypatch):
|
|
monkeypatch.setattr("database.events_collection", mock_events_collection)
|
|
monkeypatch.setattr("database.saved_searches_collection", mock_events_collection)
|
|
monkeypatch.setattr("routes.fetch.events_collection", mock_events_collection)
|
|
monkeypatch.setattr("routes.events.events_collection", mock_events_collection)
|
|
monkeypatch.setattr("routes.ask.events_collection", mock_events_collection)
|
|
monkeypatch.setattr("routes.saved_searches.saved_searches_collection", mock_events_collection)
|
|
monkeypatch.setattr("watermark.watermarks_collection", mock_watermarks_collection)
|
|
monkeypatch.setattr("routes.health.watermarks_collection", mock_watermarks_collection)
|
|
monkeypatch.setattr("routes.fetch.get_watermark", lambda source: None)
|
|
monkeypatch.setattr("routes.fetch.set_watermark", lambda source, ts: None)
|
|
monkeypatch.setattr("auth.AUTH_ENABLED", False)
|
|
monkeypatch.setattr("routes.mcp.AUTH_ENABLED", False)
|
|
monkeypatch.setattr("database.db.command", lambda cmd: {"ok": 1} if cmd == "ping" else {})
|
|
|
|
# Mock audit trail and rules collections so tests don't wait on real MongoDB
|
|
audit_client = mongomock.MongoClient()
|
|
audit_db = audit_client["micro_soc"]
|
|
monkeypatch.setattr("audit_trail.audit_collection", audit_db["aoc_audit"])
|
|
monkeypatch.setattr("rules.alerts_collection", audit_db["alerts"])
|
|
monkeypatch.setattr("rules.rules_collection", audit_db["alert_rules"])
|
|
monkeypatch.setattr("routes.rules.rules_collection", audit_db["alert_rules"])
|
|
|
|
from main import app
|
|
|
|
return TestClient(app)
|