Skip to content

Commit

Permalink
Fix to make tests pass
Browse files Browse the repository at this point in the history
  • Loading branch information
kostrykin committed Feb 1, 2024
1 parent f926ffb commit 7c6d43b
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 16 deletions.
4 changes: 2 additions & 2 deletions tournaments/frontend/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ def test_open(self):
self.assertContains(response, '<h2>Preliminaries <small class="text-muted">Current Stage</small></h2>')

def test_post_open(self):
fixture = models.Fixture.objects.create(mode = self.tournament1.stages.all()[0], level = 0, position = 0)
fixture = models.Fixture.objects.create(mode = self.tournament1.stages.all()[0], level = 0)
response = self.client.post(
reverse('tournament-progress', kwargs = dict(pk = self.tournament1.id)),
dict(
Expand Down Expand Up @@ -726,7 +726,7 @@ def test_post_wrong_stage(self):
self.test_open() ## start the tournament
self.client.force_login(self.users[0])
next_stage = self.tournament1.stages.all()[1]
fixture = models.Fixture.objects.create(mode = next_stage, level = 0, position = 0)
fixture = models.Fixture.objects.create(mode = next_stage, level = 0)
response = self.client.post(
reverse('tournament-progress', kwargs = dict(pk = self.tournament1.id)),
dict(
Expand Down
2 changes: 1 addition & 1 deletion tournaments/frontend/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ def post(self, request, *args, **kwargs):
try:
fixture.full_clean()
except ValidationError as error:
request.session['alert'] = dict(status = 'danger', text = error)
request.session['alert'] = dict(status = 'danger', text = str(error))
return redirect('tournament-progress', pk = self.object.id)

fixture.save()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name='fixture',
name='extras',
field=models.JSONField(default=list),
field=models.JSONField(blank=True, default=list),
),
migrations.RunPython(migrate_position_to_extras),
migrations.RemoveField(
Expand Down
21 changes: 10 additions & 11 deletions tournaments/tournaments/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def unwrap_list(items):
class Mode(PolymorphicModel):

identifier = models.SlugField()
name = models.CharField(max_length = 100, blank = True)
name = models.CharField(max_length = 100, blank = True)
tournament = models.ForeignKey('Tournament', on_delete = models.CASCADE, related_name = 'stages')
played_by = models.JSONField(default = list, blank = True)

Expand Down Expand Up @@ -456,7 +456,6 @@ def create_fixtures(self, participants):
Fixture.objects.create(
mode = self,
level = level,
position = position,
player1 = group[pidx1],
player2 = group[pidx2],
)
Expand Down Expand Up @@ -547,17 +546,17 @@ def create_fixtures(self, participants):
player2 = None if fixture_path * 2 < last_fixture_path else remaining_participants.pop()

Fixture.objects.create(
mode = self,
level = level,
position = fixture_path,
player1 = player1,
player2 = player2)
mode = self,
level = level,
extras = dict(position = fixture_path),
player1 = player1,
player2 = player2)

assert len(remaining_participants) == 0, remaining_participants

def get_parent_fixture(self, fixture):
if fixture.position == 1: return None
return self.fixtures.get(position = fixture.position // 2)
if fixture.extras['position'] == 1: return None
return self.fixtures.get(extras = dict(position = fixture.extras['position'] // 2))

def propagate(self, fixture):
assert fixture.mode.id == self.id
Expand All @@ -569,7 +568,7 @@ def propagate(self, fixture):
return False

# Propagate to either side of the parent fixture.
if fixture.position % 2 == 0:
if fixture.extras['position'] % 2 == 0:
if parent_fixture.player1 is not None:
return False
parent_fixture.player1 = fixture.winner
Expand Down Expand Up @@ -618,7 +617,7 @@ class Fixture(models.Model):

mode = models.ForeignKey('Mode', on_delete = models.CASCADE, related_name = 'fixtures')
level = models.PositiveSmallIntegerField()
extras = models.JSONField(default = list)
extras = models.JSONField(default = list, blank = True)
player1 = models.ForeignKey('auth.User', on_delete = models.PROTECT, related_name = 'fixtures1', null = True)
player2 = models.ForeignKey('auth.User', on_delete = models.PROTECT, related_name = 'fixtures2', null = True)
score1 = models.PositiveSmallIntegerField(null = True)
Expand Down
2 changes: 1 addition & 1 deletion tournaments/tournaments/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -952,7 +952,7 @@ def setUp(self):
password = 'password')
for user_idx in range(2)
]
self.fixture = Fixture.objects.create(mode = self.knockout, level = 0, position = 0, player1 = self.players[0], player2 = self.players[1])
self.fixture = Fixture.objects.create(mode = self.knockout, level = 0, player1 = self.players[0], player2 = self.players[1])

def test_score(self):
self.assertEqual(self.fixture.score, (None, None))
Expand Down

0 comments on commit 7c6d43b

Please sign in to comment.