From bee9204d49f365afef2c13b627726a00b6b5a95d Mon Sep 17 00:00:00 2001 From: LuizaMaluf Date: Wed, 29 Nov 2023 10:23:16 -0300 Subject: [PATCH] feat(submission_page): submissions list tests --- apps/submissions/tests.py | 41 ++++++++++++++++++++++ apps/submissions/views.py | 9 ++++- server/urls.py | 1 + templates/submission/submission_list.html | 30 ---------------- templates/submissions/submission_list.html | 0 5 files changed, 50 insertions(+), 31 deletions(-) delete mode 100644 templates/submission/submission_list.html create mode 100644 templates/submissions/submission_list.html diff --git a/apps/submissions/tests.py b/apps/submissions/tests.py index fe42958..9fedc94 100644 --- a/apps/submissions/tests.py +++ b/apps/submissions/tests.py @@ -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 _ @@ -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"]) diff --git a/apps/submissions/views.py b/apps/submissions/views.py index 964f1f2..e715b2d 100644 --- a/apps/submissions/views.py +++ b/apps/submissions/views.py @@ -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" diff --git a/server/urls.py b/server/urls.py index c9f993e..2570b89 100644 --- a/server/urls.py +++ b/server/urls.py @@ -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")), ] diff --git a/templates/submission/submission_list.html b/templates/submission/submission_list.html deleted file mode 100644 index 67dcb99..0000000 --- a/templates/submission/submission_list.html +++ /dev/null @@ -1,30 +0,0 @@ -{% extends "base.html" %} - -{% block title %}Lista de Submissões{% endblock title %} - -{% block content %} -
-

Lista de Submissões

- -
- {% for submission in submissions %} -
-
- - Submissão #{{ submission.id }} - - - Autor: {{ submission.author.username }} - - - Status: {{ submission.get_status_display }} - -
-
-

Tarefa: {{ submission.task.title }}

-
-
- {% endfor %} -
-
-{% endblock content %} diff --git a/templates/submissions/submission_list.html b/templates/submissions/submission_list.html new file mode 100644 index 0000000..e69de29