Mongomock with persistence
Reason this release was yanked:
broken description
Project description
# Mongomock with persistence
This is a package based on the [mongomock](https://github.com/mongomock/mongomock) package to test any code using MongoDB via the [PyMongo API](https://pymongo.readthedocs.io).
With [mongomock](https://github.com/mongomock/mongomock) the documents are stored in memory and not available after the process performing the tests exits. In some test cases it is necessary to have a non-volatile (persistent) storage of the database. For example, tests of command line interfaces (CLI) add things into the database and assume they are then available across several processes.
## How it works
This package adds an option to store the database in a file. This is accomplished by small extensions of the classes in store.py. The file store is not intended to keep the database synchronized instantly on disk. Rather the database is eventually dumped to a file only just before the ServerStore object is destroyed. After that the file can be used to create other ServerStore objects in exactly that state as the original ServerStore object.
## When to use
In test cases where a database must be used by several consecutive processes and the database state has to be preserved in the meantimes.
In tutorials to learn the basics of using PyMongo-based software.
In further single-client applications of MongoDB.
In all use cases one has to make sure that all PyMongo features used are covered by mongomock. See [this](https://github.com/mongomock/mongomock/blob/develop/Missing_Features.rst) for further details.
## How to install
The package can be easily installed using pip:
` pip install mongomock-persistence `
## How to use
To use the package the MongoClient class from this package must be imported instead of that from [mongomock](https://github.com/mongomock/mongomock). Then the persistence can be activated in two ways:
Set the environment variable MONGOMOCK_SERVERSTORE_FILE to the name of a non-empty JSON file (initialized with ‘{}’) and call MongoClient class as usual:
` export MONGOMOCK_SERVERSTORE_FILE=/full/path/to/mongomock_file.json `
`python from mongomock_persistence import MongoClient mongo_client = MongoClient() `
Create a custom ServerStore object explicitly by using the filename keyword argument and then pass it to MongoClient call:
`python from mongomock_persistence import MongoClient mongo_store = ServerStore(filename='/full/path/to/mongomock_file.json') mongo_client = MongoClient(_store=mongo_store) `
## How to test
Install the tests extra and then run pytest, i.e.
` pip install mongomock-persistence[tests] pytest <root folder of repository> `
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file mongomock_persistence-0.0.1.tar.gz
.
File metadata
- Download URL: mongomock_persistence-0.0.1.tar.gz
- Upload date:
- Size: 5.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fd58b4ed21350dd02e35bbbdb81e752395873d4974f949c7523e8c7c28c58807 |
|
MD5 | 9cadb7acfee64197c67e1ef3cbb826e0 |
|
BLAKE2b-256 | 33fd62196f7a8768f963d57561f646ab2ec4195205e4cbf6f9e309aeb902d501 |
File details
Details for the file mongomock_persistence-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: mongomock_persistence-0.0.1-py3-none-any.whl
- Upload date:
- Size: 4.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 76b9b07ca6e4c4d04a96cc0dae0011208a1a0cef869702b191aed0da9bcbedd4 |
|
MD5 | c174c8eaffa8691de9ebc58b83ae0df1 |
|
BLAKE2b-256 | 4a28922972ac5bf88e66579cc49df078cbdec16ad384d3072aed57817dfc102c |