Skip to main content

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.

Source Distribution

peewee-model-factory-0.1.1.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

peewee_model_factory-0.1.1-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file peewee-model-factory-0.1.1.tar.gz.

File metadata

  • Download URL: peewee-model-factory-0.1.1.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.2

File hashes

Hashes for peewee-model-factory-0.1.1.tar.gz
Algorithm Hash digest
SHA256 e651d94f3f95ce07674e2db3794d0328eb4fe55aa7f1fcba6048bfaf8ca466e6
MD5 1e04524bca64bb027650e885f753b9d7
BLAKE2b-256 0444b5943cd045069e95dc5d67c9e77d83c7cc3d34bc01fab9e86028f82e977e

See more details on using hashes here.

File details

Details for the file peewee_model_factory-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: peewee_model_factory-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.2

File hashes

Hashes for peewee_model_factory-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 af9947e44a1c6679484b8e9a83d7ebee824b4bbfda6494ca9a18d7d5b17f32c0
MD5 8a127796d771554cd5fcf4a15b9cfcf6
BLAKE2b-256 7deadd8bc6e9e9b4cf04bda3edb2a9beae320ba9d31f294eb1219c0b99f364b4

See more details on using hashes here.

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