mirror of
https://github.com/rr-/szurubooru.git
synced 2025-07-17 08:26:24 +00:00
server/posts: update tests for thumbnail rework
This commit is contained in:
@ -41,7 +41,7 @@ def test_get_post_thumbnail_url(input_mime_type, config_injector):
|
|||||||
post.mime_type = input_mime_type
|
post.mime_type = input_mime_type
|
||||||
assert (
|
assert (
|
||||||
posts.get_post_thumbnail_url(post)
|
posts.get_post_thumbnail_url(post)
|
||||||
== "http://example.com/generated-thumbnails/1_244c8840887984c4.jpg"
|
== "http://example.com/generated-thumbnails/sample_1_244c8840887984c4.jpg"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -67,7 +67,7 @@ def test_get_post_thumbnail_path(input_mime_type):
|
|||||||
post.mime_type = input_mime_type
|
post.mime_type = input_mime_type
|
||||||
assert (
|
assert (
|
||||||
posts.get_post_thumbnail_path(post)
|
posts.get_post_thumbnail_path(post)
|
||||||
== "generated-thumbnails/1_244c8840887984c4.jpg"
|
== "generated-thumbnails/sample_1_244c8840887984c4.jpg"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -78,7 +78,7 @@ def test_get_post_custom_thumbnail_path(input_mime_type):
|
|||||||
post.mime_type = input_mime_type
|
post.mime_type = input_mime_type
|
||||||
assert (
|
assert (
|
||||||
posts.get_post_custom_thumbnail_path(post)
|
posts.get_post_custom_thumbnail_path(post)
|
||||||
== "posts/custom-thumbnails/1_244c8840887984c4.dat"
|
== "generated-thumbnails/custom-thumbnails/sample_1_244c8840887984c4.jpg"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -226,7 +226,9 @@ def test_serialize_post(
|
|||||||
"canvasHeight": 300,
|
"canvasHeight": 300,
|
||||||
"contentUrl": "http://example.com/posts/1_244c8840887984c4.jpg",
|
"contentUrl": "http://example.com/posts/1_244c8840887984c4.jpg",
|
||||||
"thumbnailUrl": "http://example.com/"
|
"thumbnailUrl": "http://example.com/"
|
||||||
"generated-thumbnails/1_244c8840887984c4.jpg",
|
"generated-thumbnails/sample_1_244c8840887984c4.jpg",
|
||||||
|
"customThumbnailUrl": "http://example.com/"
|
||||||
|
"generated-thumbnails/custom-thumbnails/sample_1_244c8840887984c4.jpg",
|
||||||
"flags": ["loop"],
|
"flags": ["loop"],
|
||||||
"tags": [
|
"tags": [
|
||||||
{
|
{
|
||||||
@ -270,17 +272,27 @@ def test_serialize_post(
|
|||||||
"relationCount": 0,
|
"relationCount": 0,
|
||||||
"lastFeatureTime": datetime(1999, 1, 1),
|
"lastFeatureTime": datetime(1999, 1, 1),
|
||||||
"favoritedBy": ["fav1"],
|
"favoritedBy": ["fav1"],
|
||||||
"hasCustomThumbnail": True,
|
|
||||||
"mimeType": "image/jpeg",
|
"mimeType": "image/jpeg",
|
||||||
"comments": ["commenter1", "commenter2"],
|
"comments": ["commenter1", "commenter2"],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def test_serialize_micro_post(post_factory, user_factory):
|
def test_serialize_micro_post(tmpdir, config_injector, post_factory, user_factory):
|
||||||
with patch("szurubooru.func.posts.get_post_thumbnail_url"):
|
with patch("szurubooru.func.posts.get_post_thumbnail_url"):
|
||||||
posts.get_post_thumbnail_url.return_value = (
|
posts.get_post_thumbnail_url.return_value = (
|
||||||
"https://example.com/thumb.png"
|
"https://example.com/thumb.png"
|
||||||
)
|
)
|
||||||
|
config_injector(
|
||||||
|
{
|
||||||
|
"data_dir": str(tmpdir.mkdir("data")),
|
||||||
|
"thumbnails": {
|
||||||
|
"post_width": 300,
|
||||||
|
"post_height": 300,
|
||||||
|
},
|
||||||
|
"secret": "test",
|
||||||
|
"allow_broken_uploads": False,
|
||||||
|
}
|
||||||
|
)
|
||||||
auth_user = user_factory()
|
auth_user = user_factory()
|
||||||
post = post_factory()
|
post = post_factory()
|
||||||
db.session.add(post)
|
db.session.add(post)
|
||||||
@ -288,6 +300,7 @@ def test_serialize_micro_post(post_factory, user_factory):
|
|||||||
assert posts.serialize_micro_post(post, auth_user) == {
|
assert posts.serialize_micro_post(post, auth_user) == {
|
||||||
"id": post.post_id,
|
"id": post.post_id,
|
||||||
"thumbnailUrl": "https://example.com/thumb.png",
|
"thumbnailUrl": "https://example.com/thumb.png",
|
||||||
|
"customThumbnailUrl": None,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -605,7 +618,7 @@ def test_update_post_thumbnail_to_new_one(
|
|||||||
assert post.post_id
|
assert post.post_id
|
||||||
generated_path = (
|
generated_path = (
|
||||||
"{}/data/generated-thumbnails/".format(tmpdir)
|
"{}/data/generated-thumbnails/".format(tmpdir)
|
||||||
+ "1_244c8840887984c4.jpg"
|
+ "sample_1_244c8840887984c4.jpg"
|
||||||
)
|
)
|
||||||
source_path = (
|
source_path = (
|
||||||
"{}/data/posts/custom-thumbnails/".format(tmpdir)
|
"{}/data/posts/custom-thumbnails/".format(tmpdir)
|
||||||
@ -646,7 +659,7 @@ def test_update_post_thumbnail_to_default(
|
|||||||
assert post.post_id
|
assert post.post_id
|
||||||
generated_path = (
|
generated_path = (
|
||||||
"{}/data/generated-thumbnails/".format(tmpdir)
|
"{}/data/generated-thumbnails/".format(tmpdir)
|
||||||
+ "1_244c8840887984c4.jpg"
|
+ "sample_1_244c8840887984c4.jpg"
|
||||||
)
|
)
|
||||||
source_path = (
|
source_path = (
|
||||||
"{}/data/posts/custom-thumbnails/".format(tmpdir)
|
"{}/data/posts/custom-thumbnails/".format(tmpdir)
|
||||||
@ -686,7 +699,7 @@ def test_update_post_thumbnail_with_broken_thumbnail(
|
|||||||
assert post.post_id
|
assert post.post_id
|
||||||
generated_path = (
|
generated_path = (
|
||||||
"{}/data/generated-thumbnails/".format(tmpdir)
|
"{}/data/generated-thumbnails/".format(tmpdir)
|
||||||
+ "1_244c8840887984c4.jpg"
|
+ "sample_1_244c8840887984c4.jpg"
|
||||||
)
|
)
|
||||||
source_path = (
|
source_path = (
|
||||||
"{}/data/posts/custom-thumbnails/".format(tmpdir)
|
"{}/data/posts/custom-thumbnails/".format(tmpdir)
|
||||||
@ -705,8 +718,8 @@ def test_update_post_thumbnail_with_broken_thumbnail(
|
|||||||
assert handle.read() == read_asset("png-broken.png")
|
assert handle.read() == read_asset("png-broken.png")
|
||||||
with open(generated_path, "rb") as handle:
|
with open(generated_path, "rb") as handle:
|
||||||
image = images.Image(handle.read())
|
image = images.Image(handle.read())
|
||||||
assert image.width == 1
|
assert image.width == 300
|
||||||
assert image.height == 1
|
assert image.height == 300
|
||||||
|
|
||||||
|
|
||||||
def test_update_post_content_leaving_custom_thumbnail(
|
def test_update_post_content_leaving_custom_thumbnail(
|
||||||
@ -731,7 +744,7 @@ def test_update_post_content_leaving_custom_thumbnail(
|
|||||||
db.session.flush()
|
db.session.flush()
|
||||||
generated_path = (
|
generated_path = (
|
||||||
"{}/data/generated-thumbnails/".format(tmpdir)
|
"{}/data/generated-thumbnails/".format(tmpdir)
|
||||||
+ "1_244c8840887984c4.jpg"
|
+ "sample_1_244c8840887984c4.jpg"
|
||||||
)
|
)
|
||||||
source_path = (
|
source_path = (
|
||||||
"{}/data/posts/custom-thumbnails/".format(tmpdir)
|
"{}/data/posts/custom-thumbnails/".format(tmpdir)
|
||||||
@ -763,7 +776,7 @@ def test_update_post_content_convert_heif_to_png_when_processing(
|
|||||||
db.session.flush()
|
db.session.flush()
|
||||||
generated_path = (
|
generated_path = (
|
||||||
"{}/data/generated-thumbnails/".format(tmpdir)
|
"{}/data/generated-thumbnails/".format(tmpdir)
|
||||||
+ "1_244c8840887984c4.jpg"
|
+ "sample_1_244c8840887984c4.jpg"
|
||||||
)
|
)
|
||||||
source_path = (
|
source_path = (
|
||||||
"{}/data/posts/custom-thumbnails/".format(tmpdir)
|
"{}/data/posts/custom-thumbnails/".format(tmpdir)
|
||||||
|
Reference in New Issue
Block a user