def test_create_app_profile(self):
        # Setup Expected Response
        name = "name3373707"
        etag = "etag3123477"
        description = "description-1724546052"
        expected_response = {
            "name": name,
            "etag": etag,
            "description": description
        }
        expected_response = instance_pb2.AppProfile(**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]")
        app_profile_id = "appProfileId1262094415"
        app_profile = {}

        response = client.create_app_profile(parent, app_profile_id,
                                             app_profile)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = bigtable_instance_admin_pb2.CreateAppProfileRequest(
            parent=parent,
            app_profile_id=app_profile_id,
            app_profile=app_profile)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
    def test_create_app_profile(self):
        # Setup Expected Response
        name = 'name3373707'
        etag = 'etag3123477'
        description = 'description-1724546052'
        expected_response = {
            'name': name,
            'etag': etag,
            'description': description
        }
        expected_response = instance_pb2.AppProfile(**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]')
        app_profile_id = 'appProfileId1262094415'
        app_profile = {}

        response = client.create_app_profile(parent, app_profile_id,
                                             app_profile)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = bigtable_instance_admin_pb2.CreateAppProfileRequest(
            parent=parent,
            app_profile_id=app_profile_id,
            app_profile=app_profile)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
Ejemplo n.º 3
0
    def test_create_routing_single(self):
        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

        credentials = _make_credentials()
        client = self._make_client(project=self.PROJECT,
                                   credentials=credentials,
                                   admin=True)
        instance = client.instance(self.INSTANCE_ID)

        routing = RoutingPolicyType.SINGLE
        description = "routing policy single"
        allow_writes = False
        ignore_warnings = True

        app_profile = self._make_one(
            self.APP_PROFILE_ID,
            instance,
            routing_policy_type=routing,
            description=description,
            cluster_id=self.CLUSTER_ID,
            allow_transactional_writes=allow_writes,
        )
        expected_request_app_profile = app_profile._to_pb()
        expected_request = messages_v2_pb2.CreateAppProfileRequest(
            parent=instance.name,
            app_profile_id=self.APP_PROFILE_ID,
            app_profile=expected_request_app_profile,
            ignore_warnings=ignore_warnings,
        )

        # Patch the stub used by the API method.
        channel = ChannelStub(responses=[expected_request_app_profile])
        instance_api = bigtable_instance_admin_client.BigtableInstanceAdminClient(
            channel=channel)
        client._instance_admin_client = instance_api
        # Perform the method and check the result.
        result = app_profile.create(ignore_warnings)
        actual_request = channel.requests[0][1]

        self.assertEqual(actual_request, expected_request)
        self.assertIsInstance(result, self._get_target_class())
        self.assertEqual(result.app_profile_id, self.APP_PROFILE_ID)
        self.assertIs(result._instance, instance)
        self.assertEqual(result.routing_policy_type, routing)
        self.assertEqual(result.description, description)
        self.assertEqual(result.allow_transactional_writes, allow_writes)
        self.assertEqual(result.cluster_id, self.CLUSTER_ID)
Ejemplo n.º 4
0
def _CreateAppProfileRequestPB(*args, **kw):
    from google.cloud.bigtable_admin_v2.proto import (
        bigtable_instance_admin_pb2 as instance_v2_pb2)

    return instance_v2_pb2.CreateAppProfileRequest(*args, **kw)