summaryrefslogtreecommitdiff
path: root/factory/declarations.py
diff options
context:
space:
mode:
authorRaphaël Barrois <raphael.barrois@polyconseil.fr>2011-06-13 11:33:37 +0200
committerRaphaël Barrois <raphael.barrois@polyconseil.fr>2011-06-13 11:33:37 +0200
commitb832744b70ed811029edb045afc42ea307073c8e (patch)
treeef6e566f70e7a1004a6d1d875121df9bd12683b5 /factory/declarations.py
parente16a7e3d15c7b88bceadbbe1d75363103570e2b3 (diff)
downloadfactory-boy-b832744b70ed811029edb045afc42ea307073c8e.tar
factory-boy-b832744b70ed811029edb045afc42ea307073c8e.tar.gz
Add a new type of attribute, SelfAttribute.
Should be used as a shortcut for 'lambda o: o.some_attr' ; most useful in SubFactories. Signed-off-by: Raphaël Barrois <raphael.barrois@polyconseil.fr>
Diffstat (limited to 'factory/declarations.py')
-rw-r--r--factory/declarations.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/factory/declarations.py b/factory/declarations.py
index 238e592..d827f30 100644
--- a/factory/declarations.py
+++ b/factory/declarations.py
@@ -62,6 +62,16 @@ class LazyAttribute(OrderedDeclaration):
def evaluate(self, factory, attributes):
return self.function(attributes)
+
+class SelfAttribute(OrderedDeclaration):
+ def __init__(self, attribute_name):
+ super(SelfAttribute, self).__init__()
+ self.attribute_name = attribute_name
+
+ def evaluate(self, factory, attributes):
+ return getattr(attributes, self.attribute_name)
+
+
class Sequence(OrderedDeclaration):
def __init__(self, function, type=str):
super(Sequence, self).__init__()