feat: add port-in-use check and seed role overrides in test conftest, fix admin pagination assertion, and harden avatar fallback tests

This commit is contained in:
2026-06-10 03:22:44 +00:00
parent a0cb4ce7f2
commit 5ae2f58aa0
15 changed files with 189 additions and 74 deletions
+25
View File
@@ -109,8 +109,22 @@ def test_db_path():
shutil.rmtree(_TEST_DATA_DIR, ignore_errors=True)
def _port_in_use(port):
import socket
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
sock.settimeout(0.5)
return sock.connect_ex(("127.0.0.1", port)) == 0
@pytest.fixture(scope="session")
def app_server(test_db_path):
if _port_in_use(PORT):
raise RuntimeError(
f"Port {PORT} is already in use before app_server starts. A stale test "
f"server is running with a different database; kill it (the readiness "
f"check would otherwise bind tests to it and produce phantom failures)."
)
env = os.environ.copy()
env["PYTHONUNBUFFERED"] = "1"
log_file = tempfile.NamedTemporaryFile(suffix=f"_server_{PORT}.log", delete=False)
@@ -250,6 +264,9 @@ def assert_share_copies(page, expected_fragment):
share = page.locator("button[data-share]").first
share.scroll_into_view_if_needed()
assert expected_fragment in (share.get_attribute("data-share") or ""), (
f"data-share={share.get_attribute('data-share')!r}"
)
share.click()
expect(share).to_have_text("Copied!", timeout=3000)
expect(share).not_to_have_text("Copied!", timeout=3000)
@@ -288,6 +305,14 @@ def seeded_db(app_server):
headers={"Content-Type": "application/x-www-form-urlencoded"},
)
urllib.request.urlopen(req)
from devplacepy.database import get_table as _get_table
users_table = _get_table("users")
for username, role in (("alice_test", "Admin"), ("bob_test", "Member")):
row = users_table.find_one(username=username)
if row and row.get("role") != role:
users_table.update({"uid": row["uid"], "role": role}, ["uid"])
return {
"alice": {
"username": "alice_test",