Daedalus and Talos integration test
This commit is contained in:
@@ -4,11 +4,13 @@ from sqlalchemy import delete, select, update
|
||||
from sqlalchemy.dialects.postgresql import insert
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.models.ability import Ability
|
||||
from app.models.boss_battle import BossBattle
|
||||
from app.models.boss_pokemon import BossPokemon
|
||||
from app.models.encounter import Encounter
|
||||
from app.models.evolution import Evolution
|
||||
from app.models.game import Game
|
||||
from app.models.move import Move
|
||||
from app.models.pokemon import Pokemon
|
||||
from app.models.route import Route
|
||||
from app.models.route_encounter import RouteEncounter
|
||||
@@ -484,3 +486,59 @@ async def upsert_evolutions(
|
||||
|
||||
await session.flush()
|
||||
return count
|
||||
|
||||
|
||||
async def upsert_moves(
|
||||
session: AsyncSession,
|
||||
moves: list[dict],
|
||||
) -> int:
|
||||
"""Upsert move records, return count of upserted rows."""
|
||||
count = 0
|
||||
for move in moves:
|
||||
stmt = (
|
||||
insert(Move)
|
||||
.values(
|
||||
name=move["name"],
|
||||
introduced_gen=move["introduced_gen"],
|
||||
type=move.get("type"),
|
||||
)
|
||||
.on_conflict_do_update(
|
||||
index_elements=["name"],
|
||||
set_={
|
||||
"introduced_gen": move["introduced_gen"],
|
||||
"type": move.get("type"),
|
||||
},
|
||||
)
|
||||
)
|
||||
await session.execute(stmt)
|
||||
count += 1
|
||||
|
||||
await session.flush()
|
||||
return count
|
||||
|
||||
|
||||
async def upsert_abilities(
|
||||
session: AsyncSession,
|
||||
abilities: list[dict],
|
||||
) -> int:
|
||||
"""Upsert ability records, return count of upserted rows."""
|
||||
count = 0
|
||||
for ability in abilities:
|
||||
stmt = (
|
||||
insert(Ability)
|
||||
.values(
|
||||
name=ability["name"],
|
||||
introduced_gen=ability["introduced_gen"],
|
||||
)
|
||||
.on_conflict_do_update(
|
||||
index_elements=["name"],
|
||||
set_={
|
||||
"introduced_gen": ability["introduced_gen"],
|
||||
},
|
||||
)
|
||||
)
|
||||
await session.execute(stmt)
|
||||
count += 1
|
||||
|
||||
await session.flush()
|
||||
return count
|
||||
|
||||
Reference in New Issue
Block a user