def test_app_profile_from_pb_w_bad_app_profile_name(): from google.cloud.bigtable_admin_v2.types import instance as data_v2_pb2 from google.cloud.bigtable.app_profile import AppProfile bad_app_profile_name = "BAD_NAME" app_profile_pb = data_v2_pb2.AppProfile(name=bad_app_profile_name) with pytest.raises(ValueError): AppProfile.from_pb(app_profile_pb, None)
def test_app_profile_from_pb_w_project_mistmatch(): from google.cloud.bigtable_admin_v2.types import instance as data_v2_pb2 from google.cloud.bigtable.app_profile import AppProfile ALT_PROJECT = "ALT_PROJECT" client = _Client(project=ALT_PROJECT) instance = _Instance(INSTANCE_ID, client) assert client.project == ALT_PROJECT app_profile_pb = data_v2_pb2.AppProfile(name=APP_PROFILE_NAME) with pytest.raises(ValueError): AppProfile.from_pb(app_profile_pb, instance)
def test_app_profile_from_pb_success_w_routing_single(): from google.cloud.bigtable_admin_v2.types import instance as data_v2_pb2 from google.cloud.bigtable.app_profile import AppProfile from google.cloud.bigtable.enums import RoutingPolicyType client = _Client(PROJECT) instance = _Instance(INSTANCE_ID, client) desctiption = "routing single" allow_transactional_writes = True routing = RoutingPolicyType.SINGLE single_cluster_routing = data_v2_pb2.AppProfile.SingleClusterRouting( cluster_id=CLUSTER_ID, allow_transactional_writes=allow_transactional_writes, ) app_profile_pb = data_v2_pb2.AppProfile( name=APP_PROFILE_NAME, description=desctiption, single_cluster_routing=single_cluster_routing, ) app_profile = AppProfile.from_pb(app_profile_pb, instance) assert isinstance(app_profile, AppProfile) assert app_profile._instance is instance assert app_profile.app_profile_id == APP_PROFILE_ID assert app_profile.description == desctiption assert app_profile.routing_policy_type == routing assert app_profile.cluster_id == CLUSTER_ID assert app_profile.allow_transactional_writes == allow_transactional_writes
def test_app_profile_from_pb_success_w_routing_any(): from google.cloud.bigtable_admin_v2.types import instance as data_v2_pb2 from google.cloud.bigtable.app_profile import AppProfile from google.cloud.bigtable.enums import RoutingPolicyType client = _Client(PROJECT) instance = _Instance(INSTANCE_ID, client) desctiption = "routing any" routing = RoutingPolicyType.ANY multi_cluster_routing_use_any = data_v2_pb2.AppProfile.MultiClusterRoutingUseAny( ) app_profile_pb = data_v2_pb2.AppProfile( name=APP_PROFILE_NAME, description=desctiption, multi_cluster_routing_use_any=multi_cluster_routing_use_any, ) app_profile = AppProfile.from_pb(app_profile_pb, instance) assert isinstance(app_profile, AppProfile) assert app_profile._instance is instance assert app_profile.app_profile_id == APP_PROFILE_ID assert app_profile.description == desctiption assert app_profile.routing_policy_type == routing assert app_profile.cluster_id is None assert app_profile.allow_transactional_writes is False
def list_app_profiles(self): """Lists information about AppProfiles in an instance. :rtype: :list:[`~google.cloud.bigtable.app_profile.AppProfile`] :returns: A :list:[`~google.cloud.bigtable.app_profile.AppProfile`]. By default, this is a list of :class:`~google.cloud.bigtable.app_profile.AppProfile` instances. """ resp = self._client._instance_admin_client.list_app_profiles(self.name) return [AppProfile.from_pb(app_profile, self) for app_profile in resp]
def list_app_profiles(self): """Lists information about AppProfiles in an instance. For example: .. literalinclude:: snippets.py :start-after: [START bigtable_list_app_profiles] :end-before: [END bigtable_list_app_profiles] :rtype: :list:[`~google.cloud.bigtable.app_profile.AppProfile`] :returns: A :list:[`~google.cloud.bigtable.app_profile.AppProfile`]. By default, this is a list of :class:`~google.cloud.bigtable.app_profile.AppProfile` instances. """ resp = self._client.instance_admin_client.list_app_profiles(self.name) return [AppProfile.from_pb(app_profile, self) for app_profile in resp]