Esempio n. 1
0
    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)
Esempio n. 2
0
    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()
Esempio n. 3
0
    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')
Esempio n. 4
0
    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)