@@ -22,12 +22,18 @@ class TestTransaction(unittest.TestCase):
2222 @staticmethod
2323 def _get_target_class ():
2424 from google .cloud .datastore .transaction import Transaction
25-
2625 return Transaction
2726
27+ def _get_options_class (self , ** kw ):
28+ from google .cloud .datastore_v1 .types import TransactionOptions
29+ return TransactionOptions
30+
2831 def _make_one (self , client , ** kw ):
2932 return self ._get_target_class ()(client , ** kw )
3033
34+ def _make_options (self , ** kw ):
35+ return self ._get_options_class ()(** kw )
36+
3137 def test_ctor_defaults (self ):
3238 project = 'PROJECT'
3339 client = _Client (project )
@@ -212,6 +218,27 @@ class Foo(Exception):
212218 self .assertIsNone (xact .id )
213219 self .assertEqual (ds_api .begin_transaction .call_count , 1 )
214220
221+ def test_constructor_read_only (self ):
222+ project = 'PROJECT'
223+ id_ = 850302
224+ ds_api = _make_datastore_api (xact = id_ )
225+ client = _Client (project , datastore_api = ds_api )
226+ read_only = self ._get_options_class ().ReadOnly ()
227+ options = self ._make_options (read_only = read_only )
228+ xact = self ._make_one (client , read_only = True )
229+ self .assertEqual (xact ._options , options )
230+
231+ def test_put_read_only (self ):
232+ project = 'PROJECT'
233+ id_ = 943243
234+ ds_api = _make_datastore_api (xact_id = id_ )
235+ client = _Client (project , datastore_api = ds_api )
236+ entity = _Entity ()
237+ xact = self ._make_one (client , read_only = True )
238+ xact .begin ()
239+ with self .assertRaises (RuntimeError ):
240+ xact .put (entity )
241+
215242
216243def _make_key (kind , id_ , project ):
217244 from google .cloud .datastore_v1 .proto import entity_pb2
0 commit comments