diff options
author | Raphaël Barrois <raphael.barrois@polytechnique.org> | 2012-02-24 23:31:02 +0100 |
---|---|---|
committer | Raphaël Barrois <raphael.barrois@polytechnique.org> | 2012-02-24 23:31:02 +0100 |
commit | cbbe5cc359412c8e6c49e06d5d1f35680ad88c40 (patch) | |
tree | 0615f9a4ef481b77cd436b44047b81f07cd2a72e /tests | |
parent | 86cd8c2472dff6fe62e3c1f83bd9a1a3523ce08e (diff) | |
download | factory-boy-cbbe5cc359412c8e6c49e06d5d1f35680ad88c40.tar factory-boy-cbbe5cc359412c8e6c49e06d5d1f35680ad88c40.tar.gz |
Add support for 'generate' and 'simple_generate'
Signed-off-by: Raphaël Barrois <raphael.barrois@polytechnique.org>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_using.py | 195 |
1 files changed, 195 insertions, 0 deletions
diff --git a/tests/test_using.py b/tests/test_using.py index 7ed94e2..4e69212 100644 --- a/tests/test_using.py +++ b/tests/test_using.py @@ -102,6 +102,91 @@ class SimpleBuildTestCase(unittest.TestCase): self.assertEqual(obj.three, 3) self.assertFalse(hasattr(obj, 'two')) + def test_stub_batch(self): + objs = factory.stub_batch(FakeDjangoModel, 4, foo='bar') + + self.assertEqual(4, len(objs)) + self.assertEqual(4, len(set(objs))) + + for obj in objs: + self.assertFalse(hasattr(obj, 'id')) + self.assertEqual(obj.foo, 'bar') + + def test_generate_build(self): + obj = factory.generate(FakeDjangoModel, factory.BUILD_STRATEGY, foo='bar') + self.assertEqual(obj.id, None) + self.assertEqual(obj.foo, 'bar') + + def test_generate_create(self): + obj = factory.generate(FakeDjangoModel, factory.CREATE_STRATEGY, foo='bar') + self.assertEqual(obj.id, 1) + self.assertEqual(obj.foo, 'bar') + + def test_generate_stub(self): + obj = factory.generate(FakeDjangoModel, factory.STUB_STRATEGY, foo='bar') + self.assertFalse(hasattr(obj, 'id')) + self.assertEqual(obj.foo, 'bar') + + def test_generate_batch_build(self): + objs = factory.generate_batch(FakeDjangoModel, factory.BUILD_STRATEGY, 20, foo='bar') + + self.assertEqual(20, len(objs)) + 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(self): + objs = factory.generate_batch(FakeDjangoModel, factory.CREATE_STRATEGY, 20, foo='bar') + + self.assertEqual(20, len(objs)) + self.assertEqual(20, len(set(objs))) + + for obj in objs: + self.assertEqual(obj.id, 1) + self.assertEqual(obj.foo, 'bar') + + def test_generate_batch_stub(self): + objs = factory.generate_batch(FakeDjangoModel, factory.STUB_STRATEGY, 20, foo='bar') + + self.assertEqual(20, len(objs)) + self.assertEqual(20, len(set(objs))) + + for obj in objs: + self.assertFalse(hasattr(obj, 'id')) + self.assertEqual(obj.foo, 'bar') + + def test_simple_generate_build(self): + obj = factory.simple_generate(FakeDjangoModel, False, foo='bar') + self.assertEqual(obj.id, None) + self.assertEqual(obj.foo, 'bar') + + def test_simple_generate_create(self): + obj = factory.simple_generate(FakeDjangoModel, True, foo='bar') + self.assertEqual(obj.id, 1) + self.assertEqual(obj.foo, 'bar') + + def test_simple_generate_batch_build(self): + objs = factory.simple_generate_batch(FakeDjangoModel, False, 20, foo='bar') + + self.assertEqual(20, len(objs)) + 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(self): + objs = factory.simple_generate_batch(FakeDjangoModel, True, 20, foo='bar') + + self.assertEqual(20, len(objs)) + self.assertEqual(20, len(set(objs))) + + for obj in objs: + self.assertEqual(obj.id, 1) + self.assertEqual(obj.foo, 'bar') + def test_make_factory(self): fact = factory.make_factory(TestObject, two=2, three=factory.LazyAttribute(lambda o: o.two + 1)) @@ -275,6 +360,116 @@ class FactoryTestCase(unittest.TestCase): self.assertEqual(i, obj.two) self.assertTrue(obj.id) + def test_generate_build(self): + class TestModelFactory(factory.Factory): + one = 'one' + + test_model = TestModelFactory.generate(factory.BUILD_STRATEGY) + self.assertEqual(test_model.one, 'one') + self.assertFalse(test_model.id) + + def test_generate_create(self): + class TestModelFactory(factory.Factory): + one = 'one' + + test_model = TestModelFactory.generate(factory.CREATE_STRATEGY) + self.assertEqual(test_model.one, 'one') + self.assertTrue(test_model.id) + + def test_generate_stub(self): + class TestModelFactory(factory.Factory): + one = 'one' + + test_model = TestModelFactory.generate(factory.STUB_STRATEGY) + self.assertEqual(test_model.one, 'one') + self.assertFalse(hasattr(test_model, 'id')) + + def test_generate_batch_build(self): + class TestModelFactory(factory.Factory): + one = 'one' + + objs = TestModelFactory.generate_batch(factory.BUILD_STRATEGY, 20, two='two') + + self.assertEqual(20, len(objs)) + self.assertEqual(20, len(set(objs))) + + for i, obj in enumerate(objs): + self.assertEqual('one', obj.one) + self.assertEqual('two', obj.two) + self.assertFalse(obj.id) + + def test_generate_batch_create(self): + class TestModelFactory(factory.Factory): + one = 'one' + + objs = TestModelFactory.generate_batch(factory.CREATE_STRATEGY, 20, two='two') + + self.assertEqual(20, len(objs)) + self.assertEqual(20, len(set(objs))) + + for i, obj in enumerate(objs): + self.assertEqual('one', obj.one) + self.assertEqual('two', obj.two) + self.assertTrue(obj.id) + + def test_generate_batch_stub(self): + class TestModelFactory(factory.Factory): + one = 'one' + + objs = TestModelFactory.generate_batch(factory.STUB_STRATEGY, 20, two='two') + + self.assertEqual(20, len(objs)) + self.assertEqual(20, len(set(objs))) + + for i, obj in enumerate(objs): + self.assertEqual('one', obj.one) + self.assertEqual('two', obj.two) + self.assertFalse(hasattr(obj, 'id')) + + def test_simple_generate_build(self): + class TestModelFactory(factory.Factory): + one = 'one' + + test_model = TestModelFactory.simple_generate(False) + self.assertEqual(test_model.one, 'one') + self.assertFalse(test_model.id) + + def test_simple_generate_create(self): + class TestModelFactory(factory.Factory): + one = 'one' + + test_model = TestModelFactory.simple_generate(True) + self.assertEqual(test_model.one, 'one') + self.assertTrue(test_model.id) + + def test_simple_generate_batch_build(self): + class TestModelFactory(factory.Factory): + one = 'one' + + objs = TestModelFactory.simple_generate_batch(False, 20, two='two') + + self.assertEqual(20, len(objs)) + self.assertEqual(20, len(set(objs))) + + for i, obj in enumerate(objs): + self.assertEqual('one', obj.one) + self.assertEqual('two', obj.two) + self.assertFalse(obj.id) + + def test_simple_generate_batch_create(self): + class TestModelFactory(factory.Factory): + one = 'one' + + objs = TestModelFactory.simple_generate_batch(True, 20, two='two') + + self.assertEqual(20, len(objs)) + self.assertEqual(20, len(set(objs))) + + for i, obj in enumerate(objs): + self.assertEqual('one', obj.one) + self.assertEqual('two', obj.two) + self.assertTrue(obj.id) + def test_stub_batch(self): class TestObjectFactory(factory.Factory): one = 'one' |