This introduces the FastAPI editor implementation and related project setup so the app can be run and validated locally. Made-with: Cursor
37 lines
953 B
Python
37 lines
953 B
Python
import importlib
|
|
import os
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
from fastapi.testclient import TestClient
|
|
|
|
|
|
def test_python_completion_returns_basic_suggestions(tmp_path):
|
|
editor_dir = Path(__file__).resolve().parents[1]
|
|
src_dir = editor_dir / "src"
|
|
if str(src_dir) not in sys.path:
|
|
sys.path.insert(0, str(src_dir))
|
|
|
|
os.environ["WORKSPACE_ROOT"] = str(tmp_path)
|
|
import app as editor_app
|
|
|
|
editor_app = importlib.reload(editor_app)
|
|
editor_app.WORKSPACE_ROOT = tmp_path
|
|
client = TestClient(editor_app.app)
|
|
|
|
response = client.post(
|
|
"/api/python/completions",
|
|
json={
|
|
"file_path": "example.py",
|
|
"content": "import os\nos.pa",
|
|
"line": 2,
|
|
"column": 5,
|
|
"max_results": 20,
|
|
},
|
|
)
|
|
|
|
assert response.status_code == 200
|
|
body = response.json()
|
|
names = [item["name"] for item in body["completions"]]
|
|
assert "path" in names
|