コード例 #1
0
ファイル: util_test.py プロジェクト: bopopescu/gcloud_cli
 def SetUp(self):
   properties.VALUES.core.account.Set('fakeuser')
   self.fake_cred = client.OAuth2Credentials(
       'access-token', 'client_id', 'client_secret',
       'fake-token', None, 'token_uri', 'user_agent',
       scopes=config.CLOUDSDK_SCOPES)
   self.mock_client = mock.Client(apis.GetClientClass('iamcredentials', 'v1'))
   self.mock_client.Mock()
   self.addCleanup(self.mock_client.Unmock)
   self.messages = self.mock_client.MESSAGES_MODULE
   self.gen_request_msg = (
       self.messages
       .IamcredentialsProjectsServiceAccountsGenerateAccessTokenRequest)
   self.gen_id_msg = (
       self.messages
       .IamcredentialsProjectsServiceAccountsGenerateIdTokenRequest)
   self.refresh_mock = self.StartObjectPatch(client.OAuth2Credentials,
                                             'refresh')
    def SetUp(self):
        properties.VALUES.core.project.Set('fakeproject')
        api_name = 'appengine'

        api_version = appengine_app_update_api_client.DEFAULT_VERSION
        self.mocked_client = mock.Client(
            apis.GetClientClass(api_name, api_version),
            real_client=apis.GetClientInstance(api_name,
                                               api_version,
                                               no_http=True))
        self.mocked_client.Mock()
        self.addCleanup(self.mocked_client.Unmock)

        self.messages = apis.GetMessagesModule(api_name, api_version)

        self.client = (
            appengine_app_update_api_client.AppengineAppUpdateApiClient(
                self.mocked_client))
コード例 #3
0
    def SetUp(self):
        api_version = 'v1'
        self.apitools_client = api_mock.Client(
            core_apis.GetClientClass('compute', api_version),
            real_client=core_apis.GetClientInstance('compute',
                                                    api_version,
                                                    no_http=True))
        self.apitools_client.Mock()
        self.addCleanup(self.apitools_client.Unmock)
        self.messages = self.apitools_client.MESSAGES_MODULE

        self.resources = resources.Registry()
        self.resources.RegisterApiByName('compute', api_version)
        self.track = calliope_base.ReleaseTrack.GA
        self.service = self.apitools_client.snapshots
        self.global_operations = self.apitools_client.globalOperations

        self.StartPatch('time.sleep')
コード例 #4
0
 def SetUp(self):
     self.mock_client = api_mock.Client(
         core_apis.GetClientClass('cloudbuild', 'v1'))
     self.mock_client.Mock()
     self.addCleanup(self.mock_client.Unmock)
     self.messages = core_apis.GetMessagesModule('cloudbuild', 'v1')
     # Intercept logging output.
     self.mock_log_content = ''
     mock_log_print = self.StartPatch(
         'googlecloudsdk.api_lib.cloudbuild.logs.LogTailer._PrintLogLine')
     mock_log_print.side_effect = self._MockPrintLogLine
     self.StartPatch(
         'googlecloudsdk.core.console.console_attr_os.GetTermSize',
         return_value=(40, 100))
     self.client = build.CloudBuildClient(self.mock_client, self.messages)
     self.build = self.messages.Build(
         images=['gcr.io/my-project/output-tag'])
     self.StartObjectPatch(time, 'sleep')
コード例 #5
0
    def _MockClient(self, client_name, version):
        """Mocks a specific client for the duration of a test.

    Cleans the mock up after the test is completed.

    Args:
      client_name: The name of the api to mock.
      version: The version string to reference for the mock.

    Returns:
      A mock class that can override functionality of the underlying api, and
      specify expected inputs.
    """
        client = mock.Client(
            client_class=core_apis.GetClientClass(client_name, version))
        client.Mock()
        self.addCleanup(client.Unmock)
        return client
コード例 #6
0
def GetClientClass(release_track=base.ReleaseTrack.GA, region=None):
  """Returns the client class for Cloud Build.

  Args:
    release_track: The desired value of the enum
      googlecloudsdk.calliope.base.ReleaseTrack.
    region: str, The region of the service to use, or None for the global
      service.

  Raises:
    NoSuchRegionError: if the specified region is not a Cloud Build region.

  Returns:
    base_api.BaseApiClient, Client class for Cloud Build.
  """
  with RegionalCloudBuildContext(release_track, region):
    return apis.GetClientClass(_API_NAME,
                               RELEASE_TRACK_TO_API_VERSION[release_track])
