fix(search): the live-search tooltip says what a search costs
It always said a live search spends the shared API quota, while the default source (the website's own endpoint, scrape) spends none — the owner avoided a free search because of it. /api/me now names the running search_source, and the tooltip names the cost under it: none for scrape (the enrich step costs a unit or two), 100 units a page for the official API.
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
"""`/api/me` names the live-search source, so the search button's tooltip can say what a search costs
|
||||
under the source that actually runs (the default website source spends no API quota)."""
|
||||
|
||||
from app import sysconfig
|
||||
|
||||
_PW = "correct horse battery"
|
||||
|
||||
|
||||
def _me(client):
|
||||
r = client.get("/api/me")
|
||||
assert r.status_code == 200 and r.json()["authenticated"] is True
|
||||
return r.json()
|
||||
|
||||
|
||||
def test_me_names_the_running_search_source(client, db, make_user):
|
||||
# /api/me resolves its user through optional_current_user, which the as_user override does not
|
||||
# cover — so sign in for real (see test_me_email_flag).
|
||||
user = make_user(password=_PW)
|
||||
login = client.post("/auth/password-login", json={"email": user.email, "password": _PW})
|
||||
assert login.status_code == 200
|
||||
|
||||
assert _me(client)["search_source"] == "scrape" # the default
|
||||
|
||||
sysconfig.set_value(db, "search_source", "api")
|
||||
db.commit()
|
||||
assert _me(client)["search_source"] == "api"
|
||||
Reference in New Issue
Block a user