def test_update_app_profile_routing_single(self): from google.api_core import operation from google.longrunning import operations_pb2 from google.protobuf.any_pb2 import Any from google.cloud.bigtable_admin_v2.proto import ( bigtable_instance_admin_pb2 as messages_v2_pb2) from google.cloud.bigtable.enums import RoutingPolicyType from google.cloud.bigtable_admin_v2.gapic import ( bigtable_instance_admin_client) from google.protobuf import field_mask_pb2 credentials = _make_credentials() client = self._make_client(project=self.PROJECT, credentials=credentials, admin=True) instance = client.instance(self.INSTANCE_ID) routing = RoutingPolicyType.ANY app_profile = self._make_one(self.APP_PROFILE_ID, instance, routing_policy_type=routing) # Create response_pb metadata = messages_v2_pb2.UpdateAppProfileMetadata() type_url = 'type.googleapis.com/{}'.format( messages_v2_pb2.UpdateAppProfileMetadata.DESCRIPTOR.full_name) response_pb = operations_pb2.Operation( name=self.OP_NAME, metadata=Any( type_url=type_url, value=metadata.SerializeToString(), )) # Patch the stub used by the API method. channel = ChannelStub(responses=[response_pb]) instance_api = ( bigtable_instance_admin_client.BigtableInstanceAdminClient( channel=channel)) # Mock api calls client._instance_admin_client = instance_api # Perform the method and check the result. ignore_warnings = True expected_request_update_mask = field_mask_pb2.FieldMask( paths=['multi_cluster_routing_use_any']) expected_request = messages_v2_pb2.UpdateAppProfileRequest( app_profile=app_profile._to_pb(), update_mask=expected_request_update_mask, ignore_warnings=ignore_warnings) result = app_profile.update(ignore_warnings=ignore_warnings) actual_request = channel.requests[0][1] self.assertEqual(actual_request, expected_request) self.assertIsInstance(result, operation.Operation) self.assertEqual(result.operation.name, self.OP_NAME) self.assertIsInstance(result.metadata, messages_v2_pb2.UpdateAppProfileMetadata)
def test_update_app_profile_single_routing_policy(self): from google.api_core import operation from google.longrunning import operations_pb2 from google.protobuf.any_pb2 import Any from google.cloud.bigtable_admin_v2.proto import ( bigtable_instance_admin_pb2 as messages_v2_pb2) from google.cloud.bigtable_admin_v2.gapic import ( bigtable_instance_admin_client) from google.cloud.bigtable_admin_v2.types import instance_pb2 from google.protobuf import field_mask_pb2 from google.cloud.bigtable_admin_v2.proto import ( bigtable_instance_admin_pb2 as instance_v2_pb2) from google.cloud.bigtable.enums import RoutingPolicyType credentials = _make_credentials() client = self._make_client(project=self.PROJECT, credentials=credentials, admin=True) instance = self._make_one(self.INSTANCE_ID, client) # Create response_pb metadata = messages_v2_pb2.UpdateAppProfileMetadata() type_url = 'type.googleapis.com/{}'.format( messages_v2_pb2.UpdateAppProfileMetadata.DESCRIPTOR.full_name) response_pb = operations_pb2.Operation( name=self.OP_NAME, metadata=Any( type_url=type_url, value=metadata.SerializeToString(), )) # Patch the stub used by the API method. channel = ChannelStub(responses=[response_pb]) instance_api = ( bigtable_instance_admin_client.BigtableInstanceAdminClient( channel=channel)) # Mock api calls client._instance_admin_client = instance_api # Perform the method and check the result. app_profile_id = 'appProfileId1262094415' cluster_id = 'cluster-id' allow_transactional_writes = True ignore_warnings = True single_cluster_routing = (instance_pb2.AppProfile.SingleClusterRouting( cluster_id=cluster_id, allow_transactional_writes=allow_transactional_writes)) expected_request_app_profile = instance_pb2.AppProfile( name=self.APP_PROFILE_PATH + app_profile_id, single_cluster_routing=single_cluster_routing) expected_request_update_mask = field_mask_pb2.FieldMask( paths=['single_cluster_routing']) expected_request = instance_v2_pb2.UpdateAppProfileRequest( app_profile=expected_request_app_profile, update_mask=expected_request_update_mask, ignore_warnings=ignore_warnings) result = instance.update_app_profile( app_profile_id, RoutingPolicyType.SINGLE, ignore_warnings=ignore_warnings, cluster_id=cluster_id, allow_transactional_writes=(allow_transactional_writes)) actual_request = channel.requests[0][1] self.assertEqual(actual_request, expected_request) self.assertIsInstance(result, operation.Operation) self.assertEqual(result.operation.name, self.OP_NAME) self.assertIsInstance(result.metadata, messages_v2_pb2.UpdateAppProfileMetadata)