def test_rotate_photo(self): ''' Tests that the function correctly rotates a photo ''' from django.conf import settings #Copy test image to media area import shutil import os shutil.copy2( os.path.join(settings.BASE_DIR, 'family_tree/tests/large_test_image.jpg'), settings.MEDIA_ROOT + 'profile_photos/large_test_image.jpg') person = Person(name='譚詠麟', gender='M', family_id=self.family.id) person.photo = 'profile_photos/large_test_image.jpg' person.rotate_photo(90) #Check rotated photo is valid rotated_photo = Image.open(settings.MEDIA_ROOT + str(person.photo)) rotated_photo.verify() #Clear up mess afterwards os.remove(settings.MEDIA_ROOT + str(person.photo))
def test_crop_and_resize_photo(self): ''' Tests that the function correctly sets two thumbnails of correct size ''' from django.conf import settings #Copy test image to media area import shutil import os shutil.copy2(os.path.join(settings.BASE_DIR, 'family_tree/tests/large_test_image.jpg'), settings.MEDIA_ROOT + 'profile_photos/large_test_image.jpg') person = Person(name='譚詠麟', gender='M', family_id=self.family.id) person.photo = 'profile_photos/large_test_image.jpg' person.crop_and_resize_photo(50, 50, 20, 20, 800) #Check small thumbnail is valid small = Image.open(settings.MEDIA_ROOT + str(person.small_thumbnail)) small.verify() width, height = small.size self.assertEqual(80, width) self.assertEqual(80, height) #Check large thumbnail is valid large = Image.open(settings.MEDIA_ROOT + str(person.large_thumbnail)) large.verify() width, height = large.size self.assertEqual(200, width) self.assertEqual(200, height) #Clear up mess afterwards os.remove(settings.MEDIA_ROOT + 'profile_photos/large_test_image.jpg')
def test_crop_and_resize_photo(self): ''' Tests that the function correctly sets two thumbnails of correct size ''' from django.conf import settings #Copy test image to media area import shutil import os shutil.copy2(os.path.join(settings.BASE_DIR, 'family_tree/tests/large_test_image.jpg'), settings.MEDIA_ROOT + 'profile_photos/large_test_image.jpg') person = Person(name='譚詠麟', gender='M', family_id=self.family.id) person.photo = 'profile_photos/large_test_image.jpg' person.crop_and_resize_photo(50, 50, 20, 20) #Check small thumbnail is valid small = Image.open(settings.MEDIA_ROOT + str(person.small_thumbnail)) small.verify() width, height = small.size self.assertEqual(80, width) self.assertEqual(80, height) #Check large thumbnail is valid large = Image.open(settings.MEDIA_ROOT + str(person.large_thumbnail)) large.verify() width, height = large.size self.assertEqual(200, width) self.assertEqual(200, height) #Clear up mess afterwards os.remove(settings.MEDIA_ROOT + 'profile_photos/large_test_image.jpg')