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."], )