Example #1
0
    def test_accepted_types_field(self):

        accepted_types = ['image/bmp','image/jpg', 'image/png']
        field = RestrictedTypeFileField(accepted_types=accepted_types)

        f = File(open(os.path.join(os.path.abspath(os.path.dirname(__file__)), '__init__.py')))
        f.content_type = 'image/bmp'
        data = type("",(object,),dict(file=f, accepted_types=accepted_types))

        self.assertEquals(field.clean(data, {}).file, f)
Example #2
0
    def test_no_accepted_types_field(self):

        field = RestrictedTypeFileField()

        f = File(open(os.path.join(os.path.abspath(os.path.dirname(__file__)), '__init__.py')))
        f.content_type = 'image/bmp'
        data = type("",(object,),dict(file=f))

        with self.assertRaises(forms.ValidationError):
            field.clean(data, None)