summaryrefslogtreecommitdiff
path: root/server/szurubooru/tests/func/test_posts.py
diff options
context:
space:
mode:
Diffstat (limited to 'server/szurubooru/tests/func/test_posts.py')
-rw-r--r--server/szurubooru/tests/func/test_posts.py59
1 files changed, 50 insertions, 9 deletions
diff --git a/server/szurubooru/tests/func/test_posts.py b/server/szurubooru/tests/func/test_posts.py
index fa1b3bb..168a74a 100644
--- a/server/szurubooru/tests/func/test_posts.py
+++ b/server/szurubooru/tests/func/test_posts.py
@@ -8,13 +8,13 @@ from szurubooru import db, model
from szurubooru.func import (
comments,
files,
- image_hash,
images,
posts,
tags,
users,
util,
)
+from szurubooru.func.posts import _get_safety_list
@pytest.mark.parametrize(
@@ -101,6 +101,9 @@ def test_serialize_post(
comment_factory,
tag_factory,
tag_category_factory,
+ metric_factory,
+ post_metric_factory,
+ post_metric_range_factory,
pool_factory,
pool_category_factory,
config_injector,
@@ -122,14 +125,23 @@ def test_serialize_post(
post.post_id = 1
post.creation_time = datetime(1997, 1, 1)
post.last_edit_time = datetime(1998, 1, 1)
- post.tags = [
- tag_factory(
- names=["tag1", "tag2"],
- category=tag_category_factory("test-cat1"),
- ),
- tag_factory(
- names=["tag3"], category=tag_category_factory("test-cat2")
- ),
+ tag1 = tag_factory(
+ names=["tag1", "tag2"],
+ category=tag_category_factory("test-cat1")
+ )
+ tag1.metric = metric_factory(tag=tag1, min=-2.5, max=2.5)
+ tag3 = tag_factory(
+ names=["tag3"],
+ category=tag_category_factory("test-cat2")
+ )
+ post.tags = [tag1, tag3]
+ post.metrics = [
+ post_metric_factory(post=post, metric=tag1.metric, value=-1.2)
+ ]
+ post.metric_ranges = [
+ post_metric_range_factory(
+ post=post, metric=tag1.metric, low=2, high=3
+ )
]
post.safety = model.Post.SAFETY_SAFE
post.source = "4gag"
@@ -233,11 +245,16 @@ def test_serialize_post(
"names": ["tag1", "tag2"],
"category": "test-cat1",
"usages": 1,
+ "metric": {
+ "min": -2.5,
+ "max": 2.5
+ },
},
{
"names": ["tag3"],
"category": "test-cat2",
"usages": 1,
+ "metric": None,
},
],
"relations": [],
@@ -273,6 +290,21 @@ def test_serialize_post(
"hasCustomThumbnail": True,
"mimeType": "image/jpeg",
"comments": ["commenter1", "commenter2"],
+ "metrics": [
+ {
+ "tag_name": "tag1",
+ "post_id": 1,
+ "value": -1.2
+ }
+ ],
+ "metricRanges": [
+ {
+ "tag_name": "tag1",
+ "post_id": 1,
+ "low": 2,
+ "high": 3
+ }
+ ],
}
@@ -1221,3 +1253,12 @@ def test_search_by_image(post_factory, config_injector, read_asset):
result2 = posts.search_by_image(read_asset("png.png"))
assert not result2
+
+
+def test_get_safety_list():
+ assert _get_safety_list('') == ['safe', 'sketchy', 'unsafe']
+ assert _get_safety_list('abc') == ['safe', 'sketchy', 'unsafe']
+ assert _get_safety_list('abc rating:lol -def') ==\
+ ['safe', 'sketchy', 'unsafe']
+ assert _get_safety_list('abc -rating:sketchy,lol def') == ['safe', 'unsafe']
+ assert _get_safety_list('rating:safe,unsafe -rating:safe') == ['unsafe']