예제 #1
0
    def test_to_python(self):
        from eportfolio.views.validators import ImageUploadConverter

        validator = ImageUploadConverter()

        # Empty values
        result = validator._to_python(None, None)
        self.assertEqual(None, result)
예제 #2
0
 def test_to_python(self):
     from eportfolio.views.validators import ImageUploadConverter
     
     validator = ImageUploadConverter()
     
     # Empty values
     result = validator._to_python(None, None)
     self.assertEqual(None, result)
예제 #3
0
    def test_to_python_png(self):
        from eportfolio.views.validators import ImageUploadConverter
        from cgi import MiniFieldStorage

        validator = ImageUploadConverter()

        image_path = join(dirname(__file__), 'data', 'image.png')
        fd = open(image_path, 'rb')
        storage = MiniFieldStorage('image', 'image.png')
        storage.file = fd
        storage.filename = 'image.png'
        result = validator._to_python(storage, None)
        image = Image.open(result)
        # Image has been scaled
        # FIXME: why do we have 130 x 130 here
        self.assertEqual((130, 130), image.size)
        self.assertEqual('JPEG', image.format)
예제 #4
0
 def test_to_python_png(self):
     from eportfolio.views.validators import ImageUploadConverter
     from cgi import MiniFieldStorage
     
     validator = ImageUploadConverter()
     
     image_path = join(dirname(__file__), 'data', 'image.png')
     fd = open(image_path, 'rb')
     storage = MiniFieldStorage('image', 'image.png')
     storage.file = fd
     storage.filename = 'image.png'
     result = validator._to_python(storage, None)
     image = Image.open(result)
     # Image has been scaled 
     # FIXME: why do we have 130 x 130 here
     self.assertEqual((130, 130), image.size)
     self.assertEqual('JPEG', image.format)
예제 #5
0
class JournalEntrySchema(formencode.Schema):
    allow_extra_fields = True
    text = formencode.validators.UnicodeString(not_empty=True)
    indicators = formencode.ForEach(formencode.validators.String())
    image = ImageUploadConverter(if_missing=None)
    image_action = formencode.validators.OneOf(
        (u'nochange', u'delete', u'replace'),
        hideList=True,
        if_missing=u'nochange')
예제 #6
0
    def test_to_python_invalid(self):
        from eportfolio.views.validators import ImageUploadConverter
        from cgi import MiniFieldStorage

        validator = ImageUploadConverter()

        image_path = join(dirname(__file__), 'data', 'image.pdf')
        fd = open(image_path, 'rb')
        storage = MiniFieldStorage('image', 'image.pdf')
        storage.file = fd
        storage.filename = 'image.pdf'
        self.assertRaises(Invalid, validator._to_python, storage, None)