From 8d1e23aa63370ed2e14deaa8fef9eca11ad31eae Mon Sep 17 00:00:00 2001 From: rr- Date: Mon, 30 May 2016 22:20:42 +0200 Subject: [PATCH] server/general: flatten responses --- API.md | 133 +++--------------- client/js/api.js | 2 +- client/js/controllers/tags_controller.js | 4 +- client/js/controllers/users_controller.js | 8 +- server/szurubooru/api/comment_api.py | 10 +- server/szurubooru/api/post_api.py | 18 +-- server/szurubooru/api/tag_api.py | 8 +- server/szurubooru/api/tag_category_api.py | 8 +- server/szurubooru/api/user_api.py | 7 +- .../tests/api/test_comment_creating.py | 10 +- .../tests/api/test_comment_rating.py | 3 +- .../tests/api/test_comment_retrieving.py | 15 +- .../tests/api/test_comment_updating.py | 2 +- .../tests/api/test_post_creating.py | 4 +- .../tests/api/test_post_favoriting.py | 3 +- .../tests/api/test_post_featuring.py | 16 +-- .../szurubooru/tests/api/test_post_rating.py | 3 +- .../tests/api/test_post_retrieving.py | 7 +- .../tests/api/test_post_updating.py | 2 +- .../tests/api/test_tag_category_creating.py | 6 +- .../tests/api/test_tag_category_retrieving.py | 12 +- .../tests/api/test_tag_category_updating.py | 8 +- .../szurubooru/tests/api/test_tag_creating.py | 18 +-- .../szurubooru/tests/api/test_tag_merging.py | 6 +- .../tests/api/test_tag_retrieving.py | 18 ++- .../szurubooru/tests/api/test_tag_updating.py | 18 +-- .../tests/api/test_user_creating.py | 29 ++-- .../tests/api/test_user_retrieving.py | 18 ++- .../tests/api/test_user_updating.py | 20 ++- 29 files changed, 155 insertions(+), 261 deletions(-) diff --git a/API.md b/API.md index 38aea695..8d4eccd8 100644 --- a/API.md +++ b/API.md @@ -63,16 +63,11 @@ 3. [Resources](#resources) - [User](#user) - - [Detailed user](#detailed-user) - [Tag category](#tag-category) - - [Detailed tag category](#detailed-tag-category) - [Tag](#tag) - - [Detailed tag](#detailed-tag) - [Post](#post) - - [Detailed post](#detailed-post) - [Note](#note) - [Comment](#comment) - - [Detailed comment](#detailed-comment) - [Snapshot](#snapshot) - [Unpaged search result](#unpaged-search-result) - [Paged search result](#paged-search-result) @@ -174,7 +169,7 @@ data. - **Output** - A [detailed tag category resource](#detailed-tag-category). + A [tag category resource](#tag-category). - **Errors** @@ -205,7 +200,7 @@ data. - **Output** - A [detailed tag category resource](#detailed-tag-category). + A [tag category resource](#tag-category). - **Errors** @@ -228,7 +223,7 @@ data. - **Output** - A [detailed tag category resource](#detailed-tag-category). + A [tag category resource](#tag-category). - **Errors** @@ -275,7 +270,7 @@ data. - **Output** - A [detailed tag category resource](#detailed-tag-category). + A [tag category resource](#tag-category). - **Errors** @@ -374,7 +369,7 @@ data. - **Output** - A [detailed tag resource](#detailed-tag). + A [tag resource](#tag). - **Errors** @@ -416,7 +411,7 @@ data. - **Output** - A [detailed tag resource](#detailed-tag). + A [tag resource](#tag). - **Errors** @@ -446,7 +441,7 @@ data. - **Output** - A [detailed tag resource](#detailed-tag). + A [tag resource](#tag). - **Errors** @@ -494,7 +489,7 @@ data. - **Output** - A [detailed tag resource](#detailed-tag) containing the merged tag. + A [tag resource](#tag) containing the merged tag. - **Errors** @@ -673,7 +668,7 @@ data. - **Output** - A [detailed post resource](#detailed-post). + A [post resource](#post). - **Errors** @@ -719,7 +714,7 @@ data. - **Output** - A [detailed post resource](#detailed-post). + A [post resource](#post). - **Errors** @@ -746,7 +741,7 @@ data. - **Output** - A [detailed post resource](#detailed-post). + A [post resource](#post). - **Errors** @@ -792,7 +787,7 @@ data. - **Output** - A [detailed post resource](#detailed-post). + A [post resource](#post). - **Errors** @@ -812,7 +807,7 @@ data. - **Output** - A [detailed post resource](#detailed-post). + A [post resource](#post). - **Errors** @@ -830,7 +825,7 @@ data. - **Output** - A [detailed post resource](#detailed-post). + A [post resource](#post). - **Errors** @@ -848,7 +843,7 @@ data. - **Output** - A [detailed post resource](#detailed-post). + A [post resource](#post). - **Errors** @@ -877,7 +872,7 @@ data. - **Output** - A [detailed post resource](#detailed-post). + A [post resource](#post). - **Errors** @@ -961,7 +956,7 @@ data. - **Output** - A [detailed comment resource](#detailed-comment). + A [comment resource](#comment). - **Errors** @@ -988,7 +983,7 @@ data. - **Output** - A [detailed comment resource](#detailed-comment). + A [comment resource](#comment). - **Errors** @@ -1007,7 +1002,7 @@ data. - **Output** - A [detailed comment resource](#detailed-comment). + A [comment resource](#comment). - **Errors** @@ -1053,7 +1048,7 @@ data. - **Output** - A [detailed comment resource](#detailed-comment). + A [comment resource](#comment). - **Errors** @@ -1140,7 +1135,7 @@ data. - **Output** - A [detailed user resource](#detailed-user). + A [user resource](#user). - **Errors** @@ -1185,7 +1180,7 @@ data. - **Output** - A [detailed user resource](#detailed-user). + A [user resource](#user). - **Errors** @@ -1214,7 +1209,7 @@ data. - **Output** - A [detailed user resource](#detailed-user). + A [user resource](#user). - **Errors** @@ -1414,23 +1409,6 @@ A single user. - ``: the URL to the avatar. -## Detailed user -**Description** - -A wrapper for a user. In the future, it might offer extra information. - -**Structure** - -```json5 -{ - "user": -} -``` - -**Field meaning** - -- ``: a [user resource](#user). - ## Tag category **Description** @@ -1463,23 +1441,6 @@ experience. - ``: a [snapshot resource](#snapshot) that contains the tag category's earlier versions. -## Detailed tag category -**Description** - -A tag category with extra information. - -**Structure** - -```json5 -{ - "tagCategory": , -} -``` - -**Field meaning** - -- ``: a [tag category resource](#tag-category) - ## Tag **Description** @@ -1519,22 +1480,6 @@ A single tag. Tags are used to let users search for posts. - ``: a [snapshot resource](#snapshot) that contains the tag's earlier versions. -## Detailed tag -**Description** - -A tag with extra information. - -**Structure** - -```json5 -{ - "tag": , -} -``` - -**Field meaning** -- ``: a [tag resource](#tag) - ## Post **Description** @@ -1632,22 +1577,6 @@ One file together with its metadata posted to the site. earlier versions. - ``: a [comment resource](#comment) for given post. -## Detailed post -**Description** - -A post with extra information. - -**Structure** - -```json5 -{ - "post": , -} -``` - -**Field meaning** -- ``: a [post resource](#post). - ## Note **Description** @@ -1700,22 +1629,6 @@ A comment under a post. - ``: the score (+1/-1 rating) of the given comment by the authenticated user. -## Detailed comment -**Description** - -A wrapper for a comment. In the future, it might offer extra information. - -**Structure** - -```json5 -{ - "comment": -} -``` - -**Field meaning** -- ``: a [comment resource](#comment). - ## Snapshot **Description** diff --git a/client/js/api.js b/client/js/api.js index 9331171d..de9221fb 100644 --- a/client/js/api.js +++ b/client/js/api.js @@ -134,7 +134,7 @@ class Api { 'auth', {'user': userName, 'password': userPassword}, options); - this.user = response.user; + this.user = response; resolve(); events.notify(events.Authentication); }).catch(response => { diff --git a/client/js/controllers/tags_controller.js b/client/js/controllers/tags_controller.js index 774f1b89..bf202ea9 100644 --- a/client/js/controllers/tags_controller.js +++ b/client/js/controllers/tags_controller.js @@ -88,9 +88,9 @@ class TagsController { next(); } else { api.get('/tag/' + ctx.params.name).then(response => { - ctx.state.tag = response.tag; + ctx.state.tag = response; ctx.save(); - this._cachedTag = response.tag; + this._cachedTag = response; next(); }, response => { this._emptyView.render(); diff --git a/client/js/controllers/users_controller.js b/client/js/controllers/users_controller.js index 2872ac1f..fc9bbf2d 100644 --- a/client/js/controllers/users_controller.js +++ b/client/js/controllers/users_controller.js @@ -95,10 +95,10 @@ class UsersController { next(); } else { api.get('/user/' + ctx.params.name).then(response => { - response.user.rankName = rankNames.get(response.user.rank); - ctx.state.user = response.user; + response.rankName = rankNames.get(response.rank); + ctx.state.user = response; ctx.save(); - this._cachedUser = response.user; + this._cachedUser = response; next(); }, response => { this._emptyView.render(); @@ -170,7 +170,7 @@ class UsersController { return new Promise((resolve, reject) => { api.put('/user/' + user.name, data, files) .then(response => { - this._cachedUser = response.user; + this._cachedUser = response; return isLoggedIn ? api.login( data.name || api.userName, diff --git a/server/szurubooru/api/comment_api.py b/server/szurubooru/api/comment_api.py index b0e00742..8aeaceca 100644 --- a/server/szurubooru/api/comment_api.py +++ b/server/szurubooru/api/comment_api.py @@ -23,13 +23,13 @@ class CommentListApi(BaseApi): comment = comments.create_comment(ctx.user, post, text) ctx.session.add(comment) ctx.session.commit() - return {'comment': comments.serialize_comment(comment, ctx.user)} + return comments.serialize_comment(comment, ctx.user) class CommentDetailApi(BaseApi): def get(self, ctx, comment_id): auth.verify_privilege(ctx.user, 'comments:view') comment = comments.get_comment_by_id(comment_id) - return {'comment': comments.serialize_comment(comment, ctx.user)} + return comments.serialize_comment(comment, ctx.user) def put(self, ctx, comment_id): comment = comments.get_comment_by_id(comment_id) @@ -39,7 +39,7 @@ class CommentDetailApi(BaseApi): comment.last_edit_time = datetime.datetime.now() comments.update_comment_text(comment, text) ctx.session.commit() - return {'comment': comments.serialize_comment(comment, ctx.user)} + return comments.serialize_comment(comment, ctx.user) def delete(self, ctx, comment_id): comment = comments.get_comment_by_id(comment_id) @@ -56,11 +56,11 @@ class CommentScoreApi(BaseApi): comment = comments.get_comment_by_id(comment_id) scores.set_score(comment, ctx.user, score) ctx.session.commit() - return {'comment': comments.serialize_comment(comment, ctx.user)} + return comments.serialize_comment(comment, ctx.user) def delete(self, ctx, comment_id): auth.verify_privilege(ctx.user, 'comments:score') comment = comments.get_comment_by_id(comment_id) scores.delete_score(comment, ctx.user) ctx.session.commit() - return {'comment': comments.serialize_comment(comment, ctx.user)} + return comments.serialize_comment(comment, ctx.user) diff --git a/server/szurubooru/api/post_api.py b/server/szurubooru/api/post_api.py index b7bdafe9..3f0eb941 100644 --- a/server/szurubooru/api/post_api.py +++ b/server/szurubooru/api/post_api.py @@ -38,13 +38,13 @@ class PostListApi(BaseApi): snapshots.save_entity_creation(post, ctx.user) ctx.session.commit() tags.export_to_json() - return {'post': posts.serialize_post(post, ctx.user)} + return posts.serialize_post(post, ctx.user) class PostDetailApi(BaseApi): def get(self, ctx, post_id): auth.verify_privilege(ctx.user, 'posts:view') post = posts.get_post_by_id(post_id) - return {'post': posts.serialize_post(post, ctx.user)} + return posts.serialize_post(post, ctx.user) def put(self, ctx, post_id): post = posts.get_post_by_id(post_id) @@ -79,7 +79,7 @@ class PostDetailApi(BaseApi): snapshots.save_entity_modification(post, ctx.user) ctx.session.commit() tags.export_to_json() - return {'post': posts.serialize_post(post, ctx.user)} + return posts.serialize_post(post, ctx.user) def delete(self, ctx, post_id): auth.verify_privilege(ctx.user, 'posts:delete') @@ -104,11 +104,11 @@ class PostFeatureApi(BaseApi): snapshots.save_entity_modification(featured_post, ctx.user) snapshots.save_entity_modification(post, ctx.user) ctx.session.commit() - return {'post': posts.serialize_post(post, ctx.user)} + return posts.serialize_post(post, ctx.user) def get(self, ctx): post = posts.try_get_featured_post() - return {'post': posts.serialize_post(post, ctx.user)} + return posts.serialize_post(post, ctx.user) class PostScoreApi(BaseApi): def put(self, ctx, post_id): @@ -117,14 +117,14 @@ class PostScoreApi(BaseApi): score = ctx.get_param_as_int('score', required=True) scores.set_score(post, ctx.user, score) ctx.session.commit() - return {'post': posts.serialize_post(post, ctx.user)} + return posts.serialize_post(post, ctx.user) def delete(self, ctx, post_id): auth.verify_privilege(ctx.user, 'posts:score') post = posts.get_post_by_id(post_id) scores.delete_score(post, ctx.user) ctx.session.commit() - return {'post': posts.serialize_post(post, ctx.user)} + return posts.serialize_post(post, ctx.user) class PostFavoriteApi(BaseApi): def post(self, ctx, post_id): @@ -132,11 +132,11 @@ class PostFavoriteApi(BaseApi): post = posts.get_post_by_id(post_id) favorites.set_favorite(post, ctx.user) ctx.session.commit() - return {'post': posts.serialize_post(post, ctx.user)} + return posts.serialize_post(post, ctx.user) def delete(self, ctx, post_id): auth.verify_privilege(ctx.user, 'posts:favorite') post = posts.get_post_by_id(post_id) favorites.unset_favorite(post, ctx.user) ctx.session.commit() - return {'post': posts.serialize_post(post, ctx.user)} + return posts.serialize_post(post, ctx.user) diff --git a/server/szurubooru/api/tag_api.py b/server/szurubooru/api/tag_api.py index 6dc79461..65cecf90 100644 --- a/server/szurubooru/api/tag_api.py +++ b/server/szurubooru/api/tag_api.py @@ -41,13 +41,13 @@ class TagListApi(BaseApi): snapshots.save_entity_creation(tag, ctx.user) ctx.session.commit() tags.export_to_json() - return {'tag': tags.serialize_tag(tag)} + return tags.serialize_tag(tag) class TagDetailApi(BaseApi): def get(self, ctx, tag_name): auth.verify_privilege(ctx.user, 'tags:view') tag = tags.get_tag_by_name(tag_name) - return {'tag': tags.serialize_tag(tag)} + return tags.serialize_tag(tag) def put(self, ctx, tag_name): tag = tags.get_tag_by_name(tag_name) @@ -73,7 +73,7 @@ class TagDetailApi(BaseApi): snapshots.save_entity_modification(tag, ctx.user) ctx.session.commit() tags.export_to_json() - return {'tag': tags.serialize_tag(tag)} + return tags.serialize_tag(tag) def delete(self, ctx, tag_name): tag = tags.get_tag_by_name(tag_name) @@ -101,7 +101,7 @@ class TagMergeApi(BaseApi): tags.merge_tags(source_tag, target_tag) ctx.session.commit() tags.export_to_json() - return {'tag': tags.serialize_tag(target_tag)} + return tags.serialize_tag(target_tag) class TagSiblingsApi(BaseApi): def get(self, ctx, tag_name): diff --git a/server/szurubooru/api/tag_category_api.py b/server/szurubooru/api/tag_category_api.py index 2da83435..ffae5e0c 100644 --- a/server/szurubooru/api/tag_category_api.py +++ b/server/szurubooru/api/tag_category_api.py @@ -21,13 +21,13 @@ class TagCategoryListApi(BaseApi): snapshots.save_entity_creation(category, ctx.user) ctx.session.commit() tags.export_to_json() - return {'tagCategory': tag_categories.serialize_category(category)} + return tag_categories.serialize_category(category) class TagCategoryDetailApi(BaseApi): def get(self, ctx, category_name): auth.verify_privilege(ctx.user, 'tag_categories:view') category = tag_categories.get_category_by_name(category_name) - return {'tagCategory': tag_categories.serialize_category(category)} + return tag_categories.serialize_category(category) def put(self, ctx, category_name): category = tag_categories.get_category_by_name(category_name) @@ -43,7 +43,7 @@ class TagCategoryDetailApi(BaseApi): snapshots.save_entity_modification(category, ctx.user) ctx.session.commit() tags.export_to_json() - return {'tagCategory': tag_categories.serialize_category(category)} + return tag_categories.serialize_category(category) def delete(self, ctx, category_name): category = tag_categories.get_category_by_name(category_name) @@ -69,4 +69,4 @@ class DefaultTagCategoryApi(BaseApi): snapshots.save_entity_modification(category, ctx.user) ctx.session.commit() tags.export_to_json() - return {'tagCategory': tag_categories.serialize_category(category)} + return tag_categories.serialize_category(category) diff --git a/server/szurubooru/api/user_api.py b/server/szurubooru/api/user_api.py index 9870b4f2..29371ce6 100644 --- a/server/szurubooru/api/user_api.py +++ b/server/szurubooru/api/user_api.py @@ -28,14 +28,13 @@ class UserListApi(BaseApi): ctx.get_file('avatar')) ctx.session.add(user) ctx.session.commit() - return {'user': users.serialize_user( - user, ctx.user, force_show_email=True)} + return users.serialize_user(user, ctx.user, force_show_email=True) class UserDetailApi(BaseApi): def get(self, ctx, user_name): auth.verify_privilege(ctx.user, 'users:view') user = users.get_user_by_name(user_name) - return {'user': users.serialize_user(user, ctx.user)} + return users.serialize_user(user, ctx.user) def put(self, ctx, user_name): user = users.get_user_by_name(user_name) @@ -61,7 +60,7 @@ class UserDetailApi(BaseApi): ctx.get_param_as_string('avatarStyle'), ctx.get_file('avatar')) ctx.session.commit() - return {'user': users.serialize_user(user, ctx.user)} + return users.serialize_user(user, ctx.user) def delete(self, ctx, user_name): user = users.get_user_by_name(user_name) diff --git a/server/szurubooru/tests/api/test_comment_creating.py b/server/szurubooru/tests/api/test_comment_creating.py index 2a148358..00a9de60 100644 --- a/server/szurubooru/tests/api/test_comment_creating.py +++ b/server/szurubooru/tests/api/test_comment_creating.py @@ -29,11 +29,11 @@ def test_creating_comment(test_ctx, fake_datetime): test_ctx.context_factory( input={'text': 'input', 'postId': post.post_id}, user=user)) - assert result['comment']['text'] == 'input' - assert 'id' in result['comment'] - assert 'user' in result['comment'] - assert 'name' in result['comment']['user'] - assert 'postId' in result['comment'] + assert result['text'] == 'input' + assert 'id' in result + assert 'user' in result + assert 'name' in result['user'] + assert 'postId' in result comment = db.session.query(db.Comment).one() assert comment.text == 'input' assert comment.creation_time == datetime.datetime(1997, 1, 1) diff --git a/server/szurubooru/tests/api/test_comment_rating.py b/server/szurubooru/tests/api/test_comment_rating.py index c0a00cc1..6a8360a0 100644 --- a/server/szurubooru/tests/api/test_comment_rating.py +++ b/server/szurubooru/tests/api/test_comment_rating.py @@ -32,8 +32,7 @@ def test_simple_rating(test_ctx, fake_datetime): result = test_ctx.api.put( test_ctx.context_factory(input={'score': 1}, user=user), comment.comment_id) - assert 'comment' in result - assert 'text' in result['comment'] + assert 'text' in result comment = db.session.query(db.Comment).one() assert db.session.query(db.CommentScore).count() == 1 assert comment is not None diff --git a/server/szurubooru/tests/api/test_comment_retrieving.py b/server/szurubooru/tests/api/test_comment_retrieving.py index 5f70b42b..3338d1b4 100644 --- a/server/szurubooru/tests/api/test_comment_retrieving.py +++ b/server/szurubooru/tests/api/test_comment_retrieving.py @@ -53,14 +53,13 @@ def test_retrieving_single(test_ctx): test_ctx.context_factory( user=test_ctx.user_factory(rank=db.User.RANK_REGULAR)), comment.comment_id) - assert 'comment' in result - assert 'id' in result['comment'] - assert 'lastEditTime' in result['comment'] - assert 'creationTime' in result['comment'] - assert 'text' in result['comment'] - assert 'user' in result['comment'] - assert 'name' in result['comment']['user'] - assert 'postId' in result['comment'] + assert 'id' in result + assert 'lastEditTime' in result + assert 'creationTime' in result + assert 'text' in result + assert 'user' in result + assert 'name' in result['user'] + assert 'postId' in result def test_trying_to_retrieve_single_non_existing(test_ctx): with pytest.raises(comments.CommentNotFoundError): diff --git a/server/szurubooru/tests/api/test_comment_updating.py b/server/szurubooru/tests/api/test_comment_updating.py index 37831aa4..75822461 100644 --- a/server/szurubooru/tests/api/test_comment_updating.py +++ b/server/szurubooru/tests/api/test_comment_updating.py @@ -33,7 +33,7 @@ def test_simple_updating(test_ctx, fake_datetime): result = test_ctx.api.put( test_ctx.context_factory(input={'text': 'new text'}, user=user), comment.comment_id) - assert result['comment']['text'] == 'new text' + assert result['text'] == 'new text' comment = db.session.query(db.Comment).one() assert comment is not None assert comment.text == 'new text' diff --git a/server/szurubooru/tests/api/test_post_creating.py b/server/szurubooru/tests/api/test_post_creating.py index d049a6bf..adb0b208 100644 --- a/server/szurubooru/tests/api/test_post_creating.py +++ b/server/szurubooru/tests/api/test_post_creating.py @@ -44,7 +44,7 @@ def test_creating_minimal_posts( }, user=auth_user)) - assert result == {'post': 'serialized post'} + assert result == 'serialized post' posts.create_post.assert_called_once_with( 'post-content', ['tag1', 'tag2'], auth_user) posts.update_post_thumbnail.assert_called_once_with(post, 'post-thumbnail') @@ -92,7 +92,7 @@ def test_creating_full_posts(context_factory, post_factory, user_factory): }, user=auth_user)) - assert result == {'post': 'serialized post'} + assert result == 'serialized post' posts.create_post.assert_called_once_with( 'post-content', ['tag1', 'tag2'], auth_user) posts.update_post_safety.assert_called_once_with(post, 'safe') diff --git a/server/szurubooru/tests/api/test_post_favoriting.py b/server/szurubooru/tests/api/test_post_favoriting.py index 00a10350..0e24a01f 100644 --- a/server/szurubooru/tests/api/test_post_favoriting.py +++ b/server/szurubooru/tests/api/test_post_favoriting.py @@ -32,8 +32,7 @@ def test_adding_to_favorites(test_ctx, fake_datetime): result = test_ctx.api.post( test_ctx.context_factory(user=test_ctx.user_factory()), post.post_id) - assert 'post' in result - assert 'id' in result['post'] + assert 'id' in result post = db.session.query(db.Post).one() assert db.session.query(db.PostFavorite).count() == 1 assert post is not None diff --git a/server/szurubooru/tests/api/test_post_featuring.py b/server/szurubooru/tests/api/test_post_featuring.py index ad56e586..fbd6e45f 100644 --- a/server/szurubooru/tests/api/test_post_featuring.py +++ b/server/szurubooru/tests/api/test_post_featuring.py @@ -26,7 +26,7 @@ def test_no_featured_post(test_ctx): result = test_ctx.api.get( test_ctx.context_factory( user=test_ctx.user_factory(rank=db.User.RANK_REGULAR))) - assert result == {'post': None} + assert result is None def test_featuring(test_ctx): db.session.add(test_ctx.post_factory(id=1)) @@ -39,17 +39,15 @@ def test_featuring(test_ctx): assert posts.try_get_featured_post() is not None assert posts.try_get_featured_post().post_id == 1 assert posts.get_post_by_id(1).is_featured - assert 'post' in result - assert 'id' in result['post'] - assert 'snapshots' in result['post'] - assert 'comments' in result['post'] + assert 'id' in result + assert 'snapshots' in result + assert 'comments' in result result = test_ctx.api.get( test_ctx.context_factory( user=test_ctx.user_factory(rank=db.User.RANK_REGULAR))) - assert 'post' in result - assert 'id' in result['post'] - assert 'snapshots' in result['post'] - assert 'comments' in result['post'] + assert 'id' in result + assert 'snapshots' in result + assert 'comments' in result def test_trying_to_feature_the_same_post_twice(test_ctx): db.session.add(test_ctx.post_factory(id=1)) diff --git a/server/szurubooru/tests/api/test_post_rating.py b/server/szurubooru/tests/api/test_post_rating.py index a48830ee..fd631158 100644 --- a/server/szurubooru/tests/api/test_post_rating.py +++ b/server/szurubooru/tests/api/test_post_rating.py @@ -28,8 +28,7 @@ def test_simple_rating(test_ctx, fake_datetime): test_ctx.context_factory( input={'score': 1}, user=test_ctx.user_factory()), post.post_id) - assert 'post' in result - assert 'id' in result['post'] + assert 'id' in result post = db.session.query(db.Post).one() assert db.session.query(db.PostScore).count() == 1 assert post is not None diff --git a/server/szurubooru/tests/api/test_post_retrieving.py b/server/szurubooru/tests/api/test_post_retrieving.py index 3ceff647..41c6ead1 100644 --- a/server/szurubooru/tests/api/test_post_retrieving.py +++ b/server/szurubooru/tests/api/test_post_retrieving.py @@ -79,10 +79,9 @@ def test_retrieving_single(test_ctx): result = test_ctx.detail_api.get( test_ctx.context_factory( user=test_ctx.user_factory(rank=db.User.RANK_REGULAR)), 1) - assert 'post' in result - assert 'id' in result['post'] - assert 'snapshots' in result['post'] - assert 'comments' in result['post'] + assert 'id' in result + assert 'snapshots' in result + assert 'comments' in result def test_trying_to_retrieve_single_non_existing(test_ctx): with pytest.raises(posts.PostNotFoundError): diff --git a/server/szurubooru/tests/api/test_post_updating.py b/server/szurubooru/tests/api/test_post_updating.py index 7f1b4259..fc14c275 100644 --- a/server/szurubooru/tests/api/test_post_updating.py +++ b/server/szurubooru/tests/api/test_post_updating.py @@ -57,7 +57,7 @@ def test_post_updating( user=auth_user), post.post_id) - assert result == {'post': 'serialized post'} + assert result == 'serialized post' posts.create_post.assert_not_called() posts.update_post_tags.assert_called_once_with(post, ['tag1', 'tag2']) posts.update_post_content.assert_called_once_with(post, 'post-content') diff --git a/server/szurubooru/tests/api/test_tag_category_creating.py b/server/szurubooru/tests/api/test_tag_category_creating.py index dc43bf8d..18b57dca 100644 --- a/server/szurubooru/tests/api/test_tag_category_creating.py +++ b/server/szurubooru/tests/api/test_tag_category_creating.py @@ -21,9 +21,9 @@ def test_creating_category(test_ctx): test_ctx.context_factory( input={'name': 'meta', 'color': 'black'}, user=test_ctx.user_factory(rank=db.User.RANK_REGULAR))) - assert len(result['tagCategory']['snapshots']) == 1 - del result['tagCategory']['snapshots'] - assert result['tagCategory'] == { + assert len(result['snapshots']) == 1 + del result['snapshots'] + assert result == { 'name': 'meta', 'color': 'black', 'usages': 0, diff --git a/server/szurubooru/tests/api/test_tag_category_retrieving.py b/server/szurubooru/tests/api/test_tag_category_retrieving.py index 53537546..56446859 100644 --- a/server/szurubooru/tests/api/test_tag_category_retrieving.py +++ b/server/szurubooru/tests/api/test_tag_category_retrieving.py @@ -38,13 +38,11 @@ def test_retrieving_single(test_ctx): user=test_ctx.user_factory(rank=db.User.RANK_REGULAR)), 'cat') assert result == { - 'tagCategory': { - 'name': 'cat', - 'color': 'dummy', - 'usages': 0, - 'default': False, - 'snapshots': [], - }, + 'name': 'cat', + 'color': 'dummy', + 'usages': 0, + 'default': False, + 'snapshots': [], } def test_trying_to_retrieve_single_non_existing(test_ctx): diff --git a/server/szurubooru/tests/api/test_tag_category_updating.py b/server/szurubooru/tests/api/test_tag_category_updating.py index 7ff8bb45..045faa2e 100644 --- a/server/szurubooru/tests/api/test_tag_category_updating.py +++ b/server/szurubooru/tests/api/test_tag_category_updating.py @@ -37,9 +37,9 @@ def test_simple_updating(test_ctx): }, user=test_ctx.user_factory(rank=db.User.RANK_REGULAR)), 'name') - assert len(result['tagCategory']['snapshots']) == 1 - del result['tagCategory']['snapshots'] - assert result['tagCategory'] == { + assert len(result['snapshots']) == 1 + del result['snapshots'] + assert result == { 'name': 'changed', 'color': 'white', 'usages': 0, @@ -103,7 +103,7 @@ def test_reusing_own_name(test_ctx, new_name): input={'name': new_name}, user=test_ctx.user_factory(rank=db.User.RANK_REGULAR)), 'cat') - assert result['tagCategory']['name'] == new_name + assert result['name'] == new_name category = tag_categories.get_category_by_name('cat') assert category.name == new_name diff --git a/server/szurubooru/tests/api/test_tag_creating.py b/server/szurubooru/tests/api/test_tag_creating.py index e2dec09a..14269f52 100644 --- a/server/szurubooru/tests/api/test_tag_creating.py +++ b/server/szurubooru/tests/api/test_tag_creating.py @@ -38,9 +38,9 @@ def test_creating_simple_tags(test_ctx, fake_datetime): 'implications': [], }, user=test_ctx.user_factory(rank=db.User.RANK_REGULAR))) - assert len(result['tag']['snapshots']) == 1 - del result['tag']['snapshots'] - assert result['tag'] == { + assert len(result['snapshots']) == 1 + del result['snapshots'] + assert result == { 'names': ['tag1', 'tag2'], 'category': 'meta', 'suggestions': [], @@ -126,8 +126,8 @@ def test_duplicating_names(test_ctx): 'implications': [], }, user=test_ctx.user_factory(rank=db.User.RANK_REGULAR))) - assert result['tag']['names'] == ['tag1'] - assert result['tag']['category'] == 'meta' + assert result['names'] == ['tag1'] + assert result['category'] == 'meta' tag = tags.get_tag_by_name('tag1') assert [tag_name.name for tag_name in tag.names] == ['tag1'] @@ -205,8 +205,8 @@ def test_creating_new_suggestions_and_implications( result = test_ctx.api.post( test_ctx.context_factory( input=input, user=test_ctx.user_factory(rank=db.User.RANK_REGULAR))) - assert result['tag']['suggestions'] == expected_suggestions - assert result['tag']['implications'] == expected_implications + assert result['suggestions'] == expected_suggestions + assert result['implications'] == expected_implications tag = tags.get_tag_by_name('main') assert_relations(tag.suggestions, expected_suggestions) assert_relations(tag.implications, expected_implications) @@ -229,8 +229,8 @@ def test_reusing_suggestions_and_implications(test_ctx): }, user=test_ctx.user_factory(rank=db.User.RANK_REGULAR))) # NOTE: it should export only the first name - assert result['tag']['suggestions'] == ['tag1'] - assert result['tag']['implications'] == ['tag1'] + assert result['suggestions'] == ['tag1'] + assert result['implications'] == ['tag1'] tag = tags.get_tag_by_name('new') assert_relations(tag.suggestions, ['tag1']) assert_relations(tag.implications, ['tag1']) diff --git a/server/szurubooru/tests/api/test_tag_merging.py b/server/szurubooru/tests/api/test_tag_merging.py index 39c79e4d..54a42433 100644 --- a/server/szurubooru/tests/api/test_tag_merging.py +++ b/server/szurubooru/tests/api/test_tag_merging.py @@ -33,9 +33,9 @@ def test_merging_without_usages(test_ctx, fake_datetime): 'mergeTo': 'target', }, user=test_ctx.user_factory(rank=db.User.RANK_REGULAR))) - assert 'snapshots' in result['tag'] - del result['tag']['snapshots'] - assert result['tag'] == { + assert 'snapshots' in result + del result['snapshots'] + assert result == { 'names': ['target'], 'category': 'meta', 'suggestions': [], diff --git a/server/szurubooru/tests/api/test_tag_retrieving.py b/server/szurubooru/tests/api/test_tag_retrieving.py index d475019e..20c30033 100644 --- a/server/szurubooru/tests/api/test_tag_retrieving.py +++ b/server/szurubooru/tests/api/test_tag_retrieving.py @@ -48,16 +48,14 @@ def test_retrieving_single(test_ctx): user=test_ctx.user_factory(rank=db.User.RANK_REGULAR)), 'tag') assert result == { - 'tag': { - 'names': ['tag'], - 'category': 'dummy', - 'creationTime': datetime.datetime(1996, 1, 1), - 'lastEditTime': None, - 'suggestions': [], - 'implications': [], - 'usages': 0, - 'snapshots': [], - }, + 'names': ['tag'], + 'category': 'dummy', + 'creationTime': datetime.datetime(1996, 1, 1), + 'lastEditTime': None, + 'suggestions': [], + 'implications': [], + 'usages': 0, + 'snapshots': [], } def test_trying_to_retrieve_single_non_existing(test_ctx): diff --git a/server/szurubooru/tests/api/test_tag_updating.py b/server/szurubooru/tests/api/test_tag_updating.py index 9647d219..9400fb94 100644 --- a/server/szurubooru/tests/api/test_tag_updating.py +++ b/server/szurubooru/tests/api/test_tag_updating.py @@ -46,9 +46,9 @@ def test_simple_updating(test_ctx, fake_datetime): }, user=test_ctx.user_factory(rank=db.User.RANK_REGULAR)), 'tag1') - assert len(result['tag']['snapshots']) == 1 - del result['tag']['snapshots'] - assert result['tag'] == { + assert len(result['snapshots']) == 1 + del result['snapshots'] + assert result == { 'names': ['tag3'], 'category': 'character', 'suggestions': [], @@ -127,7 +127,7 @@ def test_reusing_own_name(test_ctx, dup_name): input={'names': [dup_name, 'tag3']}, user=test_ctx.user_factory(rank=db.User.RANK_REGULAR)), 'tag1') - assert result['tag']['names'] == ['tag1', 'tag3'] + assert result['names'] == ['tag1', 'tag3'] assert tags.try_get_tag_by_name('tag2') is None tag1 = tags.get_tag_by_name('tag1') tag2 = tags.get_tag_by_name('tag3') @@ -142,7 +142,7 @@ def test_duplicating_names(test_ctx): input={'names': ['tag3', 'TAG3']}, user=test_ctx.user_factory(rank=db.User.RANK_REGULAR)), 'tag1') - assert result['tag']['names'] == ['tag3'] + assert result['names'] == ['tag3'] assert tags.try_get_tag_by_name('tag1') is None assert tags.try_get_tag_by_name('tag2') is None tag = tags.get_tag_by_name('tag3') @@ -193,8 +193,8 @@ def test_updating_new_suggestions_and_implications( test_ctx.context_factory( input=input, user=test_ctx.user_factory(rank=db.User.RANK_REGULAR)), 'main') - assert result['tag']['suggestions'] == expected_suggestions - assert result['tag']['implications'] == expected_implications + assert result['suggestions'] == expected_suggestions + assert result['implications'] == expected_implications tag = tags.get_tag_by_name('main') assert_relations(tag.suggestions, expected_suggestions) assert_relations(tag.implications, expected_implications) @@ -219,8 +219,8 @@ def test_reusing_suggestions_and_implications(test_ctx): user=test_ctx.user_factory(rank=db.User.RANK_REGULAR)), 'tag4') # NOTE: it should export only the first name - assert result['tag']['suggestions'] == ['tag1'] - assert result['tag']['implications'] == ['tag1'] + assert result['suggestions'] == ['tag1'] + assert result['implications'] == ['tag1'] tag = tags.get_tag_by_name('new') assert_relations(tag.suggestions, ['tag1']) assert_relations(tag.implications, ['tag1']) diff --git a/server/szurubooru/tests/api/test_user_creating.py b/server/szurubooru/tests/api/test_user_creating.py index 127c612b..c512b8be 100644 --- a/server/szurubooru/tests/api/test_user_creating.py +++ b/server/szurubooru/tests/api/test_user_creating.py @@ -35,16 +35,14 @@ def test_creating_user(test_ctx, fake_datetime): }, user=test_ctx.user_factory(rank=db.User.RANK_REGULAR))) assert result == { - 'user': { - 'avatarStyle': 'gravatar', - 'avatarUrl': 'http://gravatar.com/avatar/' + - '6f370c8c7109534c3d5c394123a477d7?d=retro&s=200', - 'creationTime': datetime.datetime(1969, 2, 12), - 'lastLoginTime': None, - 'name': 'chewie1', - 'rank': 'administrator', - 'email': 'asd@asd.asd', - } + 'avatarStyle': 'gravatar', + 'avatarUrl': 'http://gravatar.com/avatar/' + + '6f370c8c7109534c3d5c394123a477d7?d=retro&s=200', + 'creationTime': datetime.datetime(1969, 2, 12), + 'lastLoginTime': None, + 'name': 'chewie1', + 'rank': 'administrator', + 'email': 'asd@asd.asd', } user = users.get_user_by_name('chewie1') assert user.name == 'chewie1' @@ -70,8 +68,8 @@ def test_first_user_becomes_admin_others_not(test_ctx): 'password': 'sok', }, user=test_ctx.user_factory(rank=db.User.RANK_ANONYMOUS))) - assert result1['user']['rank'] == 'administrator' - assert result2['user']['rank'] == 'regular' + assert result1['rank'] == 'administrator' + assert result2['rank'] == 'regular' first_user = users.get_user_by_name('chewie1') other_user = users.get_user_by_name('chewie2') assert first_user.rank == db.User.RANK_ADMINISTRATOR @@ -87,7 +85,7 @@ def test_first_user_does_not_become_admin_if_they_dont_wish_so(test_ctx): 'rank': 'regular', }, user=test_ctx.user_factory(rank=db.User.RANK_ANONYMOUS))) - assert result['user']['rank'] == 'regular' + assert result['rank'] == 'regular' def test_trying_to_become_someone_else(test_ctx): test_ctx.api.post( @@ -208,7 +206,7 @@ def test_admin_creating_mod_account(test_ctx): 'rank': 'moderator', }, user=user) result = test_ctx.api.post(context) - assert result['user']['rank'] == 'moderator' + assert result['rank'] == 'moderator' def test_uploading_avatar(test_ctx, tmpdir): config.config['data_dir'] = str(tmpdir.mkdir('data')) @@ -225,5 +223,4 @@ def test_uploading_avatar(test_ctx, tmpdir): user=test_ctx.user_factory(rank=db.User.RANK_MODERATOR))) user = users.get_user_by_name('chewie') assert user.avatar_style == user.AVATAR_MANUAL - assert response['user']['avatarUrl'] == \ - 'http://example.com/data/avatars/chewie.png' + assert response['avatarUrl'] == 'http://example.com/data/avatars/chewie.png' diff --git a/server/szurubooru/tests/api/test_user_retrieving.py b/server/szurubooru/tests/api/test_user_retrieving.py index 8ad39b22..40589161 100644 --- a/server/szurubooru/tests/api/test_user_retrieving.py +++ b/server/szurubooru/tests/api/test_user_retrieving.py @@ -48,16 +48,14 @@ def test_retrieving_single(test_ctx): user=test_ctx.user_factory(rank=db.User.RANK_REGULAR)), 'u1') assert result == { - 'user': { - 'name': 'u1', - 'rank': db.User.RANK_REGULAR, - 'creationTime': datetime.datetime(1997, 1, 1), - 'lastLoginTime': None, - 'avatarStyle': 'gravatar', - 'avatarUrl': 'http://gravatar.com/avatar/' + - '275876e34cf609db118f3d84b799a790?d=retro&s=200', - 'email': False, - } + 'name': 'u1', + 'rank': db.User.RANK_REGULAR, + 'creationTime': datetime.datetime(1997, 1, 1), + 'lastLoginTime': None, + 'avatarStyle': 'gravatar', + 'avatarUrl': 'http://gravatar.com/avatar/' + + '275876e34cf609db118f3d84b799a790?d=retro&s=200', + 'email': False, } def test_trying_to_retrieve_single_non_existing(test_ctx): diff --git a/server/szurubooru/tests/api/test_user_updating.py b/server/szurubooru/tests/api/test_user_updating.py index 3696ce90..1e8cafa9 100644 --- a/server/szurubooru/tests/api/test_user_updating.py +++ b/server/szurubooru/tests/api/test_user_updating.py @@ -49,16 +49,14 @@ def test_updating_user(test_ctx): user=user), 'u1') assert result == { - 'user': { - 'avatarStyle': 'gravatar', - 'avatarUrl': 'http://gravatar.com/avatar/' + - '6f370c8c7109534c3d5c394123a477d7?d=retro&s=200', - 'creationTime': datetime.datetime(1997, 1, 1), - 'lastLoginTime': None, - 'email': 'asd@asd.asd', - 'name': 'chewie', - 'rank': 'moderator', - } + 'avatarStyle': 'gravatar', + 'avatarUrl': 'http://gravatar.com/avatar/' + + '6f370c8c7109534c3d5c394123a477d7?d=retro&s=200', + 'creationTime': datetime.datetime(1997, 1, 1), + 'lastLoginTime': None, + 'email': 'asd@asd.asd', + 'name': 'chewie', + 'rank': 'moderator', } user = users.get_user_by_name('chewie') assert user.name == 'chewie' @@ -201,5 +199,5 @@ def test_uploading_avatar(test_ctx, tmpdir): 'u1') user = users.get_user_by_name('u1') assert user.avatar_style == user.AVATAR_MANUAL - assert response['user']['avatarUrl'] == \ + assert response['avatarUrl'] == \ 'http://example.com/data/avatars/u1.png'