summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.rst10
-rw-r--r--docs/examples.rst12
2 files changed, 14 insertions, 8 deletions
diff --git a/README.rst b/README.rst
index b4ba689..0ba4a86 100644
--- a/README.rst
+++ b/README.rst
@@ -155,6 +155,16 @@ No matter which strategy is used, it's possible to override the defined attribut
"Joe"
+It is also possible to create a bunch of objects in a single call:
+
+.. code-block:: pycon
+
+ >>> users = USerFactory.build(10, first_name="Joe")
+ >>> len(users)
+ 10
+ >>> [user.first_name for user in users]
+ ["Joe", "Joe", "Joe", "Joe", "Joe", "Joe", "Joe", "Joe", "Joe", "Joe"]
+
Lazy Attributes
"""""""""""""""
diff --git a/docs/examples.rst b/docs/examples.rst
index a57080e..ee521e3 100644
--- a/docs/examples.rst
+++ b/docs/examples.rst
@@ -114,12 +114,9 @@ We can now use our factories, for tests:
def test_get_profile_stats(self):
profiles = []
- for _ in xrange(4):
- profiles.append(factories.ProfileFactory())
- for _ in xrange(2):
- profiles.append(factories.FemaleProfileFactory())
- for _ in xrange(2):
- profiles.append(factories.ProfileFactory(planet='Tatooine'))
+ profiles.extend(factories.ProfileFactory.batch_create(4))
+ profiles.extend(factories.FemaleProfileFactory.batch_create(2))
+ profiles.extend(factories.ProfileFactory.batch_create(2, planet="Tatooine"))
stats = business_logic.profile_stats(profiles)
self.assertEqual({'Earth': 6, 'Mars': 2}, stats.planets)
@@ -133,8 +130,7 @@ Or for fixtures:
from . import factories
def make_objects():
- for _ in xrange(50):
- factories.ProfileFactory()
+ factories.ProfileFactory.batch_create(size=50)
# Let's create a few, known objects.
factories.ProfileFactory(