summaryrefslogtreecommitdiff
path: root/docs/examples.rst
diff options
context:
space:
mode:
Diffstat (limited to 'docs/examples.rst')
-rw-r--r--docs/examples.rst28
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