fix(2): mattermost functional tests share a deterministic admin bootstrap (_mm.bootstrap_admin) — only ONE unauthenticated first-user creation is allowed, so the multi-user test no longer collides with create_message

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-30 01:58:32 +01:00
parent 7672f110f6
commit e9d1e894b2
3 changed files with 62 additions and 50 deletions

View File

@ -4,7 +4,7 @@ The defining behaviour of a team-chat platform is that a message one user posts
readable by *another* user in the same channel — not just round-tripped by its own author (that is
`test_create_message.py`). This exercises the real membership + post-delivery path end-to-end:
1. Bootstrap user_a (first user = system admin) → login → create team + open channel.
1. Bootstrap the shared system admin (user_a) → create team + open channel.
2. user_a posts a unique marker message to the channel.
3. Create a SECOND user (user_b) via the admin API; add user_b to the team + the channel.
4. user_b logs in (its own session token) and GETs the channel's posts.
@ -20,19 +20,15 @@ import os
import sys
import uuid
sys.path.insert(0, os.path.dirname(__file__))
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "..", "..", "runner"))
import _mm # noqa: E402
from harness import http as harness_http # noqa: E402
_PW = "Ccci-Test-Pw-2026!"
def _bearer(token: str) -> dict[str, str]:
return {"Authorization": f"Bearer {token}"}
def _login(base: str, login_id: str) -> str:
status, _, hdrs = harness_http.post_with_headers(
f"{base}/users/login", data={"login_id": login_id, "password": _PW}, timeout=30
f"{base}/users/login", data={"login_id": login_id, "password": _mm.ADMIN_PW}, timeout=30
)
assert status == 200, f"login {login_id} failed: HTTP {status}"
token = hdrs.get("Token") or hdrs.get("token")
@ -44,16 +40,8 @@ def test_second_user_reads_first_users_message(live_app):
base = f"https://{live_app}/api/v4"
uniq = uuid.uuid4().hex[:10]
# 1) user_a = first user (system admin), login, team + channel
email_a = f"ccci{uniq}@ccci.example.com"
status, ua = harness_http.http_post(
f"{base}/users",
data={"email": email_a, "username": f"ccci{uniq}", "password": _PW},
timeout=30,
)
assert status in (200, 201) and ua.get("id"), f"user_a create HTTP {status}: {ua!r}"
auth_a = _bearer(_login(base, email_a))
# 1) user_a = shared system admin; create team + open channel
auth_a = _mm.bearer(_mm.bootstrap_admin(base))
status, team = harness_http.http_post(
f"{base}/teams",
data={"name": f"t{uniq}", "display_name": f"ccci {uniq}", "type": "O"},
@ -76,11 +64,11 @@ def test_second_user_reads_first_users_message(live_app):
)
assert status in (200, 201) and post.get("id"), f"post create HTTP {status}: {post!r}"
# 3) create user_b (admin API) + add to team + channel
# 3) create user_b (admin API — works with open-signup off) + add to team + channel
email_b = f"ccci{uniq}b@ccci.example.com"
status, ub = harness_http.http_post(
f"{base}/users",
data={"email": email_b, "username": f"ccci{uniq}b", "password": _PW},
data={"email": email_b, "username": f"ccci{uniq}b", "password": _mm.ADMIN_PW},
headers=auth_a,
timeout=30,
)
@ -101,7 +89,7 @@ def test_second_user_reads_first_users_message(live_app):
assert status in (200, 201), f"add user_b to channel HTTP {status}"
# 4) user_b logs in (own session) and reads the channel posts
auth_b = _bearer(_login(base, email_b))
auth_b = _mm.bearer(_login(base, email_b))
status, posts = harness_http.http_get(
f"{base}/channels/{chan['id']}/posts", headers=auth_b, timeout=30
)