-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a `tournament` field to a Ticket that lets us know what tournament it is linked to.
- Loading branch information
Showing
3 changed files
with
45 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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: | ||
|
@@ -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( | ||
|
@@ -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, | ||
) | ||
|
||
|
@@ -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"]) | ||
|