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("routes.fetch.events_collection", mock_events_collection) monkeypatch.setattr("routes.events.events_collection", mock_events_collection) monkeypatch.setattr("watermark.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("database.db.command", lambda cmd: {"ok": 1} if cmd == "ping" else {}) from main import app return TestClient(app)