forked from retoor/devplacepy
- Add `/block`, `/mute` endpoints with block/unblock and mute/unmute functionality in `routers/relations.py`, hiding blocked users' content everywhere except their own profile while muting only suppresses notifications - Introduce `devplace emoji-sync` CLI command to regenerate `static/js/emoji-shortcodes.js` from the emoji library, documented in `CLAUDE.md` and wired in `cli.py` - Create `get_blocked_uids()` database helper and apply it in `content.py` `load_detail()` to filter blocked users' posts from detail views - Implement `_uid_index()` and `_drop_index()` helpers in `database.py` for unique uid indexes across tables, with `user_relations` added to `SOFT_DELETE_TABLES` - Document new routes in `AGENTS.md` and `README.md`, including emoji shortcodes rendering behavior distinct from the emoji picker
72 lines
2.1 KiB
Python
72 lines
2.1 KiB
Python
# retoor <retoor@molodetz.nl>
|
|
|
|
import time
|
|
import requests
|
|
from tests.conftest import BASE_URL
|
|
from devplacepy.database import get_table
|
|
|
|
_counter = [0]
|
|
|
|
|
|
def _signup():
|
|
_counter[0] += 1
|
|
name = f"unblk{int(time.time() * 1000)}{_counter[0]}"
|
|
session = requests.Session()
|
|
session.post(
|
|
f"{BASE_URL}/auth/signup",
|
|
data={
|
|
"username": name,
|
|
"email": f"{name}@t.dev",
|
|
"password": "secret123",
|
|
"confirm_password": "secret123",
|
|
},
|
|
allow_redirects=True,
|
|
)
|
|
return session, name
|
|
|
|
|
|
def _uid(name):
|
|
return get_table("users").find_one(username=name)["uid"]
|
|
|
|
|
|
def _active_blocks(actor_uid, target_uid):
|
|
return get_table("user_relations").count(
|
|
user_uid=actor_uid, target_uid=target_uid, kind="block", deleted_at=None
|
|
)
|
|
|
|
|
|
def test_unblock_reverses_block(app_server):
|
|
blocker_session, blocker = _signup()
|
|
_, target = _signup()
|
|
blocker_session.post(f"{BASE_URL}/block/{target}", allow_redirects=False)
|
|
assert _active_blocks(_uid(blocker), _uid(target)) == 1
|
|
|
|
r = blocker_session.post(
|
|
f"{BASE_URL}/block/unblock/{target}", allow_redirects=False
|
|
)
|
|
assert r.status_code in (302, 200)
|
|
assert _active_blocks(_uid(blocker), _uid(target)) == 0
|
|
|
|
|
|
def test_unblock_then_reblock_revives_one_row(app_server):
|
|
blocker_session, blocker = _signup()
|
|
_, target = _signup()
|
|
blocker_session.post(f"{BASE_URL}/block/{target}", allow_redirects=False)
|
|
blocker_session.post(f"{BASE_URL}/block/unblock/{target}", allow_redirects=False)
|
|
blocker_session.post(f"{BASE_URL}/block/{target}", allow_redirects=False)
|
|
|
|
assert _active_blocks(_uid(blocker), _uid(target)) == 1
|
|
total = get_table("user_relations").count(
|
|
user_uid=_uid(blocker), target_uid=_uid(target), kind="block"
|
|
)
|
|
assert total == 1
|
|
|
|
|
|
def test_unblock_when_not_blocked_is_noop(app_server):
|
|
blocker_session, _ = _signup()
|
|
_, target = _signup()
|
|
r = blocker_session.post(
|
|
f"{BASE_URL}/block/unblock/{target}", allow_redirects=False
|
|
)
|
|
assert r.status_code in (302, 200)
|