Skip to content
This repository has been archived by the owner on Jan 3, 2024. It is now read-only.

Commit

Permalink
test(apps/tasks): new tests added
Browse files Browse the repository at this point in the history
  • Loading branch information
thegm445 committed Dec 2, 2023
1 parent 5bf5d80 commit daf9017
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions apps/tasks/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit daf9017

Please sign in to comment.