From daf9017b44f6363c42cda581da54083ec8799100 Mon Sep 17 00:00:00 2001 From: thegm445 Date: Fri, 1 Dec 2023 21:55:36 -0300 Subject: [PATCH] test(apps/tasks): new tests added --- apps/tasks/tests.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/apps/tasks/tests.py b/apps/tasks/tests.py index 2ebdbcd..f28eaea 100644 --- a/apps/tasks/tests.py +++ b/apps/tasks/tests.py @@ -200,6 +200,7 @@ def setUp(self) -> None: description="Some example task", score=200, contest=self.contest, + output_file="Hello, World!\n", ) self.user = User._default_manager.create( @@ -322,6 +323,50 @@ def test_handle_submission_with_wrong_output(self) -> None: fetch_redirect_response=True, ) + def test_submission_with_AC_status_increases_user_score(self) -> None: + handle_submission( + self.submission.code, self.task.id, self.submission.id + ) + + self.submission.refresh_from_db() + self.user.refresh_from_db() + + self.assertEqual(self.submission.status, SubmissionStatus.ACCEPTED) + self.assertEqual(self.user.score, self.task.score) + + def test_submission_with_non_AC_status_does_not_increase_user_score( + self, + ) -> None: + self.submission.code = 'print("Hello, Word")' + + handle_submission( + self.submission.code, self.task.id, self.submission.id + ) + + self.user.refresh_from_db() + + self.assertEqual(self.user.score, 0) + + def test_second_AC_submission_does_not_increase_user_score(self) -> None: + handle_submission( + self.submission.code, self.task.id, self.submission.id + ) + + second_submission = Submission._default_manager.create( + author=self.user, + task=self.task, + code="print('Hello, World!')", + status=SubmissionStatus.WAITING_JUDGE, + ) + + handle_submission.apply( + args=(second_submission.code, self.task.id, second_submission.id) + ) + + self.user.refresh_from_db() + + self.assertEqual(self.user.score, self.task.score) + def test_form_success_url(self) -> None: self.assertEqual(self.view.get_success_url(), self.url)