def test_list_app_profiles(self): # Setup Expected Response next_page_token = "" app_profiles_element = {} app_profiles = [app_profiles_element] expected_response = { "next_page_token": next_page_token, "app_profiles": app_profiles, } expected_response = bigtable_instance_admin_pb2.ListAppProfilesResponse( **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_admin_v2.BigtableInstanceAdminClient() # Setup Request parent = client.instance_path("[PROJECT]", "[INSTANCE]") paged_list_response = client.list_app_profiles(parent) resources = list(paged_list_response) assert len(resources) == 1 assert expected_response.app_profiles[0] == resources[0] assert len(channel.requests) == 1 expected_request = bigtable_instance_admin_pb2.ListAppProfilesRequest( parent=parent) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_list_app_profiles(self): # Setup Expected Response next_page_token = '' app_profiles_element = {} app_profiles = [app_profiles_element] expected_response = { 'next_page_token': next_page_token, 'app_profiles': app_profiles } expected_response = bigtable_instance_admin_pb2.ListAppProfilesResponse( **expected_response) # Mock the API response channel = ChannelStub(responses=[expected_response]) client = bigtable_admin_v2.BigtableInstanceAdminClient(channel=channel) # Setup Request parent = client.instance_path('[PROJECT]', '[INSTANCE]') paged_list_response = client.list_app_profiles(parent) resources = list(paged_list_response) assert len(resources) == 1 assert expected_response.app_profiles[0] == resources[0] assert len(channel.requests) == 1 expected_request = bigtable_instance_admin_pb2.ListAppProfilesRequest( parent=parent) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_list_app_profiles(self): from google.cloud.bigtable_admin_v2.gapic import ( bigtable_instance_admin_client) from google.cloud.bigtable_admin_v2.proto import ( bigtable_instance_admin_pb2 as messages_v2_pb2) from google.cloud.bigtable_admin_v2.proto import ( instance_pb2 as data_v2_pb2) from google.cloud.bigtable.app_profile import AppProfile instance_api = ( bigtable_instance_admin_client.BigtableInstanceAdminClient( mock.Mock())) credentials = _make_credentials() client = self._make_client(project=self.PROJECT, credentials=credentials, admin=True) instance = self._make_one(self.INSTANCE_ID, client) # Setup Expected Response next_page_token = '' app_profile_id1 = 'app-profile-id1' app_profile_id2 = 'app-profile-id2' app_profile_name1 = (client.instance_admin_client.app_profile_path( self.PROJECT, self.INSTANCE_ID, app_profile_id1)) app_profile_name2 = (client.instance_admin_client.app_profile_path( self.PROJECT, self.INSTANCE_ID, app_profile_id2)) routing_policy = data_v2_pb2.AppProfile.MultiClusterRoutingUseAny() expected_response = messages_v2_pb2.ListAppProfilesResponse( next_page_token=next_page_token, app_profiles=[ data_v2_pb2.AppProfile( name=app_profile_name1, multi_cluster_routing_use_any=routing_policy, ), data_v2_pb2.AppProfile( name=app_profile_name2, multi_cluster_routing_use_any=routing_policy, ) ], ) # Patch the stub used by the API method. client._instance_admin_client = instance_api bigtable_instance_stub = ( client._instance_admin_client.transport) bigtable_instance_stub.list_app_profiles.side_effect = [ expected_response] # Perform the method and check the result. app_profiles = instance.list_app_profiles() app_profile_1, app_profile_2 = app_profiles self.assertIsInstance(app_profile_1, AppProfile) self.assertEqual(app_profile_1.name, app_profile_name1) self.assertIsInstance(app_profile_2, AppProfile) self.assertEqual(app_profile_2.name, app_profile_name2)
def test_list_app_profiles(self): from google.cloud.bigtable_admin_v2.proto import ( bigtable_instance_admin_pb2 as instance_messages_v1_pb2) from google.cloud.bigtable_admin_v2.gapic import ( bigtable_instance_admin_client) instance_api = ( bigtable_instance_admin_client.BigtableInstanceAdminClient( mock.Mock())) credentials = _make_credentials() client = self._make_client(project=self.PROJECT, credentials=credentials, admin=True) instance = self._make_one(self.INSTANCE_ID, client) # Setup Expected Response next_page_token = '' app_profiles_element = {} app_profiles = [app_profiles_element] expected_response = { 'next_page_token': next_page_token, 'app_profiles': app_profiles } expected_response = instance_messages_v1_pb2.ListAppProfilesResponse( **expected_response) # Patch the stub used by the API method. client._instance_admin_client = instance_api bigtable_instance_stub = ( client._instance_admin_client.bigtable_instance_admin_stub) bigtable_instance_stub.ListAppProfiles.side_effect = [ expected_response ] # Perform the method and check the result. response = instance.list_app_profiles() self.assertEqual(response[0], expected_response.app_profiles[0])