<s> from __future__ import division <EOL> from __future__ import unicode_literals <EOL> from functools import reduce <EOL> import math <EOL> import operator <EOL> import os <EOL> from shutil import rmtree <EOL> from django import VERSION as DJANGO_VERSION <EOL> from django . conf import settings <EOL> from django . contrib . auth . models import User <EOL> from django . core . cache import cache <EOL> from django . core . exceptions import ImproperlyConfigured , ValidationError <EOL> from django . core . files import File <EOL> from django . core . files . uploadedfile import SimpleUploadedFile <EOL> from django . core import serializers <EOL> from django . template import Context <EOL> from django . template . loader import get_template <EOL> from django . test import Client , TestCase <EOL> from django . test . utils import override_settings <EOL> from django . utils . _os import upath <EOL> from django . utils import six <EOL> from django . utils . six . moves import cPickle <EOL> from PIL import Image <EOL> from rest_framework . test import APIRequestFactory <EOL> from versatileimagefield . files import VersatileImageFileDescriptor <EOL> from versatileimagefield . datastructures . filteredimage import InvalidFilter <EOL> from versatileimagefield . datastructures . sizedimage import MalformedSizedImageKey , SizedImage <EOL> from versatileimagefield . datastructures . filteredimage import FilteredImage <EOL> from versatileimagefield . image_warmer import VersatileImageFieldWarmer <EOL> from versatileimagefield . registry import ( <EOL> autodiscover , <EOL> versatileimagefield_registry , <EOL> AlreadyRegistered , <EOL> InvalidSizedImageSubclass , <EOL> InvalidFilteredImageSubclass , <EOL> NotRegistered , <EOL> UnallowedSizerName , <EOL> UnallowedFilterName <EOL> ) <EOL> from versatileimagefield . settings import ( <EOL> VERSATILEIMAGEFIELD_SIZED_DIRNAME , <EOL> VERSATILEIMAGEFIELD_FILTERED_DIRNAME , <EOL> VERSATILEIMAGEFIELD_PLACEHOLDER_DIRNAME <EOL> ) <EOL> from versatileimagefield . utils import ( <EOL> get_rendition_key_set , <EOL> InvalidSizeKey , <EOL> InvalidSizeKeySet <EOL> ) <EOL> from versatileimagefield . validators import validate_ppoi_tuple <EOL> from versatileimagefield . versatileimagefield import CroppedImage , InvertImage <EOL> from . forms import ( <EOL> VersatileImageTestModelForm , <EOL> VersatileImageWidgetTestModelForm , <EOL> VersatileImageTestModelFormDjango15 <EOL> ) <EOL> from . models import VersatileImageTestModel , VersatileImageWidgetTestModel <EOL> from . serializers import VersatileImageTestModelSerializer <EOL> ADMIN_URL = '<STR_LIT>' <EOL> if DJANGO_VERSION [ <NUM_LIT:0> ] == <NUM_LIT:1> and DJANGO_VERSION [ <NUM_LIT:1> ] >= <NUM_LIT:9> : <EOL> ADMIN_URL = '<STR_LIT>' <EOL> class VersatileImageFieldBaseTestCase ( TestCase ) : <EOL> @ classmethod <EOL> def tearDownClass ( cls ) : <EOL> """<STR_LIT>""" <EOL> filtered_path = os . path . join ( <EOL> settings . MEDIA_ROOT , <EOL> VERSATILEIMAGEFIELD_FILTERED_DIRNAME <EOL> ) <EOL> sized_path = os . path . join ( <EOL> settings . MEDIA_ROOT , <EOL> VERSATILEIMAGEFIELD_SIZED_DIRNAME <EOL> ) <EOL> placeholder_path = os . path . join ( <EOL> settings . MEDIA_ROOT , <EOL> VERSATILEIMAGEFIELD_PLACEHOLDER_DIRNAME <EOL> ) <EOL> rmtree ( filtered_path , ignore_errors = True ) <EOL> rmtree ( sized_path , ignore_errors = True ) <EOL> rmtree ( placeholder_path , ignore_errors = True ) <EOL> def assert_VersatileImageField_deleted ( self , field_instance ) : <EOL> """<STR_LIT>""" <EOL> img_url = field_instance . crop [ '<STR_LIT>' ] . url <EOL> self . assertEqual ( <EOL> cache . get ( img_url ) , <EOL> None <EOL> ) <EOL> field_instance . create_on_demand = True <EOL> field_instance . crop [ '<STR_LIT>' ] . url <EOL> self . assertEqual ( <EOL> cache . get ( img_url ) , <EOL> <NUM_LIT:1> <EOL> ) <EOL> print ( field_instance . crop [ '<STR_LIT>' ] . name ) <EOL> self . assertTrue ( <EOL> field_instance . field . storage . exists ( <EOL> field_instance . crop [ '<STR_LIT>' ] . name <EOL> ) <EOL> ) <EOL> print ( field_instance . crop [ '<STR_LIT>' ] . name ) <EOL> field_instance . field . storage . delete ( <EOL> field_instance . crop [ '<STR_LIT>' ] . name <EOL> ) <EOL> self . assertFalse ( <EOL> field_instance . field . storage . exists ( <EOL> field_instance . crop [ '<STR_LIT>' ] . name <EOL> ) <EOL> ) <EOL> print ( img_url ) <EOL> cache . delete ( img_url ) <EOL> self . assertEqual ( <EOL> cache . get ( img_url ) , <EOL> None <EOL> ) <EOL> class VersatileImageFieldTestCase ( VersatileImageFieldBaseTestCase ) : <EOL> fixtures = [ '<STR_LIT>' ] <EOL> def setUp ( self ) : <EOL> self . jpg = VersatileImageTestModel . objects . get ( img_type = '<STR_LIT>' ) <EOL> self . png = VersatileImageTestModel . objects . get ( img_type = '<STR_LIT>' ) <EOL> self . gif = VersatileImageTestModel . objects . get ( img_type = '<STR_LIT>' ) <EOL> self . delete_test = VersatileImageTestModel . objects . get ( <EOL> img_type = '<STR_LIT>' <EOL> ) <EOL> self . widget_test = VersatileImageWidgetTestModel . objects . get ( pk = <NUM_LIT:1> ) <EOL> password = '<STR_LIT>' <EOL> user = User . objects . create_user ( <EOL> username = '<STR_LIT:test>' , <EOL> email = '<STR_LIT>' , <EOL> password = password <EOL> ) <EOL> user . is_active = True <EOL> user . is_staff = True <EOL> user . is_superuser = True <EOL> user . save ( ) <EOL> client = Client ( ) <EOL> login = client . login ( <EOL> username = '<STR_LIT:test>' , <EOL> password = password <EOL> ) <EOL> self . assertTrue ( login ) <EOL> self . user = user <EOL> self . client = client <EOL> @ staticmethod <EOL> def imageEqual ( image1 , image2 ) : <EOL> """<STR_LIT>""" <EOL> h1 = image1 . histogram ( ) <EOL> h2 = image2 . histogram ( ) <EOL> rms = math . sqrt ( <EOL> reduce ( <EOL> operator . add , <EOL> map ( lambda a , b : ( a - b ) ** <NUM_LIT:2> , h1 , h2 ) <EOL> ) // len ( h1 ) <EOL> ) <EOL> return rms == <NUM_LIT:0.0> <EOL> def test_check_storage_paths ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( self . jpg . image . name , '<STR_LIT>' ) <EOL> self . assertEqual ( self . png . image . name , '<STR_LIT>' ) <EOL> self . assertEqual ( self . gif . image . name , '<STR_LIT>' ) <EOL> def test_thumbnail_resized_path ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( <EOL> self . jpg . image . thumbnail [ '<STR_LIT>' ] . url , <EOL> '<STR_LIT>' <EOL> ) <EOL> def test_crop_resized_path ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( <EOL> self . jpg . image . crop [ '<STR_LIT>' ] . url , <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assertEqual ( <EOL> self . gif . image . crop [ '<STR_LIT>' ] . url , <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assertEqual ( <EOL> self . png . image . crop [ '<STR_LIT>' ] . url , <EOL> '<STR_LIT>' <EOL> ) <EOL> def test_invert_filtered_path ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( <EOL> self . jpg . image . filters . invert . url , <EOL> '<STR_LIT>' <EOL> ) <EOL> def test_InvalidFilter ( self ) : <EOL> """<STR_LIT>""" <EOL> with self . assertRaises ( InvalidFilter ) : <EOL> invalid_filter = self . jpg . image . filters . non_existant . url <EOL> del invalid_filter <EOL> def test_invert_plus_thumbnail_sizer_filtered_path ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( <EOL> self . jpg . image . filters . invert . thumbnail [ '<STR_LIT>' ] . url , <EOL> ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> ) <EOL> def test_placeholder_image ( self ) : <EOL> """<STR_LIT>""" <EOL> self . jpg . optional_image . create_on_demand = True <EOL> self . assertEqual ( <EOL> self . jpg . optional_image . url , <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assertEqual ( <EOL> self . jpg . optional_image . crop [ '<STR_LIT>' ] . url , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assertEqual ( <EOL> self . jpg . optional_image . thumbnail [ '<STR_LIT>' ] . url , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assertEqual ( <EOL> self . jpg . optional_image . filters . invert . url , <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assertEqual ( <EOL> self . jpg . optional_image_2 . crop [ '<STR_LIT>' ] . url , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assertEqual ( <EOL> self . jpg . optional_image_2 . thumbnail [ '<STR_LIT>' ] . url , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assertEqual ( <EOL> self . jpg . optional_image_2 . filters . invert . url , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assertFalse ( <EOL> self . jpg . optional_image . field . storage . size ( <EOL> self . jpg . optional_image . name <EOL> ) is <NUM_LIT:0> <EOL> ) <EOL> self . jpg . optional_image . create_on_demand = False <EOL> def test_setting_ppoi_values ( self ) : <EOL> """<STR_LIT>""" <EOL> jpg = VersatileImageTestModel . objects . get ( img_type = '<STR_LIT>' ) <EOL> self . assertEqual ( <EOL> jpg . image . ppoi , <EOL> ( <NUM_LIT> , <NUM_LIT> ) <EOL> ) <EOL> jpg . image . ppoi = ( <NUM_LIT:0.5> , <NUM_LIT:0.5> ) <EOL> jpg . save ( ) <EOL> self . assertEqual ( <EOL> jpg . image . ppoi , <EOL> ( <NUM_LIT:0.5> , <NUM_LIT:0.5> ) <EOL> ) <EOL> jpg . image . ppoi = '<STR_LIT>' <EOL> jpg . save ( ) <EOL> self . assertEqual ( <EOL> jpg . image . ppoi , <EOL> ( <NUM_LIT> , <NUM_LIT> ) <EOL> ) <EOL> with self . assertRaises ( ValidationError ) : <EOL> versatileimagefield = VersatileImageTestModel . objects . get ( <EOL> img_type = '<STR_LIT>' <EOL> ) . image <EOL> versatileimagefield . ppoi = ( <NUM_LIT> , <NUM_LIT:2> ) <EOL> with self . assertRaises ( ValidationError ) : <EOL> versatileimagefield = VersatileImageTestModel . objects . get ( <EOL> img_type = '<STR_LIT>' <EOL> ) . image <EOL> versatileimagefield . ppoi = '<STR_LIT>' <EOL> def test_invalid_ppoi_tuple_validation ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertFalse ( <EOL> validate_ppoi_tuple ( ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:6> ) ) <EOL> ) <EOL> def test_create_on_demand_boolean ( self ) : <EOL> """<STR_LIT>""" <EOL> jpg = VersatileImageTestModel . objects . get ( img_type = '<STR_LIT>' ) <EOL> self . assertFalse ( jpg . image . create_on_demand ) <EOL> jpg . image . create_on_demand = True <EOL> self . assertTrue ( jpg . image . create_on_demand ) <EOL> with self . assertRaises ( ValueError ) : <EOL> jpg = VersatileImageTestModel . objects . get ( img_type = '<STR_LIT>' ) <EOL> jpg . image . create_on_demand = '<STR_LIT>' <EOL> def test_create_on_demand_functionality ( self ) : <EOL> """<STR_LIT>""" <EOL> jpg = VersatileImageTestModel . objects . get ( img_type = '<STR_LIT>' ) <EOL> self . assert_VersatileImageField_deleted ( jpg . image ) <EOL> def test_image_warmer ( self ) : <EOL> """<STR_LIT>""" <EOL> jpg_warmer = VersatileImageFieldWarmer ( <EOL> instance_or_queryset = self . jpg , <EOL> rendition_key_set = '<STR_LIT>' , <EOL> image_attr = '<STR_LIT:image>' <EOL> ) <EOL> num_created , failed_to_create = jpg_warmer . warm ( ) <EOL> self . assertEqual ( num_created , <NUM_LIT:5> ) <EOL> all_imgs_warmer = VersatileImageFieldWarmer ( <EOL> instance_or_queryset = VersatileImageTestModel . objects . exclude ( <EOL> img_type = '<STR_LIT>' <EOL> ) , <EOL> rendition_key_set = ( <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ) , <EOL> image_attr = '<STR_LIT:image>' , <EOL> verbose = True <EOL> ) <EOL> num_created , failed_to_create = all_imgs_warmer . warm ( ) <EOL> with self . assertRaises ( ValueError ) : <EOL> invalid_warmer = VersatileImageFieldWarmer ( <EOL> instance_or_queryset = [ '<STR_LIT>' ] , <EOL> rendition_key_set = ( <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ) , <EOL> image_attr = '<STR_LIT:image>' <EOL> ) <EOL> del invalid_warmer <EOL> def test_VersatileImageFieldSerializer_output ( self ) : <EOL> """<STR_LIT>""" <EOL> factory = APIRequestFactory ( ) <EOL> request = factory . get ( '<STR_LIT>' ) <EOL> serializer = VersatileImageTestModelSerializer ( <EOL> self . jpg , <EOL> context = { '<STR_LIT>' : request } <EOL> ) <EOL> self . assertEqual ( <EOL> serializer . data . get ( '<STR_LIT:image>' ) , <EOL> { <EOL> '<STR_LIT>' : ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) , <EOL> '<STR_LIT>' : ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) , <EOL> '<STR_LIT>' : ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) , <EOL> '<STR_LIT>' : ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) , <EOL> '<STR_LIT>' : ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> } <EOL> ) <EOL> def test_widget_javascript ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . get ( <EOL> ADMIN_URL <EOL> ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> if six . PY2 : <EOL> response_content = str ( response . content ) <EOL> else : <EOL> response_content = str ( response . content , encoding = '<STR_LIT:utf-8>' ) <EOL> self . assertInHTML ( <EOL> ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) , <EOL> response_content <EOL> ) <EOL> self . assertInHTML ( <EOL> ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) , <EOL> response_content <EOL> ) <EOL> self . assertInHTML ( <EOL> ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) , <EOL> response_content <EOL> ) <EOL> self . assertInHTML ( <EOL> ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) , <EOL> response_content <EOL> ) <EOL> self . assertInHTML ( <EOL> ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) , <EOL> response_content <EOL> ) <EOL> self . assertTrue ( <EOL> self . widget_test . image . field . storage . exists ( <EOL> self . widget_test . image . thumbnail [ '<STR_LIT>' ] . name <EOL> ) <EOL> ) <EOL> f = VersatileImageWidgetTestModelForm ( <EOL> data = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } , <EOL> instance = self . widget_test <EOL> ) <EOL> instance = f . save ( ) <EOL> self . assertEqual ( instance . optional_image_with_ppoi . name , '<STR_LIT>' ) <EOL> def test_VersatileImageFileDescriptor ( self ) : <EOL> """<STR_LIT>""" <EOL> self . jpg . image = '<STR_LIT>' <EOL> self . jpg . save ( ) <EOL> self . assertEqual ( <EOL> self . jpg . image . thumbnail [ '<STR_LIT>' ] . url , <EOL> '<STR_LIT>' <EOL> ) <EOL> self . jpg . image = '<STR_LIT>' <EOL> self . jpg . save ( ) <EOL> self . assertEqual ( <EOL> self . jpg . image . thumbnail [ '<STR_LIT>' ] . url , <EOL> '<STR_LIT>' <EOL> ) <EOL> fieldfile_obj = self . jpg . image <EOL> del fieldfile_obj . field <EOL> self . jpg . image = fieldfile_obj <EOL> img_path = self . jpg . image . path <EOL> img_file = open ( img_path , '<STR_LIT:rb>' ) <EOL> django_file = File ( img_file ) <EOL> self . jpg . image = django_file <EOL> with self . assertRaises ( AttributeError ) : <EOL> x = VersatileImageFileDescriptor ( self . jpg . image . name ) <EOL> VersatileImageFileDescriptor . __get__ ( x ) <EOL> def test_VersatileImageField_picklability ( self ) : <EOL> """<STR_LIT>""" <EOL> cPickle . dump ( <EOL> self . jpg , <EOL> open ( "<STR_LIT>" , "<STR_LIT:wb>" ) <EOL> ) <EOL> jpg_unpickled = cPickle . load ( <EOL> open ( "<STR_LIT>" , "<STR_LIT:rb>" ) <EOL> ) <EOL> jpg_instance = jpg_unpickled <EOL> self . assertEqual ( <EOL> jpg_instance . image . thumbnail [ '<STR_LIT>' ] . url , <EOL> '<STR_LIT>' <EOL> ) <EOL> pickled_state = self . jpg . image . __getstate__ ( ) <EOL> self . assertEqual ( <EOL> pickled_state , <EOL> { <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : False <EOL> } <EOL> ) <EOL> def test_VERSATILEIMAGEFIELD_RENDITION_KEY_SETS_setting ( self ) : <EOL> """<STR_LIT>""" <EOL> with self . assertRaises ( ImproperlyConfigured ) : <EOL> get_rendition_key_set ( '<STR_LIT>' ) <EOL> with self . assertRaises ( InvalidSizeKeySet ) : <EOL> get_rendition_key_set ( '<STR_LIT>' ) <EOL> with self . assertRaises ( InvalidSizeKey ) : <EOL> get_rendition_key_set ( '<STR_LIT>' ) <EOL> def __test_exif_orientation_rotate_180 ( self ) : <EOL> """<STR_LIT>""" <EOL> exif_3 = VersatileImageTestModel . objects . get ( <EOL> img_type = '<STR_LIT>' <EOL> ) <EOL> exif_3 . image . create_on_demand = True <EOL> exif_3_path = exif_3 . image . thumbnail [ '<STR_LIT>' ] . name <EOL> exif_3_img = exif_3 . image . field . storage . open ( <EOL> exif_3_path <EOL> ) <EOL> exif_3_control = exif_3 . image . field . storage . open ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> img = Image . open ( exif_3_img ) <EOL> control_img = Image . open ( exif_3_control ) <EOL> self . assertTrue ( <EOL> self . imageEqual ( <EOL> img , <EOL> control_img <EOL> ) <EOL> ) <EOL> def __test_exif_orientation_rotate_270 ( self ) : <EOL> """<STR_LIT>""" <EOL> exif_6 = VersatileImageTestModel . objects . get ( <EOL> img_type = '<STR_LIT>' <EOL> ) <EOL> exif_6 . image . create_on_demand = True <EOL> exif_6_img = exif_6 . image . field . storage . open ( <EOL> exif_6 . image . thumbnail [ '<STR_LIT>' ] . name <EOL> ) <EOL> exif_6_control = exif_6 . image . field . storage . open ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assertTrue ( <EOL> self . imageEqual ( <EOL> Image . open ( exif_6_img ) , <EOL> Image . open ( exif_6_control ) <EOL> ) <EOL> ) <EOL> def __test_exif_orientation_rotate_90 ( self ) : <EOL> """<STR_LIT>""" <EOL> exif_8 = VersatileImageTestModel . objects . get ( <EOL> img_type = '<STR_LIT>' <EOL> ) <EOL> exif_8 . image . create_on_demand = True <EOL> exif_8_img = exif_8 . image . field . storage . open ( <EOL> exif_8 . image . thumbnail [ '<STR_LIT>' ] . name <EOL> ) <EOL> exif_8_control = exif_8 . image . field . storage . open ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assertTrue ( <EOL> self . imageEqual ( <EOL> Image . open ( exif_8_img ) , <EOL> Image . open ( exif_8_control ) <EOL> ) <EOL> ) <EOL> def test_horizontal_and_vertical_crop ( self ) : <EOL> """<STR_LIT>""" <EOL> test_gif = VersatileImageTestModel . objects . get ( <EOL> img_type = '<STR_LIT>' <EOL> ) <EOL> test_gif . image . create_on_demand = True <EOL> test_gif . image . ppoi = ( <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> vertical_image_crop = test_gif . image . field . storage . open ( <EOL> test_gif . image . crop [ '<STR_LIT>' ] . name <EOL> ) <EOL> vertical_image_crop_control = test_gif . image . field . storage . open ( <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assertTrue ( <EOL> self . imageEqual ( <EOL> Image . open ( vertical_image_crop ) , <EOL> Image . open ( vertical_image_crop_control ) <EOL> ) <EOL> ) <EOL> horiz_image_crop = test_gif . image . field . storage . open ( <EOL> test_gif . image . crop [ '<STR_LIT>' ] . name <EOL> ) <EOL> horiz_image_crop_control = test_gif . image . field . storage . open ( <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assertTrue ( <EOL> self . imageEqual ( <EOL> Image . open ( horiz_image_crop ) , <EOL> Image . open ( horiz_image_crop_control ) <EOL> ) <EOL> ) <EOL> test_gif . image . ppoi = ( <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> vertical_image_crop = test_gif . image . field . storage . open ( <EOL> test_gif . image . crop [ '<STR_LIT>' ] . name <EOL> ) <EOL> vertical_image_crop_control = test_gif . image . field . storage . open ( <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assertTrue ( <EOL> self . imageEqual ( <EOL> Image . open ( vertical_image_crop ) , <EOL> Image . open ( vertical_image_crop_control ) <EOL> ) <EOL> ) <EOL> horiz_image_crop = test_gif . image . field . storage . open ( <EOL> test_gif . image . crop [ '<STR_LIT>' ] . name <EOL> ) <EOL> horiz_image_crop_control = test_gif . image . field . storage . open ( <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assertTrue ( <EOL> self . imageEqual ( <EOL> Image . open ( horiz_image_crop ) , <EOL> Image . open ( horiz_image_crop_control ) <EOL> ) <EOL> ) <EOL> def test_DummyFilter ( self ) : <EOL> """<STR_LIT>""" <EOL> test_png = VersatileImageTestModel . objects . get ( <EOL> img_type = '<STR_LIT>' <EOL> ) <EOL> test_png . optional_image . create_on_demand = True <EOL> test_png . optional_image . filters . invert . url <EOL> def test_crop_and_thumbnail_key_assignment ( self ) : <EOL> """<STR_LIT>""" <EOL> with self . assertRaises ( NotImplementedError ) : <EOL> jpg = VersatileImageTestModel . objects . get ( img_type = '<STR_LIT>' ) <EOL> jpg . image . crop [ '<STR_LIT>' ] = None <EOL> with self . assertRaises ( NotImplementedError ) : <EOL> jpg = VersatileImageTestModel . objects . get ( img_type = '<STR_LIT>' ) <EOL> jpg . image . thumbnail [ '<STR_LIT>' ] = None <EOL> def test_MalformedSizedImageKey ( self ) : <EOL> """<STR_LIT>""" <EOL> with self . assertRaises ( MalformedSizedImageKey ) : <EOL> self . jpg . image . thumbnail [ '<STR_LIT>' ] <EOL> def test_registration_exceptions ( self ) : <EOL> """<STR_LIT>""" <EOL> class A ( object ) : <EOL> pass <EOL> with self . assertRaises ( InvalidSizedImageSubclass ) : <EOL> versatileimagefield_registry . register_sizer ( '<STR_LIT:a>' , A ) <EOL> with self . assertRaises ( InvalidFilteredImageSubclass ) : <EOL> versatileimagefield_registry . register_filter ( '<STR_LIT:a>' , A ) <EOL> with self . assertRaises ( UnallowedSizerName ) : <EOL> versatileimagefield_registry . register_sizer ( '<STR_LIT>' , CroppedImage ) <EOL> with self . assertRaises ( UnallowedFilterName ) : <EOL> versatileimagefield_registry . register_filter ( '<STR_LIT>' , InvertImage ) <EOL> with self . assertRaises ( AlreadyRegistered ) : <EOL> versatileimagefield_registry . register_sizer ( '<STR_LIT>' , CroppedImage ) <EOL> with self . assertRaises ( AlreadyRegistered ) : <EOL> versatileimagefield_registry . register_filter ( '<STR_LIT>' , InvertImage ) <EOL> with self . assertRaises ( NotRegistered ) : <EOL> versatileimagefield_registry . unregister_sizer ( '<STR_LIT>' ) <EOL> with self . assertRaises ( NotRegistered ) : <EOL> versatileimagefield_registry . unregister_filter ( '<STR_LIT>' ) <EOL> def test_unregister_methods ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertTrue ( <EOL> '<STR_LIT>' in versatileimagefield_registry . _sizedimage_registry <EOL> ) <EOL> versatileimagefield_registry . unregister_sizer ( '<STR_LIT>' ) <EOL> self . assertFalse ( <EOL> '<STR_LIT>' in versatileimagefield_registry . _sizedimage_registry <EOL> ) <EOL> self . assertTrue ( <EOL> '<STR_LIT>' in versatileimagefield_registry . _filter_registry <EOL> ) <EOL> versatileimagefield_registry . unregister_filter ( '<STR_LIT>' ) <EOL> self . assertFalse ( <EOL> '<STR_LIT>' in versatileimagefield_registry . _filter_registry <EOL> ) <EOL> def test_save_form_data ( self ) : <EOL> """<STR_LIT>""" <EOL> with open ( <EOL> os . path . join ( <EOL> os . path . dirname ( upath ( __file__ ) ) , <EOL> "<STR_LIT>" <EOL> ) , <EOL> '<STR_LIT:rb>' <EOL> ) as fp : <EOL> image_data = fp . read ( ) <EOL> with open ( <EOL> os . path . join ( <EOL> os . path . dirname ( upath ( __file__ ) ) , <EOL> "<STR_LIT>" <EOL> ) , <EOL> '<STR_LIT:rb>' <EOL> ) as fp : <EOL> image_data2 = fp . read ( ) <EOL> if DJANGO_VERSION [ <NUM_LIT:0> ] == <NUM_LIT:1> and DJANGO_VERSION [ <NUM_LIT:1> ] == <NUM_LIT:5> : <EOL> form_class = VersatileImageTestModelFormDjango15 <EOL> else : <EOL> form_class = VersatileImageTestModelForm <EOL> f = form_class ( <EOL> data = { '<STR_LIT>' : '<STR_LIT>' } , <EOL> files = { <EOL> '<STR_LIT>' : SimpleUploadedFile ( '<STR_LIT>' , image_data ) , <EOL> '<STR_LIT>' : SimpleUploadedFile ( <EOL> '<STR_LIT>' , image_data2 <EOL> ) <EOL> } <EOL> ) <EOL> self . assertEqual ( f . is_valid ( ) , True ) <EOL> self . assertEqual ( type ( f . cleaned_data [ '<STR_LIT:image>' ] [ <NUM_LIT:0> ] ) , SimpleUploadedFile ) <EOL> self . assertEqual ( <EOL> type ( f . cleaned_data [ '<STR_LIT>' ] ) , SimpleUploadedFile <EOL> ) <EOL> instance = f . save ( ) <EOL> self . assertEqual ( instance . image . name , '<STR_LIT>' ) <EOL> self . assertEqual ( instance . optional_image . name , '<STR_LIT>' ) <EOL> instance . optional_image . delete ( ) <EOL> f2 = form_class ( <EOL> data = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } , <EOL> instance = instance <EOL> ) <EOL> instance = f2 . save ( ) <EOL> self . assertEqual ( instance . image . ppoi , ( <NUM_LIT> , <NUM_LIT> ) ) <EOL> self . assertEqual ( instance . optional_image . name , '<STR_LIT>' ) <EOL> instance . image . delete ( ) <EOL> def test_ProcessedImage_subclass_exceptions ( self ) : <EOL> """<STR_LIT>""" <EOL> with self . assertRaises ( NotImplementedError ) : <EOL> class SizedImageSubclass ( SizedImage ) : <EOL> pass <EOL> SizedImageSubclass ( '<STR_LIT>' , '<STR_LIT>' , False ) <EOL> with self . assertRaises ( NotImplementedError ) : <EOL> class SizedImageSubclass ( SizedImage ) : <EOL> filename_key = '<STR_LIT:test>' <EOL> x = SizedImageSubclass ( '<STR_LIT>' , '<STR_LIT>' , False ) <EOL> x . process_image ( image = None , image_format = '<STR_LIT>' , save_kwargs = { } , <EOL> width = <NUM_LIT:100> , height = <NUM_LIT:100> ) <EOL> with self . assertRaises ( NotImplementedError ) : <EOL> class FilteredImageSubclass ( FilteredImage ) : <EOL> filename_key = '<STR_LIT:test>' <EOL> x = FilteredImageSubclass ( <EOL> self . jpg . image . name , <EOL> self . jpg . image . field . storage , <EOL> False , <EOL> filename_key = '<STR_LIT:foo>' <EOL> ) <EOL> x . process_image ( image = None , image_format = '<STR_LIT>' , save_kwargs = { } ) <EOL> @ override_settings ( <EOL> INSTALLED_APPS = ( '<STR_LIT>' , ) <EOL> ) <EOL> def test_autodiscover ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertRaises ( <EOL> ImportError , <EOL> autodiscover <EOL> ) <EOL> @ override_settings ( <EOL> VERSATILEIMAGEFIELD_USE_PLACEHOLDIT = True <EOL> ) <EOL> def test_placeholdit ( self ) : <EOL> jpg = VersatileImageTestModel . objects . get ( img_type = '<STR_LIT>' ) <EOL> self . assertEqual ( <EOL> jpg . optional_image_3 . filters . invert . crop [ '<STR_LIT>' ] . url , <EOL> '<STR_LIT>' <EOL> ) <EOL> def test_template_rendering ( self ) : <EOL> t = get_template ( "<STR_LIT>" ) <EOL> c = Context ( { <EOL> '<STR_LIT>' : self . jpg <EOL> } ) <EOL> rendered = t . render ( c ) <EOL> self . assertHTMLEqual ( <EOL> rendered , <EOL> """<STR_LIT>""" <EOL> ) <EOL> def test_field_serialization ( self ) : <EOL> """<STR_LIT>""" <EOL> output = serializers . serialize ( <EOL> '<STR_LIT>' , <EOL> VersatileImageTestModel . objects . filter ( pk = <NUM_LIT:1> ) <EOL> ) <EOL> self . assertJSONEqual ( <EOL> output , <EOL> [ <EOL> { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT:width>" : <NUM_LIT> , <EOL> "<STR_LIT>" : <NUM_LIT> , <EOL> "<STR_LIT:image>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : <NUM_LIT:1> <EOL> } <EOL> ] <EOL> ) <EOL> def test_bound_form_data ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . post ( <EOL> ADMIN_URL , <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } , <EOL> follow = True <EOL> ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> if six . PY2 : <EOL> response_content = str ( response . content ) <EOL> else : <EOL> response_content = str ( response . content , encoding = '<STR_LIT:utf-8>' ) <EOL> self . assertInHTML ( <EOL> ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) , <EOL> response_content <EOL> ) <EOL> def test_individual_rendition_cache_clear ( self ) : <EOL> """<STR_LIT>""" <EOL> expected_image_url = ( <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assertEqual ( <EOL> cache . get ( expected_image_url ) , <EOL> None <EOL> ) <EOL> img = self . delete_test <EOL> img . image . create_on_demand = True <EOL> img_url = img . image . thumbnail [ '<STR_LIT>' ] . url <EOL> del img_url <EOL> self . assertEqual ( <EOL> cache . get ( expected_image_url ) , <EOL> <NUM_LIT:1> <EOL> ) <EOL> img . image . thumbnail [ '<STR_LIT>' ] . delete ( ) <EOL> self . assertEqual ( <EOL> cache . get ( expected_image_url ) , <EOL> None <EOL> ) <EOL> self . assertFalse ( <EOL> img . image . field . storage . exists ( <EOL> '<STR_LIT>' <EOL> ) <EOL> ) <EOL> def test_rendition_delete ( self ) : <EOL> """<STR_LIT>""" <EOL> img = self . delete_test <EOL> self . assertFalse ( <EOL> img . image . field . storage . exists ( <EOL> '<STR_LIT>' <EOL> ) <EOL> ) <EOL> img . image . create_on_demand = True <EOL> thumb_url = img . image . thumbnail [ '<STR_LIT>' ] . url <EOL> self . assertEqual ( <EOL> cache . get ( thumb_url ) , <EOL> <NUM_LIT:1> <EOL> ) <EOL> self . assertTrue ( <EOL> img . image . field . storage . exists ( <EOL> '<STR_LIT>' <EOL> ) <EOL> ) <EOL> invert_url = img . image . filters . invert . url <EOL> self . assertEqual ( <EOL> cache . get ( invert_url ) , <EOL> <NUM_LIT:1> <EOL> ) <EOL> self . assertTrue ( <EOL> img . image . field . storage . exists ( <EOL> '<STR_LIT>' <EOL> ) <EOL> ) <EOL> invert_and_thumb_url = img . image . filters . invert . thumbnail [ <EOL> '<STR_LIT>' <EOL> ] . url <EOL> self . assertEqual ( <EOL> cache . get ( invert_and_thumb_url ) , <EOL> <NUM_LIT:1> <EOL> ) <EOL> self . assertTrue ( <EOL> img . image . field . storage . exists ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> ) <EOL> img . image . delete_all_created_images ( ) <EOL> self . assertEqual ( <EOL> cache . get ( thumb_url ) , <EOL> None <EOL> ) <EOL> self . assertFalse ( <EOL> img . image . field . storage . exists ( <EOL> '<STR_LIT>' <EOL> ) <EOL> ) <EOL> self . assertEqual ( <EOL> cache . get ( invert_url ) , <EOL> None <EOL> ) <EOL> self . assertFalse ( <EOL> img . image . field . storage . exists ( <EOL> '<STR_LIT>' <EOL> ) <EOL> ) <EOL> self . assertEqual ( <EOL> cache . get ( invert_and_thumb_url ) , <EOL> None <EOL> ) <EOL> self . assertFalse ( <EOL> img . image . field . storage . exists ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> ) </s>