コード例 #7
0
 def SetUp(self):
     client = apis.GetClientClass('compute', 'v1')
     self.mocked_client = mock.Client(client)
     self.mocked_client.Mock()
     self.addCleanup(self.mocked_client.Unmock)
     response = client.MESSAGES_MODULE.InstanceList(
         id='projcets/foo/zones/zone1/instances',
         items=[
             client.MESSAGES_MODULE.Instance(name='instance-1'),
             client.MESSAGES_MODULE.Instance(name='instance-2')
         ])
     self.mocked_client.instances.List.Expect(
         client.MESSAGES_MODULE.ComputeInstancesListRequest(
             zone='zone1',
             project='foo',
             pageToken=None,
         ),
         response=response)
コード例 #8
0
    def SetUp(self):
        properties.VALUES.core.project.Set(self.PROJECT_NAME)

        self.services_client = core_apis.GetClientInstance('servicemanagement',
                                                           'v1',
                                                           no_http=True)
        # Mock out the service management API
        self.mocked_client = mock.Client(
            core_apis.GetClientClass('servicemanagement', 'v1'),
            real_client=core_apis.GetClientInstance('servicemanagement',
                                                    'v1',
                                                    no_http=True))
        self.mocked_client.Mock()
        self.addCleanup(self.mocked_client.Unmock)

        # Mock out time.sleep calls in operation polling
        self.time_mock = self.StartObjectPatch(time, 'time')
        self.sleep_mock = self.StartObjectPatch(time, 'sleep')
コード例 #9
0
 def testRunWithUpdateMask(self):
     client = apis.GetClientClass('cloudresourcemanager', 'v1')
     mocked_client = apitools_mock.Client(client)
     mocked_client.Mock()
     self.addCleanup(mocked_client.Unmock)
     messages = client.MESSAGES_MODULE
     policy = self._MakePolicy(bindings=[{
         'role':
         'roles/owner',
         'members': [
             'user:[email protected]', 'group:[email protected]',
             'domain:google.com'
         ]
     }],
                               messages=messages)
     self.StartObjectPatch(iam_util,
                           'ParsePolicyFileWithUpdateMask',
                           return_value=(policy, 'bindings,etag,version'))
     policy.version = 0
     set_iam_policy_request = messages.SetIamPolicyRequest(
         policy=policy, updateMask='bindings,etag,version')
     mocked_client.projects.SetIamPolicy.Expect(
         messages.CloudresourcemanagerProjectsSetIamPolicyRequest(
             resource='projects/p',
             setIamPolicyRequest=set_iam_policy_request), policy)
     d = yaml_command_schema.CommandData('set_iam_policy',
                                         self.MakeProjectCommandData())
     cli = self.MakeCLI(d)
     self.AssertArgs(cli, 'PROJECT_ID', 'POLICY_FILE')
     result = cli.Execute(['command', 'p', 'myfile'])
     self.assertEqual(result, policy)
     self.AssertErrContains('Updated IAM policy for project [p].',
                            normalize_space=True)
     self.AssertOutputEquals("""
   bindings:
   - members:
   - user:[email protected]
   - group:[email protected]
   - domain:google.com
   role: roles/owner
   etag: QUNBQg==
   version: 0
 """.lstrip('\n'),
                             normalize_space=True)
コード例 #10
0
ファイル: base.py プロジェクト: piotradamczyk5/gcloud_cli
 def SetTrack(self, track):
     self.track = track
     api_version = MlLanguageTestBase.TRACKS.get(track)
     self.messages = apis.GetMessagesModule('language', api_version)
     self.client = mock.Client(
         apis.GetClientClass(util.LANGUAGE_API, api_version))
     self.client.Mock()
     self.addCleanup(self.client.Unmock)
     # Shorten message names for convenience
     self.content_enum = self.messages.Document.TypeValueValuesEnum
     self.entity_encoding_enum = (
         self.messages.AnalyzeEntitiesRequest.EncodingTypeValueValuesEnum)
     self.sentiment_encoding_enum = (
         self.messages.AnalyzeSentimentRequest.EncodingTypeValueValuesEnum)
     self.syntax_encoding_enum = (
         self.messages.AnalyzeSyntaxRequest.EncodingTypeValueValuesEnum)
     self.entity_sentiment_encoding_enum = (
         self.messages.AnalyzeEntitySentimentRequest.
         EncodingTypeValueValuesEnum)
