How to use _get_related_manager method in autotest

Best Python code snippet using autotest_python

resource_lib.py

Source:resource_lib.py Github

copy

Full Screen

...400 for name, entry in self.entries.iteritems():401 rep[name] = entry.short_representation()402 return rep403 @classmethod404 def _get_related_manager(cls, instance):405 """Get the related objects manager for the given instance.406 The instance must be one of the related classes. This method will407 return the related manager from that instance to instances of the other408 related class.409 """410 this_model = type(instance)411 models = [entry_class.model for entry_class412 in cls.related_classes.values()]413 if isinstance(instance, models[0]):414 this_model, other_model = models415 else:416 other_model, this_model = models417 _, field = this_model.objects.determine_relationship(other_model)418 this_models_fields = (this_model._meta.fields419 + this_model._meta.many_to_many)420 if field in this_models_fields:421 manager_name = field.attname422 else:423 # related manager is on other_model, get name of reverse related424 # manager on this_model425 manager_name = field.related.get_accessor_name()426 return getattr(instance, manager_name)427 def _delete_entry(self):428 # choose order arbitrarily429 entry, other_entry = self.entries.itervalues()430 related_manager = self._get_related_manager(entry.instance)431 related_manager.remove(other_entry.instance)432 @classmethod433 def create_instance(cls, input_dict, containing_collection):434 other_name = containing_collection.unfixed_name435 cls._check_for_required_fields(input_dict, (other_name,))436 entry = containing_collection.fixed_entry437 other_entry = containing_collection.resolve_link(input_dict[other_name])438 related_manager = cls._get_related_manager(entry.instance)439 related_manager.add(other_entry.instance)440 return other_entry.instance441 def update(self, input_dict):442 pass443class RelationshipCollection(Collection):444 def __init__(self, request=None, fixed_entry=None):445 if request is None:446 request = fixed_entry._request447 super(RelationshipCollection, self).__init__(request)448 assert issubclass(self.entry_class, Relationship)449 self.related_classes = self.entry_class.related_classes450 self.fixed_name = None451 self.fixed_entry = None452 self.unfixed_name = None453 self.related_manager = None454 if fixed_entry is not None:455 self._set_fixed_entry(fixed_entry)456 entry_uri_arg = self.fixed_entry._uri_args().values()[0]457 self._query_params[self.fixed_name] = entry_uri_arg458 def _set_fixed_entry(self, entry):459 """Set the fixed entry for this collection.460 The entry must be an instance of one of the related entry classes. This461 method must be called before a relationship is used. It gets called462 either from the constructor (when collections are instantiated from463 other resource handling code) or from read_query_parameters() (when a464 request is made directly for the collection.465 """466 names = self.related_classes.keys()467 if isinstance(entry, self.related_classes[names[0]]):468 self.fixed_name, self.unfixed_name = names469 else:470 assert isinstance(entry, self.related_classes[names[1]])471 self.unfixed_name, self.fixed_name = names472 self.fixed_entry = entry473 self.unfixed_class = self.related_classes[self.unfixed_name]474 self.related_manager = self.entry_class._get_related_manager(475 entry.instance)476 def _query_parameters_accepted(self):477 return [(name, 'Show relationships for this %s' % entry_class.__name__)478 for name, entry_class479 in self.related_classes.iteritems()]480 def _resolve_query_param(self, name, uri_arg):481 entry_class = self.related_classes[name]482 return entry_class.from_uri_args(self._request, uri_arg)483 def read_query_parameters(self, query_params):484 super(RelationshipCollection, self).read_query_parameters(query_params)485 if not self._query_params:486 raise exceptions.BadRequest(487 'You must specify one of the parameters %s and %s'488 % tuple(self.related_classes.keys()))...

Full Screen

Full Screen

offer.py

Source:offer.py Github

copy

Full Screen

...8 related_object_name = "offer_id"9 display_attribute = "name"10 @property11 def conversions(self):12 return self._get_related_manager(ConversionManager)13 @property14 def files(self):15 return self._get_related_manager(OfferFileManager)16 def add_target_country(self, country_code):17 return self._manager.add_target_country(self.id, country_code)18 def get_target_countries(self):19 return self._manager.get_target_countries(self.id)20 def add_category(self, category_id):21 return self._manager.add_category(self.id, category_id)22 def block_affiliate(self, affiliate_id):23 return self._manager.block_affiliate(self.id, affiliate_id)24 def unblock_affiliate(self, affiliate_id):25 return self._manager.unblock_affiliate(self.id, affiliate_id)26 def get_categories(self):27 return self._manager.get_categories(self.id)28 def get_offer_files_with_creative_code(self, affiliate_id):29 return self._manager.get_offer_files_with_creative_code(self.id, affiliate_id)...

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