Exemplo n.º 1
0
    def test_list_instance_configs(self):
        from google.cloud.spanner_admin_instance_v1.gapic import instance_admin_client
        from google.cloud.spanner_admin_instance_v1.proto import (
            spanner_instance_admin_pb2, )
        from google.cloud.spanner_v1.client import InstanceConfig

        api = instance_admin_client.InstanceAdminClient(mock.Mock())
        credentials = _make_credentials()
        client = self._make_one(project=self.PROJECT, credentials=credentials)
        client._instance_admin_api = api

        instance_config_pbs = spanner_instance_admin_pb2.ListInstanceConfigsResponse(
            instance_configs=[
                spanner_instance_admin_pb2.InstanceConfig(
                    name=self.CONFIGURATION_NAME,
                    display_name=self.DISPLAY_NAME)
            ])

        lic_api = api._inner_api_calls["list_instance_configs"] = mock.Mock(
            return_value=instance_config_pbs)

        response = client.list_instance_configs()
        instance_configs = list(response)

        instance_config = instance_configs[0]
        self.assertIsInstance(instance_config, InstanceConfig)
        self.assertEqual(instance_config.name, self.CONFIGURATION_NAME)
        self.assertEqual(instance_config.display_name, self.DISPLAY_NAME)

        expected_metadata = [
            ("google-cloud-resource-prefix", client.project_name),
            ("x-goog-request-params", "parent={}".format(client.project_name)),
        ]
        lic_api.assert_called_once_with(
            spanner_instance_admin_pb2.ListInstanceConfigsRequest(
                parent=self.PATH),
            metadata=expected_metadata,
            retry=mock.ANY,
            timeout=mock.ANY,
        )
    def test_list_instance_configs(self, mock_create_stub):
        # Mock gRPC layer
        grpc_stub = mock.Mock()
        mock_create_stub.return_value = grpc_stub

        client = spanner_admin_instance_v1.InstanceAdminClient()

        # Mock request
        parent = client.project_path('[PROJECT]')

        # Mock response
        next_page_token = ''
        instance_configs_element = {}
        instance_configs = [instance_configs_element]
        expected_response = {
            'next_page_token': next_page_token,
            'instance_configs': instance_configs
        }
        expected_response = spanner_instance_admin_pb2.ListInstanceConfigsResponse(
            **expected_response)
        grpc_stub.ListInstanceConfigs.return_value = expected_response

        paged_list_response = client.list_instance_configs(parent)
        resources = list(paged_list_response)
        self.assertEqual(1, len(resources))
        self.assertEqual(expected_response.instance_configs[0], resources[0])

        grpc_stub.ListInstanceConfigs.assert_called_once()
        args, kwargs = grpc_stub.ListInstanceConfigs.call_args
        self.assertEqual(len(args), 2)
        self.assertEqual(len(kwargs), 1)
        self.assertIn('metadata', kwargs)
        actual_request = args[0]

        expected_request = spanner_instance_admin_pb2.ListInstanceConfigsRequest(
            parent=parent)
        self.assertEqual(expected_request, actual_request)
Exemplo n.º 3
0
    def test_list_instance_configs(self):
        from google.cloud.spanner_admin_instance_v1.gapic import (
            instance_admin_client)
        from google.cloud.spanner_admin_instance_v1.proto import (
            spanner_instance_admin_pb2)
        from google.cloud.spanner_v1.client import InstanceConfig

        api = instance_admin_client.InstanceAdminClient(mock.Mock())
        credentials = _make_credentials()
        client = self._make_one(project=self.PROJECT, credentials=credentials)
        client._instance_admin_api = api

        instance_config_pbs = (
            spanner_instance_admin_pb2.ListInstanceConfigsResponse(
                instance_configs=[
                    spanner_instance_admin_pb2.InstanceConfig(
                        name=self.CONFIGURATION_NAME,
                        display_name=self.DISPLAY_NAME),
                ]))

        api._list_instance_configs = mock.Mock(
            return_value=instance_config_pbs)

        response = client.list_instance_configs()
        instance_configs = list(response)

        instance_config = instance_configs[0]
        self.assertIsInstance(instance_config, InstanceConfig)
        self.assertEqual(instance_config.name, self.CONFIGURATION_NAME)
        self.assertEqual(instance_config.display_name, self.DISPLAY_NAME)

        api._list_instance_configs.assert_called_once_with(
            spanner_instance_admin_pb2.ListInstanceConfigsRequest(
                parent=self.PATH),
            metadata=[('google-cloud-resource-prefix', client.project_name)],
            retry=mock.ANY,
            timeout=mock.ANY)