コード例 #11
0
 def SetUp(self):
   properties.VALUES.core.project.Set(PROJECT)
   self.log_name_filter = (
       'logName=('
       '"projects/{project}/logs/appengine.googleapis.com%2Fcrash.log" OR '
       '"projects/{project}/logs/appengine.googleapis.com%2Fnginx.request" '
       'OR '
       '"projects/{project}/logs/appengine.googleapis.com%2Frequest_log" OR '
       '"projects/{project}/logs/appengine.googleapis.com%2Fstderr" OR '
       '"projects/{project}/logs/stderr" OR '
       '"projects/{project}/logs/appengine.googleapis.com%2Fstdout" OR '
       '"projects/{project}/logs/stdout")'
       .format(project=PROJECT))
   self.resource_filter = 'resource.type="gae_app"'
   self.default_filter = self.resource_filter + ' AND ' + self.log_name_filter
   self.messages = apis.GetMessagesModule('logging', 'v2')
   self.v2_client = mock.Client(apis.GetClientClass('logging', 'v2'))
   self.v2_client.Mock()
   self.addCleanup(self.v2_client.Unmock)
コード例 #12
0
 def SetUp(self):
     self.track = calliope_base.ReleaseTrack.ALPHA
     self.client = apitools_mock.Client(
         core_apis.GetClientClass('compute', 'alpha'))
     self.resources = resources.REGISTRY.Clone()
     self.resources.RegisterApiByName('compute', 'alpha')
     self.client.Mock()
     self.addCleanup(self.client.Unmock)
     make_requests_patcher = mock.patch(
         'googlecloudsdk.api_lib.compute.request_helper.MakeRequests',
         autospec=True)
     self.addCleanup(make_requests_patcher.stop)
     self.make_requests = make_requests_patcher.start()
     self.messages = self.client.MESSAGES_MODULE
     self.compute_uri = (
         'https://www.googleapis.com/compute/{0}'.format('alpha'))
     self.pdp_name = 'my-pdp'
     self.operation_status_enum = self.messages.Operation.StatusValueValuesEnum
     self.operation_name = 'operation-pizza-crust'
コード例 #13
0
    def SetUp(self):
        self.track = calliope_base.ReleaseTrack.ALPHA

        self.apitools_mock_client = mock.Client(
            client_class=apis.GetClientClass(cloudtasks_api.API_NAME,
                                             cloudtasks_api.ALPHA_API_VERSION))
        self.apitools_mock_client.Mock()
        self.addCleanup(self.apitools_mock_client.Unmock)

        api_adapter = cloudtasks_api.AlphaApiAdapter()
        self.queues_client = api_adapter.queues
        self.tasks_client = api_adapter.tasks
        self.locations_client = api_adapter.locations
        self.messages = api_adapter.messages

        self.queues_service = self.apitools_mock_client.projects_locations_queues
        self.tasks_service = (
            self.apitools_mock_client.projects_locations_queues_tasks)
        self.locations_service = self.apitools_mock_client.projects_locations
コード例 #14
0
    def SetUp(self):
        self.project = 'fake-project'
        properties.VALUES.core.project.Set(self.project)
        self.client = mock.Client(
            client_class=apis.GetClientClass('storage', 'v1'))
        self.client.Mock()
        self.addCleanup(self.client.Unmock)

        self.messages = apis.GetMessagesModule('storage', 'v1')

        self.buckets_response = self.messages.Buckets(items=[
            self.messages.Bucket(name='bucket1'),
            self.messages.Bucket(name='bucket2'),
        ])
        self.bucket1_resp = self.messages.Objects(items=[
            self.messages.Object(name='file'),
            self.messages.Object(name='file2'),
            self.messages.Object(name='dir1/sub1/a.txt'),
            self.messages.Object(name='dir1/sub1/aab.txt'),
            self.messages.Object(name='dir1/sub2/aaaa.txt'),
            self.messages.Object(name='dir1/sub2/c.txt'),
            self.messages.Object(name='dir2/sub1/aaaaaa.txt'),
            self.messages.Object(name='dir2/sub1/d.txt'),
            self.messages.Object(name='dir2/sub2/aaaaaaaa.txt'),
            self.messages.Object(name='dir2/sub2/e.txt'),
            self.messages.Object(name='dir3/deeper/sub1/a.txt'),
            self.messages.Object(name='dir3/deeper/sub2/b.txt'),
        ])

        self._Touch('some/file')
        self._Touch('some/file2')
        self._Touch('another/file')
        self._Touch('another/file2')
        self._Touch('dir1/sub1/a.txt')
        self._Touch('dir1/sub1/aab.txt')
        self._Touch('dir1/sub2/aaaa.txt')
        self._Touch('dir1/sub2/c.txt')
        self._Touch('dir2/sub1/aaaaaa.txt')
        self._Touch('dir2/sub1/d.txt')
        self._Touch('dir2/sub2/aaaaaaaa.txt')
        self._Touch('dir2/sub2/e.txt')
        self._Touch('dir3/deeper/sub1/a.txt')
        self._Touch('dir3/deeper/sub2/b.txt')
