Files
2026-11-22 01:04:28 +08:00

61 lines
2.3 KiB
Python

import pytest
from app import admin, config, db
from app.titles import uid_tier
from .conftest import login
@pytest.mark.parametrize("uid,tier", [
(0, "admin"), (114514, "114514"), (51919810, "1919810"), (1919810, "1919810"),
(11451400, "114514"), (1, None), (11451, None), (99999999, None),
])
def test_uid_tier(uid, tier):
assert uid_tier(uid) == tier
@pytest.mark.parametrize("beta", [True, False])
def test_beta_switch(client, sent, monkeypatch, beta):
monkeypatch.setattr(config, "BETA", beta)
html = client.get("/").text
assert ("(Beta)" in html) is beta
assert "<!--BETA" not in html
login(client, sent)
r = client.post("/api/checkin").json()
page = client.get(f"/c/00000001/{r['day']}").text
assert ('content="My INMU (Beta)"' in page) is beta
assert client.get(r["card_url"]).status_code == 200
def test_reset_progress(client, sent, capsys):
login(client, sent)
client.patch("/api/me", json={"display_name": "Beta tester"})
first = client.post("/api/checkin").json()
assert client.get(first["card_url"]).status_code == 200
# 沒有 --yes 不做任何事
admin.main(["reset-progress"])
assert client.get("/api/checkin/today").json()["total_days"] == 1
admin.main(["reset-progress", "--yes"])
today = client.get("/api/checkin/today").json()
assert today["total_days"] == 0 and today["checked_in"] is False
me = client.get("/api/me").json() # 帳號、名稱、session 都還在
assert me["display_name"] == "Beta tester" and me["uid_str"] == "00000001"
assert list(config.DATA_DIR.glob("inmu.db.bak-*"))
assert not any((config.DATA_DIR / "cards").iterdir())
# 同一天可以重新簽到
again = client.post("/api/checkin").json()
assert again["already"] is False and again["total_days"] == 1
assert db.connect().execute("SELECT value FROM meta WHERE key = 'next_uid'").fetchone()[0] == 2
def test_assets_versioned_and_not_cached_by_proxies(client):
html = client.get("/").text
assert "__ASSET_VERSION__" not in html
assert '/assets/app.js?v=' in html and '/assets/style.css?v=' in html
r = client.get("/assets/app.js")
assert r.headers["cache-control"] == "no-cache"
etag = r.headers["etag"]
assert client.get("/assets/app.js", headers={"If-None-Match": etag}).status_code == 304