コード例 #1
0
 def _ExpectCreateAppRequest(self, region, err=None, retries=2):
   # If err is set, it will replace response
   app_msg = self.messages.Application(id=self.Project(), locationId=region)
   if err:
     self.mock_client.apps.Create.Expect(request=app_msg,
                                         response=None,
                                         exception=err)
     return
   op_name = api_test_util.AppOperationName(self.Project())
   intermediate_response = self.messages.Operation(name=op_name)
   final_response = self.messages.Operation(
       name=op_name,
       done=True,
       response=encoding.JsonToMessage(
           self.messages.Operation.ResponseValue,
           encoding.MessageToJson(app_msg)))
   retry.ExpectWithRetries(
       method=self.mock_client.apps.Create,
       polling_method=self.mock_client.apps_operations.Get,
       request=app_msg,
       polling_request=self.messages.AppengineAppsOperationsGetRequest(
           name=op_name),
       response=intermediate_response,
       final_response=final_response,
       num_retries=retries)
コード例 #2
0
 def _ExpectPatchVersionRequest(self, project, service, version,
                                serving_status, num_retries=0):
   """Helper function for stopping and starting versions."""
   version_message = self.messages.Version(
       servingStatus=serving_status
   )
   version_name = 'apps/{0}/services/{1}/versions/{2}'.format(project, service,
                                                              version)
   stop_version_call = self.messages.AppengineAppsServicesVersionsPatchRequest(
       name=version_name,
       updateMask='servingStatus',
       version=version_message)
   op_name = VersionOperationName(project, service, version)
   req = self.messages.AppengineAppsServicesVersionsPatchRequest(
       name=version_name)
   done_message = self.messages.Operation(
       name=op_name,
       done=True,
       response=encoding.JsonToMessage(
           self.messages.Operation.ResponseValue,
           encoding.MessageToJson(req)))
   not_done_message = self.messages.Operation(
       name=op_name, done=False)
   polling_request = self.messages.AppengineAppsOperationsGetRequest(
       name=op_name)
   retry.ExpectWithRetries(
       method=self.mock_client.apps_services_versions.Patch,
       polling_method=self.mock_client.apps_operations.Get,
       request=stop_version_call,
       polling_request=polling_request,
       response=not_done_message,
       final_response=done_message,
       num_retries=num_retries)
コード例 #3
0
ファイル: api_test_util.py プロジェクト: bopopescu/gcloud_cli
    def ExpectCreateVersion(self,
                            project,
                            service,
                            version_id,
                            num_attempts=1,
                            success=True,
                            deployment=None,
                            handlers=None,
                            beta_settings=None,
                            version_call_args=None,
                            operation_metadata=None):
        """Adds expected version create call and response to mock client.

    Args:
      project: str, the project ID
      service: str, the name of the service being updated.
      version_id: str, the ID of the version being created.
      num_attempts: int, the number of total attempts to be expected
      success: bool, whether operation should succeed
      deployment: appengine_v1_messages.Deployment, the expected
          deployment manifest message.
      handlers: [handler] the list of handlers expected in the create version
          call.
      beta_settings: appengine_v1_messages.Version.BetaSettingsValue,
          the beta settings in the app.yaml if any.
      version_call_args: kwargs to be added to the Version message, if any
          (e.g. {'vm': True}.
      operation_metadata: Metadata to be returned in the operation.
    """
        version_call_args = version_call_args or self.DEFAULT_SERVICE_CONFIG
        op_name = VersionOperationName(project, service)
        version_call = self.GetCreateVersionCall(project, service, version_id,
                                                 beta_settings, deployment,
                                                 handlers, **version_call_args)
        polling_call = self.messages.AppengineAppsOperationsGetRequest(
            name=VersionOperationName(project, service))
        version_not_created_response = self.messages.Operation(name=op_name,
                                                               done=False)
        if success:
            final_response = self.messages.Operation(
                name=op_name,
                done=True,
                metadata=operation_metadata,
                response=encoding.JsonToMessage(
                    self.messages.Operation.ResponseValue,
                    encoding.MessageToJson(version_call.version)))
        else:
            final_response = version_not_created_response
        retry.ExpectWithRetries(
            method=self.mock_client.apps_services_versions.Create,
            polling_method=self.mock_client.apps_operations.Get,
            request=version_call,
            polling_request=polling_call,
            response=version_not_created_response,
            final_response=final_response,
            num_retries=num_attempts - 1)