コード例 #15
0
    def SetUp(self):
        """Setup common test components."""
        api_name = self._GetApiName()
        self.base_uri = 'https://compute.googleapis.com/compute/{}/projects/{}'.format(
            api_name, self.Project())

        apitools_client = api_mock.Client(
            core_apis.GetClientClass('compute', api_name),
            real_client=core_apis.GetClientInstance('compute',
                                                    api_name,
                                                    no_http=True))
        apitools_client.Mock()
        self.addCleanup(apitools_client.Unmock)
        self.messages = apitools_client.MESSAGES_MODULE

        self.resources = resources.Registry()
        self.resources.RegisterApiByName('compute', api_name)
        self.service = apitools_client.vpnTunnels
        self.region_operations = apitools_client.regionOperations
コード例 #16
0
  def SetUp(self):
    self.track = self.release_track
    self.client = mock.Client(
        core_apis.GetClientClass('compute', self.api_version))
    self.client.Mock()
    self.addCleanup(self.client.Unmock)
    self.messages = self.client.MESSAGES_MODULE

    self.item1 = self.messages.InternalIpOwner(
        ipCidrRange='10.128.0.0/32',
        systemOwned=True,
        owners=['projects/my-project/regions/us-central1/subnetworks/subnet-1'])
    self.item2 = self.messages.InternalIpOwner(
        ipCidrRange='10.128.0.2/32',
        systemOwned=False,
        owners=[
            'projects/my-project/zones/us-central1-b/instances/vm-1',
            'projects/my-project/zones/us-central1-b/addresses/address-1'
        ])
コード例 #17
0
    def SetUp(self):
        self.track = calliope_base.ReleaseTrack.GA
        self.api_version = 'v1'
        self.client = mock.Client(
            core_apis.GetClientClass('compute', self.api_version))
        self.client.Mock()
        self.addCleanup(self.client.Unmock)
        self.messages = self.client.MESSAGES_MODULE

        self.v1_messages = core_apis.GetMessagesModule('compute',
                                                       self.api_version)
        self.resources = resources.REGISTRY.Clone()
        self.resources.RegisterApiByName('compute', self.api_version)
        self.interconnect1_ref = self.resources.Create(
            'compute.interconnects',
            interconnect='my-interconnect1',
            project=self.Project())
        self.interconnect2_ref = self.resources.Create(
            'compute.interconnects',
            interconnect='my-interconnect2',
            project=self.Project())
コード例 #18
0
ファイル: api_util_test.py プロジェクト: bopopescu/gcloud_cli
    def SetUp(self):
        self.mock_old_kubernetes_client = self.StartPatch(
            'googlecloudsdk.command_lib.container.hub.kube_util.OldKubernetesClient'
        )()

        self.mock_kubernetes_client = self.StartPatch(
            'googlecloudsdk.command_lib.container.hub.kube_util.KubernetesClient'
        )()

        compute_api = 'compute'
        compute_api_version = core_apis.ResolveVersion(compute_api)
        self.compute_messages = core_apis.GetMessagesModule(
            compute_api, compute_api_version)
        self.mock_compute_client = apimock.Client(
            client_class=core_apis.GetClientClass(compute_api,
                                                  compute_api_version))
        self.mock_compute_client.Mock()
        self.addCleanup(self.mock_compute_client.Unmock)
        self.StartPatch(
            'googlecloudsdk.command_lib.container.hub.api_util._ComputeClient'
        ).return_value = self.mock_compute_client
