Skip to content

AMHZR/model_mommy

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Creating objects for testing shouldn't hurt

model_mommy is a tool for creating objects for testing in Django, inspired in ruby's ObjectDaddy and FactoryGirl. It generate the values according with the field type, but i will add support to custom values as well.

#Installing

pip install model_mommy

Basic Usage:

If you have a model like this in your app:

class Kid(models.Model):
    name = models.CharField(max_length=30)
    age = models.IntegerField()
    bio = models.TextField()
    birthday = models.DateField()

just call the mommy =):

from model_mommy import mommy
kid = mommy.make_one(Kid)

and your object is created! No boring attributes passing like 'foobar' every damn time.

mommy also handles relationships. Suppose the kid has a dog:

class Dog(models.Model):
    owner = models.ForeignKey('Kid')

when you do:

rex = mommy.make_one(Dog)

it will also create the Kid, automatically.

##Currently supports the fields: CharField, TextField, FloatField, ForeignKey, Date and DateTimeField, BooleanField, and all the integer-type Fields

About

Object factory for django

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published