summaryrefslogtreecommitdiff
path: root/server/szurubooru/tests/api/test_post_retrieving.py
diff options
context:
space:
mode:
authorrr- <rr-@sakuya.pl>2017-02-04 01:08:12 +0100
committerrr- <rr-@sakuya.pl>2017-02-05 16:34:45 +0100
commitad842ee8a54c57463b8e28b52970f173ea1d64ea (patch)
tree1238e8270878801a2ddb10bc4db469115c026cab /server/szurubooru/tests/api/test_post_retrieving.py
parentabf1fc2b2d135299fe7e8a700d4e7a18966d7bfe (diff)
server: refactor + add type hinting
- Added type hinting (for now, 3.5-compatible) - Split `db` namespace into `db` module and `model` namespace - Changed elastic search to be created lazily for each operation - Changed to class based approach in entity serialization to allow stronger typing - Removed `required` argument from `context.get_*` family of functions; now it's implied if `default` argument is omitted - Changed `unalias_dict` implementation to use less magic inputs
Diffstat (limited to 'server/szurubooru/tests/api/test_post_retrieving.py')
-rw-r--r--server/szurubooru/tests/api/test_post_retrieving.py22
1 files changed, 11 insertions, 11 deletions
diff --git a/server/szurubooru/tests/api/test_post_retrieving.py b/server/szurubooru/tests/api/test_post_retrieving.py
index a02c7bc..9d9db72 100644
--- a/server/szurubooru/tests/api/test_post_retrieving.py
+++ b/server/szurubooru/tests/api/test_post_retrieving.py
@@ -1,7 +1,7 @@
from datetime import datetime
from unittest.mock import patch
import pytest
-from szurubooru import api, db, errors
+from szurubooru import api, db, model, errors
from szurubooru.func import posts
@@ -9,8 +9,8 @@ from szurubooru.func import posts
def inject_config(config_injector):
config_injector({
'privileges': {
- 'posts:list': db.User.RANK_REGULAR,
- 'posts:view': db.User.RANK_REGULAR,
+ 'posts:list': model.User.RANK_REGULAR,
+ 'posts:view': model.User.RANK_REGULAR,
},
})
@@ -25,7 +25,7 @@ def test_retrieving_multiple(user_factory, post_factory, context_factory):
result = api.post_api.get_posts(
context_factory(
params={'query': '', 'page': 1},
- user=user_factory(rank=db.User.RANK_REGULAR)))
+ user=user_factory(rank=model.User.RANK_REGULAR)))
assert result == {
'query': '',
'page': 1,
@@ -36,10 +36,10 @@ def test_retrieving_multiple(user_factory, post_factory, context_factory):
def test_using_special_tokens(user_factory, post_factory, context_factory):
- auth_user = user_factory(rank=db.User.RANK_REGULAR)
+ auth_user = user_factory(rank=model.User.RANK_REGULAR)
post1 = post_factory(id=1)
post2 = post_factory(id=2)
- post1.favorited_by = [db.PostFavorite(
+ post1.favorited_by = [model.PostFavorite(
user=auth_user, time=datetime.utcnow())]
db.session.add_all([post1, post2, auth_user])
db.session.flush()
@@ -68,7 +68,7 @@ def test_trying_to_use_special_tokens_without_logging_in(
api.post_api.get_posts(
context_factory(
params={'query': 'special:fav', 'page': 1},
- user=user_factory(rank=db.User.RANK_ANONYMOUS)))
+ user=user_factory(rank=model.User.RANK_ANONYMOUS)))
def test_trying_to_retrieve_multiple_without_privileges(
@@ -77,7 +77,7 @@ def test_trying_to_retrieve_multiple_without_privileges(
api.post_api.get_posts(
context_factory(
params={'query': '', 'page': 1},
- user=user_factory(rank=db.User.RANK_ANONYMOUS)))
+ user=user_factory(rank=model.User.RANK_ANONYMOUS)))
def test_retrieving_single(user_factory, post_factory, context_factory):
@@ -86,7 +86,7 @@ def test_retrieving_single(user_factory, post_factory, context_factory):
with patch('szurubooru.func.posts.serialize_post'):
posts.serialize_post.return_value = 'serialized post'
result = api.post_api.get_post(
- context_factory(user=user_factory(rank=db.User.RANK_REGULAR)),
+ context_factory(user=user_factory(rank=model.User.RANK_REGULAR)),
{'post_id': 1})
assert result == 'serialized post'
@@ -94,7 +94,7 @@ def test_retrieving_single(user_factory, post_factory, context_factory):
def test_trying_to_retrieve_single_non_existing(user_factory, context_factory):
with pytest.raises(posts.PostNotFoundError):
api.post_api.get_post(
- context_factory(user=user_factory(rank=db.User.RANK_REGULAR)),
+ context_factory(user=user_factory(rank=model.User.RANK_REGULAR)),
{'post_id': 999})
@@ -102,5 +102,5 @@ def test_trying_to_retrieve_single_without_privileges(
user_factory, context_factory):
with pytest.raises(errors.AuthError):
api.post_api.get_post(
- context_factory(user=user_factory(rank=db.User.RANK_ANONYMOUS)),
+ context_factory(user=user_factory(rank=model.User.RANK_ANONYMOUS)),
{'post_id': 999})