Skip to content

Commit

Permalink
Blocklist: Fix already existing tests following modifications for blo…
Browse files Browse the repository at this point in the history
…cklist
  • Loading branch information
Soblow authored and Lugrim committed May 5, 2024
1 parent 82721c0 commit 9bb1115
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 2 deletions.
4 changes: 4 additions & 0 deletions server/szurubooru/tests/api/test_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
4 changes: 4 additions & 0 deletions server/szurubooru/tests/api/test_user_creating.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@ 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(
"1969-02-12"
):
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={
Expand All @@ -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"])
Expand Down
2 changes: 2 additions & 0 deletions server/szurubooru/tests/api/test_user_updating.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
2 changes: 2 additions & 0 deletions server/szurubooru/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ def factory(
id=None,
safety=model.Post.SAFETY_SAFE,
type=model.Post.TYPE_IMAGE,
tags=[],
checksum="...",
):
post = model.Post()
Expand All @@ -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
Expand Down
6 changes: 4 additions & 2 deletions server/szurubooru/tests/func/test_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down

0 comments on commit 9bb1115

Please sign in to comment.