def setUp(self) -> None: self.modules = factory.generate_batch(ModuleFactory, size=20, strategy='create') self.data_gen = DataGenerator(data=self.modules) self.lectures = self.data_gen.lectures self.gen = Generate(data=self.lectures)
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_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_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_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')
def test_generate_batch_stub(self): objs = factory.generate_batch(FakeModel, 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_generate_batch_create(self): objs = factory.generate_batch(FakeModel, 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, 2) self.assertEqual(obj.foo, 'bar')
def test_generate_batch_build(self): objs = factory.generate_batch(FakeModel, 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')