summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorRaphaël Barrois <raphael.barrois@polytechnique.org>2013-06-09 18:05:20 +0200
committerRaphaël Barrois <raphael.barrois@polytechnique.org>2013-06-09 18:05:20 +0200
commit639e5cd1c6baf1cb19d9134545e29fbb5ba16d99 (patch)
treeac1f7e194021f7e2e912af3f04ba1706f61c9ab3 /docs
parent9bfc44dba97709aa8731e87b17fb2aed29263057 (diff)
downloadfactory-boy-639e5cd1c6baf1cb19d9134545e29fbb5ba16d99.tar
factory-boy-639e5cd1c6baf1cb19d9134545e29fbb5ba16d99.tar.gz
Move DjangoModelFactory / MogoFactory to their own modules.
Diffstat (limited to 'docs')
-rw-r--r--docs/changelog.rst18
-rw-r--r--docs/introduction.rst2
-rw-r--r--docs/orms.rst32
-rw-r--r--docs/recipes.rst24
-rw-r--r--docs/reference.rst14
5 files changed, 60 insertions, 30 deletions
diff --git a/docs/changelog.rst b/docs/changelog.rst
index 0baa3f7..e820d8c 100644
--- a/docs/changelog.rst
+++ b/docs/changelog.rst
@@ -11,6 +11,8 @@ ChangeLog
- Add a :attr:`~factory.containers.LazyStub.factory_parent` attribute to the
:class:`~factory.containers.LazyStub` passed to :class:`~factory.LazyAttribute`, in order to access
fields defined in wrapping factories.
+ - Move :class:`~factory.django.DjangoModelFactory` and :class:`~factory.mogo.MogoFactory`
+ to their own modules (:mod:`factory.django` and :mod:`factory.mogo`)
*Deprecation:*
@@ -21,7 +23,7 @@ ChangeLog
*New:*
- - When :attr:`~factory.DjangoModelFactory.FACTORY_DJANGO_GET_OR_CREATE` is
+ - When :attr:`~factory.django.DjangoModelFactory.FACTORY_DJANGO_GET_OR_CREATE` is
empty, use ``Model.objects.create()`` instead of ``Model.objects.get_or_create``.
@@ -31,7 +33,7 @@ ChangeLog
*New:*
- Don't push ``defaults`` to ``get_or_create`` when
- :attr:`~factory.DjangoModelFactory.FACTORY_DJANGO_GET_OR_CREATE` is not set.
+ :attr:`~factory.django.DjangoModelFactory.FACTORY_DJANGO_GET_OR_CREATE` is not set.
2.0.0 (2013-04-15)
@@ -44,8 +46,8 @@ ChangeLog
- The default :attr:`~factory.Sequence.type` for :class:`~factory.Sequence` is now :obj:`int`
- Fields listed in :attr:`~factory.Factory.FACTORY_HIDDEN_ARGS` won't be passed to
the associated class' constructor
- - Add support for ``get_or_create`` in :class:`~factory.DjangoModelFactory`,
- through :attr:`~factory.DjangoModelFactory.FACTORY_DJANGO_GET_OR_CREATE`.
+ - Add support for ``get_or_create`` in :class:`~factory.django.DjangoModelFactory`,
+ through :attr:`~factory.django.DjangoModelFactory.FACTORY_DJANGO_GET_OR_CREATE`.
- Add support for :mod:`~factory.fuzzy` attribute definitions.
- The :class:`Sequence` counter can be overridden when calling a generating function
- Add :class:`~factory.Dict` and :class:`~factory.List` declarations (Closes #18).
@@ -75,7 +77,7 @@ New
- **Global:**
- Rewrite the whole documentation
- - Provide a dedicated :class:`~factory.MogoFactory` subclass of :class:`~factory.Factory`
+ - Provide a dedicated :class:`~factory.mogo.MogoFactory` subclass of :class:`~factory.Factory`
- **The Factory class:**
- Better creation/building customization hooks at :meth:`factory.Factory._build` and :meth:`factory.Factory.create`
@@ -92,7 +94,7 @@ New
its :attr:`~factory.Iterator.cycle` argument to ``False``
- Allow overriding default arguments in a :class:`~factory.PostGenerationMethodCall`
when generating an instance of the factory
- - An object created by a :class:`~factory.DjangoModelFactory` will be saved
+ - An object created by a :class:`~factory.django.DjangoModelFactory` will be saved
again after :class:`~factory.PostGeneration` hooks execution
@@ -127,7 +129,7 @@ In order to upgrade client code, apply the following rules:
:class:`~factory.Factory`, instead of relying on automagic associated class
discovery
- When using factory_boy for Django models, have each factory inherit from
- :class:`~factory.DjangoModelFactory`
+ :class:`~factory.django.DjangoModelFactory`
- Replace ``factory.CircularSubFactory('some.module', 'Symbol')`` with
``factory.SubFactory('some.module.Symbol')``
- Replace ``factory.InfiniteIterator(iterable)`` with ``factory.Iterator(iterable)``
@@ -216,7 +218,7 @@ In order to upgrade client code, apply the following rules:
- Introduce :data:`~factory.MOGO_BUILD` build function
- Add support for inheriting from multiple :class:`~factory.Factory`
- Base :class:`~factory.Factory` classes can now be declared :attr:`abstract <factory.Factory.ABSTRACT_FACTORY>`.
- - Provide :class:`~factory.DjangoModelFactory`, whose :class:`~factory.Sequence` counter starts at the next free database id
+ - Provide :class:`~factory.django.DjangoModelFactory`, whose :class:`~factory.Sequence` counter starts at the next free database id
- Introduce :class:`~factory.SelfAttribute`, a shortcut for ``factory.LazyAttribute(lambda o: o.foo.bar.baz``.
*Bugfix:*
diff --git a/docs/introduction.rst b/docs/introduction.rst
index 8bbb10c..356e11f 100644
--- a/docs/introduction.rst
+++ b/docs/introduction.rst
@@ -227,7 +227,7 @@ All factories support two built-in strategies:
as for a Django model.
Starting from 2.0, :meth:`factory.Factory.create` simply calls ``AssociatedClass(**kwargs)``.
- You should use :class:`~factory.DjangoModelFactory` for Django models.
+ You should use :class:`~factory.django.DjangoModelFactory` for Django models.
When a :class:`~factory.Factory` includes related fields (:class:`~factory.SubFactory`, :class:`~factory.RelatedFactory`),
diff --git a/docs/orms.rst b/docs/orms.rst
index 8e5b6f6..9cf7f8e 100644
--- a/docs/orms.rst
+++ b/docs/orms.rst
@@ -11,6 +11,8 @@ adding dedicated features.
Django
------
+.. currentmodule:: factory.django
+
The first versions of factory_boy were designed specifically for Django,
but the library has now evolved to be framework-independant.
@@ -24,14 +26,14 @@ All factories for a Django :class:`~django.db.models.Model` should use the
:class:`DjangoModelFactory` base class.
-.. class:: DjangoModelFactory(Factory)
+.. class:: DjangoModelFactory(factory.Factory)
Dedicated class for Django :class:`~django.db.models.Model` factories.
This class provides the following features:
- * :func:`~Factory.create()` uses :meth:`Model.objects.create() <django.db.models.query.QuerySet.create>`
- * :func:`~Factory._setup_next_sequence()` selects the next unused primary key value
+ * :func:`~factory.Factory.create()` uses :meth:`Model.objects.create() <django.db.models.query.QuerySet.create>`
+ * :func:`~factory.Factory._setup_next_sequence()` selects the next unused primary key value
* When using :class:`~factory.RelatedFactory` or :class:`~factory.PostGeneration`
attributes, the base object will be :meth:`saved <django.db.models.Model.save>`
once all post-generation hooks have run.
@@ -44,7 +46,7 @@ All factories for a Django :class:`~django.db.models.Model` should use the
.. code-block:: python
- class UserFactory(factory.DjangoModelFactory):
+ class UserFactory(factory.django.DjangoModelFactory):
FACTORY_FOR = models.User
FACTORY_DJANGO_GET_OR_CREATE = ('username',)
@@ -68,3 +70,25 @@ All factories for a Django :class:`~django.db.models.Model` should use the
<User: jack>
>>> User.objects.all()
[<User: john>, <User: jack>]
+
+
+Mogo
+----
+
+.. currentmodule:: factory.mogo
+
+factory_boy supports `Mogo`_-style models, through the :class:`MogoFactory` class.
+
+`Mogo`_ is a wrapper around the ``pymongo`` library for MongoDB.
+
+.. _Mogo: https://github.com/joshmarshall/mogo
+
+.. class:: MogoFactory(factory.Factory)
+
+ Dedicated class for `Mogo`_ models.
+
+ This class provides the following features:
+
+ * :func:`~factory.Factory.build()` calls a model's ``new()`` method
+ * :func:`~factory.Factory.create()` builds an instance through ``new()`` then
+ saves it.
diff --git a/docs/recipes.rst b/docs/recipes.rst
index ecdff96..82f0658 100644
--- a/docs/recipes.rst
+++ b/docs/recipes.rst
@@ -25,7 +25,7 @@ use the :class:`~factory.SubFactory` declaration:
import factory
from . import models
- class UserFactory(factory.DjangoModelFactory):
+ class UserFactory(factory.django.DjangoModelFactory):
FACTORY_FOR = models.User
first_name = factory.Sequence(lambda n: "Agent %03d" % n)
@@ -52,7 +52,7 @@ use a :class:`~factory.RelatedFactory` declaration:
# factories.py
- class UserFactory(factory.DjangoModelFactory):
+ class UserFactory(factory.django.DjangoModelFactory):
FACTORY_FOR = models.User
log = factory.RelatedFactory(UserLogFactory, 'user', action=models.UserLog.ACTION_CREATE)
@@ -74,12 +74,12 @@ factory_boy allows to define attributes of such profiles dynamically when creati
.. code-block:: python
- class ProfileFactory(factory.DjangoModelFactory):
+ class ProfileFactory(factory.django.DjangoModelFactory):
FACTORY_FOR = my_models.Profile
title = 'Dr'
- class UserFactory(factory.DjangoModelFactory):
+ class UserFactory(factory.django.DjangoModelFactory):
FACTORY_FOR = auth_models.User
username = factory.Sequence(lambda n: "user_%d" % n)
@@ -129,12 +129,12 @@ hook:
# factories.py
- class GroupFactory(factory.DjangoModelFactory):
+ class GroupFactory(factory.django.DjangoModelFactory):
FACTORY_FOR = models.Group
name = factory.Sequence(lambda n: "Group #%s" % n)
- class UserFactory(factory.DjangoModelFactory):
+ class UserFactory(factory.django.DjangoModelFactory):
FACTORY_FOR = models.User
name = "John Doe"
@@ -184,17 +184,17 @@ If more links are needed, simply add more :class:`RelatedFactory` declarations:
# factories.py
- class UserFactory(factory.DjangoModelFactory):
+ class UserFactory(factory.django.DjangoModelFactory):
FACTORY_FOR = models.User
name = "John Doe"
- class GroupFactory(factory.DjangoModelFactory):
+ class GroupFactory(factory.django.DjangoModelFactory):
FACTORY_FOR = models.Group
name = "Admins"
- class GroupLevelFactory(factory.DjangoModelFactory):
+ class GroupLevelFactory(factory.django.DjangoModelFactory):
FACTORY_FOR = models.GroupLevel
user = factory.SubFactory(UserFactory)
@@ -257,20 +257,20 @@ Here, we want:
.. code-block:: python
# factories.py
- class CountryFactory(factory.DjangoModelFactory):
+ class CountryFactory(factory.django.DjangoModelFactory):
FACTORY_FOR = models.Country
name = factory.Iterator(["France", "Italy", "Spain"])
lang = factory.Iterator(['fr', 'it', 'es'])
- class UserFactory(factory.DjangoModelFactory):
+ class UserFactory(factory.django.DjangoModelFactory):
FACTORY_FOR = models.User
name = "John"
lang = factory.SelfAttribute('country.lang')
country = factory.SubFactory(CountryFactory)
- class CompanyFactory(factory.DjangoModelFactory):
+ class CompanyFactory(factory.django.DjangoModelFactory):
FACTORY_FOR = models.Company
name = "ACME, Inc."
diff --git a/docs/reference.rst b/docs/reference.rst
index ad921fa..377feb1 100644
--- a/docs/reference.rst
+++ b/docs/reference.rst
@@ -606,7 +606,9 @@ The :class:`SubFactory` attribute should be called with:
factory
-.. note:: When passing an actual :class:`~factory.Factory` for the
+.. note::
+
+ When passing an actual :class:`~factory.Factory` for the
:attr:`~factory.SubFactory.factory` argument, make sure to pass
the class and not instance (i.e no ``()`` after the class):
@@ -1070,7 +1072,9 @@ RelatedFactory
keyword:
-.. note:: When passing an actual :class:`~factory.Factory` for the
+.. note::
+
+ When passing an actual :class:`~factory.Factory` for the
:attr:`~factory.RelatedFactory.factory` argument, make sure to pass
the class and not instance (i.e no ``()`` after the class):
@@ -1266,7 +1270,7 @@ factory during instantiation.
.. code-block:: python
- class UserFactory(factory.DjangoModelFactory):
+ class UserFactory(factory.django.DjangoModelFactory):
FACTORY_FOR = User
username = 'user'
@@ -1357,12 +1361,12 @@ Lightweight factory declaration
UserFactory = make_factory(models.User,
login='john',
email=factory.LazyAttribute(lambda u: '%s@example.com' % u.login),
- FACTORY_CLASS=factory.DjangoModelFactory,
+ FACTORY_CLASS=factory.django.DjangoModelFactory,
)
# This is equivalent to:
- class UserFactory(factory.DjangoModelFactory):
+ class UserFactory(factory.django.DjangoModelFactory):
FACTORY_FOR = models.User
login = 'john'