diff options
Diffstat (limited to 'server/szurubooru/tests/func/test_posts.py')
| -rw-r--r-- | server/szurubooru/tests/func/test_posts.py | 82 |
1 files changed, 81 insertions, 1 deletions
diff --git a/server/szurubooru/tests/func/test_posts.py b/server/szurubooru/tests/func/test_posts.py index af6121a..e1be764 100644 --- a/server/szurubooru/tests/func/test_posts.py +++ b/server/szurubooru/tests/func/test_posts.py @@ -147,6 +147,7 @@ def test_serialize_post( post.source = "4gag" post.type = model.Post.TYPE_IMAGE post.checksum = "deadbeef" + post.checksum_md5 = "deadbeef" post.mime_type = "image/jpeg" post.file_size = 100 post.user = user_factory(name="post author") @@ -231,6 +232,7 @@ def test_serialize_post( "source": "4gag", "type": "image", "checksum": "deadbeef", + "checksumMD5": "deadbeef", "fileSize": 100, "canvasWidth": 200, "canvasHeight": 300, @@ -424,6 +426,48 @@ def test_update_post_source_with_too_long_string(): ), ( False, + "bmp.bmp", + "image/bmp", + model.Post.TYPE_IMAGE, + "1_244c8840887984c4.bmp", + ), + ( + False, + "avif.avif", + "image/avif", + model.Post.TYPE_IMAGE, + "1_244c8840887984c4.avif", + ), + ( + False, + "avif-avis.avif", + "image/avif", + model.Post.TYPE_IMAGE, + "1_244c8840887984c4.avif", + ), + ( + False, + "heic.heic", + "image/heic", + model.Post.TYPE_IMAGE, + "1_244c8840887984c4.heic", + ), + ( + False, + "heic-heix.heic", + "image/heic", + model.Post.TYPE_IMAGE, + "1_244c8840887984c4.heic", + ), + ( + False, + "heif.heif", + "image/heif", + model.Post.TYPE_IMAGE, + "1_244c8840887984c4.heif", + ), + ( + False, "gif-animated.gif", "image/gif", model.Post.TYPE_ANIMATION, @@ -463,8 +507,11 @@ def test_update_post_content_for_new_post( expected_type, output_file_name, ): - with patch("szurubooru.func.util.get_sha1"): + with patch("szurubooru.func.util.get_sha1"), patch( + "szurubooru.func.util.get_md5" + ): util.get_sha1.return_value = "crc" + util.get_md5.return_value = "md5" config_injector( { "data_dir": str(tmpdir.mkdir("data")), @@ -490,6 +537,7 @@ def test_update_post_content_for_new_post( assert post.mime_type == expected_mime_type assert post.type == expected_type assert post.checksum == "crc" + assert post.checksum_md5 == "md5" assert os.path.exists(output_file_path) if post.type in (model.Post.TYPE_IMAGE, model.Post.TYPE_ANIMATION): assert db.session.query(model.PostSignature).count() == 1 @@ -725,6 +773,38 @@ def test_update_post_content_leaving_custom_thumbnail( assert os.path.exists(generated_path) +@pytest.mark.parametrize("filename", ("avif.avif", "heic.heic", "heif.heif")) +def test_update_post_content_convert_heif_to_png_when_processing( + tmpdir, config_injector, read_asset, post_factory, filename +): + config_injector( + { + "data_dir": str(tmpdir.mkdir("data")), + "thumbnails": { + "post_width": 300, + "post_height": 300, + }, + "secret": "test", + "allow_broken_uploads": False, + } + ) + post = post_factory(id=1) + db.session.add(post) + posts.update_post_content(post, read_asset(filename)) + posts.update_post_thumbnail(post, read_asset(filename)) + db.session.flush() + generated_path = ( + "{}/data/generated-thumbnails/".format(tmpdir) + + "1_244c8840887984c4.jpg" + ) + source_path = ( + "{}/data/posts/custom-thumbnails/".format(tmpdir) + + "1_244c8840887984c4.dat" + ) + assert os.path.exists(source_path) + assert os.path.exists(generated_path) + + def test_update_post_tags(tag_factory): post = model.Post() with patch("szurubooru.func.tags.get_or_create_tags_by_names"): |