Skip to content

Commit

Permalink
📒 Several tournament models modifications
Browse files Browse the repository at this point in the history
Models in the tournament field are modified thusly:
- The whole file is formatted
- A team is now always attached to a tournament, including when it is
  not validated. A boolean is added in `Team` to know if it has been
  validated
- Both player and manager registrations now have a foreign key to their
  ticket, which is null until the payment of their ticket has succeeded
- Admin view updated
- Tests updated
  • Loading branch information
Lymkwi committed Oct 15, 2023
1 parent ef1cd45 commit b9dfa9f
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 40 deletions.
6 changes: 3 additions & 3 deletions insalan/tournament/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class TournamentAdmin(admin.ModelAdmin):
class TeamAdmin(admin.ModelAdmin):
"""Admin handler for Team"""

list_display = ("id", "name", "tournament")
list_display = ("id", "name", "tournament", "validated")
search_fields = ["name", "tournament"]


Expand All @@ -53,7 +53,7 @@ class TeamAdmin(admin.ModelAdmin):
class PlayerAdmin(admin.ModelAdmin):
"""Admin handler for Player Registrations"""

list_display = ("id", "user", "team", "payment_status")
list_display = ("id", "user", "team", "payment_status", "ticket")
search_fields = ["user", "team", "payment_status"]


Expand All @@ -63,7 +63,7 @@ class PlayerAdmin(admin.ModelAdmin):
class ManagerAdmin(admin.ModelAdmin):
"""Admin handler for Manager Registrations"""

list_display = ("id", "user", "team", "payment_status")
list_display = ("id", "user", "team", "payment_status", "ticket")
search_fields = ["user", "team", "payment_status"]


Expand Down
25 changes: 22 additions & 3 deletions insalan/tournament/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,9 @@ class Team(models.Model):

tournament = models.ForeignKey(
Tournament,
null=True,
blank=True,
on_delete=models.SET_NULL,
null=False,
blank=False,
on_delete=models.CASCADE,
verbose_name=_("Tournoi"),
)
name = models.CharField(
Expand All @@ -211,6 +211,9 @@ class Team(models.Model):
null=False,
verbose_name=_("Nom d'équipe"),
)
validated = models.BooleanField(
default=False, blank=True, verbose_name=_("Équipe validée")
)

class Meta:
"""Meta Options"""
Expand Down Expand Up @@ -322,6 +325,14 @@ class Meta:
null=False,
verbose_name=_("Statut du paiement"),
)
ticket = models.ForeignKey(
Ticket,
on_delete=models.SET_NULL,
verbose_name=_("Ticket"),
null=True,
blank=True,
default=None,
)

def __str__(self) -> str:
"""Format this player registration to a str"""
Expand Down Expand Up @@ -384,6 +395,14 @@ class Manager(models.Model):
choices=PaymentStatus.choices,
null=False,
)
ticket = models.ForeignKey(
Ticket,
on_delete=models.SET_NULL,
verbose_name=_("Ticket"),
null=True,
blank=True,
default=None,
)

class Meta:
"""Meta Options"""
Expand Down
54 changes: 20 additions & 34 deletions insalan/tournament/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,23 +539,6 @@ def test_payment_status_set(self):

self.assertEqual(PaymentStatus.PAY_LATER, play_reg.payment_status)

def test_get_full_null_tournament(self):
"""Get a team with a null tournament"""
team = Team.objects.create(name="LaZone", tournament=None)

team.full_clean()

self.assertIsNone(team.get_tournament())

def test_team_null_tourney_repr(self):
"""
Test that the representation of a Team when its tournament is null is as
expectde.
"""
team = Team.objects.create(name="LaZone", tournament=None)

self.assertEqual(str(team), "LaZone (???)")

def test_get_team_players(self):
"""Get the players of a Team"""
team = Team.objects.get(name="LaLooze")
Expand Down Expand Up @@ -616,18 +599,6 @@ def test_team_name_too_long(self):
team.name = "C" * 42
team.full_clean()

def test_tournament_deletion_set_null(self):
"""Verify that a Team is deleted when its Tournament is"""
team = Team.objects.all()[0]
tourney = team.tournament

Team.objects.get(id=team.id)

# Delete and verify
tourney.delete()

self.assertIsInstance(Team.objects.get(id=team.id).tournament, NoneType)


# Player Class Tests
class PlayerTestCase(TestCase):
Expand Down Expand Up @@ -839,8 +810,10 @@ def test_get_player_team_correct(self):
def test_player_team_deletion(self):
"""Verify the behaviour of a Player when their team gets deleted"""
user_obj = User.objects.get(username="testplayer")
event = Event.objects.get(year=2023, month=8)
trnm = Tournament.objects.get(event=event)
# Create a team and player
team_obj = Team.objects.create(name="La Team Test", tournament=None)
team_obj = Team.objects.create(name="La Team Test Player", tournament=trnm)
play_obj = Player.objects.create(team=team_obj, user=user_obj)

Player.objects.get(id=play_obj.id)
Expand All @@ -853,8 +826,10 @@ def test_player_team_deletion(self):
def test_user_deletion(self):
"""Verify that a Player registration is deleted along with its user"""
user_obj = User.objects.get(username="testplayer")
event = Event.objects.get(year=2023, month=8)
trnm = Tournament.objects.get(event=event)
# Create a Player registration
team_obj = Team.objects.create(name="La Team Test", tournament=None)
team_obj = Team.objects.create(name="La Team Test User", tournament=trnm)
play_obj = Player.objects.create(team=team_obj, user=user_obj)

# Test
Expand Down Expand Up @@ -1232,8 +1207,13 @@ def test_one_manager_many_teams_diff_event_diff_tournament_diff_team(self):
def test_manager_team_deletion(self):
"""Verify the behaviour of a Manager when their team gets deleted"""
user_obj = User.objects.get(username="testplayer")
event = Event.objects.create(
name="InsaLan Test", year=2023, month=8, description=""
)
game = Game.objects.create(name="Test Game")
trnm = Tournament.objects.create(game=game, event=event)
# Create a team and player
team_obj = Team.objects.create(name="La Team Test", tournament=None)
team_obj = Team.objects.create(name="La Team Test", tournament=trnm)
play_obj = Manager.objects.create(team=team_obj, user=user_obj)

Manager.objects.get(id=play_obj.id)
Expand All @@ -1246,8 +1226,14 @@ def test_manager_team_deletion(self):
def test_user_deletion(self):
"""Verify that a Manager registration is deleted along with its user"""
user_obj = User.objects.get(username="testplayer")
# Create a Manager registration
team_obj = Team.objects.create(name="La Team Test", tournament=None)
event = Event.objects.create(
name="InsaLan Test", year=2023, month=8, description=""
)
game = Game.objects.create(name="Test Game")
trnm = Tournament.objects.create(
game=game, event=event
) # Create a Manager registration
team_obj = Team.objects.create(name="La Team Test", tournament=trnm)
man_obj = Manager.objects.create(team=team_obj, user=user_obj)

# Test
Expand Down

0 comments on commit b9dfa9f

Please sign in to comment.