1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
import unittest
from django.core.files.uploadedfile import SimpleUploadedFile
from django.test import TestCase
from ..forms import ResourceCreateForm
from ..models import ResourceCategory
from ..models import ResourceType
@unittest.skip("Skipping this test for now as it is broken")
class ResourceCreateFormTest(TestCase):
def setUp(self):
self.resource_type = ResourceType.objects.create(name="Test Resource Type")
self.resource_category = ResourceCategory.objects.create(name="Test Resource Category")
def test_clean_pdf_files_validation_error(self):
# Create a list of dummy PDF files
pdf_files = [
SimpleUploadedFile(f"file{i}.pdf", b"file_content", content_type="application/pdf")
for i in range(11)
]
# Create a list of dummy thumbnail files
thumbnail_files = [
SimpleUploadedFile(
f"thumbnail{i}.jpg",
b"thumbnail_content",
content_type="image/jpeg",
)
for i in range(6)
]
# Create a form instance with the dummy PDF files and thumbnail files
form_data = {
"name": "Test Resource",
"description": "Test Description",
"resource_type": self.resource_type.id,
"age_range": "5-7",
"curriculum": "English",
"main_resource_category": self.resource_category.id,
}
form_files = {
"pdf_files": pdf_files,
"thumbnail_files": thumbnail_files,
}
form = ResourceCreateForm(data=form_data, files=form_files)
# Validate the form
is_valid = form.is_valid()
# Check if the validation errors are raised for pdf_files and thumbnail_files
self.assertFalse(is_valid)
self.assertIn("pdf_files", form.errors)
self.assertEqual(form.errors["pdf_files"], ["Please select up to 10 PDF files."])
self.assertIn("thumbnail_files", form.errors)
self.assertEqual(
form.errors["thumbnail_files"],
["Please select up to 5 thumbnail files."],
)
|