Skip to main content
Join the official 2020 Python Developers SurveyStart the survey!

A library to create peewee model instances for testing.

Project description

peewee_model_factory

No time? Ready to use?

pip install peewee-model-factory
from peewee_model_factory import model_factory
from model import Author, Book

author = model_factory(Author, fill_nullable_values=True)
book = model_factory(Book, author=author)

Need custom type generation?

import peewee as pw
from peewee_model_factory import model_factory

def char_field_factory(field: pw.Field) -> str:
    return f"my char value for field: {field.name}"


field_type_map = {
    pw.CharField: char_field_factory,
}


def my_custom_model_factory(*args, **kwargs) -> pw.Model:
    return model_factory(*args, custom_field_type_map=field_type_map, **kwargs) 

Want to use with peewee-async?

import peewee as pw
from peewee_model_factory import model_factory
from peewee_async import Manager

manager = Manager(...)


def my_custom_model_factory(*args, **kwargs) -> pw.Model:
    with manager.allow_sync():
        return model_factory(*args, **kwargs) 

Description

A library to create peewee model instances for testing. The project creation has been inspired by django-dynamic-fixture and peewee-fake_fixtures projects.

Features

  • Recursevely creating models for foreign fields
  • An option for filling nullable values
  • Easy customization if you need to extend or change generation for types of peewee fields

Possible inconvenience

  • The project has no tests.
  • Not all field types of peeweee has factory function in the project. You have to write custom one if you want to use them

Project details


Download files

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

Files for peewee-model-factory, version 0.1.1
Filename, size File type Python version Upload date Hashes
Filename, size peewee_model_factory-0.1.1-py3-none-any.whl (6.0 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size peewee-model-factory-0.1.1.tar.gz (4.1 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page