Commits

Vladimir Mihailenco  committed 2d4a4e9

Fix tests

  • Participants
  • Parent commits 27c2bc1

Comments (0)

Files changed (1)

File tests/batch.py

         for parent in Parent.objects.all():
             print 'parent.id', parent.id
 
-        for mti in Mti.objects.only('id', 'bar'):
-            parent = Parent.objects.get(id=mti.id)
+        for mti in Mti.objects.only('bar'):
+            parent = Parent.objects.get(id=mti.parent_ptr_id)
+            self.assertEqual(parent.foo, mti.bar + 2)
 
-            print mti.id
-            print mti.pk
-            print mti.parent_ptr_id
-            print mti._meta.pk.attname
-            #parent = mti.parent_ptr
-            #self.assertEqual(mti.bar, parent.foo - 2)
-        self.fail()
+            parent = mti.parent_ptr
+            self.assertEqual(parent.foo, mti.bar + 2)
 
     def test_mti_with_params(self):
         """Test, that pool is flushed according to config"""
 
             op.save(mti2)
             self.assertNotEqual(mti1.id, None, 'Pool is not flushed yet')
-            self.assertNotEqual(mti2.id, None, 'Pool is not flushed yet')
+            self.assertNotEqual(mti2.id, None, 'Pool is not flushed yet')
+
+    def test_delete(self):
+        mti = Mti(foo=2, bar=0)
+        mti.save()
+
+        mti_id = mti.pk
+        parent_id = mti.parent_ptr_id
+
+        Mti.objects.only('bar').get(pk=mti_id)
+        parent = Parent.objects.get(pk=parent_id)
+
+        with BatchOperation() as op:
+            op.delete(mti)
+
+        try:
+            Mti.objects.only('bar').get(pk=mti_id)
+        except Mti.DoesNotExist:
+            pass
+        else:
+            self.fail('Mti record was not deleted')
+
+        try:
+            parent = Parent.objects.get(pk=parent_id)
+        except Parent.DoesNotExist:
+            pass
+        else:
+            self.fail('Parent record was not deleted')