diff options
author | Thomas Goirand <thomas@goirand.fr> | 2013-05-12 05:32:34 +0000 |
---|---|---|
committer | Thomas Goirand <thomas@goirand.fr> | 2013-05-12 05:32:34 +0000 |
commit | 28991f9514e3cd78a528bbbe956d9b4536c416e0 (patch) | |
tree | a3871392d2382f60490824d79058f8a71ae1c34e /docs/examples.rst | |
parent | 57fa2e21aed37c1af2a87f36a998046b73092a21 (diff) | |
parent | 876845102c4a217496d0f6435bfe1e3726d31fe4 (diff) | |
download | factory-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/examples.rst')
-rw-r--r-- | docs/examples.rst | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/docs/examples.rst b/docs/examples.rst index cac6bc6..aab990a 100644 --- a/docs/examples.rst +++ b/docs/examples.rst @@ -7,7 +7,10 @@ Here are some real-world examples of using FactoryBoy. Objects ------- -First, let's define a couple of objects:: +First, let's define a couple of objects: + + +.. code-block:: python class Account(object): def __init__(self, username, email): @@ -41,7 +44,10 @@ First, let's define a couple of objects:: Factories --------- -And now, we'll define the related factories:: +And now, we'll define the related factories: + + +.. code-block:: python import factory import random @@ -60,15 +66,18 @@ And now, we'll define the related factories:: FACTORY_FOR = objects.Profile account = factory.SubFactory(AccountFactory) - gender = random.choice([objects.Profile.GENDER_MALE, objects.Profile.GENDER_FEMALE]) + gender = factory.Iterator([objects.Profile.GENDER_MALE, objects.Profile.GENDER_FEMALE]) firstname = u'John' lastname = u'Doe' -We have now defined basic factories for our :py:class:`~Account` and :py:class:`~Profile` classes. +We have now defined basic factories for our :class:`~Account` and :class:`~Profile` classes. + +If we commonly use a specific variant of our objects, we can refine a factory accordingly: -If we commonly use a specific variant of our objects, we can refine a factory accordingly:: + +.. code-block:: python class FemaleProfileFactory(ProfileFactory): gender = objects.Profile.GENDER_FEMALE @@ -80,7 +89,10 @@ If we commonly use a specific variant of our objects, we can refine a factory ac Using the factories ------------------- -We can now use our factories, for tests:: +We can now use our factories, for tests: + + +.. code-block:: python import unittest @@ -112,7 +124,9 @@ We can now use our factories, for tests:: self.assertLess(stats.genders[objects.Profile.GENDER_FEMALE], 2) -Or for fixtures:: +Or for fixtures: + +.. code-block:: python from . import factories |