Skip to main content

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

Project description

Mixer is simply application for generate instances of Django or SQLAlchemy models. It’s useful for testing or fixtures replacement. Fast and convenient test-data generation.

Mixer supports:

  • Django;

  • SQLAlchemy;

  • Flask-SqlAlchemy (only for python 2.6, 2.7);

  • Custom schemes;

Build Status

Documentation on pypi: http://pythonhosted.org/mixer/index.html

Requirements

  • python (2.6, 2.7, 3.2, 3.3)

  • Django (1.4, 1.5) for django ORM suport;

  • SQLAlchemy for SQLAlchemy ORM suport;

  • Flask-SQLALchemy for SQLAlchemy ORM suport and integration as Flask application;

Installation

Mixer should be installed using pip:

pip install mixer

Usage

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

Django

Quick example:

from mixer.backend.django import mixer
from customapp.models import User, UserMessage

# Generate random User
user = mixer.blend(User)

# Generate UserMessage
message = mixer.blend(UserMessage, user=user)

# Generate UserMessage and User. Set User.username to 'testname'.
message = mixer.blend(UserMessage, user__username='testname')

# Generate SomeModel from SomeApp and select FK or M2M values from db
some = mixer.blend('someapp.somemodel', somerelation=mixer.select)

# Generate SomeModel from SomeApp and force a value of field with default to random
some = mixer.blend('someapp.somemodel', money=mixer.random)

# Generate 5 SomeModel instances and get a field values from custom generator
some_models = mixer.cycle(5).blend('someapp.somemodel', company=(company for company in companies))

Flask, Flask-SQLAlchemy

Quick example:

from mixer.backend.flask import mixer
from models import User, UserMessage

mixer.init_app(self.app)

# Generate random User
user = mixer.blend(User)

# Generate UserMessage
message = mixer.blend(UserMessage, user=user)

# Generate UserMessage and User. Set User.username to 'testname'.
message = mixer.blend(UserMessage, user__username='testname')

# Generate SomeModel and select FK or M2M values from db
some = mixer.blend('project.models.SomeModel', somerelation=mixer.select)

# Generate SomeModel from SomeApp and force a value of field with default to random
some = mixer.blend('project.models.SomeModel', money=mixer.random)

# Generate 5 SomeModel instances and get a field values from custom generator
some_models = mixer.cycle(5).blend('project.models.SomeModel', company=(company for company in companies))

SQLAlchemy

Example of initialization:

from mixer.backend.sqlalchemy import Mixer

ENGINE = create_engine('sqlite:///:memory:')
BASE = declarative_base()
SESSION = sessionmaker(bind=ENGINE)

mixer = Mixer(session=SESSION(), commit=True)
role = mixer.blend('package.models.Role')

Also see Flask, Flask-SQLALchemy.

Common usage

Quick example:

from mixer.main import Mixer

class Test:
    one = int
    two = int
    name = str

class Scheme:
    name = str
    money = int
    male = bool
    prop = Test

scheme = mixer.blend(Sheme, prop__one=1)

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 starter happens at github: https://github.com/klen/mixer

Contributors

License

Licensed under a BSD license.

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

mixer-0.3.0.tar.gz (19.6 kB view details)

Uploaded Source

File details

Details for the file mixer-0.3.0.tar.gz.

File metadata

  • Download URL: mixer-0.3.0.tar.gz
  • Upload date:
  • Size: 19.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for mixer-0.3.0.tar.gz
Algorithm Hash digest
SHA256 854be080779fd11ebb2d3f21a127bcd1ef86c6c4db49fa0253e15369399472da
MD5 fc0a44619d2365dee9e599d09f03d4d3
BLAKE2b-256 d6ddc49088ec7c7108c1e3ec58c5c8b06c17e85b636834e4cb14ed5690cbf994

See more details on using hashes here.

Supported by

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