Format source code

This commit is contained in:
Julian Lawrance 2021-02-06 21:52:36 +00:00
parent 55f77c2fdd
commit 76ba2ae00e
4 changed files with 61 additions and 27 deletions

View file

@ -1555,7 +1555,7 @@ def _build_pokemons():
pokemon_id=int(info[0]),
generation_id=int(info[1]),
type_id=int(info[2]),
slot=int(info[3])
slot=int(info[3]),
)
build_generic((PokemonTypePast,), "pokemon_types_past.csv", csv_record_to_objects)

View file

@ -7,21 +7,54 @@ import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('pokemon_v2', '0004_iso639length_20191217'),
("pokemon_v2", "0004_iso639length_20191217"),
]
operations = [
migrations.CreateModel(
name='PokemonTypePast',
name="PokemonTypePast",
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('slot', models.IntegerField()),
('generation', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='pokemontypepast', to='pokemon_v2.Generation')),
('pokemon', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='pokemontypepast', to='pokemon_v2.Pokemon')),
('type', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='pokemontypepast', to='pokemon_v2.Type')),
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("slot", models.IntegerField()),
(
"generation",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.CASCADE,
related_name="pokemontypepast",
to="pokemon_v2.Generation",
),
),
(
"pokemon",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.CASCADE,
related_name="pokemontypepast",
to="pokemon_v2.Pokemon",
),
),
(
"type",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.CASCADE,
related_name="pokemontypepast",
to="pokemon_v2.Type",
),
),
],
options={
'abstract': False,
},
options={"abstract": False,},
),
]

View file

@ -2878,9 +2878,7 @@ class PokemonDetailSerializer(serializers.ModelSerializer):
poke_past_type_objects = PokemonTypePast.objects.filter(pokemon=obj)
poke_past_types = PokemonTypePastSerializer(
poke_past_type_objects,
many=True,
context=self.context
poke_past_type_objects, many=True, context=self.context
).data
# post-process to the form we want

View file

@ -1675,14 +1675,10 @@ class APIData:
@classmethod
def setup_pokemon_past_type_data(cls, pokemon, generation, type=None, slot=1):
type = type or cls.setup_type_data(
name="tp for pkmn")
type = type or cls.setup_type_data(name="tp for pkmn")
pokemon_type_past = PokemonTypePast(
pokemon=pokemon,
generation=generation,
type=type,
slot=slot
pokemon=pokemon, generation=generation, type=type, slot=slot
)
pokemon_type_past.save()
@ -4767,10 +4763,9 @@ class APITests(APIData, APITestCase):
pokemon_ability = self.setup_pokemon_ability_data(pokemon=pokemon)
pokemon_stat = self.setup_pokemon_stat_data(pokemon=pokemon)
pokemon_type = self.setup_pokemon_type_data(pokemon=pokemon)
generation = self.setup_generation_data(name='base gen')
generation = self.setup_generation_data(name="base gen")
pokemon_past_type = self.setup_pokemon_past_type_data(
pokemon=pokemon,
generation=generation
pokemon=pokemon, generation=generation
)
pokemon_item = self.setup_pokemon_item_data(pokemon=pokemon)
pokemon_sprites = self.setup_pokemon_sprites_data(pokemon=pokemon)
@ -4875,17 +4870,25 @@ class APITests(APIData, APITestCase):
)
# past type params
past_types_obj = response.data["past_types"][0]
self.assertEqual(past_types_obj["generation"]["name"], pokemon_past_type.generation.name)
self.assertEqual(
past_types_obj["generation"]["name"], pokemon_past_type.generation.name
)
self.assertEqual(
past_types_obj["generation"]["url"],
"{}{}/generation/{}/".format(TEST_HOST, API_V2, pokemon_past_type.generation.pk))
"{}{}/generation/{}/".format(
TEST_HOST, API_V2, pokemon_past_type.generation.pk
),
)
past_types_types_obj = past_types_obj["types"][0]
self.assertEqual(past_types_types_obj["slot"], pokemon_past_type.slot)
self.assertEqual(past_types_types_obj["type"]["name"], pokemon_past_type.type.name)
self.assertEqual(
past_types_types_obj["type"]["name"], pokemon_past_type.type.name
)
self.assertEqual(
past_types_types_obj["type"]["url"],
"{}{}/type/{}/".format(TEST_HOST, API_V2, pokemon_past_type.type.pk))
"{}{}/type/{}/".format(TEST_HOST, API_V2, pokemon_past_type.type.pk),
)
# items params
self.assertEqual(