def test_image_upload(self): form_data = {"title": "test", "text": "this is a test"} form = NewNoteForm(form_data) form.picture = File(open("lmn/tests/test2.jpg")) form.save() self.assertIsNotNone(form.picture)
def test_image_size(self): form_data = {"title": "test", "text": "this is a test"} form = NewNoteForm(form_data) form.picture = File(open("lmn/tests/test1.jpg")) with self.assertRaises(ValidationError): form.save()
def test_wrong_file_type_upload(self): form_data = {"title": "test", "text": "this is a test"} form = NewNoteForm(form_data) form.picture = File(open("testFile.txt", "w")) with self.assertRaises(ValidationError): form.save() os.remove('testFile.txt')
def test_upload_of_multiple_images(self): test_picture = File(open("lmn/tests/test3.jpg")) form_data = {"title": "test", "text": "this is a test"} form = NewNoteForm(form_data) form.picture = File(open("lmn/tests/test2.jpg")) form.picture = File(open("lmn/tests/test3.jpg")) form.save() self.assertEqual(form.picture.file, test_picture.file)