summaryrefslogtreecommitdiff
path: root/docs/subfactory.rst
diff options
context:
space:
mode:
authorThomas Goirand <thomas@goirand.fr>2013-05-12 05:32:34 +0000
committerThomas Goirand <thomas@goirand.fr>2013-05-12 05:32:34 +0000
commit28991f9514e3cd78a528bbbe956d9b4536c416e0 (patch)
treea3871392d2382f60490824d79058f8a71ae1c34e /docs/subfactory.rst
parent57fa2e21aed37c1af2a87f36a998046b73092a21 (diff)
parent876845102c4a217496d0f6435bfe1e3726d31fe4 (diff)
downloadfactory-boy-28991f9514e3cd78a528bbbe956d9b4536c416e0.tar
factory-boy-28991f9514e3cd78a528bbbe956d9b4536c416e0.tar.gz
Merge tag '2.0.2' into debian/unstable
Release of factory_boy 2.0.2 Conflicts: docs/changelog.rst docs/index.rst docs/subfactory.rst tests/cyclic/bar.py tests/cyclic/foo.py
Diffstat (limited to 'docs/subfactory.rst')
-rw-r--r--docs/subfactory.rst56
1 files changed, 0 insertions, 56 deletions
diff --git a/docs/subfactory.rst b/docs/subfactory.rst
deleted file mode 100644
index 1815312..0000000
--- a/docs/subfactory.rst
+++ /dev/null
@@ -1,56 +0,0 @@
-SubFactory
-==========
-
-Some objects may use other complex objects as parameters; in order to simplify this setup, factory_boy
-provides the :py:class:`factory.SubFactory` class.
-
-This should be used when defining a :py:class:`~factory.Factory` attribute that will hold the other complex object::
-
- import factory
-
- # A standard factory
- class UserFactory(factory.Factory):
- FACTORY_FOR = User
-
- # Various fields
- first_name = 'John'
- last_name = factory.Sequence(lambda n: 'D%se' % ('o' * n)) # De, Doe, Dooe, Doooe, ...
- email = factory.LazyAttribute(lambda o: '%s.%s@example.org' % (o.first_name.lower(), o.last_name.lower()))
-
- # A factory for an object with a 'User' field
- class CompanyFactory(factory.Factory):
- FACTORY_FOR = Company
-
- name = factory.Sequence(lambda n: 'FactoryBoyz' + z * n)
-
- # Let's use our UserFactory to create that user, and override its first name.
- owner = factory.SubFactory(UserFactory, first_name='Jack')
-
-Instantiating the external factory will in turn instantiate an object of the internal factory::
-
- >>> c = CompanyFactory()
- >>> c
- <Company: FactoryBoyz>
-
- # Notice that the first_name was overridden
- >>> c.owner
- <User: Jack De>
- >>> c.owner.email
- jack.de@example.org
-
-Fields of the SubFactory can also be overridden when instantiating the external factory::
-
- >>> c = CompanyFactory(owner__first_name='Henry')
- >>> c.owner
- <User: Henry Doe>
-
- # Notice that the updated first_name was propagated to the email LazyAttribute.
- >>> c.owner.email
- henry.doe@example.org
-
- # It is also possible to override other fields of the SubFactory
- >>> c = CompanyFactory(owner__last_name='Jones')
- >>> c.owner
- <User: Henry Jones>
- >>> c.owner.email
- henry.jones@example.org