Skip to content

Commit

Permalink
Prevent non validated team to get a slot
Browse files Browse the repository at this point in the history
  • Loading branch information
KwikKill committed Dec 9, 2024
1 parent a86b3cd commit c1f052f
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
46 changes: 45 additions & 1 deletion insalan/tournament/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2615,7 +2615,11 @@ def test_can_patch_seat_slot(self):
Seat.objects.create(event=event, x=1, y=3),
])

team = Team.objects.create(name="Nom d'équipe 1", tournament=trnm2, password=make_password("password"))
team = Team.objects.create(name="Nom d'équipe 1", tournament=trnm2, password=make_password("password"), validated=True)
# Add a player in the team
pl1 = Player.objects.create(team=team, user=user, name_in_game="pseudo")
team.captain = pl1
team.save()

player = Player.objects.create(team=team, user=user, name_in_game="pseudo")

Expand All @@ -2637,6 +2641,46 @@ def test_can_patch_seat_slot(self):
team = Team.objects.get(id=team.id)
self.assertEqual(team.seat_slot, seat_slot)

def test_non_validated_cant_patch_seat_slot(self):
user: User = User.objects.get(username="validemail")

self.client.force_login(user=user)

event = Event.objects.get(name="InsaLan Test")

game2 = Game.objects.create(name="Test Game 2", short_name="TFG2", players_per_team=3)
trnm2 = Tournament.objects.create(
game=game2,
event=event,
maxTeam=16,
is_announced=True
)

seat_slot = SeatSlot.objects.create(tournament=trnm2)
seat_slot.seats.set([
Seat.objects.create(event=event, x=1, y=1),
Seat.objects.create(event=event, x=1, y=2),
Seat.objects.create(event=event, x=1, y=3),
])

team = Team.objects.create(name="Nom d'équipe 1", tournament=trnm2, password=make_password("password"))

player = Player.objects.create(team=team, user=user, name_in_game="pseudo")

# patch data
data = {
"seat_slot": seat_slot.id,
}

# patch request
request = self.client.patch(
f"/v1/tournament/team/{team.id}/",
data,
content_type="application/json",
)

self.assertEqual(request.status_code, 400)

def test_cant_patch_seat_slot(self):
user: User = User.objects.get(username="validemail")

Expand Down
4 changes: 4 additions & 0 deletions insalan/tournament/views/team.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ def patch(self, request, *args, **kwargs):
substitute.delete()

if "seat_slot" in data:
if not team.validated:
return Response({
"seat_slot": _("Équipe non validée.")
}, status=status.HTTP_400_BAD_REQUEST)
try:
seat_slot = SeatSlot.objects.get(id=data["seat_slot"])
except SeatSlot.DoesNotExist:
Expand Down

0 comments on commit c1f052f

Please sign in to comment.