dev server uses admin login too: localhost shows the public view

Drop open_access; run() prints a one-off PHYSCOM_ADMIN_TOKEN when none is set.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2026-09-25 17:27:55 -05:00
parent 8171fc023e
commit af401d6bc2
6 changed files with 25 additions and 26 deletions

View File

@@ -36,7 +36,7 @@ def db_file(tmp_path_factory):
return path, ids
def _app(monkeypatch, db_file, token: str | None, open_access: bool = False):
def _app(monkeypatch, db_file, token: str | None):
from physcom_web.app import create_app
monkeypatch.setenv("PHYSCOM_DB", str(db_file[0]))
monkeypatch.setenv("FLASK_SECRET_KEY", "test")
@@ -44,7 +44,7 @@ def _app(monkeypatch, db_file, token: str | None, open_access: bool = False):
monkeypatch.setenv("PHYSCOM_ADMIN_TOKEN", token)
else:
monkeypatch.delenv("PHYSCOM_ADMIN_TOKEN", raising=False)
return create_app(open_access=open_access)
return create_app()
@pytest.fixture
@@ -136,22 +136,21 @@ def test_admin_can_reach_everything(admin, db_file):
assert 'class="readonly"' not in html
def test_open_access_dev_server(monkeypatch, db_file):
app = _app(monkeypatch, db_file, None, open_access=True)
assert app.test_client().get("/admin/").status_code == 200
# Setting a token locks even the dev server.
app = _app(monkeypatch, db_file, TOKEN, open_access=True)
assert app.test_client().get("/admin/").status_code == 302
def test_debug_off_by_default(monkeypatch, db_file):
import physcom_web.app as web
seen = {}
monkeypatch.delenv("FLASK_DEBUG", raising=False)
monkeypatch.delenv("PHYSCOM_ADMIN_TOKEN", raising=False)
monkeypatch.setenv("PHYSCOM_DB", str(db_file[0]))
monkeypatch.setattr("flask.Flask.run", lambda self, **kw: seen.update(kw))
monkeypatch.setattr("flask.Flask.run", lambda self, **kw: seen.update(kw, app=self))
web.run()
assert seen["debug"] is False and seen["host"] == "127.0.0.1"
# Dev server shows the public view too; the printed token logs in.
client = seen["app"].test_client()
assert client.get("/admin/").status_code == 302
token = web.os.environ["PHYSCOM_ADMIN_TOKEN"]
assert client.post("/login", data={"token": token}).status_code == 302
assert client.get("/admin/").status_code == 200
def test_cli_demo_if_empty_skips_populated_db(db_file):