MongoPlugin¶
MongoPlugin
¶
Bases: BasePlugin
MongoDB interception plugin.
Patches pymongo.collection.Collection methods at the class level. Uses reference counting so nested sandboxes work correctly.
Each operation name has its own FIFO deque of MongoMockConfig objects.
Source code in src/tripwire/plugins/mongo_plugin.py
mock_operation
¶
Register a mock for a single MongoDB operation invocation.
Args: operation: The operation name (e.g., "find_one", "insert_one"). returns: Value to return when this mock is consumed (required even when raises is set, as it serves as the fallback value type). raises: If provided, this exception is raised instead of returning. required: If False, the mock is not reported as unused at teardown.
Source code in src/tripwire/plugins/mongo_plugin.py
install_patches
¶
Install pymongo Collection method patches.
Source code in src/tripwire/plugins/mongo_plugin.py
restore_patches
¶
Restore original pymongo Collection methods.
Source code in src/tripwire/plugins/mongo_plugin.py
matches
¶
Field-by-field comparison with dirty-equals support.
Source code in src/tripwire/plugins/mongo_plugin.py
get_unused_mocks
¶
Return all MongoMockConfig with required=True still in any queue.
Source code in src/tripwire/plugins/mongo_plugin.py
assert_find
¶
Typed helper: assert the next find interaction.
Source code in src/tripwire/plugins/mongo_plugin.py
assert_find_one
¶
Typed helper: assert the next find_one interaction.
Source code in src/tripwire/plugins/mongo_plugin.py
assert_insert_one
¶
Typed helper: assert the next insert_one interaction.
Source code in src/tripwire/plugins/mongo_plugin.py
assert_insert_many
¶
Typed helper: assert the next insert_many interaction.
Source code in src/tripwire/plugins/mongo_plugin.py
assert_update_one
¶
Typed helper: assert the next update_one interaction.
Source code in src/tripwire/plugins/mongo_plugin.py
assert_update_many
¶
Typed helper: assert the next update_many interaction.
Source code in src/tripwire/plugins/mongo_plugin.py
assert_delete_one
¶
Typed helper: assert the next delete_one interaction.
Source code in src/tripwire/plugins/mongo_plugin.py
assert_delete_many
¶
Typed helper: assert the next delete_many interaction.
Source code in src/tripwire/plugins/mongo_plugin.py
assert_aggregate
¶
Typed helper: assert the next aggregate interaction.
Source code in src/tripwire/plugins/mongo_plugin.py
assert_count_documents
¶
Typed helper: assert the next count_documents interaction.