How to use patch_request method in Splinter

Best Python code snippet using splinter

instances_update_util.py

Source:instances_update_util.py Github

copy

Full Screen

1# -*- coding: utf-8 -*- #2# Copyright 2018 Google Inc. All Rights Reserved.3#4# Licensed under the Apache License, Version 2.0 (the "License");5# you may not use this file except in compliance with the License.6# You may obtain a copy of the License at7#8# http://www.apache.org/licenses/LICENSE-2.09#10# Unless required by applicable law or agreed to in writing, software11# distributed under the License is distributed on an "AS IS" BASIS,12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13# See the License for the specific language governing permissions and14# limitations under the License.15"""Utility for updating Memorystore Redis instances."""16from __future__ import absolute_import17from __future__ import unicode_literals18from apitools.base.py import encoding19from googlecloudsdk.command_lib.redis import util20from googlecloudsdk.command_lib.util.args import labels_util21from googlecloudsdk.core import exceptions22from six.moves import filter # pylint: disable=redefined-builtin23class NoFieldsSpecified(exceptions.Error):24 """Error for calling update command with no args that represent fields."""25def CheckFieldsSpecified(unused_instance_ref, args, patch_request):26 update_args = ['clear_labels', 'display_name', 'remove_labels',27 'remove_redis_config', 'size', 'update_labels',28 'update_redis_config',]29 if list(filter(args.IsSpecified, update_args)):30 return patch_request31 raise NoFieldsSpecified(32 'Must specify at least one valid instance parameter to update')33def GetExistingInstance(instance_ref, unused_args, patch_request):34 """Fetch existing redis instance to update and add it to Patch request."""35 client = util.GetClientForResource(instance_ref)36 messages = util.GetMessagesForResource(instance_ref)37 get_request = messages.RedisProjectsLocationsInstancesGetRequest(38 name=instance_ref.RelativeName())39 patch_request.instance = client.projects_locations_instances.Get(get_request)40 return patch_request41def AddFieldToUpdateMask(field, patch_request):42 update_mask = patch_request.updateMask43 if update_mask:44 if update_mask.count(field) == 0:45 patch_request.updateMask = update_mask + ',' + field46 else:47 patch_request.updateMask = field48 return patch_request49def AddDisplayName(unused_instance_ref, args, patch_request):50 if args.IsSpecified('display_name'):51 patch_request.instance.displayName = args.display_name52 patch_request = AddFieldToUpdateMask('display_name', patch_request)53 return patch_request54def AddSize(unused_instance_ref, args, patch_request):55 if args.IsSpecified('size'):56 patch_request.instance.memorySizeGb = args.size57 patch_request = AddFieldToUpdateMask('memory_size_gb', patch_request)58 return patch_request59def RemoveRedisConfigs(instance_ref, args, patch_request):60 if not getattr(patch_request.instance, 'redisConfigs', None):61 return patch_request62 if args.IsSpecified('remove_redis_config'):63 config_dict = encoding.MessageToDict(patch_request.instance.redisConfigs)64 for removed_key in args.remove_redis_config:65 config_dict.pop(removed_key, None)66 patch_request = AddNewRedisConfigs(instance_ref, config_dict, patch_request)67 return patch_request68def UpdateRedisConfigs(instance_ref, args, patch_request):69 if args.IsSpecified('update_redis_config'):70 config_dict = {}71 if getattr(patch_request.instance, 'redisConfigs', None):72 config_dict = encoding.MessageToDict(patch_request.instance.redisConfigs)73 config_dict.update(args.update_redis_config)74 patch_request = AddNewRedisConfigs(instance_ref, config_dict, patch_request)75 return patch_request76def AddNewRedisConfigs(instance_ref, redis_configs_dict, patch_request):77 messages = util.GetMessagesForResource(instance_ref)78 new_redis_configs = util.PackageInstanceRedisConfig(redis_configs_dict,79 messages)80 patch_request.instance.redisConfigs = new_redis_configs81 patch_request = AddFieldToUpdateMask('redis_configs', patch_request)82 return patch_request83def UpdateLabels(instance_ref, args, patch_request):84 labels_diff = labels_util.Diff.FromUpdateArgs(args)85 if labels_diff.MayHaveUpdates():86 patch_request = AddFieldToUpdateMask('labels', patch_request)87 messages = util.GetMessagesForResource(instance_ref)88 new_labels = labels_diff.Apply(messages.Instance.LabelsValue,89 patch_request.instance.labels).GetOrNone()90 if new_labels:91 patch_request.instance.labels = new_labels...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Splinter automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful