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. :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 app_profile( self, app_profile_id, routing_policy_type=None, description=None, cluster_id=None, allow_transactional_writes=None, ): """Factory to create AppProfile associated with this instance. For example: .. literalinclude:: snippets.py :start-after: [START bigtable_api_create_app_profile] :end-before: [END bigtable_api_create_app_profile] :dedent: 4 :type app_profile_id: str :param app_profile_id: The ID of the AppProfile. Must be of the form ``[_a-zA-Z0-9][-_.a-zA-Z0-9]*``. :type: routing_policy_type: int :param: routing_policy_type: The type of the routing policy. Possible values are represented by the following constants: :data:`google.cloud.bigtable.enums.RoutingPolicyType.ANY` :data:`google.cloud.bigtable.enums.RoutingPolicyType.SINGLE` :type: description: str :param: description: (Optional) Long form description of the use case for this AppProfile. :type: cluster_id: str :param: cluster_id: (Optional) Unique cluster_id which is only required when routing_policy_type is ROUTING_POLICY_TYPE_SINGLE. :type: allow_transactional_writes: bool :param: allow_transactional_writes: (Optional) If true, allow transactional writes for ROUTING_POLICY_TYPE_SINGLE. :rtype: :class:`~google.cloud.bigtable.app_profile.AppProfile>` :returns: AppProfile for this instance. """ return AppProfile( app_profile_id, self, routing_policy_type=routing_policy_type, description=description, cluster_id=cluster_id, allow_transactional_writes=allow_transactional_writes, )
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]
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]
def _make_app_profile(*args, **kwargs): from google.cloud.bigtable.app_profile import AppProfile return AppProfile(*args, **kwargs)