diff options
Diffstat (limited to 'server/szurubooru/tests/func/test_comments.py')
| -rw-r--r-- | server/szurubooru/tests/func/test_comments.py | 47 |
1 files changed, 25 insertions, 22 deletions
diff --git a/server/szurubooru/tests/func/test_comments.py b/server/szurubooru/tests/func/test_comments.py index f1e5d0f..ef5ca4f 100644 --- a/server/szurubooru/tests/func/test_comments.py +++ b/server/szurubooru/tests/func/test_comments.py @@ -1,34 +1,36 @@ -from unittest.mock import patch from datetime import datetime +from unittest.mock import patch + import pytest + from szurubooru import db from szurubooru.func import comments, users def test_serialize_user(user_factory, comment_factory): - with patch('szurubooru.func.users.get_avatar_url'): - users.get_avatar_url.return_value = 'https://example.com/avatar.png' - comment = comment_factory(user=user_factory(name='dummy')) + with patch("szurubooru.func.users.get_avatar_url"): + users.get_avatar_url.return_value = "https://example.com/avatar.png" + comment = comment_factory(user=user_factory(name="dummy")) comment.comment_id = 77 comment.creation_time = datetime(1997, 1, 1) comment.last_edit_time = datetime(1998, 1, 1) - comment.text = 'text' + comment.text = "text" db.session.add(comment) db.session.flush() auth_user = user_factory() assert comments.serialize_comment(comment, auth_user) == { - 'id': comment.comment_id, - 'postId': comment.post.post_id, - 'creationTime': datetime(1997, 1, 1, 0, 0), - 'lastEditTime': datetime(1998, 1, 1, 0, 0), - 'score': 0, - 'ownScore': 0, - 'text': 'text', - 'user': { - 'name': 'dummy', - 'avatarUrl': 'https://example.com/avatar.png', + "id": comment.comment_id, + "postId": comment.post.post_id, + "creationTime": datetime(1997, 1, 1, 0, 0), + "lastEditTime": datetime(1998, 1, 1, 0, 0), + "score": 0, + "ownScore": 0, + "text": "text", + "user": { + "name": "dummy", + "avatarUrl": "https://example.com/avatar.png", }, - 'version': 1, + "version": 1, } @@ -53,13 +55,14 @@ def test_create_comment(user_factory, post_factory, fake_datetime): user = user_factory() post = post_factory() db.session.add_all([user, post]) - with patch('szurubooru.func.comments.update_comment_text'), \ - fake_datetime('1997-01-01'): - comment = comments.create_comment(user, post, 'text') + with patch("szurubooru.func.comments.update_comment_text"), fake_datetime( + "1997-01-01" + ): + comment = comments.create_comment(user, post, "text") assert comment.creation_time == datetime(1997, 1, 1) assert comment.user == user assert comment.post == post - comments.update_comment_text.assert_called_once_with(comment, 'text') + comments.update_comment_text.assert_called_once_with(comment, "text") def test_update_comment_text_with_emptry_string(comment_factory): @@ -70,5 +73,5 @@ def test_update_comment_text_with_emptry_string(comment_factory): def test_update_comment_text(comment_factory): comment = comment_factory() - comments.update_comment_text(comment, 'text') - assert comment.text == 'text' + comments.update_comment_text(comment, "text") + assert comment.text == "text" |