Skip to main content

Add additional feature for mongomock.

Project description

https://travis-ci.org/MacHu-GWU/mongomock_mate-project.svg?branch=master https://codecov.io/gh/MacHu-GWU/mongomock_mate-project/branch/master/graph/badge.svg https://img.shields.io/pypi/v/mongomock_mate.svg https://img.shields.io/pypi/l/mongomock_mate.svg https://img.shields.io/pypi/pyversions/mongomock_mate.svg https://img.shields.io/badge/Star_Me_on_GitHub!--None.svg?style=social

Welcome to mongomock_mate Documentation

Use mongomock_mate:

Just import mongomock_mate at begin of your script. It use monkey patch:

import mongomock_mate

Features:

Data Persistence: dump and load data

import mongomock_mate

# dump
db = client["test"]
c_user = db["user"]

c_user.insert([{"_id": 1, "name": "Alice"}, {"_id": 2, "name": "Bob"}])

db.dump_db("test.json")

# load
db = client["test"]
db.load_db("test.json")

# other params
def dump_db(self, file,
            pretty=False,
            overwrite=False,
            verbose=True):
    """
    Dump :class:`mongomock.database.Database` to a local file. Only support
    ``*.json`` or ``*.gz`` (compressed json file)

    :param file: file path.
    :param pretty: bool, toggle on jsonize into pretty format.
    :param overwrite: bool, allow overwrite to existing file.
    :param verbose: bool, toggle on log.
    """

def load_db(self, file, check_dbname=True, verbose=True):
    """
    Load :class:`mongomock.database.Database` from a local file.

    :param file: file path.
    :param check_dbname: bool, if True, the dbname has to be matched.
    :param verbose: bool, toggle on log.
    """

Working with mongoengine ORM:

2018-07-30:

At mongomock==3.10.0, insert operation doesn’t work with latest mongoengine==0.15.3, because the implementation of WriteConcern is not correct in mongomock.

Github Issue.

import mongomock_mate
from mongoengine import connect, Document, fields

connect('mongoenginetest', host='mongomock://localhost')

class User(Document):
    _id = fields.IntField(primary_key=True)
    name = fields.StringField()

User.objects.insert(User(_id=1, name="Alice"))

Install

mongomock_mate is released on PyPI, so all you need is:

$ pip install mongomock_mate

To upgrade to latest version:

$ pip install --upgrade mongomock_mate

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mongomock_mate-0.0.1.tar.gz (14.8 kB view hashes)

Uploaded Source

Built Distribution

mongomock_mate-0.0.1-py2-none-any.whl (24.9 kB view hashes)

Uploaded Python 2

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page