fix(audit): moderniser les accès ORM
CI - Security, Lint & Tests / validate (push) Failing after 19m37s
CI - Security, Lint & Tests / validate (push) Failing after 19m37s
This commit is contained in:
@@ -150,9 +150,10 @@ def _pending(bot, message_id, row_id):
|
||||
|
||||
|
||||
def _confirmed(row_id):
|
||||
from app.extensions import db
|
||||
from app.models import MatchParticipant
|
||||
|
||||
return MatchParticipant.query.get(row_id).attendance_confirmed
|
||||
return db.session.get(MatchParticipant, row_id).attendance_confirmed
|
||||
|
||||
|
||||
class TestTheDatabaseRefusedTheWrite:
|
||||
|
||||
@@ -269,6 +269,78 @@ class TestRegisteredPlayersForMatchForm:
|
||||
assert counter.total == 1
|
||||
|
||||
|
||||
class TestEvaluationLists:
|
||||
"""Evaluation pages must not issue one lookup per player or evaluator."""
|
||||
|
||||
def test_players_to_evaluate_has_a_fixed_query_budget(
|
||||
self, app, client, as_role, make_user, count_queries
|
||||
):
|
||||
coach_id = as_role('coach')
|
||||
admin_id = make_user('admin')
|
||||
player_ids = [make_user('player') for _ in range(12)]
|
||||
|
||||
with app.app_context():
|
||||
tryout = Tryout(
|
||||
title='Evaluation budget',
|
||||
game='Valorant',
|
||||
date=date(2030, 3, 1),
|
||||
created_by=admin_id,
|
||||
coach_id=coach_id,
|
||||
)
|
||||
db.session.add(tryout)
|
||||
db.session.flush()
|
||||
for player_id in player_ids:
|
||||
db.session.add(TryoutRegistration(tryout_id=tryout.id, player_id=player_id))
|
||||
db.session.commit()
|
||||
tryout_id = tryout.id
|
||||
|
||||
counter = count_queries()
|
||||
try:
|
||||
response = client.get(f'/evaluations/{tryout_id}/players')
|
||||
finally:
|
||||
counter.stop()
|
||||
|
||||
assert response.status_code == 200
|
||||
assert 1 <= counter.total <= 10, f'{counter.total} SELECTs for 12 players'
|
||||
|
||||
def test_scout_top_players_are_loaded_with_the_aggregate(
|
||||
self, app, client, as_role, make_user, count_queries
|
||||
):
|
||||
as_role('scout')
|
||||
evaluator_id = make_user('coach')
|
||||
admin_id = make_user('admin')
|
||||
player_ids = [make_user('player') for _ in range(12)]
|
||||
|
||||
with app.app_context():
|
||||
tryout = Tryout(
|
||||
title='Scout budget',
|
||||
game='Valorant',
|
||||
date=date(2030, 3, 1),
|
||||
created_by=admin_id,
|
||||
)
|
||||
db.session.add(tryout)
|
||||
db.session.flush()
|
||||
for score, player_id in enumerate(player_ids, start=1):
|
||||
db.session.add(
|
||||
Evaluation(
|
||||
player_id=player_id,
|
||||
evaluator_id=evaluator_id,
|
||||
tryout_id=tryout.id,
|
||||
overall_score=score,
|
||||
)
|
||||
)
|
||||
db.session.commit()
|
||||
|
||||
counter = count_queries()
|
||||
try:
|
||||
response = client.get('/dashboard')
|
||||
finally:
|
||||
counter.stop()
|
||||
|
||||
assert response.status_code == 200
|
||||
assert 1 <= counter.total <= 6, f'{counter.total} SELECTs for the scout dashboard'
|
||||
|
||||
|
||||
class TestViewTryout:
|
||||
"""PERF-001 — the most-visited page in the application ran one query
|
||||
per registration, one per player evaluated, one per team, and one per
|
||||
|
||||
@@ -135,9 +135,11 @@ class TestThroughTheUploadRoute:
|
||||
contract_id = Contract.query.one().id
|
||||
|
||||
response = client.get(f'/users/contracts/{contract_id}/download')
|
||||
|
||||
assert response.status_code == 200
|
||||
assert response.data.startswith(b'%PDF-')
|
||||
try:
|
||||
assert response.status_code == 200
|
||||
assert response.data.startswith(b'%PDF-')
|
||||
finally:
|
||||
response.close()
|
||||
|
||||
|
||||
def _pdf():
|
||||
|
||||
Reference in New Issue
Block a user