コード例 #19
0
  def SetUp(self):
    self.mock_gcs_client = apitools_mock.Client(
        core_apis.GetClientClass('storage', 'v1'),
        real_client=core_apis.GetClientInstance('storage', 'v1', no_http=True))
    self.mock_gcs_client.Mock()
    self.addCleanup(self.mock_gcs_client.Unmock)
    self.mock_exec = self.StartPatch(
        'googlecloudsdk.core.execution_utils.Exec')
    self.mock_config_bin_path = self.StartPropertyPatch(
        config.Paths, 'sdk_bin_path')
    self.mock_config_bin_path.return_value = 'bin'

    self.storage_client = storage_helpers.StorageClient()
    self.storage_stream = storage_helpers.StorageObjectSeriesStream(
        self.BASE_GCS_PATH, self.storage_client)
    self.storage_messages = core_apis.GetMessagesModule('storage', 'v1')

    self.storage_api_client = storage_api.StorageClient()
    self.copy_file_mock = self.StartObjectPatch(self.storage_api_client,
                                                'CopyFileToGCS')
    self.storage_bucket = 'foo'
コード例 #20
0
    def SetUp(self):
        """Creates mock client and adds Unmock on cleanup."""
        self.client = mock.Client(
            client_class=apis.GetClientClass('cloudiot', 'v1'))
        self.client.Mock()
        self.addCleanup(self.client.Unmock)
        self.messages = apis.GetMessagesModule('cloudiot', 'v1')
        self.devices_client = devices_api.DevicesClient(
            self.client, self.messages)

        self.resources = resources.REGISTRY.Clone()
        self.resources.RegisterApiByName('cloudiot', 'v1')

        self.certificate_key = self.Touch(self.temp_path,
                                          'certificate.pub',
                                          contents=self.CERTIFICATE_CONTENTS)
        self.public_key = self.Touch(self.temp_path,
                                     'public.pub',
                                     contents=self.PUBLIC_KEY_CONTENTS)
        self.key_format_enum = (
            self.messages.PublicKeyCredential.FormatValueValuesEnum)
コード例 #21
0
    def SetUp(self):
        self.track = calliope_base.ReleaseTrack.ALPHA
        self.api_version = 'alpha'
        self.client = mock.Client(
            core_apis.GetClientClass('compute', self.api_version))
        self.client.Mock()
        self.addCleanup(self.client.Unmock)
        self.messages = self.client.MESSAGES_MODULE

        self.apis_messages = core_apis.GetMessagesModule(
            'compute', self.api_version)
        self.resources = resources.REGISTRY.Clone()
        self.resources.RegisterApiByName('compute', self.api_version)

        self.location_ref1 = self.resources.Create(
            'compute.interconnectLocations',
            interconnectLocation='eap-lga07',
            project=self.Project())
        self.location_ref2 = self.resources.Create(
            'compute.interconnectLocations',
            interconnectLocation='eap-test',
            project=self.Project())
コード例 #22
0
    def _SetUp(self, release_track):
        """Setup common test components.

    Args:
      release_track: Release track the test is targetting.
    """
        api_name = self._GetApiName(release_track)
        self.track = release_track

        apitools_client = api_mock.Client(
            core_apis.GetClientClass('compute', api_name),
            real_client=core_apis.GetClientInstance('compute',
                                                    api_name,
                                                    no_http=True))
        apitools_client.Mock()
        self.addCleanup(apitools_client.Unmock)
        self.messages = apitools_client.MESSAGES_MODULE

        self.resources = resources.Registry()
        self.resources.RegisterApiByName('compute', api_name)
        self.service = apitools_client.sslPolicies
        self.global_operations = apitools_client.globalOperations
コード例 #23
0
 def SetUp(self):
   self.logging_msgs = core_apis.GetMessagesModule('logging', 'v2')
   self.mock_logging_client = mock.Client(
       core_apis.GetClientClass('logging', 'v2'))
   self.mock_logging_client.Mock()
   self.addCleanup(self.mock_logging_client.Unmock)
   self.log_entries = [
       self._createLogEntry('ERROR', 'f-1', 'e-1',
                            '2015-10-01T12:34:56.789012345Z', 'one'),
       self._createLogEntry('INFO', 'f-2', 'e-2',
                            '2015-10-02T12:34:56.789012345Z', 'two'),
       self._createLogEntry('DEBUG', 'f-3', 'e-3',
                            '2015-10-03T12:34:56.789012345Z', 'three'),
   ]
   self.output_log_lines = [
       self._createOutputLogLine('E', 'f-1', 'e-1', '2015-10-01 12:34:56.789',
                                 'one'),
       self._createOutputLogLine('I', 'f-2', 'e-2', '2015-10-02 12:34:56.789',
                                 'two'),
       self._createOutputLogLine('D', 'f-3', 'e-3', '2015-10-03 12:34:56.789',
                                 'three'),
   ]
   properties.VALUES.core.user_output_enabled.Set(False)
