Skip to content

Commit

Permalink
🧪 Added tests on email validity to join team
Browse files Browse the repository at this point in the history
  • Loading branch information
Lugrim committed Oct 10, 2023
1 parent 44434d0 commit f96716a
Showing 1 changed file with 149 additions and 0 deletions.
149 changes: 149 additions & 0 deletions insalan/tournament/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from types import NoneType

from django.db.utils import IntegrityError
from django.contrib.auth.models import Permission
from django.core.exceptions import ValidationError
from django.core.files.uploadedfile import SimpleUploadedFile
from django.test import TestCase, TransactionTestCase
Expand Down Expand Up @@ -1213,3 +1214,151 @@ def test_payment_status_set(self):
man_reg.payment_status = PaymentStatus.PAY_LATER

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


class TournamentTeamEndpoints(TestCase):
"""Tournament Registration Endpoint Test Class"""

# TODO Test all endpoints

def setUp(self):
"""Setup method for Tournament Registrations Unit Tests"""

# Basic setup for a one-tournamnent game event
event = Event.objects.create(
name="InsaLan Test", year=2023, month=3, description=""
)
game = Game.objects.create(name="Test Game")
trnm = Tournament.objects.create(game=game, event=event)
team_one = Team.objects.create(name="La Team Test", tournament=trnm)

# user_one = User.objects.create_user(
# username="testplayer",
# email="[email protected]",
# password="^ThisIsAnAdminPassword42$",
# first_name="Iam",
# last_name="Staff",
# )

invalid_email_user: User = User.objects.create_user(
username="invalidemail",
email="[email protected]",
password="IUseAVerySecurePassword",
first_name="Random",
last_name="Player",
)

valid_email_user: User = User.objects.create_user(
username="validemail",
password="ThisIsPassword",
)

valid_email_user.user_permissions.add(
Permission.objects.get(codename="email_active")
)

# Player.objects.create(team=team_one, user=user_one)
# Player.objects.create(team=team_one, user=another_player)
# Manager.objects.create(team=team_one, user=random_player)

def test_can_create_a_team_with_valid_email(self):
"""Try to create a team with a valid email"""
user: User = User.objects.get(username="validemail")
self.client.force_login(user=user)

event = Event.objects.get(name="InsaLan Test")
trnm = event.get_tournaments()[0]

request = self.client.post(
"/v1/tournament/team/",
{
"name": "Les emails valides",
"tournament": trnm.id,
"players": [user.id],
},
format="json",
)

self.assertEquals(request.status_code, 200)

def test_cant_create_a_team_with_no_valid_email(self):
"""Try to create a team with email not validated"""
user: User = User.objects.get(username="invalidemail")
self.client.force_login(user=user)

event = Event.objects.get(name="InsaLan Test")
trnm = event.get_tournaments()[0]

request = self.client.post(
"/v1/tournament/team/",
{
"name": "Flemme de valider",
"tournament": trnm.id,
"players": [
user.id,
],
},
format="json",
)

self.assertEquals(request.status_code, 403)

def test_can_join_a_team_with_a_valid_email(self):
"""Try to join an existing team with a valid email"""
user: User = User.objects.get(username="validemail")
self.client.force_login(user=user)
team: Team = Team.objects.get(name="La Team Test")
event: Event = Event.objects.get(name="InsaLan Test")

trnm = event.get_tournaments()[0]

request = self.client.put(
f"/v1/tournament/team/{team.id}/",
{
"managers": [user.id],
},
format="json",
)

self.assertEquals(request.status_code, 200)

request = self.client.put(
f"/v1/tournament/team/{team.id}/",
{
"managers": [],
"players": [user.id],
},
format="json",
)

self.assertEquals(request.status_code, 200)

def test_cant_join_a_team_with_no_valid_email(self):
"""Try to join an existing team with no valid email"""
user: User = User.objects.get(username="invalidemail")
self.client.force_login(user=User.objects.get(username="invalidemail"))
team: Team = Team.objects.get(name="La Team Test")
event: Event = Event.objects.get(name="InsaLan Test")

trnm = event.get_tournaments()[0]

request = self.client.put(
f"/v1/tournament/team/{team.id}/",
{
"managers": [user.id],
},
format="json",
)

self.assertEquals(request.status_code, 403)

request = self.client.put(
f"/v1/tournament/team/{team.id}/",
{
"managers": [],
"players": [user.id],
},
format="json",
)

self.assertEquals(request.status_code, 403)

0 comments on commit f96716a

Please sign in to comment.