Django specific Extensions for Factory Boy
Project description
FactoryMan
FactoryMan provides Django specific extensions for Factory Boy.
Installation
pip install factory-man
Usage
FactoryMan provides you with a factory function create_populated_modelfactory, which accepts the model class and automatically creates a factory class based on the model's fields. If you want to override some fields, you can pass them as keyword arguments to the __init__ method.
from factoryman import create_populated_modelfactory
from .models import Project
ProjectFactory = create_populated_modelfactory(Project)
ExpiredProjectFactory = create_populated_modelfactory(Project, deadline='1999-04-04')
To override the factory's _create method, use create_override keyword argument. This is useful to create many-to-many connections as described in the Factory Boy documentation.
Check out this article for a more detailed user guide.
Low-level Features
ModelFieldSequence extends factory.Sequence to provide a little more DRY syntax. It accepts a Django model class as parameter and uses the class name togeteher with the field name to which it is bound to for creating an unique value.
Alternatively, it can accept a string parameter, which will be used directly instead of a name derived from the class and field.
Example:
from factory.django import DjangoModelFactory as ModelFactory
from factoryman import ModelFieldSequence
class CharityFactory(ModelFactory):
class Meta:
model = Charity
name = ModelFieldSequence(Charity) # Will be `Charity__name-n`, where n is the object count
email = ModelFieldSequence(string='hello@charity.ee') # Will be `hello@charity.ee-n`, where n is the object count
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file factory-man-1.2.3.tar.gz.
File metadata
- Download URL: factory-man-1.2.3.tar.gz
- Upload date:
- Size: 4.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6efffbfb5ccd407ef9fb214be0d453a5ebb9bb5a1bd19d7cddd5f95607ee3290
|
|
| MD5 |
0145c2dcb3a95236a564b06c34ece39e
|
|
| BLAKE2b-256 |
51c925362f9d92f412296f772d9380ccbd51ec0027f86213b7675b9b9548aadb
|
File details
Details for the file factory_man-1.2.3-py3-none-any.whl.
File metadata
- Download URL: factory_man-1.2.3-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
36e937f39d7e2c81b8cc1a68ae5d7c8e59cef48a507ad12214a95792ba6bc87c
|
|
| MD5 |
eac9a7153e80940f21e5a4180f1ce110
|
|
| BLAKE2b-256 |
bb8cbbf1d018f3bdae488739d72e5d96c0ccd28244ed20e17d9a6cc0e86b3c25
|