コード例 #24
0
 def SetUp(self):
   self.client_class = apis.GetClientClass('bigquery', 'v2')
   self.client = mock.Client(self.client_class,
                             real_client=apis.GetClientInstance(
                                 'bigquery', 'v2', no_http=True))
   self.messages = self.client_class.MESSAGES_MODULE
   self._done = self.messages.JobStatus(state='DONE')
   self._pending = self.messages.JobStatus(state='RUNNING')
   self.error_entry = self.messages.ErrorProto
   self.client.Mock()
   self.addCleanup(self.client.Unmock)
   self.job_service = self.client.jobs
   self._result_data = {
       'QUERY': (self.client.jobs,
                 {'jobId': 'myjob', 'projectId': 'fakeproject'}),
       'COPY': (self.client.tables,
                {'tableId': 'test_table', 'datasetId': 'my_dataset',
                 'projectId': 'fakeproject'}),
       'LOAD': (self.client.tables,
                {'tableId': 'test_table', 'datasetId': 'my_dataset',
                 'projectId': 'fakeproject'}),
       'OTHER': (self.client.jobs,
                 {'jobId': 'myjob', 'projectId': 'fakeproject'})}
コード例 #25
0
    def SetUp(self):

        self.mock_client = apitools_mock.Client(
            client_class=apis.GetClientClass('compute', 'alpha'))
        self.mock_client.Mock()
        self.addCleanup(self.mock_client.Unmock)

        time_patcher = self.StartPatch(
            'googlecloudsdk.command_lib.util.time_util.CurrentTimeSec',
            autospec=True)
        time_patcher.side_effect = iter(range(0, 1000, 5))

        self.sleep_patcher = self.StartPatch(
            'googlecloudsdk.command_lib.util.time_util.Sleep', autospec=True)

        self.messages = apis.GetMessagesModule('compute', 'alpha')
        self.compute = apis.GetClientInstance('compute', 'alpha', no_http=True)

        self.StartObjectPatch(waiters.OperationData,
                              '_SupportOperationWait',
                              return_value=False)
        self.pending_operation_data = _CreateOperationData(
            self.compute, self.messages, 'PENDING')
コード例 #26
0
    def SetUp(self):
        # Mock ServerlessApiClient
        self.client_class = core_apis.GetClientClass(_API_NAME,
                                                     self.API_VERSION)
        self.real_client = core_apis.GetClientInstance(_API_NAME,
                                                       self.API_VERSION,
                                                       no_http=True)
        self.mock_serverless_client = apitools_mock.Client(
            self.client_class, self.real_client)
        self.mock_serverless_client.Mock()
        self.addCleanup(self.mock_serverless_client.Unmock)

        # apitools_mock has trouble mocking the same API client twice, so
        # mock_serverless_client must be used for both `client` and `op_client`.
        # This doesn't cause a problem because the only difference between the two
        # is the api_endpoint_overrides parameter at time of initialization, which
        # is immaterial to unit tests.
        self.serverless_client = (serverless_operations.ServerlessOperations(
            client=self.mock_serverless_client,
            api_name='run',
            api_version=self.API_VERSION,
            region='us-central1',
            op_client=self.mock_serverless_client))

        # Convenience attributes for IAM policy testing.
        self.etag = b'my-etag'
        self.b64etag = base64.b64encode(self.etag).decode('utf-8')
        self.service_format = ('projects/fake-project/locations/'
                               '{region}/services/{service}')
        self.service = self.service_format.format(service='my-service',
                                                  region=DEFAULT_REGION)
        self.my_binding = self.serverless_messages.Binding(
            members=['user:[email protected]'], role='roles/my-role')
        self.next_binding = self.serverless_messages.Binding(
            members=['user:[email protected]'], role='roles/next')
        self.other_binding = self.serverless_messages.Binding(
            members=['user:[email protected]'], role='roles/other-role')
