summaryrefslogtreecommitdiff
path: root/factory/declarations.py
diff options
context:
space:
mode:
authorRaphaël Barrois <raphael.barrois@polyconseil.fr>2011-05-24 09:58:16 +0200
committerRaphaël Barrois <raphael.barrois@polyconseil.fr>2011-05-24 09:58:16 +0200
commitcb66c88859d8de161561ae42c9eccd8af56440c8 (patch)
treea9c37f4ad39c661b5f698f08080fb64adda41e44 /factory/declarations.py
parente42516b995053d0d5f8d4d13a94cea4953ea1850 (diff)
downloadfactory-boy-cb66c88859d8de161561ae42c9eccd8af56440c8.tar
factory-boy-cb66c88859d8de161561ae42c9eccd8af56440c8.tar.gz
Fix the SubFactory/Sequence behaviour.
Signed-off-by: Raphaël Barrois <raphael.barrois@polyconseil.fr>
Diffstat (limited to 'factory/declarations.py')
-rw-r--r--factory/declarations.py16
1 files changed, 15 insertions, 1 deletions
diff --git a/factory/declarations.py b/factory/declarations.py
index a4a62af..238e592 100644
--- a/factory/declarations.py
+++ b/factory/declarations.py
@@ -76,7 +76,13 @@ class LazyAttributeSequence(Sequence):
return self.function(attributes, self.type(factory.sequence))
class SubFactory(OrderedDeclaration):
- """Base class for attributes based upon a sub-factory."""
+ """Base class for attributes based upon a sub-factory.
+
+ Attributes:
+ defaults: DeclarationsHolder, the declarations from the wrapped factory
+ factory: Factory, the wrapped factory
+ """
+
def __init__(self, factory, **kwargs):
super(SubFactory, self).__init__()
self.defaults = factory.declarations()
@@ -84,6 +90,14 @@ class SubFactory(OrderedDeclaration):
self.factory = factory
def evaluate(self, factory, create, attributes):
+ """Evaluate the current definition and fill its attributes.
+
+ Uses attributes definition in the following order:
+ - attributes defined in the wrapped factory class
+ - values defined when defining the SubFactory
+ - additional valued defined in attributes
+ """
+
attrs = self.defaults.build_attributes(self.factory, create, attributes)
if create:
return self.factory.create(**attrs)