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
|
from django.core.files.uploadedfile import SimpleUploadedFile
from django.test import TestCase
from django.utils.datastructures import MultiValueDict
from pyblackbird_cc.resources.forms import ResourceCreateForm
from pyblackbird_cc.resources.models import ResourceCategory
from pyblackbird_cc.resources.models import ResourceType
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")
self.form_data = {
"name": "Test Resource",
"description": "Test Description",
"resource_type": self.resource_type.id,
"age_range": "5-7",
"curriculum": "English",
"feature_slot": 1,
"main_resource_category": self.resource_category.id,
}
self.pdf_files = [
SimpleUploadedFile(f"file{i}.pdf", b"file_content", content_type="application/pdf")
for i in range(11)
]
self.thumbnail_files = [
SimpleUploadedFile(
f"thumbnail{i}.jpg",
b"thumbnail_content",
content_type="image/jpeg",
)
for i in range(6)
]
# This needs to be a MultiValueDict for the test to mimic production code
# see clean_pdf_files - self.files.getlist()
self.form_files = MultiValueDict(
{"pdf_files": self.pdf_files, "thumbnail_files": self.thumbnail_files},
)
def test_form_valid(self):
# Create a list of dummy thumbnail files
form = ResourceCreateForm(data=self.form_data, files=self.form_files)
is_valid = form.is_valid()
|