summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRaphaël Barrois <raphael.barrois@polytechnique.org>2013-03-11 22:12:43 +0100
committerRaphaël Barrois <raphael.barrois@polytechnique.org>2013-03-11 22:12:43 +0100
commit7121fbe268b366bf543b9862ff384453edbce414 (patch)
tree477b222044cbbab98587c201a92e717fbf02deef /tests
parentba1fd987dad9268a1e5a41fe10513727aadfd9b5 (diff)
downloadfactory-boy-7121fbe268b366bf543b9862ff384453edbce414.tar
factory-boy-7121fbe268b366bf543b9862ff384453edbce414.tar.gz
Remove building_function/creation_function.
Stop defaulting to Django's .objects.create().
Diffstat (limited to 'tests')
-rw-r--r--tests/test_using.py87
1 files changed, 55 insertions, 32 deletions
diff --git a/tests/test_using.py b/tests/test_using.py
index 8f43813..5287a6d 100644
--- a/tests/test_using.py
+++ b/tests/test_using.py
@@ -54,6 +54,12 @@ class FakeModel(object):
instance.id = 2
return instance
+ def values_list(self, *args, **kwargs):
+ return self
+
+ def order_by(self, *args, **kwargs):
+ return [1]
+
objects = FakeModelManager()
def __init__(self, **kwargs):
@@ -104,13 +110,16 @@ class SimpleBuildTestCase(unittest.TestCase):
self.assertEqual(obj.three, 3)
self.assertEqual(obj.four, None)
- @tools.disable_warnings
def test_create(self):
obj = factory.create(FakeModel, foo='bar')
+ self.assertEqual(obj.id, None)
+ self.assertEqual(obj.foo, 'bar')
+
+ def test_create_custom_base(self):
+ obj = factory.create(FakeModel, foo='bar', FACTORY_CLASS=factory.DjangoModelFactory)
self.assertEqual(obj.id, 2)
self.assertEqual(obj.foo, 'bar')
- @tools.disable_warnings
def test_create_batch(self):
objs = factory.create_batch(FakeModel, 4, foo='bar')
@@ -118,6 +127,17 @@ class SimpleBuildTestCase(unittest.TestCase):
self.assertEqual(4, len(set(objs)))
for obj in objs:
+ self.assertEqual(obj.id, None)
+ self.assertEqual(obj.foo, 'bar')
+
+ def test_create_batch_custom_base(self):
+ objs = factory.create_batch(FakeModel, 4, foo='bar',
+ FACTORY_CLASS=factory.DjangoModelFactory)
+
+ self.assertEqual(4, len(objs))
+ self.assertEqual(4, len(set(objs)))
+
+ for obj in objs:
self.assertEqual(obj.id, 2)
self.assertEqual(obj.foo, 'bar')
@@ -141,9 +161,14 @@ class SimpleBuildTestCase(unittest.TestCase):
self.assertEqual(obj.id, None)
self.assertEqual(obj.foo, 'bar')
- @tools.disable_warnings
def test_generate_create(self):
obj = factory.generate(FakeModel, factory.CREATE_STRATEGY, foo='bar')
+ self.assertEqual(obj.id, None)
+ self.assertEqual(obj.foo, 'bar')
+
+ def test_generate_create_custom_base(self):
+ obj = factory.generate(FakeModel, factory.CREATE_STRATEGY, foo='bar',
+ FACTORY_CLASS=factory.DjangoModelFactory)
self.assertEqual(obj.id, 2)
self.assertEqual(obj.foo, 'bar')
@@ -162,7 +187,6 @@ class SimpleBuildTestCase(unittest.TestCase):
self.assertEqual(obj.id, None)
self.assertEqual(obj.foo, 'bar')
- @tools.disable_warnings
def test_generate_batch_create(self):
objs = factory.generate_batch(FakeModel, factory.CREATE_STRATEGY, 20, foo='bar')
@@ -170,6 +194,17 @@ class SimpleBuildTestCase(unittest.TestCase):
self.assertEqual(20, len(set(objs)))
for obj in objs:
+ self.assertEqual(obj.id, None)
+ self.assertEqual(obj.foo, 'bar')
+
+ def test_generate_batch_create_custom_base(self):
+ objs = factory.generate_batch(FakeModel, factory.CREATE_STRATEGY, 20, foo='bar',
+ FACTORY_CLASS=factory.DjangoModelFactory)
+
+ self.assertEqual(20, len(objs))
+ self.assertEqual(20, len(set(objs)))
+
+ for obj in objs:
self.assertEqual(obj.id, 2)
self.assertEqual(obj.foo, 'bar')
@@ -188,9 +223,13 @@ class SimpleBuildTestCase(unittest.TestCase):
self.assertEqual(obj.id, None)
self.assertEqual(obj.foo, 'bar')
- @tools.disable_warnings
def test_simple_generate_create(self):
obj = factory.simple_generate(FakeModel, True, foo='bar')
+ self.assertEqual(obj.id, None)
+ self.assertEqual(obj.foo, 'bar')
+
+ def test_simple_generate_create_custom_base(self):
+ obj = factory.simple_generate(FakeModel, True, foo='bar', FACTORY_CLASS=factory.DjangoModelFactory)
self.assertEqual(obj.id, 2)
self.assertEqual(obj.foo, 'bar')
@@ -204,7 +243,6 @@ class SimpleBuildTestCase(unittest.TestCase):
self.assertEqual(obj.id, None)
self.assertEqual(obj.foo, 'bar')
- @tools.disable_warnings
def test_simple_generate_batch_create(self):
objs = factory.simple_generate_batch(FakeModel, True, 20, foo='bar')
@@ -212,6 +250,17 @@ class SimpleBuildTestCase(unittest.TestCase):
self.assertEqual(20, len(set(objs)))
for obj in objs:
+ self.assertEqual(obj.id, None)
+ self.assertEqual(obj.foo, 'bar')
+
+ def test_simple_generate_batch_create_custom_base(self):
+ objs = factory.simple_generate_batch(FakeModel, True, 20, foo='bar',
+ FACTORY_CLASS=factory.DjangoModelFactory)
+
+ self.assertEqual(20, len(objs))
+ self.assertEqual(20, len(set(objs)))
+
+ for obj in objs:
self.assertEqual(obj.id, 2)
self.assertEqual(obj.foo, 'bar')
@@ -693,32 +742,6 @@ class UsingFactoryTestCase(unittest.TestCase):
self.assertEqual('three', obj.three)
self.assertEqual('four', obj.four)
- @tools.disable_warnings
- def test_set_building_function(self):
- def building_function(class_to_create, **kwargs):
- return "This doesn't even return an instance of {0}".format(class_to_create.__name__)
-
- class TestModelFactory(FakeModelFactory):
- FACTORY_FOR = TestModel
-
- TestModelFactory.set_building_function(building_function)
-
- test_object = TestModelFactory.build()
- self.assertEqual(test_object, "This doesn't even return an instance of TestModel")
-
- @tools.disable_warnings
- def testSetCreationFunction(self):
- def creation_function(class_to_create, **kwargs):
- return "This doesn't even return an instance of {0}".format(class_to_create.__name__)
-
- class TestModelFactory(FakeModelFactory):
- FACTORY_FOR = TestModel
-
- TestModelFactory.set_creation_function(creation_function)
-
- test_object = TestModelFactory.create()
- self.assertEqual(test_object, "This doesn't even return an instance of TestModel")
-
def testClassMethodAccessible(self):
class TestObjectFactory(factory.Factory):
FACTORY_FOR = TestObject