diff options
| author | Hunternif | 2019-05-02 03:57:31 +0700 |
|---|---|---|
| committer | Hunternif | 2019-05-02 03:57:31 +0700 |
| commit | 0b4bdc57894c885ba055aed74de8b9c94c8e2f60 (patch) | |
| tree | 4d217e71aa02fef005afe86d8845e90fe93a9f83 /server/szurubooru/tests/api/test_post_retrieving.py | |
| parent | 82facef4aa1f1ede518acf1435d6ed98d37f8df1 (diff) | |
server: implement median for posts, for any query
Diffstat (limited to 'server/szurubooru/tests/api/test_post_retrieving.py')
| -rw-r--r-- | server/szurubooru/tests/api/test_post_retrieving.py | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/server/szurubooru/tests/api/test_post_retrieving.py b/server/szurubooru/tests/api/test_post_retrieving.py index 7270547..1e4ed03 100644 --- a/server/szurubooru/tests/api/test_post_retrieving.py +++ b/server/szurubooru/tests/api/test_post_retrieving.py @@ -8,6 +8,8 @@ from szurubooru.func import posts @pytest.fixture(autouse=True) def inject_config(config_injector): config_injector({ + 'data_url': 'http://example.com/', + 'secret': 'test', 'privileges': { 'posts:list': model.User.RANK_REGULAR, 'posts:view': model.User.RANK_REGULAR, @@ -104,3 +106,44 @@ def test_trying_to_retrieve_single_without_privileges( api.post_api.get_post( context_factory(user=user_factory(rank=model.User.RANK_ANONYMOUS)), {'post_id': 999}) + + +@pytest.mark.parametrize('query,expected_id', [ + ('sort:id,asc', 2), + ('sort:id,asc id:2..', 2), + ('sort:id,desc id:2..', 3), + ('sort:id,asc id:3..', 3), + ('sort:id,desc id:3..', 3), + ('sort:id id:4..', None), + ('sort:tag-count', 3), + ('sort:tag-count,asc id:..2', 1), + ('sort:tag-count,desc id:..2', 2), +]) +def test_median( + query, + expected_id, + post_factory, + tag_factory, + context_factory, + user_factory): + tag1 = tag_factory() + tag2 = tag_factory() + tag3 = tag_factory() + post1 = post_factory(id=1, tags=[tag1]) + post2 = post_factory(id=2, tags=[tag1, tag2, tag3]) + post3 = post_factory(id=3, tags=[tag1, tag2]) + db.session.add_all([tag1, tag2, tag3, post1, post2, post3]) + db.session.flush() + with patch('szurubooru.func.comments.serialize_comment'), \ + patch('szurubooru.func.users.serialize_micro_user'), \ + patch('szurubooru.func.posts.files.has'): + response = api.post_api.get_posts_median( + context_factory( + params={'query': query}, + user=user_factory(rank=model.User.RANK_REGULAR))) + if not expected_id: + assert response['total'] == 0 + assert len(response['results']) == 0 + else: + assert response['total'] == 1 + assert response['results'][0]['id'] == expected_id |