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
Release files for factory-man 1.2.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| factory-man-1.2.3.tar.gz | 4.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| factory_man-1.2.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.5 kB
Release files / factory-man-1.2.3.tar.gz
| Download URL | factory-man-1.2.3.tar.gz |
|---|---|
| Size | 4.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6efffbfb5ccd407ef9fb214be0d453a5ebb9bb5a1bd19d7cddd5f95607ee3290
|
|
BLAKE2b-256 checksum How to use checksums |
51c925362f9d92f412296f772d9380ccbd51ec0027f86213b7675b9b9548aadb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Release files / factory_man-1.2.3-py3-none-any.whl
| Download URL | factory_man-1.2.3-py3-none-any.whl |
|---|---|
| Size | 5.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
36e937f39d7e2c81b8cc1a68ae5d7c8e59cef48a507ad12214a95792ba6bc87c
|
|
BLAKE2b-256 checksum How to use checksums |
bb8cbbf1d018f3bdae488739d72e5d96c0ccd28244ed20e17d9a6cc0e86b3c25
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|