def test_formatted_photo_has_zero_crop_box_if_smaller_than_format(self): format = Format.objects.create( name="sample", max_width=300, max_height=300, flexible_height=False, stretch=False, nocrop=False ) format.sites.add(Site.objects.get_current()) fp = FormatedPhoto(photo=self.photo, format=format) fp.generate(False) tools.assert_equals((0, 0, 0, 0), (fp.crop_left, fp.crop_top, fp.crop_width, fp.crop_height))
def test_formatted_photo_has_zero_crop_box_if_smaller_than_format(self): format = Format.objects.create( name='sample', max_width=300, max_height=300, flexible_height=False, stretch=False, nocrop=False ) format.sites.add(Site.objects.get_current()) fp = FormatedPhoto(photo=self.photo, format=format) fp.generate(False) tools.assert_equals((0, 0, 0, 0), (fp.crop_left, fp.crop_top, fp.crop_width, fp.crop_height))
def test_formated_photo_from_master_format_is_used(self): master_format = Format.objects.create( name='sample', max_width=300, max_height=200, flexible_height=False, stretch=False, nocrop=False ) slave_format = Format.objects.create( name='slave', max_width=300, max_height=100, flexible_height=False, stretch=False, nocrop=False, master=master_format ) master_fp = FormatedPhoto(photo=self.photo, format=master_format) p2 = create_photo(self, color=(123, 123, 123), size=(300, 200)) p2.image.open() master_fp.image.save(p2.image.name, p2.image) master_fp.save() fp = FormatedPhoto(photo=self.photo, format=slave_format) fp.save() fp.image.open() i = Image.open(fp.image) tools.assert_equals((123, 123, 123), i.getpixel((10, 10))) tools.assert_equals((300, 100), i.size) p2.image.close()