diff options
author | Raphaël Barrois <raphael.barrois@polytechnique.org> | 2012-05-04 01:17:59 +0200 |
---|---|---|
committer | Raphaël Barrois <raphael.barrois@polytechnique.org> | 2012-05-04 01:17:59 +0200 |
commit | d96c651f51b25988235ff79b50c7f9355fb16dd7 (patch) | |
tree | 02972dccdf0301df2e8781d44de47fd7d3b99598 /tests/test_declarations.py | |
parent | fbd66ede5617a40f73dfb3f518c9887d48ab401e (diff) | |
download | factory-boy-d96c651f51b25988235ff79b50c7f9355fb16dd7.tar factory-boy-d96c651f51b25988235ff79b50c7f9355fb16dd7.tar.gz |
Only absorb dependant arguments for SubFactory fields (Closes #15).
Signed-off-by: Raphaël Barrois <raphael.barrois@polytechnique.org>
Diffstat (limited to 'tests/test_declarations.py')
-rw-r--r-- | tests/test_declarations.py | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/tests/test_declarations.py b/tests/test_declarations.py index f15645f..1c0502b 100644 --- a/tests/test_declarations.py +++ b/tests/test_declarations.py @@ -21,7 +21,8 @@ # THE SOFTWARE. -from factory.declarations import deepgetattr, OrderedDeclaration, Sequence +from factory.declarations import deepgetattr, OrderedDeclaration, \ + PostGenerationDeclaration, Sequence from .compat import unittest @@ -55,6 +56,23 @@ class DigTestCase(unittest.TestCase): self.assertEqual(42, deepgetattr(obj, 'a.b.c.n.x', 42)) +class PostGenerationDeclarationTestCase(unittest.TestCase): + def test_extract_no_prefix(self): + decl = PostGenerationDeclaration() + + extracted, kwargs = decl.extract('foo', {'foo': 13, 'foo__bar': 42}) + self.assertEqual(extracted, 13) + self.assertEqual(kwargs, {'bar': 42}) + + def test_extract_with_prefix(self): + decl = PostGenerationDeclaration(extract_prefix='blah') + + extracted, kwargs = decl.extract('foo', + {'foo': 13, 'foo__bar': 42, 'blah': 42, 'blah__baz': 1}) + self.assertEqual(extracted, 42) + self.assertEqual(kwargs, {'baz': 1}) + + if __name__ == '__main__': unittest.main() |