def test_delete_parent(self): trekA = TrekFactory(name=u"A") trekB = TrekFactory(name=u"B") trekC = TrekFactory(name=u"C") OrderedTrekChild(parent=trekB, child=trekA, order=1).save() OrderedTrekChild(parent=trekC, child=trekA, order=2).save() self.assertTrue(OrderedTrekChild.objects.filter(parent=trekB).exists()) self.assertQuerysetEqual(trekA.parents, ['<Trek: B>', '<Trek: C>'], ordered=False) self.assertQuerysetEqual(trekB.children, ['<Trek: A>']) self.assertQuerysetEqual(trekC.children, ['<Trek: A>']) self.assertEqual(trekA.parents_id, [trekB.id, trekC.id]) self.assertEqual(list(trekB.children_id), [trekA.id]) self.assertEqual(list(trekC.children_id), [trekA.id]) trekB.delete() self.assertEqual(trekA.previous_id_for(trekC), None) self.assertEqual(trekA.next_id_for(trekC), None) self.assertEqual(trekA.next_id, {trekC.id: None}) self.assertEqual(trekA.previous_id, {trekC.id: None}) self.assertFalse( OrderedTrekChild.objects.filter(parent=trekB).exists()) self.assertQuerysetEqual(trekA.parents, ['<Trek: C>']) self.assertQuerysetEqual(trekC.children, ['<Trek: A>']) self.assertEqual(trekA.parents_id, [trekC.id]) self.assertEqual(list(trekC.children_id), [trekA.id])
def test_next_previous(self): trekA = TrekFactory(name="A") trekB = TrekFactory(name="B") trekC = TrekFactory(name="C") trekD = TrekFactory(name="D") OrderedTrekChild(parent=trekC, child=trekA, order=42).save() OrderedTrekChild(parent=trekC, child=trekB, order=15).save() OrderedTrekChild(parent=trekD, child=trekA, order=1).save() self.assertEqual(list(trekA.children_id), []) self.assertEqual(list(trekB.children_id), []) self.assertEqual(list(trekC.children_id), [trekB.id, trekA.id]) self.assertEqual(list(trekD.children_id), [trekA.id]) self.assertEqual(trekA.next_id, {trekC.id: None, trekD.id: None}) self.assertEqual(trekB.next_id, {trekC.id: trekA.id}) self.assertEqual(trekC.next_id, {}) self.assertEqual(trekD.next_id, {}) self.assertEqual(trekA.previous_id, {trekC.id: trekB.id, trekD.id: None}) self.assertEqual(trekB.previous_id, {trekC.id: None}) self.assertEqual(trekC.previous_id, {}) self.assertEqual(trekD.previous_id, {})