コード例 #27
0
    def SetUp(self):
        self.api_version = 'v1'
        self.client_class = core_apis.GetClientClass('compute',
                                                     self.api_version)
        self.messages = self.client_class.MESSAGES_MODULE
        status_enum = self.messages.Operation.StatusValueValuesEnum
        self.status_done = status_enum.DONE
        self.status_pending = status_enum.PENDING
        self.error_entry = self.messages.Operation.ErrorValue.ErrorsValueListEntry

        self.operation_x_ref = resources.REGISTRY.Create(
            _GLOBAL_OPERATIONS_COLLECTION,
            project='mickey',
            operation='operationX')

        self.operation_y_ref = resources.REGISTRY.Create(
            _GLOBAL_OPERATIONS_COLLECTION,
            project='mickey',
            operation='operationY')

        self.instance_x_ref = resources.REGISTRY.Create(
            'compute.instances',
            project='mickey',
            zone='disney',
            instance='Super-Cheese-X')

        self.instance_y_ref = resources.REGISTRY.Create(
            'compute.instances',
            project='mickey',
            zone='disney',
            instance='Super-Cheese-Y')

        self.adapter = client_adapter.ClientAdapter(self.api_version,
                                                    no_http=True)
        self.batch_fake = waiter_test_base.OperationBatchFake(
            self.adapter.apitools_client.instances, 'compute.instances',
            self.adapter.apitools_client.globalOperations)
コード例 #28
0
    def SetUp(self):
        self.track = calliope_base.ReleaseTrack.BETA
        properties.VALUES.core.user_output_enabled.Set(False)
        properties.VALUES.core.color_theme.Set('off')

        self.client = mock.Client(
            client_class=apis.GetClientClass('pubsub', 'v1'))
        self.client.Mock()
        self.addCleanup(self.client.Unmock)

        # List of test message IDs
        self.message_ids = ['123456', '654321', '987654']

        # List of message data
        self.message_data = ['Hello, World!', 'World on Fire!', b'Hello \xAA']

        attributes = self.msgs.PubsubMessage.AttributesValue(
            additionalProperties=[])

        # List of actual Cloud Pub/Sub message objects
        self.messages = [
            self.msgs.PubsubMessage(data=self.message_data[0].encode('utf-8'),
                                    attributes=attributes),
            self.msgs.PubsubMessage(data=self.message_data[1].encode('utf-8'),
                                    attributes=attributes),
            self.msgs.PubsubMessage(data=self.message_data[2],
                                    attributes=attributes)
        ]

        # Policy object used for IAM tests.
        self.policy = self.msgs.Policy(
            version=1,
            bindings=[
                self.msgs.Binding(role='roles/owner',
                                  members=['user:[email protected]']),
                self.msgs.Binding(role='roles/viewer', members=['allUsers'])
            ])
コード例 #29
0
    def SetUpForAPI(self, api_version):
        self.include_unrestricted_services = {
            'v1alpha': False,
            'v1beta': True,
            'v1': False
        }[api_version]

        self.support_service_filters = {
            'v1alpha': True,
            'v1beta': True,
            'v1': True
        }[api_version]

        self.support_directional_policies = {
            'v1alpha': True,
            'v1beta': False,
            'v1': False
        }[api_version]

        self.client = mock.Client(
            client_class=apis.GetClientClass(self._API_NAME, api_version))
        self.client.Mock()
        self.addCleanup(self.client.Unmock)
        self.messages = apis.GetMessagesModule(self._API_NAME, api_version)
コード例 #30
0
    def SetUp(self):
        self.api_version = gkehub_api_util.GetApiVersionForTrack(self.track)
        self.messages = core_apis.GetMessagesModule(self.MODULE_NAME,
                                                    self.api_version)
        self.mocked_client = apimock.Client(
            client_class=core_apis.GetClientClass(self.MODULE_NAME,
                                                  self.api_version))
        self.mocked_client.Mock()
        self.addCleanup(self.mocked_client.Unmock)

        self.wait_operation_ref = resources.REGISTRY.Parse(
            'operation-1414184316101-d4546dd2',
            collection='gkehub.projects.locations.operations',
            params={
                'locationsId': 'global',
                'projectsId': self.Project(),
            },
            api_version=self.api_version)
        self.wait_operation_relative_name = self.wait_operation_ref.RelativeName(
        )

        self.parent = 'projects/{0}/locations/global'.format(self.Project())
        self.membership = '{0}/memberships/{1}'.format(self.parent,
                                                       self.MEMBERSHIP_NAME)