How to use _read_protection method in autotest

Best Python code snippet using autotest_python

resources.py

Source:resources.py Github

copy

Full Screen

...169 doc='Username of user with access to this host')170 query_processor.add_related_existence_selector(171 'has_label', models.Label, 'name')172 @classmethod173 def _read_protection(cls, protection_input):174 return host_protections.Protection.get_value(protection_input)175 @classmethod176 def from_uri_args(cls, request, hostname, **kwargs):177 return cls(request, models.Host.objects.get(hostname=hostname))178 def _uri_args(self):179 return {'hostname': self.instance.hostname}180 def short_representation(self):181 rep = super(Host, self).short_representation()182 # TODO calling platform() over and over is inefficient183 platform_rep = (Label.from_optional_instance(self._request,184 self.instance.platform())185 .short_representation())186 rep.update({'hostname': self.instance.hostname,187 'locked': bool(self.instance.locked),188 'status': self.instance.status,189 'platform': platform_rep})190 return rep191 def full_representation(self):192 rep = super(Host, self).full_representation()193 protection = host_protections.Protection.get_string(194 self.instance.protection)195 locked_by = (User.from_optional_instance(self._request,196 self.instance.locked_by)197 .short_representation())198 labels = HostLabelingCollection(fixed_entry=self)199 acls = HostAclMembershipCollection(fixed_entry=self)200 queue_entries = QueueEntryCollection(self._request)201 queue_entries.set_query_parameters(host=self.instance.hostname)202 health_tasks = HealthTaskCollection(self._request)203 health_tasks.set_query_parameters(host=self.instance.hostname)204 rep.update({'locked_by': locked_by,205 'locked_on': self._format_datetime(self.instance.lock_time),206 'invalid': self.instance.invalid,207 'protection_level': protection,208 # TODO make these efficient209 'labels': labels.full_representation(),210 'acls': acls.full_representation(),211 'queue_entries': queue_entries.link(),212 'health_tasks': health_tasks.link()})213 return rep214 @classmethod215 def create_instance(cls, input_dict, containing_collection):216 cls._check_for_required_fields(input_dict, ('hostname',))217 # include locked here, rather than waiting for update(), to avoid race218 # conditions219 host = models.Host.add_object(hostname=input_dict['hostname'],220 locked=input_dict.get('locked', False))221 return host222 def update(self, input_dict):223 data = {'locked': input_dict.get('locked'),224 'protection': input_dict.get('protection_level')}225 data = input_dict.remove_unspecified_fields(data)226 if 'protection' in data:227 data['protection'] = self._read_protection(data['protection'])228 self.instance.update_object(**data)229 if 'platform' in input_dict:230 label = self.resolve_link(input_dict['platform']) .instance231 if not label.platform:232 raise exceptions.BadRequest('Label %s is not a platform' % label.name)233 for label in self.instance.labels.filter(platform=True):234 self.instance.labels.remove(label)235 self.instance.labels.add(label)236class HostCollection(resource_lib.Collection):237 queryset = models.Host.valid_objects.all()238 entry_class = Host239class HostLabeling(resource_lib.Relationship):240 related_classes = {'host': Host, 'label': Label}241class HostLabelingCollection(resource_lib.RelationshipCollection):...

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 autotest 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