diff options
author | Raphaël Barrois <raphael.barrois@polytechnique.org> | 2012-03-17 02:29:24 +0100 |
---|---|---|
committer | Raphaël Barrois <raphael.barrois@polytechnique.org> | 2012-03-17 02:29:24 +0100 |
commit | db643d44c51659d9460aa73eb21e7888b22896de (patch) | |
tree | ec38350de8e827cc0ff418f7946f3b399ab29e80 /factory | |
parent | 84019217057d1752fba021b2bfe940af5636977d (diff) | |
download | factory-boy-db643d44c51659d9460aa73eb21e7888b22896de.tar factory-boy-db643d44c51659d9460aa73eb21e7888b22896de.tar.gz |
Add a '@use_strategy' decorator for forcing alternate strategies.
Signed-off-by: Raphaël Barrois <raphael.barrois@polytechnique.org>
Diffstat (limited to 'factory')
-rw-r--r-- | factory/__init__.py | 1 | ||||
-rw-r--r-- | factory/base.py | 11 |
2 files changed, 12 insertions, 0 deletions
diff --git a/factory/__init__.py b/factory/__init__.py index 1d4408f..dd91343 100644 --- a/factory/__init__.py +++ b/factory/__init__.py @@ -44,6 +44,7 @@ from base import ( BUILD_STRATEGY, CREATE_STRATEGY, STUB_STRATEGY, + use_strategy, DJANGO_CREATION, NAIVE_BUILD, diff --git a/factory/base.py b/factory/base.py index 62131fb..ef782c7 100644 --- a/factory/base.py +++ b/factory/base.py @@ -614,3 +614,14 @@ def simple_generate(klass, create, **kwargs): def simple_generate_batch(klass, create, size, **kwargs): """Create a factory for the given class, and simple_generate instances.""" return make_factory(klass, **kwargs).simple_generate_batch(create, size) + + +def use_strategy(new_strategy): + """Force the use of a different strategy. + + This is an alternative to setting default_strategy in the class definition. + """ + def wrapped_class(klass): + klass.default_strategy = new_strategy + return klass + return wrapped_class |