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
42 lines
1.3 KiB
Python
42 lines
1.3 KiB
Python
# retoor <retoor@molodetz.nl>
|
|
|
|
import time
|
|
import requests
|
|
from tests.conftest import BASE_URL
|
|
from devplacepy.database import get_table, refresh_snapshot
|
|
_counter_aiusage = [0]
|
|
JSON_aiusage = {"Accept": "application/json"}
|
|
def _db_user(name):
|
|
refresh_snapshot()
|
|
return get_table("users").find_one(username=name)
|
|
def _admin_aiusage(seeded_db):
|
|
key = _db_user("alice_test")["api_key"]
|
|
s = requests.Session()
|
|
s.headers.update({"X-API-KEY": key})
|
|
return s
|
|
|
|
|
|
def test_admin_ai_usage_page_requires_admin(app_server):
|
|
r = requests.get(f"{BASE_URL}/admin/ai-usage", allow_redirects=False)
|
|
assert r.status_code in (302, 303, 401, 403)
|
|
|
|
|
|
def test_admin_ai_usage_page_returns_html(app_server, seeded_db):
|
|
admin = _admin_aiusage(seeded_db)
|
|
r = admin.get(f"{BASE_URL}/admin/ai-usage")
|
|
assert r.status_code == 200
|
|
assert "AI usage" in r.text or "ai-usage" in r.text
|
|
|
|
|
|
def test_admin_ai_usage_data_requires_auth(app_server):
|
|
r = requests.get(f"{BASE_URL}/admin/ai-usage/data", headers=JSON_aiusage)
|
|
assert r.status_code == 401
|
|
|
|
|
|
def test_admin_ai_usage_data_returns_json(app_server, seeded_db):
|
|
admin = _admin_aiusage(seeded_db)
|
|
r = admin.get(f"{BASE_URL}/admin/ai-usage/data", headers=JSON_aiusage)
|
|
assert r.status_code == 200
|
|
data = r.json()
|
|
assert isinstance(data, dict)
|