Example #1
0
    def test_preview_size(self, pngcrush_image_mock):
        addon = Addon.objects.get(pk=3615)
        name = 'teamaddons.jpg'
        form = forms.PreviewForm({
            'caption': 'test',
            'upload_hash': name,
            'position': 1
        })
        with storage.open(os.path.join(self.dest, name), 'wb') as f:
            shutil.copyfileobj(open(get_image_path(name), 'rb'), f)
        assert form.is_valid()
        form.save(addon)
        preview = addon.previews.all()[0]
        assert preview.sizes == ({
            'image': [2400, 1600],
            'thumbnail': [533, 355],
            'original': [3000, 2000],
            'thumbnail_format': 'jpg',
        })
        assert os.path.exists(preview.image_path)
        assert os.path.exists(preview.thumbnail_path)
        assert os.path.exists(preview.original_path)

        assert pngcrush_image_mock.call_count == 1  # the thumbnail isn't a png now
        assert pngcrush_image_mock.call_args_list[0][0][0] == (
            preview.image_path)
    def test_preview_size(self, pngcrush_image_mock):
        addon = Addon.objects.get(pk=3615)
        name = 'non-animated.gif'
        form = forms.PreviewForm({
            'caption': 'test',
            'upload_hash': name,
            'position': 1
        })
        with storage.open(os.path.join(self.dest, name), 'w') as f:
            shutil.copyfileobj(open(get_image_path(name)), f)
        assert form.is_valid()
        form.save(addon)
        preview = addon.previews.all()[0]
        assert preview.sizes == ({
            u'image': [250, 297],
            u'thumbnail': [168, 200],
            u'original': [250, 297]
        })
        assert os.path.exists(preview.image_path)
        assert os.path.exists(preview.thumbnail_path)
        assert os.path.exists(preview.original_path)

        assert pngcrush_image_mock.call_count == 2
        assert pngcrush_image_mock.call_args_list[0][0][0] == (
            preview.thumbnail_path)
        assert pngcrush_image_mock.call_args_list[1][0][0] == (
            preview.image_path)
Example #3
0
 def test_preview_modified(self, update_mock):
     addon = Addon.objects.get(pk=3615)
     name = 'transparent.png'
     form = forms.PreviewForm({'caption': 'test', 'upload_hash': name,
                               'position': 1})
     with storage.open(os.path.join(self.dest, name), 'w') as f:
         copyfileobj(open(get_image_path(name)), f)
     assert form.is_valid()
     form.save(addon)
     assert update_mock.called
Example #4
0
 def test_preview_size(self):
     addon = Addon.objects.get(pk=3615)
     name = 'non-animated.gif'
     form = forms.PreviewForm({'caption': 'test', 'upload_hash': name,
                               'position': 1})
     with storage.open(os.path.join(self.dest, name), 'w') as f:
         copyfileobj(open(get_image_path(name)), f)
     assert form.is_valid()
     form.save(addon)
     assert addon.previews.all()[0].sizes == (
         {u'image': [250, 297], u'thumbnail': [126, 150]})
Example #5
0
 def test_preview_transparency(self):
     addon = Addon.objects.get(pk=3615)
     name = 'transparent-cotton'
     hash = '12345678abcd'
     form = forms.PreviewForm(
         {'caption': 'test', 'upload_hash': hash, 'position': 1}
     )
     with storage.open(os.path.join(self.dest, hash), 'wb') as f:
         shutil.copyfileobj(open(get_image_path(name + '.png'), 'rb'), f)
     assert form.is_valid()
     form.save(addon)
     preview = addon.previews.all()[0]
     assert os.path.exists(preview.thumbnail_path)
     with storage.open(preview.thumbnail_path, 'rb') as thumb_file, open(
         get_image_path(name + '.jpg'), 'rb'
     ) as sample_file:
         assert thumb_file.read() == sample_file.read()