Skip to content

Fix removing round removes problems #521

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion oioioi/contests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ class ProblemInstance(models.Model):
on_delete=models.CASCADE,
)
round = models.ForeignKey(
Round, verbose_name=_("round"), null=True, blank=True, on_delete=models.CASCADE
Round, verbose_name=_("round"), null=True, blank=True, on_delete=models.SET_NULL
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add missing migration

)
problem = models.ForeignKey(
'problems.Problem', verbose_name=_("problem"), on_delete=models.CASCADE
Expand Down
34 changes: 34 additions & 0 deletions oioioi/contests/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3397,6 +3397,40 @@ def test_modify_contest(self):
self.assertNotContains(response, "Judging priority")
self.assertNotContains(response, "Judging weight")

class TestRemovingRoundDoesNotRemoveProblems(TestCase):
fixtures = [
'test_contest',
'test_full_package',
'test_problem_instance',
'test_problem_site',
]

def test_removing_round_does_not_remove_problems(self):
# Only one ProblemInstance
prev_num_problems = ProblemInstance.objects.all().count()
self.assertEqual(prev_num_problems, 1)

round = Round.objects.get()
# This ProblemInstance is assigned to the only round
self.assertEqual(ProblemInstance.objects.filter(round=round).count(), 1)

problem = ProblemInstance.objects.get(round=round)

# Delete the round
round.delete()
self.assertEqual(Round.objects.count(), 0)

problems = ProblemInstance.objects.all()

# Make sure no problems have been deleted
self.assertEqual(problems.count(), prev_num_problems)

# We have to fetch the ProblemInstance again to make sure we
# don't have a previous cached version.
problem.refresh_from_db()

# Make sure the foreign key is NULL
self.assertTrue(problem.round is None)

class TestRegistrationController(TestCase):
fixtures = ['test_two_empty_contests', 'test_users']
Expand Down
Loading