paulchubatyy / mixer

Mixer -- Is a fixtures replacement. Supported Django, Flask, SqlAlchemy and custom python objects.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

image

The Mixer is a helper to generate instances of Django or SQLAlchemy models. It's useful for testing and fixture replacement. Fast and convenient test-data generation.

Mixer supports:

Tests Status

Version

Downloads

License

Docs are available at https://mixer.readthedocs.org/. Pull requests with documentation enhancements and/or fixes are awesome and most welcome.

Описание на русском языке: http://klen.github.io/mixer.html

Important

From version 6.2 the Mixer library doesn't support Python 2. The latest version with python<3 support is mixer 6.1.3

Requirements

  • Python 3.7+
  • Django (3.0, 3.1) for Django ORM support;
  • Flask-SQLALchemy for SQLAlchemy ORM support and integration as Flask application;
  • Faker >= 0.7.3
  • Mongoengine for Mongoengine ODM support;
  • SQLAlchemy for SQLAlchemy ORM support;
  • Peewee ORM support;

Installation

Mixer should be installed using pip: :

pip install mixer

Usage

  By default Mixer tries to generate fake (human-friendly) data.
  If you want to randomize the generated values initialize the Mixer
  by manual: Mixer(fake=False)
  By default Mixer saves the generated objects in a database. If you want to disable
  this, initialize the Mixer by manual like Mixer(commit=False)

Django workflow

Quick example:

Flask, Flask-SQLAlchemy

Quick example:

Support for Flask-SQLAlchemy models that have __init__ arguments

For support this scheme, just create your own mixer class, like this:

SQLAlchemy workflow

Example of initialization:

Also, see Flask, Flask-SQLAlchemy.

Mongoengine workflow

Example usage:

Marshmallow workflow

Example usage:

Common usage

Quick example:

DB commits

By default 'django', 'flask', 'mongoengine' backends tries to save objects in database. For preventing this behavior init mixer manually:

Or you can temporary switch context use the mixer as context manager:

Custom fields

The mixer allows you to define generators for fields by manually. Quick example:

Also, you can make your own factory for field types:

Middlewares

You can add middleware layers to process generation:

You can add several middlewares. Each middleware should get one argument (generated value) and return them.

It's also possible to unregister a middleware:

Locales

By default mixer uses 'en' locale. You could switch mixer default locale by creating your own mixer:

At any time you could switch mixer current locale:

Bug tracker

If you have any suggestions, bug reports or annoyances please report them to the issue tracker at https://github.com/klen/mixer/issues

Contributing

Development of mixer happens at Github: https://github.com/klen/mixer

Contributors

License

Licensed under a BSD license.

About

Mixer -- Is a fixtures replacement. Supported Django, Flask, SqlAlchemy and custom python objects.

License:Other


Languages

Language:Python 98.6%Language:Makefile 1.4%