How to use _get_field_names method in autotest

Best Python code snippet using autotest_python

serializers.py

Source:serializers.py Github

copy

Full Screen

...18 data['login'], data['password'])19class DefaultUserProfileSerializer(serializers.ModelSerializer):20 def __init__(self, *args, **kwargs):21 user_class = get_user_model()22 field_names = _get_field_names(allow_primary_key=True)23 read_only_field_names = _get_field_names(24 allow_primary_key=True,25 non_editable=True)26 self.Meta = MetaObj()27 self.Meta.model = user_class28 self.Meta.fields = field_names29 self.Meta.read_only_fields = read_only_field_names30 super().__init__(*args, **kwargs)31class DefaultRegisterUserSerializer(serializers.ModelSerializer):32 def __init__(self, *args, **kwargs):33 user_class = get_user_model()34 field_names = _get_field_names(allow_primary_key=True)35 field_names = field_names + ('password',)36 read_only_field_names = _get_field_names(37 allow_primary_key=True,38 non_editable=True)39 self.Meta = MetaObj()40 self.Meta.model = user_class41 self.Meta.fields = field_names42 self.Meta.read_only_fields = read_only_field_names43 super().__init__(*args, **kwargs)44 @property45 def has_password_confirm(self):46 return registration_settings.REGISTER_SERIALIZER_PASSWORD_CONFIRM47 def validate_password(self, password):48 user = _build_initial_user(self.initial_data)49 validate_password(password, user=user)50 return password51 def get_fields(self):52 fields = super().get_fields()53 if self.has_password_confirm:54 fields['password_confirm'] = serializers.CharField(write_only=True)55 return fields56 def validate(self, data):57 if self.has_password_confirm:58 if data['password'] != data['password_confirm']:59 raise ValidationError('Passwords don\'t match')60 return data61 def create(self, validated_data):62 data = validated_data.copy()63 if self.has_password_confirm:64 del data['password_confirm']65 return self.Meta.model.objects.create_user(**data)66def _build_initial_user(data):67 user_field_names = _get_field_names(allow_primary_key=False)68 user_data = {}69 for field_name in user_field_names:70 if field_name in data:71 user_data[field_name] = data[field_name]72 user_class = get_user_model()73 return user_class(**user_data)74def _get_field_names(allow_primary_key=True, non_editable=False):75 def not_in_seq(names):76 return lambda name: name not in names77 user_class = get_user_model()78 fields = user_class._meta.get_fields()79 default_field_names = [f.name for f in fields80 if (getattr(f, 'serialize', False) or81 getattr(f, 'primary_key', False))]82 pk_field_names = [f.name for f in fields83 if getattr(f, 'primary_key', False)]84 hidden_field_names = set(get_user_setting('HIDDEN_FIELDS'))85 hidden_field_names = hidden_field_names.union(['last_login', 'password'])86 public_field_names = get_user_setting('PUBLIC_FIELDS')87 editable_field_names = get_user_setting('EDITABLE_FIELDS')88 field_names = (public_field_names if public_field_names is not None...

Full Screen

Full Screen

parser.py

Source:parser.py Github

copy

Full Screen

...7import vcf8class SnpEffParser(object):9 def __init__(self, file_name):10 self._reader = vcf.Reader(filename=file_name)11 self.fields = self._get_field_names()12 self._buffer = []13 def __iter__(self):14 while True:15 try:16 yield self.next()17 except StopIteration:18 break19 def next(self):20 while len(self._buffer) == 0:21 record = next(self._reader)22 if 'ANN' not in record.INFO:23 continue24 for row in self._parse_record(record):25 self._buffer.append(row)26 return self._buffer.pop(0)27 def _get_field_names(self):28 fields = []29 match = re.search(":(.*)", self._reader.infos['ANN'].desc).groups()[0].replace("'", "")30 for x in match.split('|'):31 fields.append(x.strip().lower())32 return fields33 def _parse_record(self, record):34 for annotation in record.INFO['ANN']:35 out_row = OrderedDict((36 ('chrom', record.CHROM),37 ('coord', record.POS),38 ('ref', record.REF),39 ('alt', ','.join([str(x) for x in record.ALT])),40 ))41 fields = annotation.split('|')42 for i, key in enumerate(self.fields):43 out_row[key] = fields[i]44 yield out_row45class ClassicSnpEffParser(object):46 def __init__(self, file_name):47 self._reader = vcf.Reader(filename=file_name)48 self.fields = self._get_field_names()49 self._buffer = []50 self._effect_matcher = re.compile(r'(.*)\(')51 self._fields_matcher = re.compile(r'\((.*)\)')52 def __iter__(self):53 while True:54 try:55 yield self.next()56 except StopIteration:57 break58 def next(self):59 while len(self._buffer) == 0:60 record = next(self._reader)61 if 'EFF' not in record.INFO:62 continue63 for row in self._parse_record(record):64 self._buffer.append(row)65 return self._buffer.pop(0)66 def _get_field_names(self):67 fields = []68 match = re.search(r'\((.*)\[', self._reader.infos['EFF'].desc)69 for x in match.groups()[0].split('|'):70 fields.append(x.strip().lower())71 return fields72 def _parse_record(self, record):73 for annotation in record.INFO['EFF']:74 effect = self._effect_matcher.search(annotation).groups()[0]75 out_row = OrderedDict((76 ('chrom', record.CHROM),77 ('coord', record.POS),78 ('ref', record.REF),79 ('alt', ','.join([str(x) for x in record.ALT])),80 ('effect', effect),...

Full Screen

Full Screen

entities.py

Source:entities.py Github

copy

Full Screen

1import dataclasses2from typing import Iterable, List3def _get_field_names(obj_or_clazz: dataclasses.dataclass) -> List[str]:4 fields = dataclasses.fields(obj_or_clazz)5 return list(6 map(lambda f: f.name, fields)7 )8@dataclasses.dataclass9class CsvContentProvider:10 @classmethod11 def csv_header(cls) -> str:12 fields = _get_field_names(cls)13 fields = map(str, fields)14 return CsvContentProvider._to_csv_row(fields)15 def to_csv_row(self) -> str:16 fields = _get_field_names(self)17 values = map(lambda field: str(self.__getattribute__(field)), fields)18 return CsvContentProvider._to_csv_row(values)19 @staticmethod20 def _to_csv_row(values: Iterable[str]) -> str:21 return ",".join(values)22@dataclasses.dataclass23class ParsedItem(CsvContentProvider):24 item_id: str25 car_name: str26 car_img: str27 plate_number: str...

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