Skip to content

Latest commit

 

History

History
40 lines (30 loc) · 907 Bytes

README.md

File metadata and controls

40 lines (30 loc) · 907 Bytes

factoryboy-gaendb

Factoryboy base factories and helpers for Google App Engine ndb models

Example:

from gaendb.factories import NDBFactory, KeyAttribute

class UserFactory(NDBFactory):
    class Meta:
        model = User

    name = fuzzy.FuzzyText()
    gender = fuzzy.FuzzyChoice(['M', 'F'])

class ArticleFactory(NDBFactory):
    class Meta:
        model = Article

    author = KeyAttribute(UserFactory)
    title = fuzzy.FuzzyText()
In  [1]: article = ArticleFactory()  # build
In  [2]: article.author
Out [2]: Key('User', 1)
In  [3]: article.author.get()
Out [3]: User(key=Key('User', 1), gender='F', name=u'UvaxfhCjiwlg')  # built instance

Can set id and/or parent of the key when building:

In  [1]: article = ArticleFactory(id=27)
In  [2]: article.key
Out [2]: Key('Article', 27)