How to use _convert_value method in autotest

Best Python code snippet using autotest_python

lookups.py

Source:lookups.py Github

copy

Full Screen

...39 return lookup_type, value40 def convert_value(self, value):41 if value is not None:42 if isinstance(value, (tuple, list)):43 value = [self._convert_value(val) for val in value if val is not None]44 else:45 value = self._convert_value(value)46 return value47 def _convert_value(self, value):48 return value49 def matches_filter(self, model, field_name, lookup_type, value):50 return self.model == model and lookup_type in self.lookup_types \51 and field_name == self.field_name52 @classmethod53 def matches_lookup_def(cls, lookup_def):54 if lookup_def in cls.lookup_types:55 return True56 return False57 def get_field_to_add(self, field_to_index):58 field_to_add = deepcopy(self.field_to_add)59 if isinstance(field_to_index, ListField):60 field_to_add = ListField(field_to_add, editable=False, null=True)61 return field_to_add62class DateLookup(ExtraFieldLookup):63 # DateLookup is abstract so set lookup_types to None so it doesn't match64 lookup_types = None65 def __init__(self, *args, **kwargs):66 defaults = {'new_lookup': 'exact',67 'field_to_add': models.IntegerField(editable=False, null=True)}68 defaults.update(kwargs)69 ExtraFieldLookup.__init__(self, *args, **defaults)70 def _convert_lookup(self, value, lookup_type):71 return self.new_lookup, value72class Day(DateLookup):73 lookup_types = 'day'74 def _convert_value(self, value):75 return value.day76class Month(DateLookup):77 lookup_types = 'month'78 def _convert_value(self, value):79 return value.month80class Year(DateLookup):81 lookup_types = 'year'82 def _convert_value(self, value):83 return value.year84class Weekday(DateLookup):85 lookup_types = 'week_day'86 def _convert_value(self, value):87 return value.isoweekday()88class Contains(ExtraFieldLookup):89 lookup_types = 'contains'90 def __init__(self, *args, **kwargs):91 defaults = {'new_lookup': 'startswith',92 'field_to_add': ListField(models.CharField(500),93 editable=False, null=True)94 }95 defaults.update(kwargs)96 ExtraFieldLookup.__init__(self, *args, **defaults)97 def get_field_to_add(self, field_to_index):98 # always return a ListField of CharFields even in the case of99 # field_to_index being a ListField itself!100 return deepcopy(self.field_to_add)101 def convert_value(self, value):102 new_value = []103 if isinstance(value, (tuple, list)):104 for val in value:105 new_value.extend(self.contains_indexer(val))106 else:107 new_value = self.contains_indexer(value)108 return new_value109 def _convert_lookup(self, value, lookup_type):110 return self.new_lookup, value111 def contains_indexer(self, value):112 # In indexing mode we add all postfixes ('o', 'lo', ..., 'hello')113 result = []114 if value:115 result.extend([value[count:] for count in range(len(value))])116 return result117class Icontains(Contains):118 lookup_types = 'icontains'119 def convert_value(self, value):120 return [val.lower() for val in Contains.convert_value(self, value)]121 def _convert_lookup(self, value, lookup_type):122 return self.new_lookup, value.lower()123class Iexact(ExtraFieldLookup):124 lookup_types = 'iexact'125 def _convert_lookup(self, value, lookup_type):126 return self.new_lookup, value.lower()127 def _convert_value(self, value):128 return value.lower()129class Istartswith(ExtraFieldLookup):130 lookup_types = 'istartswith'131 def __init__(self, *args, **kwargs):132 defaults = {'new_lookup': 'startswith'}133 defaults.update(kwargs)134 ExtraFieldLookup.__init__(self, *args, **defaults)135 def _convert_lookup(self, value, lookup_type):136 return self.new_lookup, value.lower()137 def _convert_value(self, value):138 return value.lower()139class Endswith(ExtraFieldLookup):140 lookup_types = 'endswith'141 def __init__(self, *args, **kwargs):142 defaults = {'new_lookup': 'startswith'}143 defaults.update(kwargs)144 ExtraFieldLookup.__init__(self, *args, **defaults)145 def _convert_lookup(self, value, lookup_type):146 return self.new_lookup, value[::-1]147 def _convert_value(self, value):148 return value[::-1]149class Iendswith(Endswith):150 lookup_types = 'iendswith'151 def _convert_lookup(self, value, lookup_type):152 return self.new_lookup, value[::-1].lower()153 def _convert_value(self, value):154 return value[::-1].lower()155class RegexLookup(ExtraFieldLookup):156 lookup_types = ('regex', 'iregex')157 def __init__(self, *args, **kwargs):158 defaults = {'field_to_add': models.NullBooleanField(editable=False,159 null=True)160 }161 defaults.update(kwargs)162 ExtraFieldLookup.__init__(self, *args, **defaults)163 def contribute(self, model, field_name, lookup_def):164 ExtraFieldLookup.contribute(self, model, field_name, lookup_def)165 if isinstance(lookup_def, regex):166 self.lookup_def = re.compile(lookup_def.pattern, re.S | re.U |167 (lookup_def.flags & re.I))168 @property169 def index_name(self):170 return 'idxf_%s_l_%s' % (self.field_name,171 self.lookup_def.pattern.encode('hex'))172 def is_icase(self):173 return self.lookup_def.flags & re.I174 def _convert_lookup(self, value, lookup_type):175 return self.new_lookup, True176 def _convert_value(self, value):177 if self.lookup_def.match(value):178 return True179 return False180 def matches_filter(self, model, field_name, lookup_type, value):181 return self.model == model and lookup_type == \182 '%sregex' % ('i' if self.is_icase() else '') and \183 value == self.lookup_def.pattern and field_name == self.field_name184 @classmethod185 def matches_lookup_def(cls, lookup_def):186 if isinstance(lookup_def, regex):187 return True188 return False189class StandardLookup(ExtraFieldLookup):190 ''' Creates a copy of the field_to_index in order to allow querying for...

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