Add browser Python editor with Pyodide, user auth, and workspace API
- FastAPI serves static UI, file CRUD under code/ and read-only lib/ - Pyodide worker runs Python and Jedi completions in the browser - SQLite accounts: login/register, session cookies, superuser user management - Optional EDITOR_API_KEY, AUTH_* env vars, .env.example - Pipenv, pytest, Selenium smoke test, README Made-with: Cursor
This commit is contained in:
45
tests/test_internal.py
Normal file
45
tests/test_internal.py
Normal file
@@ -0,0 +1,45 @@
|
||||
import importlib
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
def test_load_env_file_sets_missing_keys_only(tmp_path, monkeypatch):
|
||||
import editor_app.config as config
|
||||
|
||||
env_file = tmp_path / ".env"
|
||||
env_file.write_text(
|
||||
"# comment\nFOO=bar\nBAZ='quoted'\nEXISTING=from_file\n", encoding="utf-8"
|
||||
)
|
||||
|
||||
monkeypatch.setenv("EXISTING", "kept")
|
||||
monkeypatch.delenv("FOO", raising=False)
|
||||
monkeypatch.delenv("BAZ", raising=False)
|
||||
|
||||
config.load_env_file(env_file)
|
||||
|
||||
assert __import__("os").environ["FOO"] == "bar"
|
||||
assert __import__("os").environ["BAZ"] == "quoted"
|
||||
assert __import__("os").environ["EXISTING"] == "kept"
|
||||
|
||||
|
||||
def test_load_env_file_ignores_missing_file(tmp_path):
|
||||
import editor_app.config as config
|
||||
|
||||
config.load_env_file(tmp_path / "missing.env")
|
||||
|
||||
|
||||
def test_collect_python_sources_skips_hidden_and_binary(tmp_path):
|
||||
import editor_app.config as config
|
||||
import editor_app.services.filesystem as filesystem
|
||||
|
||||
(tmp_path / "code").mkdir()
|
||||
(tmp_path / "code" / "ok.py").write_text("a = 1\n", encoding="utf-8")
|
||||
(tmp_path / "code" / ".venv").mkdir()
|
||||
(tmp_path / "code" / ".venv" / "skip.py").write_text("x\n", encoding="utf-8")
|
||||
(tmp_path / "bad.py").write_bytes(b"\xff\xff")
|
||||
|
||||
config.WORKSPACE_ROOT = tmp_path
|
||||
out = filesystem.collect_python_sources()
|
||||
assert out["code/ok.py"] == "a = 1\n"
|
||||
assert "bad.py" not in out
|
||||
Reference in New Issue
Block a user