aboutsummaryrefslogtreecommitdiff
path: root/server/szurubooru/tests/conftest.py
diff options
context:
space:
mode:
authorIlya Tetin2019-04-19 16:49:24 +0700
committerIlya Tetin2019-04-19 16:49:24 +0700
commit09d55f35394b84a983c7cf06af1bcb6802c2d5f8 (patch)
treec0b2825c3e1e3675d00ed3101c4fa99b6f98f8a2 /server/szurubooru/tests/conftest.py
parent77de3c1ca3a935567b4afeaae9da9835366ff540 (diff)
server: serialize post metrics and metric ranges in post
Diffstat (limited to 'server/szurubooru/tests/conftest.py')
-rw-r--r--server/szurubooru/tests/conftest.py37
1 files changed, 24 insertions, 13 deletions
diff --git a/server/szurubooru/tests/conftest.py b/server/szurubooru/tests/conftest.py
index b8af456..084e6e5 100644
--- a/server/szurubooru/tests/conftest.py
+++ b/server/szurubooru/tests/conftest.py
@@ -168,7 +168,7 @@ def tag_category_factory():
@pytest.fixture
def tag_factory():
- def factory(names=None, category=None):
+ def factory(names=None, category=None, metric=None):
if not category:
category = model.TagCategory(get_unique_name())
db.session.add(category)
@@ -178,6 +178,8 @@ def tag_factory():
tag.names.append(model.TagName(name, i))
tag.category = category
tag.creation_time = datetime(1996, 1, 1)
+ if metric:
+ tag.metric = metric
return tag
return factory
@@ -254,35 +256,44 @@ def post_favorite_factory(user_factory, post_factory):
@pytest.fixture
def metric_factory(tag_factory):
def factory(tag=None, min=0, max=10):
- if tag is None:
+ if not tag:
tag = tag_factory()
return model.Metric(tag=tag, min=min, max=max)
return factory
@pytest.fixture
-def post_metric_factory(post_factory, metric_factory):
- def factory(post=None, metric=None, value=None):
- if post is None:
+def post_metric_factory(post_factory, tag_factory, metric_factory):
+ def factory(post=None, metric=None, value=None, tag=None, tag_name=None):
+ if not post:
post = post_factory()
- if metric is None:
+ if tag_name:
+ tag = tag_factory(names=[tag_name])
+ if tag:
+ metric = metric_factory(tag=tag)
+ elif not metric:
metric = metric_factory()
- if value is None:
+ if not value:
value = (metric.min + metric.max)/2
return model.PostMetric(post=post, metric=metric, value=value)
return factory
@pytest.fixture
-def post_metric_range_factory(post_factory, metric_factory):
- def factory(post=None, metric=None, low=None, high=None):
- if post is None:
+def post_metric_range_factory(post_factory, tag_factory, metric_factory):
+ def factory(post=None, metric=None, low=None, high=None, tag=None,
+ tag_name=None):
+ if not post:
post = post_factory()
- if metric is None:
+ if tag_name:
+ tag = tag_factory(names=[tag_name])
+ if tag:
+ metric = metric_factory(tag=tag)
+ elif not metric:
metric = metric_factory()
- if low is None:
+ if not low:
low = metric.min
- if high is None:
+ if not high:
high = metric.max
return model.PostMetricRange(
post=post, metric=metric, low=low, high=high)

© 2015 - 2026 Jakob L. Kreuze