Documents & queries
CRUD, bulk, search, count, pagination, and scrolling. Selected term, match, range, bool, and aggregation behavior.
A PYTHON TESTING LIBRARY
Keep the OpenSearch client API. Replace the server with a stateful, in-memory fake. Test what happens after a document is written, found, updated, and deleted.
uv add --dev openmockimport opensearchpy
from openmock import openmock
@openmock
def test_find_a_book():
client = opensearchpy.OpenSearch()
client.index(
index="books", id="1",
body={"title": "Dune"},
)
result = client.search(
index="books",
body={"query": {
"match": {"title": "Dune"}
}},
)
assert result["hits"]["total"]["value"] == 1One decorator. Real state transitions. An ordinary assertion.
01 / THE WORKFLOW
@openmock patches client constructors for the decorated call. Construct your client inside that scope.
Index documents, run supported queries, and update or delete records. Later calls see the state left by earlier calls.
Check your application’s outcome using familiar OpenSearch-shaped responses. Each decorated call starts with fresh client caches.
02 / A DELIBERATELY SMALL FAKE
Use the mock where a small, predictable model is enough. Keep real-server tests for the behavior that needs OpenSearch.
Explore the supported API →CRUD, bulk, search, count, pagination, and scrolling. Selected term, match, range, bool, and aggregation behavior.
Fake clients for both programming styles. Core document workflows are shared; sub-client coverage differs.
No relevance engine, full analyzer pipeline, distributed execution, or complete Painless runtime. Verify those with a real cluster.
03 / EXPLORE THE FAKE
Optional tools for manual experiments. Each runs with its own in-memory state.
Explore indices, search, fake security, and ingest pipelines with Streamlit.
openmockInstall the web extraTry the supported HTTP routes from curl or another local tool.
openmock serveInstall the rest extraInspect fake data in a desktop interface using Python’s Tk support.
openmock guiRequires Tk and a graphical displayBUILD CONFIDENCE, ONE TEST AT A TIME
Install the library, decorate a function, and make your first assertion.