@@ -368,44 +368,110 @@ def test_direct_row_delete_cells_with_string_columns():
368368
369369
370370def test_direct_row_commit ():
371+ from google .cloud .bigtable_v2 .services .bigtable import BigtableClient
372+ from google .rpc import code_pb2 , status_pb2
373+
371374 project_id = "project-id"
372375 row_key = b"row_key"
373376 table_name = "projects/more-stuff"
377+ app_profile_id = "app_profile_id"
374378 column_family_id = "column_family_id"
375379 column = b"column"
376380
377381 credentials = _make_credentials ()
378382 client = _make_client (project = project_id , credentials = credentials , admin = True )
379- table = _Table (table_name , client = client )
383+ table = _Table (table_name , client = client , app_profile_id = app_profile_id )
380384 row = _make_direct_row (row_key , table )
381385 value = b"bytes-value"
382386
387+ # Set mock
388+ api = mock .create_autospec (BigtableClient )
389+ response_pb = _MutateRowResponsePB ()
390+ api .mutate_row .side_effect = [response_pb ]
391+ client .table_data_client
392+ client ._table_data_client ._gapic_client = api
393+
383394 # Perform the method and check the result.
384395 row .set_cell (column_family_id , column , value )
385- row .commit ()
386- assert table .mutated_rows == [row ]
396+ response = row .commit ()
397+ assert row ._mutations == []
398+ assert response == status_pb2 .Status (code = code_pb2 .OK )
399+ call_args = api .mutate_row .call_args
400+ assert app_profile_id == call_args .app_profile_id [0 ]
387401
388402
389403def test_direct_row_commit_with_exception ():
390- from google .rpc import status_pb2
404+ from google .api_core .exceptions import InternalServerError
405+ from google .cloud .bigtable_v2 .services .bigtable import BigtableClient
406+ from google .rpc import code_pb2 , status_pb2
391407
392408 project_id = "project-id"
393409 row_key = b"row_key"
394410 table_name = "projects/more-stuff"
411+ app_profile_id = "app_profile_id"
395412 column_family_id = "column_family_id"
396413 column = b"column"
397414
398415 credentials = _make_credentials ()
399416 client = _make_client (project = project_id , credentials = credentials , admin = True )
400- table = _Table (table_name , client = client )
417+ table = _Table (table_name , client = client , app_profile_id = app_profile_id )
401418 row = _make_direct_row (row_key , table )
402419 value = b"bytes-value"
403420
421+ # Set mock
422+ api = mock .create_autospec (BigtableClient )
423+ exception_message = "Boom!"
424+ exception = InternalServerError (exception_message )
425+ api .mutate_row .side_effect = [exception ]
426+ client .table_data_client
427+ client ._table_data_client ._gapic_client = api
428+
404429 # Perform the method and check the result.
405430 row .set_cell (column_family_id , column , value )
406431 result = row .commit ()
407- expected = status_pb2 .Status (code = 0 )
408- assert result == expected
432+ assert row ._mutations == []
433+ assert result == status_pb2 .Status (
434+ code = code_pb2 .Code .INTERNAL , message = exception_message
435+ )
436+ call_args = api .mutate_row .call_args
437+ assert app_profile_id == call_args .app_profile_id [0 ]
438+
439+
440+ def test_direct_row_commit_with_unknown_exception ():
441+ from google .api_core .exceptions import GoogleAPICallError
442+ from google .cloud .bigtable_v2 .services .bigtable import BigtableClient
443+ from google .rpc import code_pb2 , status_pb2
444+
445+ project_id = "project-id"
446+ row_key = b"row_key"
447+ table_name = "projects/more-stuff"
448+ app_profile_id = "app_profile_id"
449+ column_family_id = "column_family_id"
450+ column = b"column"
451+
452+ credentials = _make_credentials ()
453+ client = _make_client (project = project_id , credentials = credentials , admin = True )
454+ table = _Table (table_name , client = client , app_profile_id = app_profile_id )
455+ row = _make_direct_row (row_key , table )
456+ value = b"bytes-value"
457+
458+ # Set mock
459+ api = mock .create_autospec (BigtableClient )
460+ exception_message = "Boom!"
461+ exception = GoogleAPICallError (message = exception_message )
462+ api .mutate_row .side_effect = [exception ]
463+ client .table_data_client
464+ client ._table_data_client ._gapic_client = api
465+
466+ # Perform the method and check the result.
467+ row .set_cell (column_family_id , column , value )
468+ result = row .commit ()
469+ assert row ._mutations == []
470+ assert result == status_pb2 .Status (
471+ code = code_pb2 .Code .UNKNOWN , message = exception_message
472+ )
473+ call_args = api .mutate_row .call_args
474+ assert app_profile_id == call_args .app_profile_id [0 ]
409475
410476
411477def _make_conditional_row (* args , ** kwargs ):
@@ -729,6 +795,12 @@ def test__parse_rmw_row_response():
729795 assert expected_output == _parse_rmw_row_response (sample_input )
730796
731797
798+ def _MutateRowResponsePB ():
799+ from google .cloud .bigtable_v2 .types import bigtable as messages_v2_pb2
800+
801+ return messages_v2_pb2 .MutateRowResponse ()
802+
803+
732804def _CheckAndMutateRowResponsePB (* args , ** kw ):
733805 from google .cloud .bigtable_v2 .types import bigtable as messages_v2_pb2
734806
@@ -778,16 +850,9 @@ def __init__(self, name, client=None, app_profile_id=None):
778850 self ._instance = _Instance (client )
779851 self ._app_profile_id = app_profile_id
780852 self .client = client
781- self .mutated_rows = []
782853
783854 self ._table_impl = self ._instance ._client ._veneer_data_client .get_table (
784855 _INSTANCE_ID ,
785856 self .name ,
786857 app_profile_id = self ._app_profile_id ,
787858 )
788-
789- def mutate_rows (self , rows ):
790- from google .rpc import status_pb2
791-
792- self .mutated_rows .extend (rows )
793- return [status_pb2 .Status (code = 0 )]
0 commit comments