def test_resize_exception_is_handled(self):
        with HTTMock(image_url_mock):
            with self.assertRaises(Exception) as io_error:
                resize('test.jpg')

        self.assertEqual(io_error.exception.message,
                         u'The image file couldn\'t be identified')
 def handle(self, *args, **options):
     attachments_qs = Attachment.objects.select_related(
         'instance', 'instance__xform')
     if options.get('username'):
         username = options.get('username')
         try:
             user = User.objects.get(username=username)
         except User.DoesNotExist:
             raise CommandError(
                 "Error: username %(username)s does not exist" %
                 {'username': username})
         attachments_qs = attachments_qs.filter(instance__user=user)
     if options.get('id_string'):
         id_string = options.get('id_string')
         try:
             xform = XForm.objects.get(id_string=id_string)
         except XForm.DoesNotExist:
             raise CommandError(
                 "Error: Form with id_string %(id_string)s does not exist" %
                 {'id_string': id_string})
         attachments_qs = attachments_qs.filter(instance__xform=xform)
     fs = get_storage_class('django.core.files.storage.FileSystemStorage')()
     for att in queryset_iterator(attachments_qs):
         filename = att.media_file.name
         default_storage = get_storage_class()()
         full_path = get_path(filename,
                              settings.THUMB_CONF['small']['suffix'])
         if options.get('force') is not None:
             for s in ['small', 'medium', 'large']:
                 fp = get_path(filename, settings.THUMB_CONF[s]['suffix'])
                 if default_storage.exists(fp):
                     default_storage.delete(fp)
         if not default_storage.exists(full_path):
             try:
                 if default_storage.__class__ != fs.__class__:
                     resize(filename, att.extension)
                 else:
                     resize_local_env(filename, att.extension)
                 path = get_path(
                     filename, '%s' % THUMB_CONF['small']['suffix'])
                 if default_storage.exists(path):
                     self.stdout.write(
                         _(u'Thumbnails created for %(file)s') %
                         {'file': filename})
                 else:
                     self.stdout.write(
                         _(u'Problem with the file %(file)s') %
                         {'file': filename})
             except (IOError, OSError) as e:
                 self.stderr.write(_(
                     u'Error on %(filename)s: %(error)s')
                     % {'filename': filename, 'error': e})