def test_clear_m2m(self): """Tests that set_m2m_field clear the m2m before calling populator method""" builder = BaseBuilder(None, None) instance = ModelForBuilderTests(simple_field=1) instance.save() builder.set_m2m_field(None, instance, 'm2m') self.assertEqual(0, instance.m2m.count())
def test_do_not_populate(self): """If there is no populator method with the proper name, nothing happens""" builder = BaseBuilder(None, None) instance = ModelForBuilderTests(simple_field=1) instance.save() builder.set_m2m_field(None, instance, 'm2m') self.assertEqual(0, instance.m2m.count())
def test_clear_m2m(self): """Tests that set_m2m_field clear the m2m before calling populator method""" builder = BaseBuilder(None, None) instance = ModelForBuilderTests(simple_field=1) instance.save() builder.set_m2m_field(None, instance, 'm2m') self.assertEqual(0, instance.m2m.count())
def test_do_not_populate(self): """If there is no populator method with the proper name, nothing happens""" builder = BaseBuilder(None, None) instance = ModelForBuilderTests(simple_field=1) instance.save() builder.set_m2m_field(None, instance, 'm2m') self.assertEqual(0, instance.m2m.count())
def test_populate_through_method(self): """If the populator has a method with the same name as the field is it called""" class Populator(BasePopulator): def m2m(self): related = RelatedM2M() related.save() self.related = related self._instance.m2m.add(related) builder = BaseBuilder(None, None) instance = ModelForBuilderTests(simple_field=1) instance.save() populator = Populator(None, instance, None, builder) builder.set_m2m_field(populator, instance, 'm2m') self.assertEqual(1, instance.m2m.count()) db_related = instance.m2m.all()[0] self.assertEqual(db_related, populator.related)
def test_populate_through_method(self): """If the populator has a method with the same name as the field is it called""" class Populator(BasePopulator): def m2m(self): related = RelatedM2M() related.save() self.related = related self._instance.m2m.add(related) builder = BaseBuilder(None, None) instance = ModelForBuilderTests(simple_field=1) instance.save() populator = Populator(None, instance, None, builder) builder.set_m2m_field(populator, instance, 'm2m') self.assertEqual(1, instance.m2m.count()) db_related = instance.m2m.all()[0] self.assertEqual(db_related, populator.related)