Skip to content

Commit

Permalink
Add tests for started tournaments
Browse files Browse the repository at this point in the history
  • Loading branch information
kostrykin committed Jan 29, 2024
1 parent 0489f65 commit 72040a0
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tournaments/frontend/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,17 @@ def test(self):
self.assertTrue(self.user1_tournament.published)


def start_tournament(tournament):
if not tournament.published:
tournament.published = True
tournament.save()
users = [models.User.objects.create(username = f'user{idx}') for idx in range(10)]
for user in users:
models.Participation.objects.create(tournament = tournament, user = user, slot_id = models.Participation.next_slot_id(tournament))
tournament.update_state()
assert tournament.state == 'active'


class DraftTournamentViewTests(TestCase):

def setUp(self):
Expand Down Expand Up @@ -358,6 +369,11 @@ def test_drafted(self):
response = self.client.get(reverse('draft-tournament', kwargs = dict(pk = self.user1_tournament.id)))
self.assertEqual(response.status_code, 412)

def test_active(self):
start_tournament(self.user1_tournament)
response = self.client.get(reverse('draft-tournament', kwargs = dict(pk = self.user1_tournament.id)))
self.assertEqual(response.status_code, 412)

def test(self):
response = self.client.get(reverse('draft-tournament', kwargs = dict(pk = self.user1_tournament.id)), follow = True)
self.assertEqual(response.status_code, 200)
Expand Down Expand Up @@ -403,6 +419,11 @@ def test_published(self):
response = self.client.get(reverse('delete-tournament', kwargs = dict(pk = self.user1_tournament.id)))
self.assertEqual(response.status_code, 412)

def test_active(self):
start_tournament(self.user1_tournament)
response = self.client.get(reverse('delete-tournament', kwargs = dict(pk = self.user1_tournament.id)))
self.assertEqual(response.status_code, 412)

def test(self):
response = self.client.get(reverse('delete-tournament', kwargs = dict(pk = self.user1_tournament.id)), follow = True)
self.assertEqual(response.status_code, 200)
Expand Down Expand Up @@ -443,6 +464,11 @@ def test_drafted(self):
response = self.client.get(reverse('join-tournament', kwargs = dict(pk = self.user1_tournament.id)), follow = True)
self.assertEqual(response.status_code, 412)

def test_active(self):
start_tournament(self.user1_tournament)
response = self.client.get(reverse('join-tournament', kwargs = dict(pk = self.user1_tournament.id)))
self.assertEqual(response.status_code, 412)

def test_joined(self):
self.test()
self.test()
Expand Down Expand Up @@ -491,6 +517,11 @@ def test_drafted(self):
response = self.client.get(reverse('withdraw-tournament', kwargs = dict(pk = self.user1_tournament.id)), follow = True)
self.assertEqual(response.status_code, 412)

def test_active(self):
start_tournament(self.user1_tournament)
response = self.client.get(reverse('withdraw-tournament', kwargs = dict(pk = self.user1_tournament.id)))
self.assertEqual(response.status_code, 412)

def test_withdrawn(self):
self.test()
self.test()
Expand Down

0 comments on commit 72040a0

Please sign in to comment.