Django object manager for tests
Project description
django-object-manager
Simple, declarative, repeatable object management for Django tests
Examples:
# Model registration - usuallu in app/tests.py
# from .models import ...
from .models import User, Film, FilmCategory
from django_object_manager import ObjManagerMixin, ObjectManager
ObjectManager.register(
User,
{
'bob': {
'name': 'Bob',
'email': 'bob@domain.com',
},
'alice': {
'name': 'Alice',
'email': 'alice@example.com',
},
})
ObjectManager.register(
FilmCategory,
{
'drama': {
'name': 'Drama',
},
'crime': {
'name': 'Crime',
},
'serious': {
'name': 'Adult films',
},
'anime': {
'name': 'Anime',
'parent': 'serious',
},
})
ObjectManager.register(
Film,
{
'memento': {
'name': 'Memento',
'year': 2000,
'uploaded_by': 'bob',
'categories': ['crime', 'drama']
},
})
# Further usage in tests:
object_manager = ObjectManager() # or self.object_manager if inherited from
# Single object creation - 'bob' is previously registered idenitifier
bob = object_manager.get_user('bob')
# Object creation with attribute owerwriting
user3 = object_manager.get_user('bob', email='other@domain.com')
# Fully custom object creation
user = object_manager.get_user(name='Jack',
email='test@test.org')
# All predefined objects of given model - returns id:object dictionary
user = object_manager.get_users()
# Object with dependencies - dependencies are referenced by
# - their registered indentifiers
# - by passing already created object
memento = object_manager.get_film('memento') # Will create two categories and one user
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
File details
Details for the file django_object_manager-0.0.9-py2.py3-none-any.whl
.
File metadata
- Download URL: django_object_manager-0.0.9-py2.py3-none-any.whl
- Upload date:
- Size: 9.9 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.7.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5beccadc849b6e4731e687cd127a911a324e301af5436fde15759f211be3a61a |
|
MD5 | 3c876c2848360d1a4c3fae0131db79bd |
|
BLAKE2b-256 | fc77b8e0ac6f0f18cb8bf19d9a4984583feaa135c169557f1a90b6a1033e8057 |