From 4ad90007aa6285cb1e4b3625cebff2cfce03a0e3 Mon Sep 17 00:00:00 2001 From: Amras Date: Thu, 9 Nov 2023 16:47:05 +0100 Subject: [PATCH] Add unit test updating a post with EXIF metadata The test creates a new post, containing a known image which has been rotated 90 degrees. It then checks: - the size of the canvas - the size of the thumbnail - if the image is searchable using non-exif data --- server/szurubooru/tests/assets/exif.jpg | Bin 0 -> 4302 bytes server/szurubooru/tests/func/test_posts.py | 39 +++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 server/szurubooru/tests/assets/exif.jpg diff --git a/server/szurubooru/tests/assets/exif.jpg b/server/szurubooru/tests/assets/exif.jpg new file mode 100644 index 0000000000000000000000000000000000000000..784adec784ae16b45cfdeaeb8c918642c47216c8 GIT binary patch literal 4302 zcmYjS2Q-}B)_!MAPN8g4L}KE1}H8R2%x$kE`aji8US=bu>aE-knn#z7k7YJ{;My%e{ga7 z-#9-5nDp)Z9b_cLCB+dE62LhTPzPwJsHmx^Y5ombT3R|fx(oiZU4Vgs;eW&*#lU!p zk&*F&FEKGOF*8GP=cxd-6NO+fI_ZPGP59zs08lVAz1}+_C9Ko>6pi*Y}6UXcsRRyR5KI+T_jOZ zLn!`J>|%USimOJ5JIr=IkWv<0I`VIUzGl{Mlo+)={CO_`r2!lPJ&KD#f-h#t44f|k z41aopQa}L};7$L$8jg%K@31r_H+0q4Y&UXOe4PyGUkZF0r&#>Si28cdp;DH1lbGha zs2?^WD1(RF@_ufn-xJ(gkoWjfpRfD(aFBscpDXqtQL(a)p2%I*QkISDq$f58my}JO z!ZyFh$0Y+)Bf~ucdYzgh3&Oj?kvY|DS9C<<@%qdTYjWHR{yvX~bu&c-n&XdsPuE5b zwj-Ow)jz4T-VKpz5SWEs)+p4m_2W;9{#Z*Yq}gARBM&Bu@Jxy|G-GBSH0L#nc1(ZJ zdpt!yRp9L9?{E}`Qb?SU&Ej+BFt(6jMy&|#oS>}Xqxw~LuMCVY4Gp~;nCO{tB(Gcc zXqm6S+U`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ubooru/tests/func/test_posts.py b/server/szurubooru/tests/func/test_posts.py index fa1b3bb6..5250bf82 100644 --- a/server/szurubooru/tests/func/test_posts.py +++ b/server/szurubooru/tests/func/test_posts.py @@ -773,6 +773,45 @@ def test_update_post_content_convert_heif_to_png_when_processing( assert os.path.exists(generated_path) +def test_update_post_content_with_exif_orientation( + tmpdir, config_injector, read_asset, post_factory): + # exif.jpg is a copy of jpeg.jpg, + # rotated counter-clockwise by 90 degrees, + # and assigned the EXIF Orientation tag "Rotate 90 CW" + 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("exif.jpg")) + thumbnail_path = ( + "{}/data/generated-thumbnails/1_244c8840887984c4.jpg".format(tmpdir)) + db.session.flush() + + assert post.canvas_width == 100 + assert post.canvas_height == 75 + + with open(thumbnail_path, "rb") as handle: + thumbnail = images.Image(handle.read()) + assert thumbnail.width == 400 + assert thumbnail.height == 300 + + search_result = posts.search_by_image(read_asset("jpeg.jpg")) + assert len(search_result) == 1 + search_distance, search_post = search_result[0] + assert search_post.post_id == post.post_id + assert abs(search_distance) < 0.15 + + def test_update_post_tags(tag_factory): post = model.Post() with patch("szurubooru.func.tags.get_or_create_tags_by_names"):