diff options
Diffstat (limited to 'server/szurubooru/tests/conftest.py')
| -rw-r--r-- | server/szurubooru/tests/conftest.py | 53 |
1 files changed, 52 insertions, 1 deletions
diff --git a/server/szurubooru/tests/conftest.py b/server/szurubooru/tests/conftest.py index 280987c..45113f5 100644 --- a/server/szurubooru/tests/conftest.py +++ b/server/szurubooru/tests/conftest.py @@ -151,7 +151,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) @@ -161,6 +161,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 @@ -173,6 +175,7 @@ def post_factory(): safety=model.Post.SAFETY_SAFE, type=model.Post.TYPE_IMAGE, checksum="...", + tags=[], ): post = model.Post() post.post_id = id @@ -182,6 +185,7 @@ def post_factory(): post.flags = [] post.mime_type = "application/octet-stream" post.creation_time = datetime(1996, 1, 1) + post.tags = tags return post return factory @@ -286,6 +290,53 @@ def pool_post_factory(pool_factory, post_factory): @pytest.fixture +def metric_factory(tag_factory): + def factory(tag=None, min=0, max=10): + 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, tag_factory, metric_factory): + def factory(post=None, metric=None, value=None, tag=None, tag_name=None): + if not post: + post = post_factory() + if tag_name: + tag = tag_factory(names=[tag_name]) + if tag: + metric = metric_factory(tag=tag) + elif not metric: + metric = metric_factory() + 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, 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 tag_name: + tag = tag_factory(names=[tag_name]) + if tag: + metric = metric_factory(tag=tag) + elif not metric: + metric = metric_factory() + if not low: + low = metric.min + if not high: + high = metric.max + return model.PostMetricRange( + post=post, metric=metric, low=low, high=high) + return factory + + +@pytest.fixture def read_asset(): def get(path): path = os.path.join(os.path.dirname(__file__), "assets", path) |