Example #1
0
    def test_cmyk_to_rgb(self):
        def tests():
            img_200x200_cmyk = create_test_image(200, 200, c='CMYK')
            f_200x200_jpeg_cmyk = get_img_file(img_200x200_cmyk)
            t = adjust_image(f_200x200_jpeg_cmyk, return_new_image=True)
            self.assertIsInstance(t,
                                  (cStringIO.InputType, cStringIO.OutputType))
            self.assertEqual(Image.open(t).mode, 'RGB')

            img_200x200_p = create_test_image(200, 200, c='P')
            f_200x200_png_p = get_img_file(img_200x200_p, img_format='PNG')
            t = adjust_image(f_200x200_png_p,
                             new_format='JPEG',
                             return_new_image=True)
            self.assertIsInstance(t,
                                  (cStringIO.InputType, cStringIO.OutputType))
            self.assertEqual(Image.open(t).mode, 'RGB')

        with safe_change_dju_settings():
            dju_settings.DJU_IMG_CONVERT_JPEG_TO_RGB = True
            tests()

        with safe_change_dju_settings():
            dju_settings.DJU_IMG_CONVERT_JPEG_TO_RGB = False
            tests()
Example #2
0
    def test_cmyk_to_rgb(self):
        def tests():
            img_200x200_cmyk = create_test_image(200, 200, c="CMYK")
            f_200x200_jpeg_cmyk = get_img_file(img_200x200_cmyk)
            t = adjust_image(f_200x200_jpeg_cmyk, return_new_image=True)
            self.assertIsInstance(t, (cStringIO.InputType, cStringIO.OutputType))
            self.assertEqual(Image.open(t).mode, "RGB")

            img_200x200_p = create_test_image(200, 200, c="P")
            f_200x200_png_p = get_img_file(img_200x200_p, img_format="PNG")
            t = adjust_image(f_200x200_png_p, new_format="JPEG", return_new_image=True)
            self.assertIsInstance(t, (cStringIO.InputType, cStringIO.OutputType))
            self.assertEqual(Image.open(t).mode, "RGB")

        with safe_change_dju_settings():
            dju_settings.DJU_IMG_CONVERT_JPEG_TO_RGB = True
            tests()

        with safe_change_dju_settings():
            dju_settings.DJU_IMG_CONVERT_JPEG_TO_RGB = False
            tests()
Example #3
0
 def test_upload_image_wrong_image_format(self):
     with safe_change_dju_settings():
         dju_settings.DJU_IMG_UPLOAD_PROFILE_DEFAULT['TYPES'] = ('PNG',)
         clear_profile_configs_cache()
         f = get_img_file(create_test_image(1000, 1000))
         r = self.client.post(self.upload_url, {'images[]': [f]})
         self.assertEqual(r.status_code, 200)
         d = self.get_json(r)
         self.assertEqual(len(d['uploaded']), 0)
         self.assertEqual(len(d['errors']), 1)
         self.assertEqual(
             d['errors'][0],
             unicode(VIEWS_ERRORS['wrong_file_format']) % {
                 'name': 'images[]',
                 'formats': ', '.join(map(lambda t: t.upper(), dju_settings.DJU_IMG_UPLOAD_PROFILE_DEFAULT['TYPES']))
             }
         )
Example #4
0
 def test_upload_image_wrong_image_format(self):
     with safe_change_dju_settings():
         dju_settings.DJU_IMG_UPLOAD_PROFILE_DEFAULT['TYPES'] = ('PNG', )
         clear_profile_configs_cache()
         f = get_img_file(create_test_image(1000, 1000))
         r = self.client.post(self.upload_url, {'images[]': [f]})
         self.assertEqual(r.status_code, 200)
         d = self.get_json(r)
         self.assertEqual(len(d['uploaded']), 0)
         self.assertEqual(len(d['errors']), 1)
         self.assertEqual(
             d['errors'][0],
             unicode(VIEWS_ERRORS['wrong_file_format']) % {
                 'name':
                 'images[]',
                 'formats':
                 ', '.join(
                     map(
                         lambda t: t.upper(), dju_settings.
                         DJU_IMG_UPLOAD_PROFILE_DEFAULT['TYPES']))
             })