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): add test
Browse files Browse the repository at this point in the history
  • Loading branch information
HladczukLe committed Dec 10, 2023
1 parent 587c982 commit 1d2974a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
22 changes: 21 additions & 1 deletion apps/tasks/tests.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
import os
from datetime import timedelta
from io import BytesIO
from typing import cast

from django.contrib.admin.sites import AdminSite
from django.core.files.uploadedfile import (
InMemoryUploadedFile,
SimpleUploadedFile,
UploadedFile,
)
from django.test import TestCase
from django.test.client import RequestFactory
from django.urls import resolve, reverse
from django.utils import timezone
from django.utils.datastructures import MultiValueDict

from apps.contests.models import Contest
from apps.submissions.forms import SubmissionForm
from apps.submissions.forms import SubmissionForm, UploadFileForm
from apps.submissions.models import Submission, SubmissionStatus
from apps.tasks.admin import TaskAdmin, TaskModelForm
from apps.tasks.models import Task
Expand Down Expand Up @@ -540,6 +543,23 @@ def test_handle_uploaded_file(self) -> None:
content = file.read()
self.assertEqual(content, file_content)

def test_upload_file_form_valid(self) -> None:
file_content = b"Test file content"

uploaded_file = SimpleUploadedFile("test_file.txt", file_content)

form_data = {"title": "Test Title"}
files_data = MultiValueDict(
{"file": [cast(UploadedFile, uploaded_file)]}
)

form = UploadFileForm(data=form_data, files=files_data)

if not form.is_valid():
print(form.errors)

self.assertTrue(form.is_valid())


class BackgroundJobTaskTest(TestCase):
def setUp(self) -> None:
Expand Down
1 change: 1 addition & 0 deletions apps/tasks/uploads/test_file.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Test file content

0 comments on commit 1d2974a

Please sign in to comment.