From 9bb11158a3dbeada485821d788c6f0b26638e41e Mon Sep 17 00:00:00 2001 From: "Soblow (Opale) Xaselgio" <113846014+Soblow@users.noreply.github.com> Date: Sun, 3 Mar 2024 16:53:23 +0100 Subject: [PATCH] Blocklist: Fix already existing tests following modifications for blocklist --- server/szurubooru/tests/api/test_info.py | 4 ++++ server/szurubooru/tests/api/test_user_creating.py | 4 ++++ server/szurubooru/tests/api/test_user_updating.py | 2 ++ server/szurubooru/tests/conftest.py | 2 ++ server/szurubooru/tests/func/test_users.py | 6 ++++-- 5 files changed, 16 insertions(+), 2 deletions(-) diff --git a/server/szurubooru/tests/api/test_info.py b/server/szurubooru/tests/api/test_info.py index 37099e8d4..c804867f6 100644 --- a/server/szurubooru/tests/api/test_info.py +++ b/server/szurubooru/tests/api/test_info.py @@ -26,6 +26,8 @@ def test_info_api( "tag_name_regex": "3", "tag_category_name_regex": "4", "default_rank": "5", + "default_tag_blocklist": "testTag", + "default_tag_blocklist_for_anonymous": True, "privileges": { "test_key1": "test_value1", "test_key2": "test_value2", @@ -48,6 +50,8 @@ def test_info_api( "tagNameRegex": "3", "tagCategoryNameRegex": "4", "defaultUserRank": "5", + "defaultTagBlocklist": "testTag", + "defaultTagBlocklistForAnonymous": True, "privileges": { "testKey1": "test_value1", "testKey2": "test_value2", diff --git a/server/szurubooru/tests/api/test_user_creating.py b/server/szurubooru/tests/api/test_user_creating.py index d55e1f7fa..2b2f22e80 100644 --- a/server/szurubooru/tests/api/test_user_creating.py +++ b/server/szurubooru/tests/api/test_user_creating.py @@ -21,6 +21,8 @@ def test_creating_user(user_factory, context_factory, fake_datetime): "szurubooru.func.users.update_user_rank" ), patch( "szurubooru.func.users.update_user_avatar" + ), patch( + "szurubooru.func.users.update_user_blocklist" ), patch( "szurubooru.func.users.serialize_user" ), fake_datetime( @@ -28,6 +30,7 @@ def test_creating_user(user_factory, context_factory, fake_datetime): ): users.serialize_user.return_value = "serialized user" users.create_user.return_value = user + users.update_user_blocklist.return_value = ([],[]) result = api.user_api.create_user( context_factory( params={ @@ -50,6 +53,7 @@ def test_creating_user(user_factory, context_factory, fake_datetime): assert not users.update_user_email.called users.update_user_rank.called_once_with(user, "moderator") users.update_user_avatar.called_once_with(user, "manual", b"...") + users.update_user_blocklist.called_once_with(user, None) @pytest.mark.parametrize("field", ["name", "password"]) diff --git a/server/szurubooru/tests/api/test_user_updating.py b/server/szurubooru/tests/api/test_user_updating.py index 304e4892f..412d4b466 100644 --- a/server/szurubooru/tests/api/test_user_updating.py +++ b/server/szurubooru/tests/api/test_user_updating.py @@ -14,11 +14,13 @@ def inject_config(config_injector): "users:edit:self:name": model.User.RANK_REGULAR, "users:edit:self:pass": model.User.RANK_REGULAR, "users:edit:self:email": model.User.RANK_REGULAR, + "users:edit:self:blocklist": model.User.RANK_REGULAR, "users:edit:self:rank": model.User.RANK_MODERATOR, "users:edit:self:avatar": model.User.RANK_MODERATOR, "users:edit:any:name": model.User.RANK_MODERATOR, "users:edit:any:pass": model.User.RANK_MODERATOR, "users:edit:any:email": model.User.RANK_MODERATOR, + "users:edit:any:blocklist": model.User.RANK_MODERATOR, "users:edit:any:rank": model.User.RANK_ADMINISTRATOR, "users:edit:any:avatar": model.User.RANK_ADMINISTRATOR, }, diff --git a/server/szurubooru/tests/conftest.py b/server/szurubooru/tests/conftest.py index 280987caf..d5be0a69c 100644 --- a/server/szurubooru/tests/conftest.py +++ b/server/szurubooru/tests/conftest.py @@ -172,6 +172,7 @@ def factory( id=None, safety=model.Post.SAFETY_SAFE, type=model.Post.TYPE_IMAGE, + tags=[], checksum="...", ): post = model.Post() @@ -182,6 +183,7 @@ def factory( post.flags = [] post.mime_type = "application/octet-stream" post.creation_time = datetime(1996, 1, 1) + post.tags = tags return post return factory diff --git a/server/szurubooru/tests/func/test_users.py b/server/szurubooru/tests/func/test_users.py index 94e9c7c1b..908e39f07 100644 --- a/server/szurubooru/tests/func/test_users.py +++ b/server/szurubooru/tests/func/test_users.py @@ -158,6 +158,7 @@ def test_serialize_user(user_factory): "avatarUrl": "https://example.com/avatar.png", "likedPostCount": 66, "dislikedPostCount": 33, + "blocklist": [], "commentCount": 0, "favoritePostCount": 0, "uploadedPostCount": 0, @@ -235,7 +236,7 @@ def test_create_user_for_first_user(fake_datetime): "szurubooru.func.users.update_user_password" ), patch("szurubooru.func.users.update_user_email"), fake_datetime( "1997-01-01" - ): + ), patch("szurubooru.func.users.update_user_blocklist"): user = users.create_user("name", "password", "email") assert user.creation_time == datetime(1997, 1, 1) assert user.last_login_time is None @@ -251,7 +252,8 @@ def test_create_user_for_subsequent_users(user_factory, config_injector): db.session.flush() with patch("szurubooru.func.users.update_user_name"), patch( "szurubooru.func.users.update_user_email" - ), patch("szurubooru.func.users.update_user_password"): + ), patch("szurubooru.func.users.update_user_password" + ), patch("szurubooru.func.users.update_user_blocklist"): user = users.create_user("name", "password", "email") assert user.rank == model.User.RANK_REGULAR