def test_check_and_mutate_row(self): # Setup Expected Response predicate_matched = True expected_response = {"predicate_matched": predicate_matched} expected_response = bigtable_pb2.CheckAndMutateRowResponse(**expected_response) # Mock the API response channel = ChannelStub(responses=[expected_response]) patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = bigtable_v2.BigtableClient() # Setup Request table_name = client.table_path("[PROJECT]", "[INSTANCE]", "[TABLE]") row_key = b"122" response = client.check_and_mutate_row(table_name, row_key) assert expected_response == response assert len(channel.requests) == 1 expected_request = bigtable_pb2.CheckAndMutateRowRequest( table_name=table_name, row_key=row_key ) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_sample_row_keys(self): # Setup Expected Response row_key = b"122" offset_bytes = 889884095 expected_response = {"row_key": row_key, "offset_bytes": offset_bytes} expected_response = bigtable_pb2.SampleRowKeysResponse(**expected_response) # Mock the API response channel = ChannelStub(responses=[iter([expected_response])]) patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = bigtable_v2.BigtableClient() # Setup Request table_name = client.table_path("[PROJECT]", "[INSTANCE]", "[TABLE]") response = client.sample_row_keys(table_name) resources = list(response) assert len(resources) == 1 assert expected_response == resources[0] assert len(channel.requests) == 1 expected_request = bigtable_pb2.SampleRowKeysRequest(table_name=table_name) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_read_modify_write_row(self): # Setup Expected Response expected_response = {} expected_response = bigtable_pb2.ReadModifyWriteRowResponse(**expected_response) # Mock the API response channel = ChannelStub(responses=[expected_response]) patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = bigtable_v2.BigtableClient() # Setup Request table_name = client.table_path("[PROJECT]", "[INSTANCE]", "[TABLE]") row_key = b"122" rules = [] response = client.read_modify_write_row(table_name, row_key, rules) assert expected_response == response assert len(channel.requests) == 1 expected_request = bigtable_pb2.ReadModifyWriteRowRequest( table_name=table_name, row_key=row_key, rules=rules ) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_sample_row_keys(self): # Setup Expected Response row_key = b'122' offset_bytes = 889884095 expected_response = {'row_key': row_key, 'offset_bytes': offset_bytes} expected_response = bigtable_pb2.SampleRowKeysResponse( **expected_response) # Mock the API response channel = ChannelStub(responses=[iter([expected_response])]) client = bigtable_v2.BigtableClient(channel=channel) # Setup Request table_name = client.table_path('[PROJECT]', '[INSTANCE]', '[TABLE]') response = client.sample_row_keys(table_name) resources = list(response) assert len(resources) == 1 assert expected_response == resources[0] assert len(channel.requests) == 1 expected_request = bigtable_pb2.SampleRowKeysRequest( table_name=table_name) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_read_rows(self): # Setup Expected Response last_scanned_row_key = b"-126" expected_response = {"last_scanned_row_key": last_scanned_row_key} expected_response = bigtable_pb2.ReadRowsResponse(**expected_response) # Mock the API response channel = ChannelStub(responses=[iter([expected_response])]) patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = bigtable_v2.BigtableClient() # Setup Request table_name = client.table_path("[PROJECT]", "[INSTANCE]", "[TABLE]") response = client.read_rows(table_name) resources = list(response) assert len(resources) == 1 assert expected_response == resources[0] assert len(channel.requests) == 1 expected_request = bigtable_pb2.ReadRowsRequest(table_name=table_name) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_mutate_rows(self): # Setup Expected Response expected_response = {} expected_response = bigtable_pb2.MutateRowsResponse( **expected_response) # Mock the API response channel = ChannelStub(responses=[iter([expected_response])]) patch = mock.patch('google.api_core.grpc_helpers.create_channel') with patch as create_channel: create_channel.return_value = channel client = bigtable_v2.BigtableClient() # Setup Request table_name = client.table_path('[PROJECT]', '[INSTANCE]', '[TABLE]') entries = [] response = client.mutate_rows(table_name, entries) resources = list(response) assert len(resources) == 1 assert expected_response == resources[0] assert len(channel.requests) == 1 expected_request = bigtable_pb2.MutateRowsRequest( table_name=table_name, entries=entries) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_mutate_row(self): # Setup Expected Response expected_response = {} expected_response = bigtable_pb2.MutateRowResponse(**expected_response) # Mock the API response channel = ChannelStub(responses=[expected_response]) patch = mock.patch('google.api_core.grpc_helpers.create_channel') with patch as create_channel: create_channel.return_value = channel client = bigtable_v2.BigtableClient() # Setup Request table_name = client.table_path('[PROJECT]', '[INSTANCE]', '[TABLE]') row_key = b'122' mutations = [] response = client.mutate_row(table_name, row_key, mutations) assert expected_response == response assert len(channel.requests) == 1 expected_request = bigtable_pb2.MutateRowRequest(table_name=table_name, row_key=row_key, mutations=mutations) actual_request = channel.requests[0][1] assert expected_request == actual_request
def _table_data_client(self): """Getter for the gRPC stub used for the Table Admin API. :rtype: :class:`.bigtable_v2.BigtableClient` :returns: A BigtableClient object. """ return bigtable_v2.BigtableClient(channel=self._channel, credentials=self._credentials)
def test_read_rows_exception(self): # Mock the API response channel = ChannelStub(responses=[CustomException()]) client = bigtable_v2.BigtableClient(channel=channel) # Setup request table_name = client.table_path('[PROJECT]', '[INSTANCE]', '[TABLE]') with pytest.raises(CustomException): client.read_rows(table_name)
def test_check_and_mutate_row_exception(self): # Mock the API response channel = ChannelStub(responses=[CustomException()]) client = bigtable_v2.BigtableClient(channel=channel) # Setup request table_name = client.table_path('[PROJECT]', '[INSTANCE]', '[TABLE]') row_key = b'122' with pytest.raises(CustomException): client.check_and_mutate_row(table_name, row_key)
def table_data_client(self): """Getter for the gRPC stub used for the Table Admin API. :rtype: :class:`.bigtable_v2.BigtableClient` :returns: A BigtableClient object. """ if self._table_data_client is None: self._table_data_client = (bigtable_v2.BigtableClient( credentials=self._credentials, client_info=_CLIENT_INFO)) return self._table_data_client
def table_data_client(self): """Getter for the gRPC stub used for the Table Admin API. :rtype: :class:`.bigtable_v2.BigtableClient` :returns: A BigtableClient object. """ if self._table_data_client is None: if not self._admin: raise ValueError('Client is not an admin client.') self._table_data_client = (bigtable_v2.BigtableClient( credentials=self._credentials, client_info=_CLIENT_INFO)) return self._table_data_client
def test_read_rows_exception(self): # Mock the API response channel = ChannelStub(responses=[CustomException()]) patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = bigtable_v2.BigtableClient() # Setup request table_name = client.table_path("[PROJECT]", "[INSTANCE]", "[TABLE]") with pytest.raises(CustomException): client.read_rows(table_name)
def test_check_and_mutate_row_exception(self): # Mock the API response channel = ChannelStub(responses=[CustomException()]) patch = mock.patch('google.api_core.grpc_helpers.create_channel') with patch as create_channel: create_channel.return_value = channel client = bigtable_v2.BigtableClient() # Setup request table_name = client.table_path('[PROJECT]', '[INSTANCE]', '[TABLE]') row_key = b'122' with pytest.raises(CustomException): client.check_and_mutate_row(table_name, row_key)
def test_read_rows(self): # Setup Expected Response last_scanned_row_key = b'-126' expected_response = {'last_scanned_row_key': last_scanned_row_key} expected_response = bigtable_pb2.ReadRowsResponse(**expected_response) # Mock the API response channel = ChannelStub(responses=[iter([expected_response])]) client = bigtable_v2.BigtableClient(channel=channel) # Setup Request table_name = client.table_path('[PROJECT]', '[INSTANCE]', '[TABLE]') response = client.read_rows(table_name) resources = list(response) assert len(resources) == 1 assert expected_response == resources[0] assert len(channel.requests) == 1 expected_request = bigtable_pb2.ReadRowsRequest(table_name=table_name) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_check_and_mutate_row(self): # Setup Expected Response predicate_matched = True expected_response = {'predicate_matched': predicate_matched} expected_response = bigtable_pb2.CheckAndMutateRowResponse( **expected_response) # Mock the API response channel = ChannelStub(responses=[expected_response]) client = bigtable_v2.BigtableClient(channel=channel) # Setup Request table_name = client.table_path('[PROJECT]', '[INSTANCE]', '[TABLE]') row_key = b'122' response = client.check_and_mutate_row(table_name, row_key) assert expected_response == response assert len(channel.requests) == 1 expected_request = bigtable_pb2.CheckAndMutateRowRequest( table_name=table_name, row_key=row_key) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_read_modify_write_row(self): # Setup Expected Response expected_response = {} expected_response = bigtable_pb2.ReadModifyWriteRowResponse( **expected_response) # Mock the API response channel = ChannelStub(responses=[expected_response]) client = bigtable_v2.BigtableClient(channel=channel) # Setup Request table_name = client.table_path('[PROJECT]', '[INSTANCE]', '[TABLE]') row_key = b'122' rules = [] response = client.read_modify_write_row(table_name, row_key, rules) assert expected_response == response assert len(channel.requests) == 1 expected_request = bigtable_pb2.ReadModifyWriteRowRequest( table_name=table_name, row_key=row_key, rules=rules) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_mutate_rows(self): # Setup Expected Response expected_response = {} expected_response = bigtable_pb2.MutateRowsResponse( **expected_response) # Mock the API response channel = ChannelStub(responses=[iter([expected_response])]) client = bigtable_v2.BigtableClient(channel=channel) # Setup Request table_name = client.table_path('[PROJECT]', '[INSTANCE]', '[TABLE]') entries = [] response = client.mutate_rows(table_name, entries) resources = list(response) assert len(resources) == 1 assert expected_response == resources[0] assert len(channel.requests) == 1 expected_request = bigtable_pb2.MutateRowsRequest( table_name=table_name, entries=entries) actual_request = channel.requests[0][1] assert expected_request == actual_request