@@ -1536,19 +1536,16 @@ def MakeContext(self, *args, **kwargs):
1536
1536
1537
1537
1538
1538
@real_unittest .skipUnless (datastore_pbs ._CLOUD_DATASTORE_ENABLED ,
1539
- "V1 must be supported to run V1 tests." )
1540
- class ContextV1WithRemoteAPITests (ContextTestMixin ,
1541
- ContextMemcacheTestMixin ,
1542
- ContextTaskQueueTestMixin ,
1543
- test_utils .NDBCloudDatastoreV1Test ):
1539
+ 'V1 must be supported to run V1 tests.' )
1540
+ class ContextV1Tests (ContextTestMixin ,
1541
+ test_utils .NDBCloudDatastoreV1Test ):
1544
1542
"""Context tests that use a Cloud Datastore V1 connection.
1545
1543
1546
- These tests run with memcache and taskqueue stubs available."""
1544
+ These tests run with memcache and taskqueue stubs available.
1545
+ """
1547
1546
1548
1547
def setUp (self ):
1549
- super (ContextV1WithRemoteAPITests , self ).setUp ()
1550
- self .testbed .init_memcache_stub ()
1551
- self .testbed .init_taskqueue_stub ()
1548
+ super (ContextV1Tests , self ).setUp ()
1552
1549
self .HRTest ()
1553
1550
MyAutoBatcher .reset_log ()
1554
1551
self .ctx = self .MakeContext (default_model = model .Expando ,
@@ -1558,75 +1555,74 @@ def setUp(self):
1558
1555
def make_bad_transaction (* arg , ** kwargs ):
1559
1556
return ''
1560
1557
1558
+ def testContext_AutoBatcher_Errors (self ):
1559
+ # Performs tests via direct memcache call, which is disabled by default
1560
+ # in V1.
1561
+ pass
1562
+
1563
+ def testContext_AllocateIds (self ):
1564
+ # V1 does not support Allocate id range.
1565
+ pass
1566
+
1561
1567
def testContext_TransactionAddTask (self ):
1562
1568
# Transactional AddTask still will be unavailable.
1563
- self .ExpectWarnings ()
1564
- key = model .Key ('Foo' , 1 )
1565
-
1566
- @tasklets .tasklet
1567
1569
def foo ():
1568
- ent = model .Expando (key = key , bar = 1 )
1569
-
1570
- @tasklets .tasklet
1571
- def callback ():
1572
- ctx = tasklets .get_context ()
1573
- yield ctx .put (ent )
1574
- taskqueue .add (url = '/' , transactional = True )
1575
- yield self .ctx .transaction (callback )
1576
- self .assertRaises (ValueError , foo ().check_success )
1570
+ taskqueue .add (url = '/' , transactional = True )
1571
+ self .assertRaises (ValueError , model .transaction , foo )
1577
1572
1578
1573
def MakeContext (self , * args , ** kwargs ):
1579
- ctx = super (ContextV1WithRemoteAPITests , self ).MakeContext (* args , ** kwargs )
1580
- # Re-enable default cache policy.
1574
+ ctx = super (ContextV1Tests , self ).MakeContext (* args , ** kwargs )
1575
+ # Re-enable in-context cache. Memcache must remain off because
1576
+ # the stub is not enabled.
1581
1577
ctx .set_cache_policy (None )
1582
- ctx .set_memcache_policy (None )
1583
1578
return ctx
1584
1579
1580
+
1585
1581
@real_unittest .skipUnless (datastore_pbs ._CLOUD_DATASTORE_ENABLED ,
1586
- "V1 must be supported to run V1 tests." )
1587
- class ContextV1Tests (ContextTestMixin ,
1588
- test_utils .NDBCloudDatastoreV1Test ):
1582
+ 'V1 must be supported to run V1 tests.' )
1583
+ class ContextV1WithRemoteAPITests (ContextV1Tests ,
1584
+ ContextMemcacheTestMixin ,
1585
+ ContextTaskQueueTestMixin ):
1589
1586
"""Context tests that use a Cloud Datastore V1 connection.
1590
1587
1591
- These tests run with memcache and taskqueue stubs available."""
1588
+ These tests run with memcache and taskqueue stubs available.
1589
+ """
1592
1590
1593
1591
def setUp (self ):
1594
- super (ContextV1Tests , self ).setUp ()
1592
+ # testbed needs to get set up first.
1593
+ super (ContextV1WithRemoteAPITests , self ).setUp ()
1595
1594
self .testbed .init_memcache_stub ()
1596
1595
self .testbed .init_taskqueue_stub ()
1597
- self .HRTest ()
1598
- MyAutoBatcher .reset_log ()
1599
- self .ctx = self .MakeContext (default_model = model .Expando ,
1600
- auto_batcher_class = MyAutoBatcher )
1601
- tasklets .set_context (self .ctx )
1602
-
1603
- def make_bad_transaction (* arg , ** kwargs ):
1604
- return ''
1605
1596
1606
- def testContext_TransactionAddTask (self ):
1607
- # Transactional AddTask still will be unavailable .
1597
+ def testContext_AutoBatcher_Errors (self ):
1598
+ # Test that errors are properly distributed over all Futures .
1608
1599
self .ExpectWarnings ()
1609
- key = model .Key ('Foo' , 1 )
1610
-
1611
- @tasklets .tasklet
1612
- def foo ():
1613
- ent = model .Expando (key = key , bar = 1 )
1614
1600
1615
- @tasklets .tasklet
1616
- def callback ():
1617
- ctx = tasklets .get_context ()
1618
- yield ctx .put (ent )
1619
- taskqueue .add (url = '/' , transactional = True )
1620
- yield self .ctx .transaction (callback )
1621
- self .assertRaises (ValueError , foo ().check_success )
1601
+ class Blobby (model .Model ):
1602
+ blob = model .BlobProperty ()
1603
+ ent1 = Blobby ()
1604
+ ent2 = Blobby (blob = 'x' * 2000000 )
1605
+ fut1 = self .ctx .put (ent1 )
1606
+ fut2 = self .ctx .put (ent2 ) # Error
1607
+ err1 = fut1 .get_exception ()
1608
+ err2 = fut2 .get_exception ()
1609
+ self .assertTrue (isinstance (err1 , datastore_errors .BadRequestError ))
1610
+ self .assertTrue (err1 is err2 )
1611
+ # Try memcache as well (different tasklet, different error).
1612
+ fut1 = self .ctx .memcache_set ('key1' , 'x' )
1613
+ fut2 = self .ctx .memcache_set ('key2' , 'x' * 1000001 )
1614
+ err1 = fut1 .get_exception ()
1615
+ err2 = fut1 .get_exception ()
1616
+ self .assertTrue (isinstance (err1 , ValueError ))
1617
+ self .assertTrue (err1 is err2 )
1622
1618
1623
1619
def MakeContext (self , * args , ** kwargs ):
1624
- ctx = super (ContextV1Tests , self ).MakeContext (* args , ** kwargs )
1625
- # Re-enable in-context cache. Memcache must remain off because
1626
- # the stub is not enabled.
1627
- ctx .set_cache_policy (None )
1620
+ ctx = super (ContextV1WithRemoteAPITests , self ).MakeContext (* args , ** kwargs )
1621
+ # Re-enable memcache.
1622
+ ctx .set_memcache_policy (None )
1628
1623
return ctx
1629
1624
1625
+
1630
1626
class ContextFutureCachingTests (test_utils .NDBTest ):
1631
1627
# See issue 62. http://goo.gl/5zLkK
1632
1628
0 commit comments