Ticket #21169: test_related_manager_fk_removal.diff

File test_related_manager_fk_removal.diff, 1.9 KB (added by Sebastian Goll, 11 years ago)
  • tests/custom_managers/tests.py

    diff --git a/tests/custom_managers/tests.py b/tests/custom_managers/tests.py
    index f9a9f33..2761b92 100644
    a b class CustomManagerTests(TestCase):  
    189189            ],
    190190            lambda c: c.first_name
    191191        )
     192
     193    def test_related_manager_fk_removal(self):
     194        self.p1.favorite_book = self.b1
     195        self.p1.save()
     196        self.p2.favorite_book = self.b1
     197        self.p2.save()
     198
     199        # This should not remove anything because p1 is not considered boring.
     200        self.b1.favorite_books(manager='boring_people').remove(self.p1)
     201        self.assertQuerysetEqual(
     202            self.b1.favorite_books(manager='boring_people').all(), [
     203                "Droopy",
     204            ],
     205            lambda c: c.first_name
     206        )
     207        self.assertQuerysetEqual(
     208            self.b1.favorite_books(manager='fun_people').all(), [
     209                "Bugs",
     210            ],
     211            lambda c: c.first_name
     212        )
     213
     214        # This should only remove fun people, not boring peopel.
     215        self.b1.favorite_books(manager='fun_people').clear()
     216        self.assertQuerysetEqual(
     217            self.b1.favorite_books(manager='boring_people').all(), [
     218                "Droopy",
     219            ],
     220            lambda c: c.first_name
     221        )
     222        self.assertQuerysetEqual(
     223            self.b1.favorite_books(manager='fun_people').all(), [
     224            ],
     225            lambda c: c.first_name
     226        )
     227
     228        # This should succeed because p2 IS considered boring.
     229        self.b1.favorite_books(manager='boring_people').remove(self.p2)
     230        self.assertQuerysetEqual(
     231            self.b1.favorite_books(manager='boring_people').all(), [
     232            ],
     233            lambda c: c.first_name
     234        )
     235        self.assertQuerysetEqual(
     236            self.b1.favorite_books(manager='fun_people').all(), [
     237            ],
     238            lambda c: c.first_name
     239        )
Back to Top