aboutsummaryrefslogtreecommitdiff
path: root/server/szurubooru/tests/api
diff options
context:
space:
mode:
authorrr-2016-05-07 21:42:03 +0200
committerrr-2016-05-07 21:50:37 +0200
commit58964bcdc9cfeccd72a017fdbd2f4ffc8ba7b6f3 (patch)
tree1996c877f0ad62e56605fe259a6cd6294bcb59e7 /server/szurubooru/tests/api
parent9b591c3f1ba36f8aabee57d7ce46457acbb20794 (diff)
server/posts: add post listing
Diffstat (limited to 'server/szurubooru/tests/api')
-rw-r--r--server/szurubooru/tests/api/test_post_retrieving.py53
1 files changed, 53 insertions, 0 deletions
diff --git a/server/szurubooru/tests/api/test_post_retrieving.py b/server/szurubooru/tests/api/test_post_retrieving.py
index 369fa79..b32e52d 100644
--- a/server/szurubooru/tests/api/test_post_retrieving.py
+++ b/server/szurubooru/tests/api/test_post_retrieving.py
@@ -21,9 +21,62 @@ def test_ctx(
ret.context_factory = context_factory
ret.user_factory = user_factory
ret.post_factory = post_factory
+ ret.list_api = api.PostListApi()
ret.detail_api = api.PostDetailApi()
return ret
+def test_retrieving_multiple(test_ctx):
+ post1 = test_ctx.post_factory(id=1)
+ post2 = test_ctx.post_factory(id=2)
+ db.session.add_all([post1, post2])
+ result = test_ctx.list_api.get(
+ test_ctx.context_factory(
+ input={'query': '', 'page': 1},
+ user=test_ctx.user_factory(rank='regular_user')))
+ assert result['query'] == ''
+ assert result['page'] == 1
+ assert result['pageSize'] == 100
+ assert result['total'] == 2
+ assert [t['id'] for t in result['results']] == [1, 2]
+
+def test_using_special_tokens(
+ test_ctx, config_injector):
+ auth_user = test_ctx.user_factory(rank='regular_user')
+ post1 = test_ctx.post_factory(id=1)
+ post2 = test_ctx.post_factory(id=2)
+ post1.favorited_by = [db.PostFavorite(
+ user=auth_user, time=datetime.datetime.now())]
+ db.session.add_all([post1, post2, auth_user])
+ db.session.flush()
+ result = test_ctx.list_api.get(
+ test_ctx.context_factory(
+ input={'query': 'special:fav', 'page': 1},
+ user=auth_user))
+ assert result['query'] == 'special:fav'
+ assert result['page'] == 1
+ assert result['pageSize'] == 100
+ assert result['total'] == 1
+ assert [t['id'] for t in result['results']] == [1]
+
+def test_trying_to_use_special_tokens_without_logging_in(
+ test_ctx, config_injector):
+ config_injector({
+ 'privileges': {'posts:list': 'anonymous'},
+ 'ranks': ['anonymous'],
+ })
+ with pytest.raises(errors.SearchError):
+ test_ctx.list_api.get(
+ test_ctx.context_factory(
+ input={'query': 'special:fav', 'page': 1},
+ user=test_ctx.user_factory(rank='anonymous')))
+
+def test_trying_to_retrieve_multiple_without_privileges(test_ctx):
+ with pytest.raises(errors.AuthError):
+ test_ctx.list_api.get(
+ test_ctx.context_factory(
+ input={'query': '', 'page': 1},
+ user=test_ctx.user_factory(rank='anonymous')))
+
def test_retrieving_single(test_ctx):
db.session.add(test_ctx.post_factory(id=1))
result = test_ctx.detail_api.get(

© 2015 - 2026 Jakob L. Kreuze