def test_each_filter__should_create_its_own_rendition(self): image = Image.objects.create(title='Some Title', file=get_temporary_image()) image.get_rendition('original') image.get_rendition('height-100') image.get_rendition('width-100') # should have three renditions self.assertEqual(image.renditions.count(), 3)
def test_same_filter_called_twice__should_not_create_another_rendition( self): image = Image.objects.create(title='Some Title', file=get_temporary_image()) image.get_rendition('original') image.get_rendition('original') # should have one rendition self.assertEqual(image.renditions.count(), 1)
def test_clears_renditions_on_save(self): image = Image.objects.create(title='Some Title', file=get_temporary_image()) image.get_rendition('width-50') image.get_rendition('width-150') self.assertEqual(image.renditions.count(), 3) image.save() self.assertEqual(image.renditions.count(), 1)
def test_original(self): image = Image.objects.create(title='Some Title', file=get_temporary_image()) filter_spec = 'original' rendition = image.get_rendition(filter_spec) # should have one rendition self.assertEqual(image.renditions.count(), 1) image_filename = os.path.basename(image.file.name) image_filename_without_extension, image_extension = os.path.splitext( image_filename) rendition_filename = os.path.basename(rendition.file.name) self.assertEqual( rendition_filename, '%s.%s%s' % (image_filename_without_extension, filter_spec, image_extension)) self.assertEqual(rendition.file.width, image.file.width) self.assertEqual(rendition.file.height, image.file.height) self.assertEqual(rendition.filter_spec, filter_spec)
def test_width_and_height__wont_stretch_original_image_size(self): image = Image.objects.create(title='Some Title', file=get_temporary_image()) filter_spec = 'width-1000|height-1000' rendition = image.get_rendition(filter_spec) self.assertEqual(image.renditions.count(), 1) image_filename = os.path.basename(image.file.name) image_filename_without_extension, image_extension = os.path.splitext( image_filename) rendition_filename = os.path.basename(rendition.file.name) self.assertEqual( rendition_filename, '%s.%s%s' % (image_filename_without_extension, filter_spec.replace('|', '.'), image_extension)) # original image is 400x200 self.assertEqual(rendition.file.width, image.file.width) self.assertEqual(rendition.file.height, image.file.height) self.assertEqual(rendition.filter_spec, filter_spec)
def test_width_and_height(self): image = Image.objects.create(title='Some Title', file=get_temporary_image()) filter_spec = 'width-100|height-100' rendition = image.get_rendition(filter_spec) # should have one rendition self.assertEqual(image.renditions.count(), 1) image_filename = os.path.basename(image.file.name) image_filename_without_extension, image_extension = os.path.splitext( image_filename) rendition_filename = os.path.basename(rendition.file.name) self.assertEqual( rendition_filename, '%s.%s%s' % (image_filename_without_extension, filter_spec.replace('|', '.'), image_extension)) # original image is 400x200 will result in 100x50 so to not screw up image ratio self.assertEqual(rendition.file.width, 100) self.assertEqual(rendition.file.height, 50) self.assertEqual(rendition.filter_spec, filter_spec)
def setUp(self): # Create an image for running tests on self.image = Image.objects.create( title="Test image", file=get_temporary_image(), )
def test_no_default_renditions_are_created(self): image = Image.objects.create(title='Some Title', file=get_temporary_image()) self.assertEqual(image.renditions.count(), 0)
def test_thumbnail_rendition_is_created(self): image = Image.objects.create(title='Some Title', file=get_temporary_image()) self.assertEqual(image.renditions.count(), 1)
def test_alt(self): image = Image.objects.create(title='Some Title', file=get_temporary_image()) rendition = image.get_rendition('original') self.assertEqual(rendition.alt, rendition.image.title)