forked from retoor/devplacepy
feat: add featured/locked columns and auto-rotation logic to news pipeline
- Add `ai_grade`, `featured`, `featured_locked`, `landing_locked`, `author`, `article_published`, `image_url`, `has_unique_image` columns to news table - Extend `news_images` schema with `alt_text`, `phash`, `width`, `height`, `is_placeholder` columns - Create `idx_news_featured` index for efficient featured queries - Update admin toggle endpoints to set `featured_locked`/`landing_locked` when manually toggling - Propagate `featured` and `image_url` fields through landing page, news list, and detail page rendering - Update `get_featured_news` to return `featured` and `image_url` fields - Document in AGENTS.md the full zero-maintenance pipeline: image perceptual hashing, placeholder detection, AI grading on cleaned text, reliability gate, effective score computation, and post-loop landing rotation - Update README.md service description to reflect automatic image comparison and landing rotation capabilities - Clarify docs_api.py summaries that toggling featured/landing now locks articles from auto-rotation
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
# 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, 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)
|
||||
Reference in New Issue
Block a user