コード例 #4
0
 def ExpectRepairApplicationRequest(self, project, num_retries=0):
   op_name = AppOperationName(project)
   method = self.mock_client.apps.Repair
   request = self._GetRepairApplicationRequest(self.Project())
   response = self.messages.Operation(name=op_name, done=False)
   final_response = self.messages.Operation(name=op_name, done=True)
   polling_method = self.mock_client.apps_operations.Get
   polling_request = self.messages.AppengineAppsOperationsGetRequest(
       name=op_name)
   retry.ExpectWithRetries(
       method, request, response, polling_method=polling_method,
       polling_request=polling_request, final_response=final_response,
       num_retries=num_retries)
コード例 #5
0
ファイル: api_test_util.py プロジェクト: bopopescu/gcloud_cli
    def ExpectSetDefault(self,
                         project,
                         service,
                         version,
                         num_tries=1,
                         success=True):
        """Adds expected set-default call and response to mock client.

    Args:
      project: str, the project ID
      service: str, the name of the service being updated.
      version: str, the ID of the version being created.
      num_tries: int, number of times that setting default will be attempted.
      success: bool, whether operation is expected to succeed.
    """
        op_name = 'apps/{0}/services/{1}/versions/{2}'.format(
            project, service, version)
        traffic_split = encoding.PyValueToMessage(self.messages.TrafficSplit, {
            'allocations': {
                version: 1.0
            },
            'shardBy': 'UNSPECIFIED'
        })
        patch_call = self.messages.AppengineAppsServicesPatchRequest(
            name='apps/{0}/services/{1}'.format(project, service),
            updateMask='split',
            migrateTraffic=False,
            service=self.messages.Service(split=traffic_split))
        err = http_error.MakeDetailedHttpError(
            message='Service does not exist',
            details=http_error.ExampleErrorDetails())
        if success:
            final_response = self.messages.Operation(
                name=op_name,
                done=True,
                response=encoding.JsonToMessage(
                    self.messages.Operation.ResponseValue,
                    encoding.MessageToJson(patch_call)))
        else:
            final_response = err
        retry.ExpectWithRetries(method=self.mock_client.apps_services.Patch,
                                request=patch_call,
                                response=err,
                                final_response=final_response,
                                num_retries=num_tries - 1)
コード例 #6
0
ファイル: api_test_util.py プロジェクト: bopopescu/gcloud_cli
    def ExpectDeleteServiceRequest(self,
                                   project,
                                   service,
                                   exception=None,
                                   retries=0):
        """Adds expected delete services request and response to mock client.

    Args:
      project: str, the project ID.
      service: str, the service ID to delete.
      exception: None|apitools.base.py.exceptions.HttpError, the error to be
          returned, if any.
      retries: Number of retries required to succeed.
    """
        request = self.messages.AppengineAppsServicesDeleteRequest(
            name='apps/{0}/services/{1}'.format(project, service))
        op_name = ServiceOperationName(project, service)
        service = self.messages.Service(name='apps/{0}/services/{1}'.format(
            project, service),
                                        id=service)
        if not exception:
            polling_request = self.messages.AppengineAppsOperationsGetRequest(
                name=op_name)
            intermediate_response = self.messages.Operation(name=op_name,
                                                            done=False)
            response = self.messages.Operation(
                name=op_name,
                done=True,
                response=encoding.JsonToMessage(
                    self.messages.Operation.ResponseValue,
                    encoding.MessageToJson(service)))
            retry.ExpectWithRetries(
                method=self.mock_client.apps_services.Delete,
                polling_method=self.mock_client.apps_operations.Get,
                request=request,
                polling_request=polling_request,
                response=intermediate_response,
                final_response=response,
                num_retries=retries)
        else:
            self.mock_client.apps_services.Delete.Expect(request,
                                                         exception=exception)
コード例 #7
0
 def _ExpectCreateAppRequest(self):
     app_msg = self.app_engine_messages.Application(id=self.project_id,
                                                    locationId='us-central')
     op_name = app_api_test_util.AppOperationName(self.project_id)
     intermediate_response = self.app_engine_messages.Operation(
         name=op_name)
     final_response = self.app_engine_messages.Operation(
         name=op_name,
         done=True,
         response=encoding.JsonToMessage(
             self.app_engine_messages.Operation.ResponseValue,
             encoding.MessageToJson(app_msg)))
     op_get_request = self.app_engine_messages.AppengineAppsOperationsGetRequest
     retry.ExpectWithRetries(
         method=self.app_engine_client.apps.Create,
         polling_method=self.app_engine_client.apps_operations.Get,
         request=app_msg,
         polling_request=op_get_request(name=op_name),
         response=intermediate_response,
         final_response=final_response,
         num_retries=2)