forked from retoor/devplacepy
Render markdown in gist and project sidebar titles; add content visibility and GIF picker
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -331,6 +331,71 @@ def test_model_edit_page_404_for_missing_model(seeded_db):
|
||||
)
|
||||
|
||||
|
||||
def test_model_test_marks_unreachable_route_bad(seeded_db):
|
||||
admin = admin_session(seeded_db)
|
||||
provider = _unique_gateway("testprov").lower()
|
||||
source = _unique_gateway("testroute")
|
||||
|
||||
created_provider = admin.post(
|
||||
f"{BASE_URL}/admin/gateway/providers",
|
||||
json={
|
||||
"name": provider,
|
||||
"base_url": "http://127.0.0.1:9/v1/chat/completions",
|
||||
"api_key": "sk-test",
|
||||
"is_active": True,
|
||||
},
|
||||
)
|
||||
assert created_provider.status_code == 200, created_provider.text[:300]
|
||||
created_route = admin.post(
|
||||
f"{BASE_URL}/admin/gateway/models",
|
||||
json={
|
||||
"source_model": source,
|
||||
"provider": provider,
|
||||
"target_model": "vendor/dead",
|
||||
"kind": "chat",
|
||||
},
|
||||
)
|
||||
assert created_route.status_code == 200, created_route.text[:300]
|
||||
try:
|
||||
tested = admin.post(
|
||||
f"{BASE_URL}/admin/gateway/models/{source}/test",
|
||||
allow_redirects=False,
|
||||
)
|
||||
assert tested.status_code == 302
|
||||
assert tested.headers["location"].startswith("/admin/gateway?tab=models")
|
||||
listed = admin.get(f"{BASE_URL}/admin/gateway/models").json()
|
||||
row = next(m for m in listed["models"] if m["source_model"] == source)
|
||||
assert row["health_status"] == "bad"
|
||||
assert row["health_code"] == "connection_error"
|
||||
assert row["health_checked_at"]
|
||||
finally:
|
||||
admin.delete(f"{BASE_URL}/admin/gateway/models/{source}")
|
||||
admin.delete(f"{BASE_URL}/admin/gateway/providers/{provider}")
|
||||
|
||||
|
||||
def test_model_test_pages_require_admin_and_known_route(seeded_db):
|
||||
assert (
|
||||
requests.post(
|
||||
f"{BASE_URL}/admin/gateway/models/x/test",
|
||||
headers=JSON_gateway,
|
||||
allow_redirects=False,
|
||||
).status_code
|
||||
== 401
|
||||
)
|
||||
key = member_key()
|
||||
assert (
|
||||
requests.post(
|
||||
f"{BASE_URL}/admin/gateway/models/x/test",
|
||||
headers={**JSON_gateway, "X-API-KEY": key},
|
||||
allow_redirects=False,
|
||||
).status_code
|
||||
== 403
|
||||
)
|
||||
admin = admin_session(seeded_db)
|
||||
missing = _unique_gateway("ghosttest")
|
||||
assert admin.post(f"{BASE_URL}/admin/gateway/models/{missing}/test").status_code == 404
|
||||
|
||||
|
||||
def test_model_route_validation(seeded_db):
|
||||
admin = admin_session(seeded_db)
|
||||
missing_target = admin.post(
|
||||
@@ -349,3 +414,75 @@ def test_model_route_validation(seeded_db):
|
||||
},
|
||||
)
|
||||
assert bad_kind.status_code == 400
|
||||
|
||||
|
||||
def test_model_route_tools_mode_round_trip_and_validation(seeded_db):
|
||||
admin = admin_session(seeded_db)
|
||||
source = _unique_gateway("tools-mode")
|
||||
|
||||
default = admin.post(
|
||||
f"{BASE_URL}/admin/gateway/models",
|
||||
json={"source_model": source, "target_model": "vendor/t", "kind": "chat"},
|
||||
)
|
||||
assert default.status_code == 200, default.text[:300]
|
||||
assert default.json()["model"]["tools_mode"] == "native"
|
||||
|
||||
emulated = admin.post(
|
||||
f"{BASE_URL}/admin/gateway/models",
|
||||
json={
|
||||
"source_model": source,
|
||||
"target_model": "vendor/t",
|
||||
"kind": "chat",
|
||||
"tools_mode": "emulated",
|
||||
},
|
||||
)
|
||||
assert emulated.status_code == 200, emulated.text[:300]
|
||||
assert emulated.json()["model"]["tools_mode"] == "emulated"
|
||||
listed = admin.get(f"{BASE_URL}/admin/gateway/models").json()
|
||||
row = next(m for m in listed["models"] if m["source_model"] == source)
|
||||
assert row["tools_mode"] == "emulated"
|
||||
|
||||
invalid = admin.post(
|
||||
f"{BASE_URL}/admin/gateway/models",
|
||||
json={
|
||||
"source_model": source,
|
||||
"target_model": "vendor/t",
|
||||
"kind": "chat",
|
||||
"tools_mode": "magic",
|
||||
},
|
||||
)
|
||||
assert invalid.json().get("ok") is not True
|
||||
|
||||
admin.delete(f"{BASE_URL}/admin/gateway/models/{source}")
|
||||
|
||||
|
||||
def test_model_route_edit_page_renders_html_and_shows_tools_mode(seeded_db):
|
||||
admin = admin_session(seeded_db)
|
||||
source = _unique_gateway("edit-page")
|
||||
created = admin.post(
|
||||
f"{BASE_URL}/admin/gateway/models",
|
||||
json={
|
||||
"source_model": source,
|
||||
"target_model": "vendor/e",
|
||||
"kind": "chat",
|
||||
"tools_mode": "emulated",
|
||||
},
|
||||
)
|
||||
assert created.status_code == 200, created.text[:300]
|
||||
|
||||
page = admin.get(
|
||||
f"{BASE_URL}/admin/gateway/models/{source}/edit",
|
||||
headers={"Accept": "text/html"},
|
||||
)
|
||||
assert page.status_code == 200, page.text[:500]
|
||||
assert 'name="tools_mode"' in page.text
|
||||
assert '<option value="emulated" selected>' in page.text
|
||||
|
||||
index = admin.get(
|
||||
f"{BASE_URL}/admin/gateway?tab=models", headers={"Accept": "text/html"}
|
||||
)
|
||||
assert index.status_code == 200
|
||||
assert f"/admin/gateway/models/{source}/edit" in index.text
|
||||
assert "tools: emulated" in index.text
|
||||
|
||||
admin.delete(f"{BASE_URL}/admin/gateway/models/{source}")
|
||||
|
||||
@@ -0,0 +1,167 @@
|
||||
# retoor <retoor@molodetz.nl>
|
||||
|
||||
import time
|
||||
from datetime import datetime, timezone
|
||||
import pytest
|
||||
import requests
|
||||
from tests.conftest import BASE_URL
|
||||
from devplacepy.database import get_table, refresh_snapshot
|
||||
from devplacepy.utils import generate_uid, make_combined_slug
|
||||
|
||||
JSON = {"Accept": "application/json"}
|
||||
_counter = [0]
|
||||
|
||||
|
||||
def _seed_article(status="published"):
|
||||
_counter[0] += 1
|
||||
uid = generate_uid()
|
||||
title = f"Visibility News {int(time.time() * 1000)}{_counter[0]}"
|
||||
slug = make_combined_slug(title, uid)
|
||||
get_table("news").insert(
|
||||
{
|
||||
"deleted_at": None,
|
||||
"deleted_by": None,
|
||||
"uid": uid,
|
||||
"slug": slug,
|
||||
"title": title,
|
||||
"description": "Seeded article for visibility tests.",
|
||||
"content": "Body.",
|
||||
"url": "https://example.com/visibility",
|
||||
"source_name": "Example",
|
||||
"status": status,
|
||||
"synced_at": datetime.now(timezone.utc).isoformat(),
|
||||
"show_on_landing": 0,
|
||||
"grade": 9,
|
||||
}
|
||||
)
|
||||
return {"uid": uid, "slug": slug, "title": title}
|
||||
|
||||
|
||||
def _session(username):
|
||||
refresh_snapshot()
|
||||
session = requests.Session()
|
||||
session.headers.update(
|
||||
{"X-API-KEY": get_table("users").find_one(username=username)["api_key"]}
|
||||
)
|
||||
return session
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def admin(seeded_db):
|
||||
return _session("alice_test")
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def member(seeded_db):
|
||||
return _session("bob_test")
|
||||
|
||||
|
||||
def _set(session, uid, value):
|
||||
return session.post(
|
||||
f"{BASE_URL}/admin/news/{uid}/visibility", data={"value": value}, headers=JSON
|
||||
)
|
||||
|
||||
|
||||
def _set_ok(session, uid, value):
|
||||
response = _set(session, uid, value)
|
||||
assert response.status_code == 200, response.text[:200]
|
||||
return response
|
||||
|
||||
|
||||
def _listed(slug_or_title):
|
||||
response = requests.get(f"{BASE_URL}/news", headers=JSON)
|
||||
assert response.status_code == 200
|
||||
return slug_or_title in {
|
||||
row["article"]["title"] for row in response.json()["articles"]
|
||||
}
|
||||
|
||||
|
||||
def _read(uid):
|
||||
refresh_snapshot()
|
||||
return get_table("news").find_one(uid=uid)
|
||||
|
||||
|
||||
def test_published_article_is_listed_and_open(app_server):
|
||||
article = _seed_article()
|
||||
assert _listed(article["title"])
|
||||
assert requests.get(f"{BASE_URL}/news/{article['slug']}").status_code == 200
|
||||
|
||||
|
||||
@pytest.mark.parametrize("value", ["hidden", "offline", "draft"])
|
||||
def test_admin_sets_visibility_and_listing_follows(admin, value):
|
||||
article = _seed_article()
|
||||
response = _set(admin, article["uid"], value)
|
||||
assert response.status_code == 200, response.text[:300]
|
||||
assert response.json()["data"]["visibility"] == value
|
||||
assert _read(article["uid"])["status"] == value
|
||||
assert not _listed(article["title"])
|
||||
|
||||
|
||||
def test_hidden_article_opens_by_link_with_noindex(admin):
|
||||
article = _seed_article()
|
||||
_set_ok(admin, article["uid"], "hidden")
|
||||
page = requests.get(f"{BASE_URL}/news/{article['slug']}")
|
||||
assert page.status_code == 200
|
||||
assert "noindex" in page.text
|
||||
assert article["slug"] not in requests.get(f"{BASE_URL}/sitemap.xml").text
|
||||
|
||||
|
||||
@pytest.mark.parametrize("value", ["offline", "draft"])
|
||||
def test_offline_and_draft_articles_are_admin_only(admin, member, value):
|
||||
article = _seed_article()
|
||||
_set_ok(admin, article["uid"], value)
|
||||
assert requests.get(f"{BASE_URL}/news/{article['slug']}", headers=JSON).status_code == 404
|
||||
assert member.get(f"{BASE_URL}/news/{article['slug']}", headers=JSON).status_code == 404
|
||||
assert admin.get(f"{BASE_URL}/news/{article['slug']}").status_code == 200
|
||||
|
||||
|
||||
def test_article_can_be_published_again(admin):
|
||||
article = _seed_article()
|
||||
_set_ok(admin, article["uid"], "offline")
|
||||
assert _set(admin, article["uid"], "published").status_code == 200
|
||||
assert _listed(article["title"])
|
||||
assert requests.get(f"{BASE_URL}/news/{article['slug']}").status_code == 200
|
||||
|
||||
|
||||
def test_member_cannot_change_article_visibility(member):
|
||||
article = _seed_article()
|
||||
response = _set(member, article["uid"], "offline")
|
||||
assert response.status_code == 403
|
||||
assert _read(article["uid"])["status"] == "published"
|
||||
|
||||
|
||||
def test_guest_cannot_change_article_visibility(app_server):
|
||||
article = _seed_article()
|
||||
response = requests.post(
|
||||
f"{BASE_URL}/admin/news/{article['uid']}/visibility",
|
||||
data={"value": "offline"},
|
||||
headers=JSON,
|
||||
)
|
||||
assert response.status_code in (401, 403)
|
||||
|
||||
|
||||
def test_invalid_value_is_refused(admin):
|
||||
article = _seed_article()
|
||||
response = _set(admin, article["uid"], "nonsense")
|
||||
assert response.status_code in (400, 422)
|
||||
assert _read(article["uid"])["status"] == "published"
|
||||
|
||||
|
||||
def test_publish_toggle_still_switches_draft_and_published(admin):
|
||||
article = _seed_article()
|
||||
admin.post(f"{BASE_URL}/admin/news/{article['uid']}/publish", headers=JSON)
|
||||
assert _read(article["uid"])["status"] == "draft"
|
||||
admin.post(f"{BASE_URL}/admin/news/{article['uid']}/publish", headers=JSON)
|
||||
assert _read(article["uid"])["status"] == "published"
|
||||
|
||||
|
||||
def test_news_visibility_change_is_audited(admin):
|
||||
article = _seed_article()
|
||||
_set_ok(admin, article["uid"], "offline")
|
||||
response = admin.get(
|
||||
f"{BASE_URL}/admin/audit-log", params={"event_key": "news.visibility.set"}, headers=JSON
|
||||
)
|
||||
assert any(
|
||||
entry.get("target_uid") == article["uid"] and entry.get("new_value") == "offline"
|
||||
for entry in response.json()["entries"]
|
||||
)
|
||||
@@ -0,0 +1,395 @@
|
||||
# retoor <retoor@molodetz.nl>
|
||||
|
||||
import time
|
||||
import pytest
|
||||
import requests
|
||||
from tests.conftest import BASE_URL
|
||||
from devplacepy.database import get_table, refresh_snapshot
|
||||
|
||||
JSON = {"Accept": "application/json"}
|
||||
KINDS = ("post", "gist", "project")
|
||||
AREA = {"post": "posts", "gist": "gists", "project": "projects"}
|
||||
LISTING = {"post": "/feed", "gist": "/gists", "project": "/projects"}
|
||||
_counter = [0]
|
||||
|
||||
|
||||
def _unique(prefix):
|
||||
_counter[0] += 1
|
||||
return f"{prefix}{int(time.time() * 1000)}{_counter[0]}"
|
||||
|
||||
|
||||
def _signup():
|
||||
name = _unique("vis")
|
||||
session = requests.Session()
|
||||
session.post(
|
||||
f"{BASE_URL}/auth/signup",
|
||||
data={
|
||||
"username": name,
|
||||
"email": f"{name}@t.dev",
|
||||
"password": "secret123",
|
||||
"confirm_password": "secret123",
|
||||
"birth_date": "1990-01-01",
|
||||
"accept_terms": "1",
|
||||
},
|
||||
allow_redirects=True,
|
||||
)
|
||||
refresh_snapshot()
|
||||
key = get_table("users").find_one(username=name)["api_key"]
|
||||
session.headers.update({"X-API-KEY": key})
|
||||
return session
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def owner(app_server):
|
||||
return _signup()
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def stranger(app_server):
|
||||
return _signup()
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def admin(seeded_db):
|
||||
refresh_snapshot()
|
||||
session = requests.Session()
|
||||
session.headers.update(
|
||||
{"X-API-KEY": get_table("users").find_one(username="alice_test")["api_key"]}
|
||||
)
|
||||
return session
|
||||
|
||||
|
||||
def _create(session, kind, token, visibility=None):
|
||||
extra = {} if visibility is None else {"visibility": visibility}
|
||||
if kind == "post":
|
||||
path, data = "/posts/create", {"content": f"visibility post body {token}", "title": token}
|
||||
elif kind == "gist":
|
||||
path, data = "/gists/create", {"title": token, "source_code": "print(1)"}
|
||||
else:
|
||||
path, data = "/projects/create", {"title": token, "description": f"project {token}"}
|
||||
response = session.post(
|
||||
f"{BASE_URL}{path}", data={**data, **extra}, headers=JSON, allow_redirects=False
|
||||
)
|
||||
return response
|
||||
|
||||
|
||||
def _make(session, kind, visibility=None):
|
||||
token = _unique(f"tok{kind}")
|
||||
response = _create(session, kind, token, visibility)
|
||||
assert response.status_code == 200, response.text[:300]
|
||||
payload = response.json()["data"]
|
||||
return {"token": token, "slug": payload["slug"], "uid": payload["uid"], "url": payload["url"]}
|
||||
|
||||
|
||||
def _set(session, kind, item, value):
|
||||
path, data = _edit_payload(kind, item["token"], value)
|
||||
return session.post(
|
||||
f"{BASE_URL}{path.format(slug=item['slug'])}", data=data, headers=JSON
|
||||
)
|
||||
|
||||
|
||||
def _listed_uids(kind, token, session=None):
|
||||
getter = session.get if session is not None else requests.get
|
||||
response = getter(f"{BASE_URL}{LISTING[kind]}", params={"search": token}, headers=JSON)
|
||||
assert response.status_code == 200, response.text[:300]
|
||||
data = response.json()
|
||||
rows = data[AREA[kind]]
|
||||
return {row[kind]["uid"] if kind in row else row["uid"] for row in rows}
|
||||
|
||||
|
||||
def _detail(kind, item, session=None):
|
||||
getter = session.get if session is not None else requests.get
|
||||
return getter(f"{BASE_URL}{item['url']}", headers=JSON, allow_redirects=False)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("kind", KINDS)
|
||||
def test_default_visibility_is_published(owner, kind):
|
||||
item = _make(owner, kind)
|
||||
detail = _detail(kind, item, owner)
|
||||
assert detail.status_code == 200
|
||||
assert detail.json()[kind]["visibility"] == "published"
|
||||
assert item["uid"] in _listed_uids(kind, item["token"])
|
||||
|
||||
|
||||
@pytest.mark.parametrize("kind", KINDS)
|
||||
@pytest.mark.parametrize("value", ["hidden", "offline", "draft"])
|
||||
def test_create_with_visibility(owner, kind, value):
|
||||
item = _make(owner, kind, value)
|
||||
assert _detail(kind, item, owner).json()[kind]["visibility"] == value
|
||||
assert item["uid"] not in _listed_uids(kind, item["token"])
|
||||
|
||||
|
||||
@pytest.mark.parametrize("kind", KINDS)
|
||||
def test_create_rejects_unknown_visibility(owner, kind):
|
||||
response = _create(owner, kind, _unique("bad"), "secret")
|
||||
assert response.status_code in (400, 422)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("kind", KINDS)
|
||||
def test_toggle_cycle_updates_listing_and_detail(owner, stranger, kind):
|
||||
item = _make(owner, kind)
|
||||
for value in ("hidden", "offline", "draft", "published"):
|
||||
response = _set(owner, kind, item, value)
|
||||
assert response.status_code == 200, response.text[:300]
|
||||
assert _detail(kind, item, owner).json()[kind]["visibility"] == value
|
||||
listed = item["uid"] in _listed_uids(kind, item["token"])
|
||||
assert listed == (value == "published")
|
||||
reachable = _detail(kind, item, stranger).status_code == 200
|
||||
assert reachable == (value in ("published", "hidden"))
|
||||
|
||||
|
||||
@pytest.mark.parametrize("kind", KINDS)
|
||||
def test_hidden_is_open_by_link_for_everyone_but_noindex(owner, kind):
|
||||
item = _make(owner, kind, "hidden")
|
||||
guest = requests.get(f"{BASE_URL}{item['url']}", allow_redirects=False)
|
||||
assert guest.status_code == 200
|
||||
assert "noindex" in guest.text
|
||||
assert item["uid"] not in _listed_uids(kind, item["token"])
|
||||
|
||||
|
||||
@pytest.mark.parametrize("kind", KINDS)
|
||||
@pytest.mark.parametrize("value", ["offline", "draft"])
|
||||
def test_offline_and_draft_are_404_for_guests_and_strangers(owner, stranger, kind, value):
|
||||
item = _make(owner, kind, value)
|
||||
assert _detail(kind, item).status_code == 404
|
||||
assert _detail(kind, item, stranger).status_code == 404
|
||||
assert _detail(kind, item, owner).status_code == 200
|
||||
|
||||
|
||||
@pytest.mark.parametrize("kind", KINDS)
|
||||
def test_admin_can_open_offline_item(owner, admin, kind):
|
||||
item = _make(owner, kind, "offline")
|
||||
assert _detail(kind, item, admin).status_code == 200
|
||||
|
||||
|
||||
@pytest.mark.parametrize("kind", KINDS)
|
||||
def test_only_owner_can_change_visibility(owner, stranger, admin, kind):
|
||||
item = _make(owner, kind)
|
||||
assert _set(stranger, kind, item, "offline").status_code == 403
|
||||
assert _set(admin, kind, item, "offline").status_code == 403
|
||||
assert _detail(kind, item, owner).json()[kind]["visibility"] == "published"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("kind", KINDS)
|
||||
def test_guest_cannot_change_visibility(owner, kind):
|
||||
item = _make(owner, kind)
|
||||
path, data = _edit_payload(kind, item["token"], "offline")
|
||||
response = requests.post(
|
||||
f"{BASE_URL}{path.format(slug=item['slug'])}", data=data, headers=JSON
|
||||
)
|
||||
assert response.status_code in (401, 403)
|
||||
assert _detail(kind, item, owner).json()[kind]["visibility"] == "published"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("kind", KINDS)
|
||||
def test_invalid_value_is_refused(owner, kind):
|
||||
item = _make(owner, kind)
|
||||
response = _set(owner, kind, item, "nonsense")
|
||||
assert response.status_code in (400, 422)
|
||||
assert _detail(kind, item, owner).json()[kind]["visibility"] == "published"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("kind", KINDS)
|
||||
def test_missing_item_visibility_change_is_denied(owner, kind):
|
||||
response = _set(owner, kind, {"slug": "does-not-exist", "token": "x"}, "hidden")
|
||||
assert response.status_code == 403
|
||||
|
||||
|
||||
def _edit_payload(kind, token, visibility):
|
||||
if kind == "post":
|
||||
return "/posts/edit/{slug}", {"content": f"edited body for {token}", "title": token, "visibility": visibility}
|
||||
if kind == "gist":
|
||||
return "/gists/edit/{slug}", {"title": token, "source_code": "print(2)", "visibility": visibility}
|
||||
return "/projects/edit/{slug}", {"title": token, "description": f"edited {token}", "visibility": visibility}
|
||||
|
||||
|
||||
@pytest.mark.parametrize("kind", KINDS)
|
||||
def test_edit_form_changes_visibility(owner, kind):
|
||||
item = _make(owner, kind)
|
||||
path, data = _edit_payload(kind, item["token"], "hidden")
|
||||
response = owner.post(f"{BASE_URL}{path.format(slug=item['slug'])}", data=data, headers=JSON)
|
||||
assert response.status_code == 200, response.text[:300]
|
||||
assert _detail(kind, item, owner).json()[kind]["visibility"] == "hidden"
|
||||
assert item["uid"] not in _listed_uids(kind, item["token"])
|
||||
|
||||
|
||||
@pytest.mark.parametrize("kind", KINDS)
|
||||
def test_edit_without_visibility_keeps_current_value(owner, kind):
|
||||
item = _make(owner, kind, "offline")
|
||||
path, data = _edit_payload(kind, item["token"], "")
|
||||
data.pop("visibility")
|
||||
response = owner.post(f"{BASE_URL}{path.format(slug=item['slug'])}", data=data, headers=JSON)
|
||||
assert response.status_code == 200, response.text[:300]
|
||||
assert _detail(kind, item, owner).json()[kind]["visibility"] == "offline"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("kind", ("gist", "project"))
|
||||
def test_owner_sees_unlisted_items_on_own_listing_only(owner, stranger, kind):
|
||||
item = _make(owner, kind, "offline")
|
||||
uid = get_table("users").find_one(username=_owner_name(owner))["uid"]
|
||||
own = owner.get(
|
||||
f"{BASE_URL}{LISTING[kind]}", params={"search": item["token"], "user_uid": uid}, headers=JSON
|
||||
)
|
||||
assert own.status_code == 200
|
||||
rows = own.json()[AREA[kind]]
|
||||
found = {row[kind]["uid"] if kind in row else row["uid"] for row in rows}
|
||||
assert item["uid"] in found
|
||||
other = stranger.get(
|
||||
f"{BASE_URL}{LISTING[kind]}", params={"search": item["token"], "user_uid": uid}, headers=JSON
|
||||
)
|
||||
rows = other.json()[AREA[kind]]
|
||||
assert item["uid"] not in {row[kind]["uid"] if kind in row else row["uid"] for row in rows}
|
||||
|
||||
|
||||
def _owner_name(session):
|
||||
refresh_snapshot()
|
||||
key = session.headers["X-API-KEY"]
|
||||
return get_table("users").find_one(api_key=key)["username"]
|
||||
|
||||
|
||||
def test_unlisted_post_leaves_profile_for_visitors(owner, stranger):
|
||||
item = _make(owner, "post", "hidden")
|
||||
name = _owner_name(owner)
|
||||
visitor = stranger.get(f"{BASE_URL}/profile/{name}", params={"tab": "posts"}, headers=JSON)
|
||||
assert visitor.status_code == 200
|
||||
assert item["uid"] not in {row["post"]["uid"] for row in visitor.json()["posts"]}
|
||||
mine = owner.get(f"{BASE_URL}/profile/{name}", params={"tab": "posts"}, headers=JSON)
|
||||
assert item["uid"] in {row["post"]["uid"] for row in mine.json()["posts"]}
|
||||
|
||||
|
||||
@pytest.mark.parametrize("kind", KINDS)
|
||||
def test_unlisted_items_are_absent_from_sitemap(owner, kind):
|
||||
visible = _make(owner, kind)
|
||||
hidden = _make(owner, kind, "hidden")
|
||||
offline = _make(owner, kind, "offline")
|
||||
sitemap = requests.get(f"{BASE_URL}/sitemap.xml").text
|
||||
assert visible["slug"] in sitemap
|
||||
assert hidden["slug"] not in sitemap
|
||||
assert offline["slug"] not in sitemap
|
||||
|
||||
|
||||
def test_offline_post_refuses_engagement_from_strangers(owner, stranger):
|
||||
item = _make(owner, "post", "offline")
|
||||
comment = stranger.post(
|
||||
f"{BASE_URL}/comments/create",
|
||||
data={"content": "should not land", "target_uid": item["uid"], "target_type": "post"},
|
||||
headers=JSON,
|
||||
)
|
||||
assert comment.status_code == 404
|
||||
vote = stranger.post(f"{BASE_URL}/votes/post/{item['uid']}", data={"value": 1}, headers=JSON)
|
||||
assert vote.status_code == 404
|
||||
reaction = stranger.post(
|
||||
f"{BASE_URL}/reactions/post/{item['uid']}", data={"emoji": "\U0001F44D"}, headers=JSON
|
||||
)
|
||||
assert reaction.status_code == 404
|
||||
bookmark = stranger.post(f"{BASE_URL}/bookmarks/post/{item['uid']}", headers=JSON)
|
||||
assert bookmark.status_code == 404
|
||||
|
||||
|
||||
def test_offline_post_still_accepts_engagement_from_owner(owner):
|
||||
item = _make(owner, "post", "offline")
|
||||
comment = owner.post(
|
||||
f"{BASE_URL}/comments/create",
|
||||
data={"content": "owner note", "target_uid": item["uid"], "target_type": "post"},
|
||||
headers=JSON,
|
||||
)
|
||||
assert comment.status_code == 200
|
||||
|
||||
|
||||
def test_hidden_post_accepts_engagement_from_strangers(owner, stranger):
|
||||
item = _make(owner, "post", "hidden")
|
||||
comment = stranger.post(
|
||||
f"{BASE_URL}/comments/create",
|
||||
data={"content": "still reachable by link", "target_uid": item["uid"], "target_type": "post"},
|
||||
headers=JSON,
|
||||
)
|
||||
assert comment.status_code == 200
|
||||
|
||||
|
||||
def test_offline_post_leaves_next_post_and_related_lists(owner):
|
||||
item = _make(owner, "post", "offline")
|
||||
detail = requests.get(f"{BASE_URL}/posts/{item['slug']}", headers=JSON)
|
||||
assert detail.status_code == 404
|
||||
|
||||
|
||||
def test_audit_log_records_visibility_change(owner, admin):
|
||||
item = _make(owner, "post")
|
||||
assert _set(owner, "post", item, "offline").status_code == 200
|
||||
response = admin.get(
|
||||
f"{BASE_URL}/admin/audit-log", params={"event_key": "post.visibility.set"}, headers=JSON
|
||||
)
|
||||
assert response.status_code == 200
|
||||
entries = response.json()["entries"]
|
||||
assert any(
|
||||
entry.get("target_uid") == item["uid"] and entry.get("new_value") == "offline"
|
||||
for entry in entries
|
||||
)
|
||||
|
||||
|
||||
def test_denied_change_is_audited(owner, stranger, admin):
|
||||
item = _make(owner, "gist")
|
||||
assert _set(stranger, "gist", item, "offline").status_code == 403
|
||||
response = admin.get(
|
||||
f"{BASE_URL}/admin/audit-log", params={"event_key": "gist.edit"}, headers=JSON
|
||||
)
|
||||
entries = response.json()["entries"]
|
||||
assert any(
|
||||
entry.get("target_uid") == item["uid"] and entry.get("result") == "denied"
|
||||
for entry in entries
|
||||
)
|
||||
|
||||
|
||||
def test_devrant_feed_hides_unlisted_rants(owner):
|
||||
item = _make(owner, "post", "hidden")
|
||||
response = requests.get(f"{BASE_URL}/api/devrant/rants", params={"app": 3, "limit": 50})
|
||||
assert response.status_code == 200
|
||||
assert item["token"] not in response.text
|
||||
|
||||
|
||||
LEGACY_CREATE = {
|
||||
"post": ("/posts/create", {"content": "legacy client post body text"}),
|
||||
"gist": ("/gists/create", {"title": "legacy gist", "source_code": "print(1)"}),
|
||||
"project": ("/projects/create", {"title": "legacy project", "description": "legacy"}),
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.parametrize("kind", KINDS)
|
||||
def test_legacy_form_create_without_the_field_is_published(owner, kind):
|
||||
path, data = LEGACY_CREATE[kind]
|
||||
response = owner.post(f"{BASE_URL}{path}", data=data, headers=JSON)
|
||||
assert response.status_code == 200, response.text[:300]
|
||||
url = response.json()["data"]["url"]
|
||||
detail = owner.get(f"{BASE_URL}{url}", headers=JSON)
|
||||
assert detail.json()[kind]["visibility"] == "published"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("kind", KINDS)
|
||||
def test_legacy_json_create_without_the_field_is_published(owner, kind):
|
||||
path, data = LEGACY_CREATE[kind]
|
||||
response = owner.post(f"{BASE_URL}{path}", json=data, headers=JSON)
|
||||
assert response.status_code == 200, response.text[:300]
|
||||
url = response.json()["data"]["url"]
|
||||
assert owner.get(f"{BASE_URL}{url}", headers=JSON).json()[kind]["visibility"] == "published"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("kind", KINDS)
|
||||
def test_legacy_json_create_with_the_field_is_honoured(owner, kind):
|
||||
path, data = LEGACY_CREATE[kind]
|
||||
response = owner.post(
|
||||
f"{BASE_URL}{path}", json={**data, "visibility": "hidden"}, headers=JSON
|
||||
)
|
||||
assert response.status_code == 200, response.text[:300]
|
||||
url = response.json()["data"]["url"]
|
||||
assert owner.get(f"{BASE_URL}{url}", headers=JSON).json()[kind]["visibility"] == "hidden"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("kind", KINDS)
|
||||
def test_legacy_json_edit_without_the_field_keeps_the_value(owner, kind):
|
||||
item = _make(owner, kind, "hidden")
|
||||
path, data = _edit_payload(kind, item["token"], "")
|
||||
data.pop("visibility")
|
||||
response = owner.post(
|
||||
f"{BASE_URL}{path.format(slug=item['slug'])}", json=data, headers=JSON
|
||||
)
|
||||
assert response.status_code == 200, response.text[:300]
|
||||
assert _detail(kind, item, owner).json()[kind]["visibility"] == "hidden"
|
||||
@@ -0,0 +1,248 @@
|
||||
# retoor <retoor@molodetz.nl>
|
||||
|
||||
import threading
|
||||
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
|
||||
|
||||
import pytest
|
||||
from starlette.testclient import TestClient
|
||||
|
||||
from devplacepy.database import get_table, init_db, set_setting
|
||||
from devplacepy.routers import giphy as giphy_router
|
||||
from devplacepy.services.giphy import runtime
|
||||
from devplacepy.services.giphy.fake import FakeGiphyClient
|
||||
from devplacepy.utils import create_session
|
||||
|
||||
JSON = {"Accept": "application/json"}
|
||||
_seq = [0]
|
||||
|
||||
GIF_BYTES = (
|
||||
b"GIF89a\x01\x00\x01\x00\x80\x00\x00\x00\x00\x00\xff\xff\xff"
|
||||
b"\x21\xf9\x04\x01\x00\x00\x00\x00\x2c\x00\x00\x00\x00\x01\x00"
|
||||
b"\x01\x00\x00\x02\x02\x44\x01\x00\x3b"
|
||||
)
|
||||
|
||||
SETTINGS = {
|
||||
"giphy_api_key": "test-giphy-key",
|
||||
"giphy_base_url": "https://api.giphy.test/v1/gifs",
|
||||
"giphy_rating": "pg",
|
||||
"max_upload_size_mb": "10",
|
||||
"allowed_file_types": "",
|
||||
"max_attachments_per_resource": "10",
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def _init_db_giphy():
|
||||
init_db()
|
||||
yield
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def giphy_env():
|
||||
fake = FakeGiphyClient()
|
||||
runtime.set_client(fake)
|
||||
giphy_router.limiter.reset()
|
||||
for key, value in SETTINGS.items():
|
||||
set_setting(key, value)
|
||||
yield fake
|
||||
runtime.set_client(None)
|
||||
for key in ("giphy_api_key", "giphy_base_url", "giphy_rating"):
|
||||
set_setting(key, "")
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def remote_gif():
|
||||
class Handler(BaseHTTPRequestHandler):
|
||||
def do_GET(self):
|
||||
self.send_response(200)
|
||||
self.send_header("Content-Type", "image/gif")
|
||||
self.send_header("Content-Length", str(len(GIF_BYTES)))
|
||||
self.end_headers()
|
||||
self.wfile.write(GIF_BYTES)
|
||||
|
||||
def log_message(self, *args):
|
||||
return
|
||||
|
||||
server = ThreadingHTTPServer(("127.0.0.1", 0), Handler)
|
||||
threading.Thread(target=server.serve_forever, daemon=True).start()
|
||||
yield f"http://127.0.0.1:{server.server_port}/giphy.gif"
|
||||
server.shutdown()
|
||||
server.server_close()
|
||||
|
||||
|
||||
def _user():
|
||||
_seq[0] += 1
|
||||
uid = f"giphy-user-{_seq[0]}"
|
||||
get_table("users").insert(
|
||||
{
|
||||
"uid": uid,
|
||||
"username": f"giphytest{_seq[0]}",
|
||||
"terms_version": "1",
|
||||
"role": "member",
|
||||
"xp": 0,
|
||||
"level": 1,
|
||||
"is_active": True,
|
||||
}
|
||||
)
|
||||
return uid
|
||||
|
||||
|
||||
def _client(uid=None):
|
||||
import devplacepy.main as m
|
||||
|
||||
client = TestClient(m.app)
|
||||
if uid:
|
||||
client.cookies.set("session", create_session(uid))
|
||||
return client
|
||||
|
||||
|
||||
def test_status_requires_auth():
|
||||
response = _client().get("/giphy/status", headers=JSON)
|
||||
assert response.status_code == 401
|
||||
|
||||
|
||||
def test_status_configured(giphy_env):
|
||||
response = _client(_user()).get("/giphy/status", headers=JSON)
|
||||
assert response.status_code == 200, response.text
|
||||
assert response.json() == {"configured": True}
|
||||
|
||||
|
||||
def test_status_unconfigured():
|
||||
runtime.set_client(FakeGiphyClient(configured=False))
|
||||
try:
|
||||
set_setting("giphy_api_key", "")
|
||||
client = _client(_user())
|
||||
assert client.get("/giphy/status", headers=JSON).json() == {"configured": False}
|
||||
assert client.get("/giphy/trending", headers=JSON).status_code == 503
|
||||
assert (
|
||||
client.get("/giphy/search", params={"q": "cat"}, headers=JSON).status_code == 503
|
||||
)
|
||||
finally:
|
||||
runtime.set_client(None)
|
||||
|
||||
|
||||
def test_search_and_trending(giphy_env):
|
||||
client = _client(_user())
|
||||
|
||||
response = client.get("/giphy/trending", headers=JSON)
|
||||
assert response.status_code == 200, response.text
|
||||
assert [item["id"] for item in response.json()["results"]] == ["fake1", "fake2"]
|
||||
|
||||
response = client.get("/giphy/search", params={"q": "dance"}, headers=JSON)
|
||||
assert response.status_code == 200, response.text
|
||||
assert response.json()["query"] == "dance"
|
||||
assert [item["id"] for item in response.json()["results"]] == ["fake2"]
|
||||
assert giphy_env.queries == ["dance"]
|
||||
|
||||
response = client.get("/giphy/search", params={"q": " "}, headers=JSON)
|
||||
assert response.status_code == 400
|
||||
|
||||
|
||||
def test_attach(giphy_env, remote_gif, monkeypatch):
|
||||
import devplacepy.attachments as attachments
|
||||
import devplacepy.net_guard as net_guard
|
||||
|
||||
async def _no_guard(url, **kwargs):
|
||||
return url
|
||||
|
||||
async def _no_host_guard(host):
|
||||
return host
|
||||
|
||||
monkeypatch.setattr(attachments, "_guard_public_url", _no_guard)
|
||||
monkeypatch.setattr(net_guard, "guard_public_url", _no_guard)
|
||||
monkeypatch.setattr(net_guard, "guard_public_host", _no_host_guard)
|
||||
giphy_env.gifs[0]["images"]["original"]["url"] = remote_gif
|
||||
client = _client(_user())
|
||||
|
||||
response = client.post(
|
||||
"/giphy/attach", json={"gif_id": "fake1", "title": "Fake happy"}, headers=JSON
|
||||
)
|
||||
assert response.status_code == 201, response.text
|
||||
payload = response.json()
|
||||
assert payload["uid"]
|
||||
assert payload["mime_type"] == "image/gif"
|
||||
assert payload["original_filename"] == "Fake happy.gif"
|
||||
|
||||
row = get_table("attachments").find_one(uid=payload["uid"])
|
||||
assert row is not None
|
||||
|
||||
response = client.post("/giphy/attach", json={"gif_id": "missing"}, headers=JSON)
|
||||
assert response.status_code == 404
|
||||
|
||||
response = client.post("/giphy/attach", json={"gif_id": ""}, headers=JSON)
|
||||
assert response.status_code == 422
|
||||
|
||||
|
||||
def test_every_route_requires_a_signed_in_user():
|
||||
client = _client()
|
||||
assert client.get("/giphy/search", params={"q": "cat"}, headers=JSON).status_code == 401
|
||||
assert client.get("/giphy/trending", headers=JSON).status_code == 401
|
||||
assert client.post("/giphy/attach", json={"gif_id": "fake1"}, headers=JSON).status_code == 401
|
||||
|
||||
|
||||
def test_errors_use_the_shared_error_shape(giphy_env):
|
||||
client = _client(_user())
|
||||
response = client.get("/giphy/search", params={"q": " "}, headers=JSON)
|
||||
assert response.status_code == 400
|
||||
assert response.json() == {"error": {"status": 400, "message": "q is required"}}
|
||||
response = client.post("/giphy/attach", json={"gif_id": "missing"}, headers=JSON)
|
||||
assert response.status_code == 404
|
||||
assert response.json()["error"]["message"] == "GIF not found"
|
||||
|
||||
|
||||
def test_search_is_rate_limited_per_user(giphy_env):
|
||||
limiter = giphy_router.limiter
|
||||
first, second = _client(_user()), _client(_user())
|
||||
statuses = [first.get("/giphy/trending", headers=JSON).status_code for _ in range(limiter.max_calls + 3)]
|
||||
assert statuses == [200] * limiter.max_calls + [429] * 3
|
||||
refused = first.get("/giphy/search", params={"q": "dance"}, headers=JSON)
|
||||
assert refused.status_code == 429
|
||||
assert refused.headers["Retry-After"] == str(int(limiter.window_seconds))
|
||||
assert refused.json()["error"]["status"] == 429
|
||||
assert second.get("/giphy/trending", headers=JSON).status_code == 200
|
||||
|
||||
|
||||
def test_oversized_limit_is_clamped(giphy_env):
|
||||
response = _client(_user()).get("/giphy/trending", params={"limit": 100000}, headers=JSON)
|
||||
assert response.status_code == 200
|
||||
|
||||
|
||||
def test_attach_refuses_when_gifs_are_not_an_allowed_type(giphy_env):
|
||||
set_setting("allowed_file_types", ".png,.jpg")
|
||||
try:
|
||||
response = _client(_user()).post("/giphy/attach", json={"gif_id": "fake1"}, headers=JSON)
|
||||
assert response.status_code == 415, response.text
|
||||
finally:
|
||||
set_setting("allowed_file_types", "")
|
||||
|
||||
|
||||
def test_attach_is_audited_and_the_record_is_the_upload_shape(giphy_env, remote_gif, monkeypatch):
|
||||
import devplacepy.attachments as attachments
|
||||
|
||||
async def _no_guard(url, **kwargs):
|
||||
return url
|
||||
|
||||
monkeypatch.setattr(attachments, "_guard_public_url", _no_guard)
|
||||
import devplacepy.net_guard as net_guard
|
||||
|
||||
monkeypatch.setattr(net_guard, "guard_public_url", _no_guard)
|
||||
giphy_env.gifs[1]["images"]["original"]["url"] = remote_gif
|
||||
owner = _user()
|
||||
response = _client(owner).post("/giphy/attach", json={"gif_id": "fake2"}, headers=JSON)
|
||||
assert response.status_code == 201, response.text
|
||||
payload = response.json()
|
||||
for key in ("uid", "url", "mime_type", "original_filename", "file_size", "is_image", "is_video"):
|
||||
assert key in payload
|
||||
assert payload["is_image"] is True
|
||||
assert payload["url"].endswith(".gif")
|
||||
event = get_table("audit_log").find_one(event_key="attachment.giphy", target_uid=payload["uid"])
|
||||
assert event is not None
|
||||
assert event["actor_uid"] == owner
|
||||
|
||||
|
||||
def test_attach_surfaces_an_unreachable_gif_as_an_error(giphy_env):
|
||||
giphy_env.gifs[0]["images"]["original"]["url"] = "http://127.0.0.1:9/never.gif"
|
||||
giphy_env.gifs[0]["images"]["fixed_width"]["url"] = "http://127.0.0.1:9/never.gif"
|
||||
response = _client(_user()).post("/giphy/attach", json={"gif_id": "fake1"}, headers=JSON)
|
||||
assert response.status_code in (400, 502)
|
||||
assert "message" in response.json()["error"]
|
||||
@@ -0,0 +1,122 @@
|
||||
# retoor <retoor@molodetz.nl>
|
||||
|
||||
import time
|
||||
|
||||
import pytest
|
||||
import requests
|
||||
|
||||
from tests.conftest import BASE_URL
|
||||
from devplacepy.database import get_table, refresh_snapshot, set_setting
|
||||
|
||||
JSON = {"Accept": "application/json"}
|
||||
|
||||
|
||||
@pytest.fixture(scope="module", autouse=True)
|
||||
def _delete_settings(app_server):
|
||||
for key, value in {
|
||||
"rate_limit_per_minute": "1000000",
|
||||
"rate_limit_window_seconds": "60",
|
||||
"registration_open": "1",
|
||||
"maintenance_mode": "0",
|
||||
}.items():
|
||||
set_setting(key, value)
|
||||
yield
|
||||
|
||||
|
||||
def _login(seeded_db, who):
|
||||
session = requests.Session()
|
||||
creds = seeded_db[who]
|
||||
session.post(
|
||||
f"{BASE_URL}/auth/login",
|
||||
data={"email": creds["email"], "password": creds["password"]},
|
||||
allow_redirects=True,
|
||||
)
|
||||
return session
|
||||
|
||||
|
||||
def _uid(username):
|
||||
refresh_snapshot()
|
||||
return get_table("users").find_one(username=username)["uid"]
|
||||
|
||||
|
||||
def _send(session, receiver_uid, text):
|
||||
response = session.post(
|
||||
f"{BASE_URL}/messages/send",
|
||||
data={"receiver_uid": receiver_uid, "content": text},
|
||||
headers=JSON,
|
||||
)
|
||||
assert response.status_code == 200, response.text
|
||||
return response.json()["data"]["uid"]
|
||||
|
||||
|
||||
def _thread_text(session, with_uid):
|
||||
response = session.get(f"{BASE_URL}/messages", params={"with_uid": with_uid}, headers=JSON)
|
||||
assert response.status_code == 200, response.text
|
||||
return [m["message"]["content"] for m in response.json()["messages"]]
|
||||
|
||||
|
||||
def test_admin_deletes_own_message(seeded_db):
|
||||
alice = _login(seeded_db, "alice")
|
||||
bob = _login(seeded_db, "bob")
|
||||
bob_uid = _uid("bob_test")
|
||||
text = f"admin own delete {int(time.time() * 1000)}"
|
||||
uid = _send(alice, bob_uid, text)
|
||||
assert text in _thread_text(alice, bob_uid)
|
||||
|
||||
response = alice.post(f"{BASE_URL}/messages/{uid}/delete", headers=JSON)
|
||||
assert response.status_code == 200, response.text
|
||||
assert response.json()["data"]["deleted_uid"] == uid
|
||||
|
||||
assert text not in _thread_text(alice, bob_uid)
|
||||
assert text not in _thread_text(bob, _uid("alice_test"))
|
||||
refresh_snapshot()
|
||||
row = get_table("messages").find_one(uid=uid)
|
||||
assert row["deleted_at"] and row["deleted_by"] == _uid("alice_test")
|
||||
|
||||
|
||||
def test_member_cannot_delete_own_message(seeded_db):
|
||||
alice = _login(seeded_db, "alice")
|
||||
bob = _login(seeded_db, "bob")
|
||||
alice_uid = _uid("alice_test")
|
||||
text = f"member cannot delete {int(time.time() * 1000)}"
|
||||
uid = _send(bob, alice_uid, text)
|
||||
|
||||
response = bob.post(f"{BASE_URL}/messages/{uid}/delete", headers=JSON)
|
||||
assert response.status_code == 403
|
||||
assert text in _thread_text(alice, _uid("bob_test"))
|
||||
|
||||
|
||||
def test_admin_cannot_delete_other_users_message(seeded_db):
|
||||
alice = _login(seeded_db, "alice")
|
||||
bob = _login(seeded_db, "bob")
|
||||
alice_uid = _uid("alice_test")
|
||||
text = f"admin cannot delete theirs {int(time.time() * 1000)}"
|
||||
uid = _send(bob, alice_uid, text)
|
||||
|
||||
response = alice.post(f"{BASE_URL}/messages/{uid}/delete", headers=JSON)
|
||||
assert response.status_code == 403
|
||||
assert text in _thread_text(bob, alice_uid)
|
||||
|
||||
|
||||
def test_delete_unknown_message_is_404(seeded_db):
|
||||
alice = _login(seeded_db, "alice")
|
||||
response = alice.post(f"{BASE_URL}/messages/does-not-exist/delete", headers=JSON)
|
||||
assert response.status_code == 404
|
||||
|
||||
|
||||
def test_delete_requires_login(app_server):
|
||||
response = requests.post(
|
||||
f"{BASE_URL}/messages/anything/delete", headers=JSON, allow_redirects=False
|
||||
)
|
||||
assert response.status_code in (401, 303)
|
||||
|
||||
|
||||
def test_deleted_message_leaves_conversation_preview(seeded_db):
|
||||
alice = _login(seeded_db, "alice")
|
||||
bob_uid = _uid("bob_test")
|
||||
text = f"preview delete {int(time.time() * 1000)}"
|
||||
uid = _send(alice, bob_uid, text)
|
||||
alice.post(f"{BASE_URL}/messages/{uid}/delete", headers=JSON)
|
||||
response = alice.get(f"{BASE_URL}/messages/conversations")
|
||||
previews = [c["last_message"] for c in response.json()["conversations"]]
|
||||
assert text not in previews
|
||||
Reference in New Issue
Block a user