Add the shared document API, constructor and expert editors, isolated preview, and fragment catalog metadata with typed block IDs. Include design references, specification 001, QA scripts, project guidance, and cached Docker dependency installation. Leave example sites for a separate commit.
110 lines
4.1 KiB
Python
110 lines
4.1 KiB
Python
"""Install a wheel and smoke real FastAPI outside the checkout, without design/."""
|
|
|
|
import os
|
|
import shutil
|
|
import subprocess
|
|
import sys
|
|
import tempfile
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
|
|
|
|
def main():
|
|
with tempfile.TemporaryDirectory(prefix="cms-installed-001-") as tmp:
|
|
work = Path(tmp)
|
|
project = work / "project"
|
|
project.mkdir()
|
|
for name in ("pyproject.toml", "README.md"):
|
|
shutil.copyfile(ROOT / name, project / name)
|
|
shutil.copytree(
|
|
ROOT / "src",
|
|
project / "src",
|
|
ignore=shutil.ignore_patterns("*.egg-info", "__pycache__"),
|
|
)
|
|
subprocess.run(
|
|
[
|
|
sys.executable,
|
|
"-m",
|
|
"pip",
|
|
"wheel",
|
|
str(project),
|
|
"--no-deps",
|
|
"--no-build-isolation",
|
|
"-q",
|
|
"-w",
|
|
str(work / "wheels"),
|
|
],
|
|
check=True,
|
|
)
|
|
wheel = next((work / "wheels").glob("*.whl"))
|
|
target = work / "installed"
|
|
subprocess.run(
|
|
[
|
|
sys.executable,
|
|
"-m",
|
|
"pip",
|
|
"install",
|
|
"--no-deps",
|
|
"--target",
|
|
str(target),
|
|
str(wheel),
|
|
"-q",
|
|
],
|
|
check=True,
|
|
)
|
|
shutil.copytree(
|
|
ROOT / "examples/studio-site", work / "site", ignore=shutil.ignore_patterns(".engine")
|
|
)
|
|
env = dict(
|
|
os.environ,
|
|
PYTHONPATH=str(target),
|
|
SITE_ROOT=str(work / "site"),
|
|
SITE_DIST=str(work / "dist"),
|
|
SITE_STATE_DIR=str(work / "state"),
|
|
SITE_COOKIE_SECURE="0",
|
|
SITE_SECRET_KEY="installed-test-secret-" * 3,
|
|
SITE_ADMIN_ORIGIN="http://127.0.0.1:9100",
|
|
SITE_PREVIEW_ORIGIN="http://127.0.0.1:9101",
|
|
)
|
|
program = """
|
|
import html, os, re
|
|
from pathlib import Path
|
|
from fastapi.testclient import TestClient
|
|
from site_engine.services.auth import hash_password
|
|
from site_engine.web.app import create_app
|
|
from site_engine.web.preview_app import create_preview_app
|
|
import site_engine
|
|
assert str(Path(site_engine.__file__).resolve()).startswith(os.environ['PYTHONPATH'])
|
|
os.environ['SITE_ADMIN_PASSWORD_HASH']=hash_password('installed wheel password',n=2**10)
|
|
os.environ['SITE_ADMIN_LOGIN']='admin'
|
|
app=create_app()
|
|
with TestClient(app) as client:
|
|
response=client.post('/admin/login',data={'login':'admin','password':'installed wheel password'},headers={'Origin':'http://testserver'})
|
|
assert response.status_code==200
|
|
response=client.get('/admin/pages/index')
|
|
assert response.status_code==200 and 'document-editor' in response.text
|
|
for name in ('antirion-rework.css','shell.css','pages.css','pages.js','admin.css','admin.js','editor.js','builder.css','builder-adapter.css','builder.js','htmx.min.js'):
|
|
assert client.get('/admin/static/'+name).status_code==200,name
|
|
assert 'pages-screen' in client.get('/admin/pages').text
|
|
cookie=client.cookies.get('se_session')
|
|
principal=app.state.auth.authenticate(cookie)
|
|
csrf=app.state.auth.csrf_token(principal)
|
|
source=(Path(os.environ['SITE_ROOT'])/'pages/index.md').read_text()
|
|
from site_engine.storage.fs import etag_of
|
|
result=client.post('/admin/editor/pages/index/preview',data={'source':source,'etag':etag_of(source.encode()),'csrf':csrf},headers={'Origin':'http://testserver','HX-Request':'true'})
|
|
assert result.status_code==200,result.text
|
|
url=html.unescape(re.search(r"src='([^']+)'",result.text)[1])
|
|
with TestClient(create_preview_app()) as preview:
|
|
result=preview.get(url)
|
|
assert result.status_code==200,result.text
|
|
assert 'preview:ready' in result.text and 'data-preview-id' in result.text
|
|
assert app.state.api_calls>0
|
|
print('installed wheel: static, templates, API, bridge, separate preview OK; design/ absent')
|
|
"""
|
|
subprocess.run([sys.executable, "-c", program], cwd=work, env=env, check=True)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|