Skip to content

Commit

Permalink
🎟️ Link a ticket with a tournament
Browse files Browse the repository at this point in the history
Add a `tournament` field to a Ticket that lets us know what tournament
it is linked to.
  • Loading branch information
Lymkwi committed Oct 23, 2023
1 parent fc1ff1b commit c41efb9
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 9 deletions.
2 changes: 1 addition & 1 deletion insalan/tickets/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


class TicketAdmin(admin.ModelAdmin):
list_display = ("id", "user", "status", "token")
list_display = ("id", "user", "status", "tournament", "token")
search_fields = ["user"]


Expand Down
4 changes: 4 additions & 0 deletions insalan/tickets/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,7 @@ class Meta:
choices=Status.choices,
default=Status.VALID,
)
tournament = models.ForeignKey(
"tournament.Tournament", verbose_name=_("Tournoi"),
on_delete=models.CASCADE, blank=False, null=False
)
48 changes: 40 additions & 8 deletions insalan/tickets/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,41 @@
from rest_framework.test import APITestCase

from .models import Ticket
from insalan.tournament.models import Event, Game, Tournament
from insalan.user.models import User


def create_ticket(
username: str, token: str, status: Ticket.Status = Ticket.Status.VALID
username: str,
token: str,
tourney: Tournament,
status: Ticket.Status = Ticket.Status.VALID,
) -> None:
user = User.objects.create_user(
username=username, password=username, email=f"{username}@example.com"
username=username,
password=username,
email=f"{username}@example.com",
)
Ticket.objects.create(
user=user, token=uuid.UUID(token), status=status, tournament=tourney
)
Ticket.objects.create(user=user, token=uuid.UUID(token), status=status)


class TicketTestCase(TestCase):
def setUp(self) -> None:
create_ticket("user1", "00000000-0000-0000-0000-000000000001")
event_one = Event.objects.create(
name="InsaLan Test", description="Test", month=2023, year=12, ongoing=True
)
game_one = Game.objects.create(name="Counter-Strike 2", short_name="CS2")
tourney_one = Tournament.objects.create(
name="Tournament", event=event_one, game=game_one, rules=""
)
create_ticket("user1", "00000000-0000-0000-0000-000000000001", tourney_one)
create_ticket(
"user2", "00000000-0000-0000-0000-000000000002", Ticket.Status.CANCELLED
"user2",
"00000000-0000-0000-0000-000000000002",
tourney_one,
Ticket.Status.CANCELLED,
)

def test_get_existing_tickets(self) -> None:
Expand Down Expand Up @@ -53,12 +71,20 @@ def setUp(self) -> None:
User.objects.create_user(
username="admin", password="admin", email="[email protected]", is_staff=True
)
event_one = Event.objects.create(
name="InsaLan Test", description="Test", month=2023, year=12, ongoing=True
)
game_one = Game.objects.create(name="Counter-Strike 2", short_name="CS2")
Tournament.objects.create(
name="Tournament", event=event_one, game=game_one, rules=""
)

def login(self, username: str) -> None:
self.assertTrue(self.client.login(username=username, password=username))

def test_get(self) -> None:
create_ticket("user1", "00000000-0000-0000-0000-000000000001")
tourney = Tournament.objects.all()[0]
create_ticket("user1", "00000000-0000-0000-0000-000000000001", tourney)

response = self.client.get(
reverse(
Expand Down Expand Up @@ -116,15 +142,18 @@ def test_get(self) -> None:
)

def test_scan(self) -> None:
create_ticket("user1", "00000000-0000-0000-0000-000000000001")
tourney = Tournament.objects.all()[0]
create_ticket("user1", "00000000-0000-0000-0000-000000000001", tourney)
create_ticket(
"user2",
"00000000-0000-0000-0000-000000000002",
tourney,
status=Ticket.Status.CANCELLED,
)
create_ticket(
"user3",
"00000000-0000-0000-0000-000000000003",
tourney,
status=Ticket.Status.SCANNED,
)

Expand Down Expand Up @@ -171,7 +200,10 @@ def test_scan(self) -> None:
self.assertEqual(response.json(), {"err": _("Ticket déjà scanné")})

def test_qrcode(self) -> None:
create_ticket("user1", "00000000-0000-0000-0000-000000000001")
tourney = Tournament.objects.all()[0]
create_ticket(
"user1", "00000000-0000-0000-0000-000000000001", tourney
)

response = self.client.get(
reverse("tickets:qrcode", args=["00000000-0000-0000-0000-000000000001"])
Expand Down

0 comments on commit c41efb9

Please sign in to comment.