#NEWLINE# def test_as_context_mgr_nested( self ) : #NEWLINE# #INDENT# _PROJECT = 'PROJECT' #NEWLINE# _PROPERTIES = { #NEWLINE# #INDENT# 'foo' : 'bar' , #NEWLINE# #UNINDENT# } #NEWLINE# connection = _Connection ( ) #NEWLINE# entity1 = _Entity ( _PROPERTIES ) #NEWLINE# key1 = entity1 . key = _Key ( _PROJECT ) #NEWLINE# entity2 = _Entity ( _PROPERTIES ) #NEWLINE# key2 = entity2 . key = _Key ( _PROJECT ) #NEWLINE# client = _Client ( _PROJECT , connection ) #NEWLINE# self . assertEqual ( list ( client . _batches ) , [ ] ) #NEWLINE# with self . _makeOne ( client ) as batch1 : #NEWLINE# #INDENT# self . assertEqual ( list ( client . _batches ) , [ batch1 ] ) #NEWLINE# batch1 . put ( entity1 ) #NEWLINE# with self . _makeOne ( client ) as batch2 : #NEWLINE# #INDENT# self . assertEqual ( list ( client . _batches ) , [ batch2 , batch1 ] ) #NEWLINE# batch2 . put ( entity2 ) #NEWLINE# #UNINDENT# self . assertEqual ( list ( client . _batches ) , [ batch1 ] ) #NEWLINE# #UNINDENT# self . assertEqual ( list ( client . _batches ) , [ ] ) #NEWLINE# mutated_entity1 = _mutated_pb ( self , batch1 . mutations , 'upsert' ) #NEWLINE# self . assertEqual ( mutated_entity1 . key , key1 . _key ) #NEWLINE# mutated_entity2 = _mutated_pb ( self , batch2 . mutations , 'upsert' ) #NEWLINE# self . assertEqual ( mutated_entity2 . key , key2 . _key ) #NEWLINE# self . assertEqual ( connection . _committed , [ ( _PROJECT , batch2 . _commit_request , None ) , ( _PROJECT , batch1 . _commit_request , None ) ] )