Exemplo n.º 1
0
    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())
Exemplo n.º 2
0
    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())
Exemplo n.º 3
0
    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())
Exemplo n.º 4
0
    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())
Exemplo n.º 5
0
    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)
Exemplo n.º 6
0
    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)