diff options
author | Raphaël Barrois <raphael.barrois@polyconseil.fr> | 2011-05-16 14:48:23 +0200 |
---|---|---|
committer | Raphaël Barrois <raphael.barrois@polyconseil.fr> | 2011-05-16 14:48:23 +0200 |
commit | f7cb0a040cab507541405d64efbf44b874acf207 (patch) | |
tree | 54f7eb2603bb21ff5e5410a3b634e6261763cae0 /factory/base.py | |
parent | df8b1e10e06a6a6faa15808caa7167f3a8361c55 (diff) | |
download | factory-boy-f7cb0a040cab507541405d64efbf44b874acf207.tar factory-boy-f7cb0a040cab507541405d64efbf44b874acf207.tar.gz |
Add SubFactories, and full testing.
Signed-off-by: Raphaël Barrois <raphael.barrois@polyconseil.fr>
Diffstat (limited to 'factory/base.py')
-rw-r--r-- | factory/base.py | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/factory/base.py b/factory/base.py index e78ec6e..733b130 100644 --- a/factory/base.py +++ b/factory/base.py @@ -153,7 +153,7 @@ class BaseFactory(object): return next_sequence @classmethod - def attributes(cls, **kwargs): + def attributes(cls, create=False, **kwargs): """Build a dict of attribute values, respecting declaration order. The process is: @@ -166,7 +166,11 @@ class BaseFactory(object): attributes = {} cls.sequence = cls._generate_next_sequence() - return getattr(cls, CLASS_ATTRIBUTE_DECLARATIONS).build_attributes(cls, kwargs) + return getattr(cls, CLASS_ATTRIBUTE_DECLARATIONS).build_attributes(cls, create, kwargs) + + @classmethod + def declarations(cls): + return DeclarationsHolder(getattr(cls, CLASS_ATTRIBUTE_DECLARATIONS)) @classmethod def build(cls, **kwargs): @@ -230,8 +234,8 @@ class Factory(BaseFactory): @classmethod def build(cls, **kwargs): - return cls._build(**cls.attributes(**kwargs)) + return cls._build(**cls.attributes(create=False, **kwargs)) @classmethod def create(cls, **kwargs): - return cls._create(**cls.attributes(**kwargs)) + return cls._create(**cls.attributes(create=True, **kwargs)) |