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

Commit

Permalink
feat(submission_page): submissions list tests
Browse files Browse the repository at this point in the history
  • Loading branch information
LuizaMaluf committed Nov 29, 2023
1 parent a47836d commit bee9204
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 31 deletions.
41 changes: 41 additions & 0 deletions apps/submissions/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from django.contrib.admin.sites import AdminSite
from django.core.exceptions import ValidationError
from django.test import TestCase
from django.urls import reverse
from django.utils import timezone
from django.utils.translation import gettext as _

Expand Down Expand Up @@ -94,3 +95,43 @@ def test_fieldsets(self) -> None:
(_("Details"), {"fields": ("author", "task", "code", "status")})
]
self.assertEqual(self.submission_admin.fieldsets, expected)


class SubmissionListView(TestCase):
def setUp(self) -> None:
self.user = User.objects.create_user(
username="testuser",
email="testuser@example",
password="testpassword",
)

self.contest = Contest._default_manager.create(
title="Test Contest",
description="This is a test contest",
start_time=timezone.now(),
end_time=timezone.now() + timedelta(hours=1),
cancelled=False,
)

self.task = Task._default_manager.create(
title="Test Task",
description="This is a test task",
contest=self.contest,
)

self.submission = Submission._default_manager.create(
author=self.user,
task=self.task,
code="test code",
)

def test_submission_list_view(self) -> None:
self.client.login(email="testuser@example", password="testpassword")

url = reverse("submission_list")

response = self.client.get(url)

self.assertEqual(response.status_code, 200)
self.assertTrue("submissions" in response.context)
self.assertIn(self.submission, response.context["submissions"])
9 changes: 8 additions & 1 deletion apps/submissions/views.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
from typing import TYPE_CHECKING

from django.views.generic import ListView

from apps.submissions.models import Submission

if TYPE_CHECKING:
SubmissionViewBase = ListView[Submission]
else:
SubmissionViewBase = ListView


class SubmissionListView(ListView[Submission]):
class SubmissionListView(SubmissionViewBase):
model = Submission
template_name = "submission_list.html"
context_object_name = "submissions"
1 change: 1 addition & 0 deletions server/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@
path("contests/", include("apps.contests.urls"), name="contests"),
path("tasks/", include("apps.tasks.urls")),
path("", include("apps.users.urls")),
path("submissions/", include("apps.submissions.urls")),
]
30 changes: 0 additions & 30 deletions templates/submission/submission_list.html

This file was deleted.

Empty file.

0 comments on commit bee9204

Please sign in to comment.