style: formater le depot avec ruff format
QUA-002, premiere moitie. **Ce commit ne fait que reformater** : aucun changement de comportement, aucune ligne de logique touchee. 72 fichiers, 4 restaient deja conformes. Il est isole exprès, pour que `git log -p` sur les commits voisins reste lisible. `quote-style = "preserve"` etait deja pose dans pyproject.toml, ce qui evite le brassage guillemets simples / doubles : le diff porte sur les retours a la ligne, l indentation des appels longs et les virgules finales, pas sur le style de chaine. Verification : 263 tests passent avant et apres, ruff check propre. L activation en CI arrive dans le commit suivant, separement, pour que ce diff-ci ne contienne rien d autre. Co-Authored-By: Claude Opus 5 <[email protected]>
This commit is contained in:
+86
-59
@@ -19,11 +19,19 @@ import pytest
|
||||
|
||||
from app.extensions import db
|
||||
from app.models import (
|
||||
Contract, OrgTeam, PersonalNote, TeamPlayer, Tryout, TryoutRegistration,
|
||||
Contract,
|
||||
OrgTeam,
|
||||
PersonalNote,
|
||||
TeamPlayer,
|
||||
Tryout,
|
||||
TryoutRegistration,
|
||||
)
|
||||
from app.permissions import (
|
||||
can_manage_player_contract, coach_can_access_player, coach_org_team_ids,
|
||||
coach_player_ids, visible_org_teams,
|
||||
can_manage_player_contract,
|
||||
coach_can_access_player,
|
||||
coach_org_team_ids,
|
||||
coach_player_ids,
|
||||
visible_org_teams,
|
||||
)
|
||||
|
||||
|
||||
@@ -33,8 +41,9 @@ def team_factory(app):
|
||||
with app.app_context():
|
||||
from app.models import User
|
||||
|
||||
team = OrgTeam(name=name, created_by=coach_id or legacy_coach_id,
|
||||
coach_id=legacy_coach_id)
|
||||
team = OrgTeam(
|
||||
name=name, created_by=coach_id or legacy_coach_id, coach_id=legacy_coach_id
|
||||
)
|
||||
db.session.add(team)
|
||||
db.session.flush()
|
||||
if coach_id:
|
||||
@@ -48,25 +57,23 @@ def team_factory(app):
|
||||
|
||||
|
||||
class TestTeamResolution:
|
||||
def test_a_coach_attached_by_the_relationship_is_found(
|
||||
self, app, make_user, team_factory
|
||||
):
|
||||
def test_a_coach_attached_by_the_relationship_is_found(self, app, make_user, team_factory):
|
||||
coach_id = make_user('coach')
|
||||
team_id = team_factory('Varsity', coach_id=coach_id)
|
||||
|
||||
with app.app_context():
|
||||
from app.models import User
|
||||
|
||||
coach = db.session.get(User, coach_id)
|
||||
assert coach_org_team_ids(coach) == [team_id]
|
||||
|
||||
def test_a_coach_attached_by_the_legacy_column_is_found(
|
||||
self, app, make_user, team_factory
|
||||
):
|
||||
def test_a_coach_attached_by_the_legacy_column_is_found(self, app, make_user, team_factory):
|
||||
coach_id = make_user('coach')
|
||||
team_id = team_factory('JV', legacy_coach_id=coach_id)
|
||||
|
||||
with app.app_context():
|
||||
from app.models import User
|
||||
|
||||
coach = db.session.get(User, coach_id)
|
||||
assert coach_org_team_ids(coach) == [team_id]
|
||||
|
||||
@@ -74,6 +81,7 @@ class TestTeamResolution:
|
||||
coach_id = make_user('coach')
|
||||
with app.app_context():
|
||||
from app.models import User
|
||||
|
||||
assert coach_org_team_ids(db.session.get(User, coach_id)) == []
|
||||
|
||||
|
||||
@@ -85,47 +93,45 @@ class TestPlayerAccess:
|
||||
|
||||
with app.app_context():
|
||||
from app.models import User
|
||||
|
||||
assert coach_can_access_player(db.session.get(User, coach_id), player_id)
|
||||
|
||||
def test_a_second_coach_of_the_team_also_reaches_the_player(
|
||||
self, app, make_user, team_factory
|
||||
):
|
||||
def test_a_second_coach_of_the_team_also_reaches_the_player(self, app, make_user, team_factory):
|
||||
"""The case that used to fail everywhere users.py looked at coach_id."""
|
||||
first_coach = make_user('coach')
|
||||
second_coach = make_user('coach')
|
||||
player_id = make_user('player')
|
||||
team_id = team_factory('Varsity', legacy_coach_id=first_coach,
|
||||
player_ids=[player_id])
|
||||
team_id = team_factory('Varsity', legacy_coach_id=first_coach, player_ids=[player_id])
|
||||
|
||||
with app.app_context():
|
||||
from app.models import User
|
||||
|
||||
team = db.session.get(OrgTeam, team_id)
|
||||
team.coaches.append(db.session.get(User, second_coach))
|
||||
db.session.commit()
|
||||
|
||||
assert coach_can_access_player(db.session.get(User, second_coach), player_id)
|
||||
|
||||
def test_a_coach_does_not_reach_an_unrelated_player(
|
||||
self, app, make_user, team_factory
|
||||
):
|
||||
def test_a_coach_does_not_reach_an_unrelated_player(self, app, make_user, team_factory):
|
||||
coach_id = make_user('coach')
|
||||
stranger_id = make_user('player')
|
||||
team_factory('Varsity', coach_id=coach_id)
|
||||
|
||||
with app.app_context():
|
||||
from app.models import User
|
||||
|
||||
assert not coach_can_access_player(db.session.get(User, coach_id), stranger_id)
|
||||
|
||||
def test_a_coach_reaches_a_player_registered_in_their_tryout(
|
||||
self, app, make_user
|
||||
):
|
||||
def test_a_coach_reaches_a_player_registered_in_their_tryout(self, app, make_user):
|
||||
coach_id = make_user('coach')
|
||||
player_id = make_user('player')
|
||||
|
||||
with app.app_context():
|
||||
from app.models import User
|
||||
tryout = Tryout(title='Open tryout', game='Valorant',
|
||||
date=date(2030, 3, 1), created_by=coach_id)
|
||||
|
||||
tryout = Tryout(
|
||||
title='Open tryout', game='Valorant', date=date(2030, 3, 1), created_by=coach_id
|
||||
)
|
||||
db.session.add(tryout)
|
||||
db.session.flush()
|
||||
tryout.coaches.append(db.session.get(User, coach_id))
|
||||
@@ -138,6 +144,7 @@ class TestPlayerAccess:
|
||||
coach_id = make_user('coach')
|
||||
with app.app_context():
|
||||
from app.models import User
|
||||
|
||||
assert not coach_can_access_player(db.session.get(User, coach_id), None)
|
||||
|
||||
|
||||
@@ -152,9 +159,14 @@ class TestPersonalNoteRoutes:
|
||||
coach_id = as_role('coach')
|
||||
team_factory('Varsity', coach_id=coach_id)
|
||||
|
||||
client.post('/users/personal-notes/manage', data={
|
||||
'player_id': stranger_id, 'content': 'Unrelated observation',
|
||||
}, follow_redirects=True)
|
||||
client.post(
|
||||
'/users/personal-notes/manage',
|
||||
data={
|
||||
'player_id': stranger_id,
|
||||
'content': 'Unrelated observation',
|
||||
},
|
||||
follow_redirects=True,
|
||||
)
|
||||
|
||||
with app.app_context():
|
||||
assert PersonalNote.query.filter_by(player_id=stranger_id).count() == 0
|
||||
@@ -167,9 +179,14 @@ class TestPersonalNoteRoutes:
|
||||
coach_id = as_role('coach')
|
||||
team_factory('Varsity', coach_id=coach_id, player_ids=[player_id])
|
||||
|
||||
client.post('/users/personal-notes/manage', data={
|
||||
'player_id': player_id, 'content': 'Good positioning today',
|
||||
}, follow_redirects=True)
|
||||
client.post(
|
||||
'/users/personal-notes/manage',
|
||||
data={
|
||||
'player_id': player_id,
|
||||
'content': 'Good positioning today',
|
||||
},
|
||||
follow_redirects=True,
|
||||
)
|
||||
|
||||
with app.app_context():
|
||||
note = PersonalNote.query.filter_by(player_id=player_id).one()
|
||||
@@ -184,17 +201,18 @@ class TestContractVisibility:
|
||||
def _contract(app, player_id, uploader_id, team_id=None):
|
||||
with app.app_context():
|
||||
contract = Contract(
|
||||
player_id=player_id, team_id=team_id, uploaded_by_id=uploader_id,
|
||||
original_filename='c.pdf', stored_filename='uuid.pdf',
|
||||
player_id=player_id,
|
||||
team_id=team_id,
|
||||
uploaded_by_id=uploader_id,
|
||||
original_filename='c.pdf',
|
||||
stored_filename='uuid.pdf',
|
||||
file_path='/tmp/uuid.pdf',
|
||||
)
|
||||
db.session.add(contract)
|
||||
db.session.commit()
|
||||
return contract.id
|
||||
|
||||
def test_a_teamless_contract_is_not_visible_to_every_coach(
|
||||
self, app, make_user, team_factory
|
||||
):
|
||||
def test_a_teamless_contract_is_not_visible_to_every_coach(self, app, make_user, team_factory):
|
||||
coach_id = make_user('coach')
|
||||
stranger_id = make_user('player')
|
||||
admin_id = make_user('admin')
|
||||
@@ -203,12 +221,11 @@ class TestContractVisibility:
|
||||
|
||||
with app.app_context():
|
||||
from app.models import User
|
||||
|
||||
contract = db.session.get(Contract, contract_id)
|
||||
assert not contract.can_view(db.session.get(User, coach_id))
|
||||
|
||||
def test_a_coach_sees_the_contract_of_their_own_player(
|
||||
self, app, make_user, team_factory
|
||||
):
|
||||
def test_a_coach_sees_the_contract_of_their_own_player(self, app, make_user, team_factory):
|
||||
coach_id = make_user('coach')
|
||||
player_id = make_user('player')
|
||||
admin_id = make_user('admin')
|
||||
@@ -217,6 +234,7 @@ class TestContractVisibility:
|
||||
|
||||
with app.app_context():
|
||||
from app.models import User
|
||||
|
||||
contract = db.session.get(Contract, contract_id)
|
||||
assert contract.can_view(db.session.get(User, coach_id))
|
||||
|
||||
@@ -227,6 +245,7 @@ class TestContractVisibility:
|
||||
|
||||
with app.app_context():
|
||||
from app.models import User
|
||||
|
||||
contract = db.session.get(Contract, contract_id)
|
||||
assert contract.can_view(db.session.get(User, player_id))
|
||||
|
||||
@@ -237,6 +256,7 @@ class TestContractVisibility:
|
||||
|
||||
with app.app_context():
|
||||
from app.models import User
|
||||
|
||||
contract = db.session.get(Contract, contract_id)
|
||||
assert contract.can_view(db.session.get(User, admin_id))
|
||||
|
||||
@@ -251,9 +271,7 @@ class TestSecondTeam:
|
||||
attached by the relationship only reached none of it. Both defects were
|
||||
live, and silent: the pages rendered, just empty."""
|
||||
|
||||
def test_a_coach_of_two_teams_reaches_both_squads(
|
||||
self, app, make_user, team_factory
|
||||
):
|
||||
def test_a_coach_of_two_teams_reaches_both_squads(self, app, make_user, team_factory):
|
||||
coach_id = make_user('coach')
|
||||
first_player = make_user('player')
|
||||
second_player = make_user('player')
|
||||
@@ -262,6 +280,7 @@ class TestSecondTeam:
|
||||
|
||||
with app.app_context():
|
||||
from app.models import User
|
||||
|
||||
coach = db.session.get(User, coach_id)
|
||||
assert sorted(coach_player_ids(coach)) == sorted([first_player, second_player])
|
||||
|
||||
@@ -275,6 +294,7 @@ class TestSecondTeam:
|
||||
|
||||
with app.app_context():
|
||||
from app.models import User
|
||||
|
||||
coach = db.session.get(User, coach_id)
|
||||
assert can_manage_player_contract(coach, second_player)
|
||||
|
||||
@@ -287,6 +307,7 @@ class TestSecondTeam:
|
||||
|
||||
with app.app_context():
|
||||
from app.models import User
|
||||
|
||||
coach = db.session.get(User, coach_id)
|
||||
assert not can_manage_player_contract(coach, stranger_id)
|
||||
|
||||
@@ -326,6 +347,7 @@ class TestTeamVisibility:
|
||||
|
||||
with app.app_context():
|
||||
from app.models import User
|
||||
|
||||
teams = visible_org_teams(db.session.get(User, coach_id))
|
||||
assert [t.name for t in teams] == ['Varsity']
|
||||
|
||||
@@ -337,6 +359,7 @@ class TestTeamVisibility:
|
||||
|
||||
with app.app_context():
|
||||
from app.models import User
|
||||
|
||||
teams = visible_org_teams(db.session.get(User, admin_id))
|
||||
assert [t.name for t in teams] == ['JV', 'Varsity']
|
||||
|
||||
@@ -347,11 +370,10 @@ class TestTeamVisibility:
|
||||
|
||||
with app.app_context():
|
||||
from app.models import User
|
||||
|
||||
assert visible_org_teams(db.session.get(User, scout_id)) == []
|
||||
|
||||
def test_the_team_listing_shows_the_relationship_team(
|
||||
self, app, client, as_role, team_factory
|
||||
):
|
||||
def test_the_team_listing_shows_the_relationship_team(self, app, client, as_role, team_factory):
|
||||
coach_id = as_role('coach')
|
||||
team_factory('Northern Lights', coach_id=coach_id)
|
||||
|
||||
@@ -366,49 +388,54 @@ class TestTryoutVisibility:
|
||||
@staticmethod
|
||||
def _tryout(app, *, creator_id, title, target_team_id=None, legacy_coach_id=None):
|
||||
with app.app_context():
|
||||
tryout = Tryout(title=title, game='Valorant', date=date(2030, 5, 1),
|
||||
created_by=creator_id, target_org_team_id=target_team_id,
|
||||
coach_id=legacy_coach_id)
|
||||
tryout = Tryout(
|
||||
title=title,
|
||||
game='Valorant',
|
||||
date=date(2030, 5, 1),
|
||||
created_by=creator_id,
|
||||
target_org_team_id=target_team_id,
|
||||
coach_id=legacy_coach_id,
|
||||
)
|
||||
db.session.add(tryout)
|
||||
db.session.commit()
|
||||
return tryout.id
|
||||
|
||||
def test_a_tryout_targeting_a_legacy_team_is_visible(
|
||||
self, app, make_user, team_factory
|
||||
):
|
||||
def test_a_tryout_targeting_a_legacy_team_is_visible(self, app, make_user, team_factory):
|
||||
coach_id = make_user('coach')
|
||||
team_id = team_factory('Varsity', legacy_coach_id=coach_id)
|
||||
self._tryout(app, creator_id=coach_id, title='Spring intake',
|
||||
target_team_id=team_id)
|
||||
self._tryout(app, creator_id=coach_id, title='Spring intake', target_team_id=team_id)
|
||||
|
||||
with app.app_context():
|
||||
from app.models import User
|
||||
|
||||
coach = db.session.get(User, coach_id)
|
||||
assert [t.title for t in coach.get_visible_tryouts()] == ['Spring intake']
|
||||
|
||||
def test_the_same_tryout_is_manageable(self, app, make_user, team_factory):
|
||||
coach_id = make_user('coach')
|
||||
team_id = team_factory('Varsity', legacy_coach_id=coach_id)
|
||||
tryout_id = self._tryout(app, creator_id=coach_id, title='Spring intake',
|
||||
target_team_id=team_id)
|
||||
tryout_id = self._tryout(
|
||||
app, creator_id=coach_id, title='Spring intake', target_team_id=team_id
|
||||
)
|
||||
|
||||
with app.app_context():
|
||||
from app.models import User
|
||||
|
||||
coach = db.session.get(User, coach_id)
|
||||
assert coach.can_manage_this_tryout(db.session.get(Tryout, tryout_id))
|
||||
|
||||
def test_another_coachs_tryout_stays_out_of_reach(
|
||||
self, app, make_user, team_factory
|
||||
):
|
||||
def test_another_coachs_tryout_stays_out_of_reach(self, app, make_user, team_factory):
|
||||
coach_id = make_user('coach')
|
||||
other_id = make_user('coach')
|
||||
team_factory('Varsity', coach_id=coach_id)
|
||||
other_team = team_factory('JV', coach_id=other_id)
|
||||
tryout_id = self._tryout(app, creator_id=other_id, title='Their intake',
|
||||
target_team_id=other_team)
|
||||
tryout_id = self._tryout(
|
||||
app, creator_id=other_id, title='Their intake', target_team_id=other_team
|
||||
)
|
||||
|
||||
with app.app_context():
|
||||
from app.models import User
|
||||
|
||||
coach = db.session.get(User, coach_id)
|
||||
assert coach.get_visible_tryouts() == []
|
||||
assert not coach.can_manage_this_tryout(db.session.get(Tryout, tryout_id))
|
||||
|
||||
Reference in New Issue
Block a user