mongoengine_fuel

A factory for mongoengine documents
Download

mongoengine_fuel Ranking & Summary

Advertisement

  • Rating:
  • License:
  • LGPL
  • Publisher Name:
  • Bernardo Fontes
  • Publisher web site:
  • http://bernardofontes.net

mongoengine_fuel Tags


mongoengine_fuel Description

A factory for mongoengine documents mongoengine_fuel is a Python utility for creating objects for testing in Python projetcs which uses mongoengine ORM to talk to MongoDB. mongoengine_fuel is inspired in model_mommy, a tool with the same purpose but for Django projects.Installingpip install mongoengine_fuelSimple example:Here is our pretty new car document and a person document:from mongoengine import *class Person(Document): name = StringField() age = IntField() def __unicode__(self): return u'%s - %d years' % (self.name, self.age)class Car(Document): wheels = IntField() name = StringField() max_speed = DecimalField() owner = ReferenceField(Person) def __unicode__(self): return u'Car --> name: %s, wheels: %d, max_speed:%f, owner:%s' \ % (self.name, self.wheels, self.max_speed, self.owner)Now, just add some fuel:from mongoengine_fuel import MongoFuelfrom your_models import Car, Personcar = MongoFuel.create_one(Car)And now you can ride with your car! Note that mongoengine_fuel already handles relationships like ReferenceField just like the example above. It creates an Person's instance automatically for you and persists both documents.Please, don't polute my databaseIf you don't want the behaviour mentioned above, you just need to ask to mongoengine_fuel to don't save your document on the database like this:car = MongoFuel.create_one(Car, persists=False)This call will just return an Car's instance without saving it. The Person's instance which is created for you isn't save either.I wanna a specific value for a fieldIf you need a particular value for a field inside your document, you can force a value to it. You just need to give it as a parameter. Like this:richard = Person.objects.create(name='Richard', age=30)car = MongoFuel.create_one(Car, owner=richard)You will see that a random Car object is created, but the owner is the one that you specified.What about embedded documents?mongoengine_fuel hanle with these guys to. It creates randoms embedded documents for you with exactly the same usage as common documents.mongoengine's fields supported: BooleanField StringField FloatField DecimalField IntField URLField EmailField ReferenceField EmbeddedDocumentField ListField Requirements: · Python


mongoengine_fuel Related Software