summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRaphaël Barrois <raphael.barrois@polytechnique.org>2012-08-16 19:00:21 +0200
committerRaphaël Barrois <raphael.barrois@polytechnique.org>2012-08-16 22:38:42 +0200
commitbe6227b52ac07b8df58f0f393026f3c4d51078a0 (patch)
tree3ae4cbf14fecbfd07c3bf75973470ffea9c3e17d /tests
parentc34d01278bd9cadff3f1ebea4579ef556cf75480 (diff)
downloadfactory-boy-be6227b52ac07b8df58f0f393026f3c4d51078a0.tar
factory-boy-be6227b52ac07b8df58f0f393026f3c4d51078a0.tar.gz
Explicitly set FACTORY_FOR in tests.
Signed-off-by: Raphaël Barrois <raphael.barrois@polytechnique.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/test_base.py26
-rw-r--r--tests/test_using.py78
2 files changed, 103 insertions, 1 deletions
diff --git a/tests/test_base.py b/tests/test_base.py
index 7575ee2..f8ba605 100644
--- a/tests/test_base.py
+++ b/tests/test_base.py
@@ -67,6 +67,8 @@ class FactoryTestCase(unittest.TestCase):
def testLazyAttributeNonExistentParam(self):
class TestObjectFactory(base.Factory):
+ FACTORY_FOR = TestObject
+
one = declarations.LazyAttribute(lambda a: a.does_not_exist )
self.assertRaises(AttributeError, TestObjectFactory)
@@ -74,9 +76,13 @@ class FactoryTestCase(unittest.TestCase):
def testInheritanceWithSequence(self):
"""Tests that sequence IDs are shared between parent and son."""
class TestObjectFactory(base.Factory):
+ FACTORY_FOR = TestObject
+
one = declarations.Sequence(lambda a: a)
class TestSubFactory(TestObjectFactory):
+ FACTORY_FOR = TestObject
+
pass
parent = TestObjectFactory.build()
@@ -97,6 +103,8 @@ class FactoryDefaultStrategyTestCase(unittest.TestCase):
base.Factory.default_strategy = base.BUILD_STRATEGY
class TestModelFactory(base.Factory):
+ FACTORY_FOR = TestModel
+
one = 'one'
test_model = TestModelFactory()
@@ -107,6 +115,8 @@ class FactoryDefaultStrategyTestCase(unittest.TestCase):
# Default default_strategy
class TestModelFactory(base.Factory):
+ FACTORY_FOR = TestModel
+
one = 'one'
test_model = TestModelFactory()
@@ -117,6 +127,8 @@ class FactoryDefaultStrategyTestCase(unittest.TestCase):
base.Factory.default_strategy = base.STUB_STRATEGY
class TestModelFactory(base.Factory):
+ FACTORY_FOR = TestModel
+
one = 'one'
test_model = TestModelFactory()
@@ -127,12 +139,16 @@ class FactoryDefaultStrategyTestCase(unittest.TestCase):
base.Factory.default_strategy = 'unknown'
class TestModelFactory(base.Factory):
+ FACTORY_FOR = TestModel
+
one = 'one'
self.assertRaises(base.Factory.UnknownStrategy, TestModelFactory)
def testStubWithNonStubStrategy(self):
class TestModelFactory(base.StubFactory):
+ FACTORY_FOR = TestModel
+
one = 'one'
TestModelFactory.default_strategy = base.CREATE_STRATEGY
@@ -145,6 +161,8 @@ class FactoryDefaultStrategyTestCase(unittest.TestCase):
def test_change_strategy(self):
@base.use_strategy(base.CREATE_STRATEGY)
class TestModelFactory(base.StubFactory):
+ FACTORY_FOR = TestModel
+
one = 'one'
self.assertEqual(base.CREATE_STRATEGY, TestModelFactory.default_strategy)
@@ -186,6 +204,8 @@ class FactoryCreationTestCase(unittest.TestCase):
def testInheritanceWithStub(self):
class TestObjectFactory(base.StubFactory):
+ FACTORY_FOR = TestObject
+
pass
class TestFactory(TestObjectFactory):
@@ -195,6 +215,8 @@ class FactoryCreationTestCase(unittest.TestCase):
def testCustomCreation(self):
class TestModelFactory(base.Factory):
+ FACTORY_FOR = TestModel
+
@classmethod
def _prepare(cls, create, **kwargs):
kwargs['four'] = 4
@@ -233,12 +255,16 @@ class PostGenerationParsingTestCase(unittest.TestCase):
def test_extraction(self):
class TestObjectFactory(base.Factory):
+ FACTORY_FOR = TestObject
+
foo = declarations.PostGenerationDeclaration()
self.assertIn('foo', TestObjectFactory._postgen_declarations)
def test_classlevel_extraction(self):
class TestObjectFactory(base.Factory):
+ FACTORY_FOR = TestObject
+
foo = declarations.PostGenerationDeclaration()
foo__bar = 42
diff --git a/tests/test_using.py b/tests/test_using.py
index 1d0b875..33dd3e3 100644
--- a/tests/test_using.py
+++ b/tests/test_using.py
@@ -208,6 +208,8 @@ class SimpleBuildTestCase(unittest.TestCase):
class UsingFactoryTestCase(unittest.TestCase):
def testAttribute(self):
class TestObjectFactory(factory.Factory):
+ FACTORY_FOR = TestObject
+
one = 'one'
test_object = TestObjectFactory.build()
@@ -226,6 +228,8 @@ class UsingFactoryTestCase(unittest.TestCase):
def testSequence(self):
class TestObjectFactory(factory.Factory):
+ FACTORY_FOR = TestObject
+
one = factory.Sequence(lambda n: 'one' + n)
two = factory.Sequence(lambda n: 'two' + n)
@@ -239,6 +243,8 @@ class UsingFactoryTestCase(unittest.TestCase):
def testSequenceCustomBegin(self):
class TestObjectFactory(factory.Factory):
+ FACTORY_FOR = TestObject
+
@classmethod
def _setup_next_sequence(cls):
return 42
@@ -256,6 +262,8 @@ class UsingFactoryTestCase(unittest.TestCase):
def test_sequence_batch(self):
class TestObjectFactory(factory.Factory):
+ FACTORY_FOR = TestObject
+
one = factory.Sequence(lambda n: 'one' + n)
two = factory.Sequence(lambda n: 'two' + n)
@@ -269,6 +277,8 @@ class UsingFactoryTestCase(unittest.TestCase):
def testLazyAttribute(self):
class TestObjectFactory(factory.Factory):
+ FACTORY_FOR = TestObject
+
one = factory.LazyAttribute(lambda a: 'abc' )
two = factory.LazyAttribute(lambda a: a.one + ' xyz')
@@ -278,6 +288,8 @@ class UsingFactoryTestCase(unittest.TestCase):
def testLazyAttributeSequence(self):
class TestObjectFactory(factory.Factory):
+ FACTORY_FOR = TestObject
+
one = factory.LazyAttributeSequence(lambda a, n: 'abc' + n)
two = factory.LazyAttributeSequence(lambda a, n: a.one + ' xyz' + n)
@@ -291,6 +303,8 @@ class UsingFactoryTestCase(unittest.TestCase):
def testLazyAttributeDecorator(self):
class TestObjectFactory(factory.Factory):
+ FACTORY_FOR = TestObject
+
@factory.lazy_attribute
def one(a):
return 'one'
@@ -303,6 +317,8 @@ class UsingFactoryTestCase(unittest.TestCase):
n = 3
class TestObjectFactory(factory.Factory):
+ FACTORY_FOR = TestObject
+
one = 'xx'
two = factory.SelfAttribute('one')
three = TmpObj()
@@ -317,6 +333,8 @@ class UsingFactoryTestCase(unittest.TestCase):
def testSequenceDecorator(self):
class TestObjectFactory(factory.Factory):
+ FACTORY_FOR = TestObject
+
@factory.sequence
def one(n):
return 'one' + n
@@ -326,6 +344,8 @@ class UsingFactoryTestCase(unittest.TestCase):
def testLazyAttributeSequenceDecorator(self):
class TestObjectFactory(factory.Factory):
+ FACTORY_FOR = TestObject
+
@factory.lazy_attribute_sequence
def one(a, n):
return 'one' + n
@@ -339,6 +359,8 @@ class UsingFactoryTestCase(unittest.TestCase):
def testBuildWithParameters(self):
class TestObjectFactory(factory.Factory):
+ FACTORY_FOR = TestObject
+
one = factory.Sequence(lambda n: 'one' + n)
two = factory.Sequence(lambda n: 'two' + n)
@@ -353,6 +375,8 @@ class UsingFactoryTestCase(unittest.TestCase):
def testCreate(self):
class TestModelFactory(factory.Factory):
+ FACTORY_FOR = TestModel
+
one = 'one'
test_model = TestModelFactory.create()
@@ -361,6 +385,8 @@ class UsingFactoryTestCase(unittest.TestCase):
def test_create_batch(self):
class TestModelFactory(factory.Factory):
+ FACTORY_FOR = TestModel
+
one = 'one'
objs = TestModelFactory.create_batch(20, two=factory.Sequence(int))
@@ -375,6 +401,8 @@ class UsingFactoryTestCase(unittest.TestCase):
def test_generate_build(self):
class TestModelFactory(factory.Factory):
+ FACTORY_FOR = TestModel
+
one = 'one'
test_model = TestModelFactory.generate(factory.BUILD_STRATEGY)
@@ -383,6 +411,8 @@ class UsingFactoryTestCase(unittest.TestCase):
def test_generate_create(self):
class TestModelFactory(factory.Factory):
+ FACTORY_FOR = TestModel
+
one = 'one'
test_model = TestModelFactory.generate(factory.CREATE_STRATEGY)
@@ -391,6 +421,8 @@ class UsingFactoryTestCase(unittest.TestCase):
def test_generate_stub(self):
class TestModelFactory(factory.Factory):
+ FACTORY_FOR = TestModel
+
one = 'one'
test_model = TestModelFactory.generate(factory.STUB_STRATEGY)
@@ -399,6 +431,8 @@ class UsingFactoryTestCase(unittest.TestCase):
def test_generate_batch_build(self):
class TestModelFactory(factory.Factory):
+ FACTORY_FOR = TestModel
+
one = 'one'
objs = TestModelFactory.generate_batch(factory.BUILD_STRATEGY, 20, two='two')
@@ -413,6 +447,8 @@ class UsingFactoryTestCase(unittest.TestCase):
def test_generate_batch_create(self):
class TestModelFactory(factory.Factory):
+ FACTORY_FOR = TestModel
+
one = 'one'
objs = TestModelFactory.generate_batch(factory.CREATE_STRATEGY, 20, two='two')
@@ -427,6 +463,8 @@ class UsingFactoryTestCase(unittest.TestCase):
def test_generate_batch_stub(self):
class TestModelFactory(factory.Factory):
+ FACTORY_FOR = TestModel
+
one = 'one'
objs = TestModelFactory.generate_batch(factory.STUB_STRATEGY, 20, two='two')
@@ -441,6 +479,8 @@ class UsingFactoryTestCase(unittest.TestCase):
def test_simple_generate_build(self):
class TestModelFactory(factory.Factory):
+ FACTORY_FOR = TestModel
+
one = 'one'
test_model = TestModelFactory.simple_generate(False)
@@ -449,6 +489,8 @@ class UsingFactoryTestCase(unittest.TestCase):
def test_simple_generate_create(self):
class TestModelFactory(factory.Factory):
+ FACTORY_FOR = TestModel
+
one = 'one'
test_model = TestModelFactory.simple_generate(True)
@@ -457,6 +499,8 @@ class UsingFactoryTestCase(unittest.TestCase):
def test_simple_generate_batch_build(self):
class TestModelFactory(factory.Factory):
+ FACTORY_FOR = TestModel
+
one = 'one'
objs = TestModelFactory.simple_generate_batch(False, 20, two='two')
@@ -471,6 +515,8 @@ class UsingFactoryTestCase(unittest.TestCase):
def test_simple_generate_batch_create(self):
class TestModelFactory(factory.Factory):
+ FACTORY_FOR = TestModel
+
one = 'one'
objs = TestModelFactory.simple_generate_batch(True, 20, two='two')
@@ -485,6 +531,8 @@ class UsingFactoryTestCase(unittest.TestCase):
def test_stub_batch(self):
class TestObjectFactory(factory.Factory):
+ FACTORY_FOR = TestObject
+
one = 'one'
two = factory.LazyAttribute(lambda a: a.one + ' two')
three = factory.Sequence(lambda n: int(n))
@@ -502,6 +550,8 @@ class UsingFactoryTestCase(unittest.TestCase):
def testInheritance(self):
class TestObjectFactory(factory.Factory):
+ FACTORY_FOR = TestObject
+
one = 'one'
two = factory.LazyAttribute(lambda a: a.one + ' two')
@@ -522,6 +572,8 @@ class UsingFactoryTestCase(unittest.TestCase):
def testInheritanceWithInheritedClass(self):
class TestObjectFactory(factory.Factory):
+ FACTORY_FOR = TestObject
+
one = 'one'
two = factory.LazyAttribute(lambda a: a.one + ' two')
@@ -537,6 +589,8 @@ class UsingFactoryTestCase(unittest.TestCase):
def testDualInheritance(self):
class TestObjectFactory(factory.Factory):
+ FACTORY_FOR = TestObject
+
one = 'one'
class TestOtherFactory(factory.Factory):
@@ -558,7 +612,7 @@ class UsingFactoryTestCase(unittest.TestCase):
return "This doesn't even return an instance of {0}".format(class_to_create.__name__)
class TestModelFactory(factory.Factory):
- pass
+ FACTORY_FOR = TestModel
TestModelFactory.set_creation_function(creation_function)
@@ -567,6 +621,8 @@ class UsingFactoryTestCase(unittest.TestCase):
def testClassMethodAccessible(self):
class TestObjectFactory(factory.Factory):
+ FACTORY_FOR = TestObject
+
@classmethod
def alt_create(cls, **kwargs):
return kwargs
@@ -575,6 +631,8 @@ class UsingFactoryTestCase(unittest.TestCase):
def testStaticMethodAccessible(self):
class TestObjectFactory(factory.Factory):
+ FACTORY_FOR = TestObject
+
@staticmethod
def alt_create(**kwargs):
return kwargs
@@ -804,6 +862,8 @@ class IteratorTestCase(unittest.TestCase):
def test_iterator(self):
class TestObjectFactory(factory.Factory):
+ FACTORY_FOR = TestObject
+
one = factory.Iterator(xrange(10, 30))
objs = TestObjectFactory.build_batch(20)
@@ -813,6 +873,8 @@ class IteratorTestCase(unittest.TestCase):
def test_infinite_iterator(self):
class TestObjectFactory(factory.Factory):
+ FACTORY_FOR = TestObject
+
one = factory.InfiniteIterator(xrange(5))
objs = TestObjectFactory.build_batch(20)
@@ -822,6 +884,8 @@ class IteratorTestCase(unittest.TestCase):
def test_infinite_iterator_list_comprehension(self):
class TestObjectFactory(factory.Factory):
+ FACTORY_FOR = TestObject
+
one = factory.InfiniteIterator([j * 3 for j in xrange(5)])
# Scope bleeding: j will end up in TestObjectFactory's scope.
@@ -830,6 +894,8 @@ class IteratorTestCase(unittest.TestCase):
def test_infinite_iterator_list_comprehension_protected(self):
class TestObjectFactory(factory.Factory):
+ FACTORY_FOR = TestObject
+
one = factory.InfiniteIterator([_j * 3 for _j in xrange(5)])
# Scope bleeding : _j will end up in TestObjectFactory's scope.
@@ -841,6 +907,8 @@ class IteratorTestCase(unittest.TestCase):
def test_iterator_decorator(self):
class TestObjectFactory(factory.Factory):
+ FACTORY_FOR = TestObject
+
@factory.iterator
def one():
for i in xrange(10, 50):
@@ -853,6 +921,8 @@ class IteratorTestCase(unittest.TestCase):
def test_infinite_iterator_decorator(self):
class TestObjectFactory(factory.Factory):
+ FACTORY_FOR = TestObject
+
@factory.infinite_iterator
def one():
for i in xrange(5):
@@ -867,6 +937,8 @@ class IteratorTestCase(unittest.TestCase):
class PostGenerationTestCase(unittest.TestCase):
def test_post_generation(self):
class TestObjectFactory(factory.Factory):
+ FACTORY_FOR = TestObject
+
one = 1
@factory.post_generation()
@@ -883,6 +955,8 @@ class PostGenerationTestCase(unittest.TestCase):
def test_post_generation_extraction(self):
class TestObjectFactory(factory.Factory):
+ FACTORY_FOR = TestObject
+
one = 1
@factory.post_generation()
@@ -906,6 +980,8 @@ class PostGenerationTestCase(unittest.TestCase):
self.assertEqual(kwargs, {'foo': 13})
class TestObjectFactory(factory.Factory):
+ FACTORY_FOR = TestObject
+
bar = factory.PostGeneration(my_lambda)
obj = TestObjectFactory.build(bar=42, bar__foo=13)