コード例 #1
0
ファイル: test_models.py プロジェクト: bartjkdp/signals
    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")
コード例 #2
0
ファイル: test_models.py プロジェクト: bartjkdp/signals
    def test_cache_file_without_mimetype(self):
        with open(self.json_upload_location, "rb") as f:
            doc_upload = SimpleUploadedFile("upload.json", f.read(),
                                            content_type="application/json")

            attachment = Attachment()
            attachment.file = doc_upload
            attachment._signal = self.signal
            attachment.save()

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

        self.assertEqual("application/json", attachment.mimetype, "Mimetype should be set "
                                                                  "automatically when not set "
                                                                  "explicitly")

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