Commits

Vladimir Mihailenco  committed fea5914

Batch tests

  • Participants
  • Parent commits 1bfe32a

Comments (0)

Files changed (4)

File db/compiler.py

 from djangotoolbox.db.basecompiler import NonrelQuery, NonrelCompiler, \
     NonrelInsertCompiler, NonrelUpdateCompiler, NonrelDeleteCompiler
 
-from .mutation_pool import MutationPool
-
 # Valid query types (a dictionary is used for speedy lookups).
 OPERATORS_MAP = {
     'exact': '=',

File tests/__init__.py

 from .not_return_sets import NonReturnSetsTest
 from .decimals import DecimalTest
 from .batch import BatchTest
+from .batch import BatchMtiTest

File tests/batch.py

 from google.appengine.api.datastore import Put
 from google.appengine.api.datastore import Delete
 
+from .testmodels import Parent
+from .testmodels import Mti
+
 
 class mem(object):
     """Global AppEngine datastore operations counters"""
             self.assertEqual(BatchCategory.objects.count(), 1)
 
         self.assertIsInstance(appengine.pk, int)
+        self.assertIsInstance(appengine.id, int)
+        self.assertEqual(appengine.pk, appengine.id)
+
         self.assertIsInstance(django.pk, int)
+        self.assertIsInstance(django.id, int)
+        self.assertEqual(django.pk, django.id)
 
         self.assertEqual(BatchCategory.objects.count(), 2)
         self.assertEqual(mem.put_count, 2)
         self.assertEqual(django.pk, None)
 
         self.assertEqual(BatchCategory.objects.count(), 0)
-        self.assertEqual(mem.delete_count, 2)
+        self.assertEqual(mem.delete_count, 2)
+
+    def test_batch_operation_params(self):
+        """Test, that pool is flushed according to config"""
+        c1 = BatchCategory(name='test1')
+        c2 = BatchCategory(name='test2')
+
+        config = {'default': {'pool_size': 2,
+                              'batch_size': 2,
+                              'datastore_deadline': 30}}
+        with BatchOperation(config) as op:
+            op.save(c1)
+            self.assertEqual(c1.id, None, 'Pool is already flushed')
+
+            op.save(c2)
+            self.assertNotEqual(c1.id, None, 'Pool is not flushed yet')
+            self.assertNotEqual(c2.id, None, 'Pool is not flushed yet')
+
+        self.assertEqual(BatchCategory.objects.count(), 2)
+
+
+class BatchMtiTest(TestCase):
+    def test_mti(self):
+        with BatchOperation() as op:
+            op.save(Mti(foo=4, bar=2))
+            op.save(Mti(foo=5, bar=3))
+
+        self.assertEqual(Parent.objects.count(), 2)
+        self.assertEqual(Mti.objects.only('bar').count(), 2)
+
+        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)
+
+            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()
+
+    def test_mti_with_params(self):
+        """Test, that pool is flushed according to config"""
+        mti1 = Mti(foo=2, bar=0)
+        mti2 = Mti(foo=4, bar=2)
+
+        config = {'default': {'pool_size': 4,
+                              'batch_size': 8,
+                              'datastore_deadline': 30}}
+        with BatchOperation(config) as op:
+            op.save(mti1)
+            self.assertEqual(mti1.id, None, 'Pool is already flushed')
+
+            op.save(mti2)
+            self.assertNotEqual(mti1.id, None, 'Pool is not flushed yet')
+            self.assertNotEqual(mti2.id, None, 'Pool is not flushed yet')

File tests/testmodels.py

 
 class SelfReferenceModel(models.Model):
     ref = models.ForeignKey('self', null=True)
+
+class Parent(models.Model):
+    foo = models.IntegerField()
+
+class Mti(Parent):
+    bar = models.IntegerField()