How to use validated method in yandex-tank

Best Python code snippet using yandex-tank

serializers.py

Source:serializers.py Github

copy

Full Screen

1from rest_framework import serializers2from stattrak.models import League, Team, PlayerDataType, TeamDataType, PlayerData, TeamData, Result3from authentication.models import Account4from authentication.serializers import AccountSerializer5class LeagueSerializer(serializers.ModelSerializer):6 class Meta:7 model = League8 fields = ('teamSize', 'name', 'logo')9 def create(self, validated_data):10 league = League()11 league.teamSize = validated_data.get('teamSize', league.teamSize)12 league.name = validated_data.get('name', league.name)13 league.logo = validated_data.get('logo', league.logo)14 league.save()15 return league16 def update(self, instance, validated_data):17 instance.teamSize = validated_data.get('teamSize', instance.teamSize)18 instance.name = validated_data.get('name', instance.name)19 instance.logo = validated_data.get('logo', instance.logo)20 instance.save()21 return instance22 23class TeamSerializer(serializers.ModelSerializer):24 players = AccountSerializer(many=True, read_only=True)25 26 class Meta:27 model = Team28 fields = ('id', 'name', 'players')29 read_only_fields = ('id')30 def create(self, validated_data):31 team = Team()32 team.name = validated_data.get('name', team.name)33 teammates = validated_data.get('players', [])34 for teammate in teammates:35 team.players.add(Account.objects.get(username=teammate.username))36 team.save()37 return team38 def update(self, instance, validated_data):39 instance.name = validated_data.get('name', instance.name)40 instance.save()41 return instance42 43class PlayerDataTypeSerializer(serializers.ModelSerializer):44 class Meta:45 model = PlayerDataType46 fields = ('id', 'key')47 read_only_fields = ('id')48 def create(self, validated_data):49 playerDT = PlayerDataType()50 playerDT.key = serializer.validated_data.get('key', None)51 playerDT.save()52 return playerDT53 def update(self, instance, validated_data):54 instance.key = validated_data.get('key', instance.key)55 instance.save()56 return instance57class TeamDataTypeSerializer(serializers.ModelSerializer):58 class Meta:59 model = TeamDataType60 fields = ('id', 'key')61 read_only_fields = ('id')62 def create(self, validated_data):63 teamDT = TeamDataType()64 teamDT.key = serializer.validated_data.get('key', None)65 teamDT.save()66 return teamDT67 def update(self, instance, validated_data):68 instance.key = validated_data.get('key', instance.key)69 instance.save()70 return instance 71class PlayerDataSerializer(serializers.ModelSerializer):72 player = AccountSerializer(read_only=True)73 74 class Meta:75 model = PlayerData76 fields = ('id', 'player', 'result', 'key', 'value')77 read_only_fields = ('id')78 def create(self, validated_data):79 data = PlayerData()80 user = validated_data.get('player', {})81 result = validated_data.get('result', {})82 data.player = Account.objects.get(username=user.username)83 data.result = Result.objects.get(id=result.id)84 data.key = validatd_data.get('key', '')85 data.value = validated_data.get('value', 0)86 data.save()87 return data88class TeamDataSerializer(serializers.ModelSerializer):89 team = TeamSerializer(read_only=True)90 91 class Meta:92 model = TeamData93 fields = ('id', 'team', 'result', 'key', 'value')94 read_only_fields = ('id')95 def create(self, validated_data):96 data = TeamData()97 team = validated_data.get('team', {})98 result = validated_data.get('result', {})99 data.team = Team.objects.get(name=team.name)100 data.result = Result.objects.get(id=result.id)101 data.key = validatd_data.get('key', '')102 data.value = validated_data.get('value', 0)103 data.save()104 return data 105 106class ResultSerializer(serializers.ModelSerializer):107 homeTeam = TeamSerializer(read_only=True)108 awayTeam = TeamSerializer(read_only=True)109 reporter = AccountSerializer(read_only=True)110 111 class Meta:112 model = Result113 fields = ('id', 'outcome', 'homeTeam', 'awayTeam', 'reporter')114 read_only_fields = ('id')115 def create(self, validated_data):116 user = validated_data.get('reporter', {})117 data = validated_data118 data.reporter = Account.objects.get(username=user)119 return data120 def update(self, instance, validated_data):...

Full Screen

Full Screen

serializer_method_override.py

Source:serializer_method_override.py Github

copy

Full Screen

1def franchisee_update_method(instance, validated_data):2 instance.mid = validated_data.get('mid', instance.mid)3 instance.gid = validated_data.get('gid', instance.gid)4 instance.mid_name = validated_data.get('mid_name', instance.mid_name)5 instance.main_homepage = validated_data.get('main_homepage', instance.main_homepage)6 instance.sub_homepage = validated_data.get('sub_homepage', instance.sub_homepage)7 instance.is_active = validated_data.get('is_active', instance.is_active)8 instance.user_type = validated_data.get('user_type', instance.user_type)9 instance.boss_name = validated_data.get('boss_name', instance.boss_name)10 instance.email = validated_data.get('email', instance.email)11 instance.phone_number = validated_data.get('phone_number', instance.phone_number)12 instance.fax_number = validated_data.get('fax_number', instance.fax_number)13 instance.store_modified_date = validated_data.get('store_modified_date', instance.store_modified_date)14 instance.transfer_or_not = validated_data.get('transfer_or_not', instance.transfer_or_not)15 instance.published_or_not = validated_data.get('published_or_not', instance.published_or_not)16 instance.pay_link_or_not = validated_data.get('pay_link_or_not', instance.pay_link_or_not)17 instance.pg_info_auto_save_or_not = validated_data.get('pg_info_auto_save_or_not',18 instance.pg_info_auto_save_or_not)19 instance.delivery_pay_or_not = validated_data.get('delivery_pay_or_not', instance.delivery_pay_or_not)20 instance.save()21 return instance22def pay_go_manager_update_method(instance, validated_data):23 print('validated_data', validated_data)24 instance.name = validated_data.get('name', instance.name)25 print(instance.name)26 instance.department = validated_data.get('department', instance.department)27 instance.position = validated_data.get('position', instance.position)28 instance.phone_number = validated_data.get('phone_number', instance.phone_number)29 instance.email = validated_data.get('email', instance.email)30 instance.save()31 return instance32def memo_update_method(instance, validated_data):33 instance.sales_slip = validated_data.get('sales_slip', instance.sales_slip)34 instance.vat_notation = validated_data.get('vat_notation', instance.vat_notation)35 instance.payment_notice = validated_data.get('payment_notice', instance.payment_notice)36 instance.modify_text = validated_data.get('modify_text', instance.modify_text)37 instance.save()...

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 yandex-tank 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