summaryrefslogtreecommitdiff
path: root/factory
diff options
context:
space:
mode:
authorRaphaël Barrois <raphael.barrois@polytechnique.org>2012-01-06 23:43:52 +0100
committerRaphaël Barrois <raphael.barrois@polytechnique.org>2012-01-06 23:43:52 +0100
commitbcc1ad6fdce458ae3b24270789ab60ddd2425c4a (patch)
treeba73ba9cc16e6bffed9f843500a23c1ddb3013c7 /factory
parent8563a98022b8b3e855bf036a57aad4fd86319eff (diff)
downloadfactory-boy-bcc1ad6fdce458ae3b24270789ab60ddd2425c4a.tar
factory-boy-bcc1ad6fdce458ae3b24270789ab60ddd2425c4a.tar.gz
Publish the make_factory method, and make sure that complex declarations work with it.
Signed-off-by: Raphaël Barrois <raphael.barrois@polytechnique.org>
Diffstat (limited to 'factory')
-rw-r--r--factory/__init__.py1
-rw-r--r--factory/base.py12
2 files changed, 9 insertions, 4 deletions
diff --git a/factory/__init__.py b/factory/__init__.py
index f2652f2..b673162 100644
--- a/factory/__init__.py
+++ b/factory/__init__.py
@@ -31,6 +31,7 @@ from base import (
build,
create,
stub,
+ make_factory,
BUILD_STRATEGY,
CREATE_STRATEGY,
diff --git a/factory/base.py b/factory/base.py
index 80c49ca..19d441b 100644
--- a/factory/base.py
+++ b/factory/base.py
@@ -442,7 +442,8 @@ class DjangoModelFactory(Factory):
return 1
-def _make_factory(klass, **kwargs):
+def make_factory(klass, **kwargs):
+ """Create a new, simple factory for the given class."""
factory_name = '%sFactory' % klass.__name__
kwargs[FACTORY_CLASS_DECLARATION] = klass
factory_class = type(Factory).__new__(type(Factory), factory_name, (Factory,), kwargs)
@@ -452,10 +453,13 @@ def _make_factory(klass, **kwargs):
def build(klass, **kwargs):
- return _make_factory(klass, **kwargs).build()
+ """Create a factory for the given class, and build an instance."""
+ return make_factory(klass, **kwargs).build()
def create(klass, **kwargs):
- return _make_factory(klass, **kwargs).create()
+ """Create a factory for the given class, and create an instance."""
+ return make_factory(klass, **kwargs).create()
def stub(klass, **kwargs):
- return _make_factory(klass, **kwargs).stub()
+ """Create a factory for the given class, and stub an instance."""
+ return make_factory(klass, **kwargs).stub()