예제 #1
0
    def test_is_image_gif(self):
        attachment = Attachment()
        attachment.file = self.gif_upload
        attachment._signal = self.signal
        attachment.mimetype = "image/gif"
        attachment.save()

        self.assertTrue(attachment.is_image)
예제 #2
0
    def test_is_image_doc_renamed_to_gif(self):
        with open(self.doc_upload_location, "rb") as f:
            doc_upload = SimpleUploadedFile("file.gif",
                                            f.read(),
                                            content_type="application/msword")

            attachment = Attachment()
            attachment.file = doc_upload
            attachment.mimetype = "application/msword"
            attachment._signal = self.signal
            attachment.save()

            self.assertFalse(attachment.is_image)
예제 #3
0
    def test_cache_file_with_word_doc(self):
        with open(self.doc_upload_location, "rb") as f:
            doc_upload = SimpleUploadedFile("file.doc", f.read(), content_type="application/msword")

            attachment = Attachment()
            attachment.file = doc_upload
            attachment.mimetype = "application/msword"
            attachment._signal = self.signal
            attachment.save()

        with self.assertRaises(Attachment.NotAnImageException):
            attachment.image_crop()

        resp = requests.get(self.live_server_url + attachment.file.url)
        self.assertEqual(200, resp.status_code, "Original file is not reachable")
예제 #4
0
    def test_cropping_image_cache_file(self):
        attachment = Attachment()
        attachment.file = self.gif_upload
        attachment._signal = self.signal
        attachment.mimetype = "image/gif"
        attachment.save()

        self.assertIsInstance(attachment.image_crop.url, str)
        self.assertTrue(attachment.image_crop.url.endswith(".jpg"))

        resp = requests.get(self.live_server_url + attachment.file.url)
        self.assertEqual(200, resp.status_code, "Original image is not reachable")

        resp = requests.get(self.live_server_url + attachment.image_crop.url)
        self.assertEqual(200, resp.status_code, "Cropped image is not reachable")